Skip to content

Commit

Permalink
Add test for cloud-netconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
clanig committed Nov 24, 2023
1 parent d83eaee commit da5bb2a
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/main_publiccloud.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ sub load_maintenance_publiccloud_tests {
loadtest("publiccloud/img_proof", run_args => $args);
} elsif (get_var('PUBLIC_CLOUD_LTP')) {
loadtest('publiccloud/run_ltp', run_args => $args);
} elsif (get_var('PUBLIC_CLOUD_NETCONFIG')) {
loadtest('publiccloud/cloud_netconfig', run_args => $args);
} elsif (check_var('PUBLIC_CLOUD_AHB', 1)) {
loadtest('publiccloud/ahb');
} elsif (get_var('PUBLIC_CLOUD_NEW_INSTANCE_TYPE')) {
Expand Down
81 changes: 81 additions & 0 deletions tests/publiccloud/cloud_netconfig.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright SUSE LLC
# SPDX-License-Identifier: FSFAP

# Package: cloud-netconfig-{azure, gc2, gce}
# Summary: This test ensures the consistency of cloud-netconfig's
# functionality. The test shall be conducted on a VM in the cloud
# infrastructure of a supported CSP.
#
# This test only contains minimal functionality that needs to be
# extended in future.
#
# Maintainer: qa-c team <qa-c@suse.de>

use Mojo::Base 'publiccloud::basetest';
use Test::Assert 'assert_equals';
use testapi;
use version_utils 'is_sle';

sub run {
my ($self, $args) = @_;
my $instance = $args->{my_instance};
my $os_version = get_var('VERSION');

my $cloud_netconfig_svc_status = $instance->ssh_script_run(
cmd => 'systemctl status cloud-netconfig.service');
if ($cloud_netconfig_svc_status == 0 || $cloud_netconfig_svc_status == 3)
{
record_info('Success', 'Status of cloud-netconfig.service is OK.');
}
else {
die('cloud-netconfig.service status appears to be incorrect!');
}
$instance->ssh_assert_script_run(
cmd => 'systemctl status cloud-netconfig.timer',
fail_message => 'cloud-netconfig.timer appears not to be started.'
);

# 75-persistent-net-generator.rules is required for SLES 12-SPX
if (is_sle('12-sp5')) {
$instance->ssh_assert_script_run(
cmd => 'test -s /etc/udev/rules.d/75-persistent-net-generator.rules',
fail_message => 'File '
. '"/etc/udev/rules.d/75-persistent-net-generator.rules" is '
. 'required but missing'
);

$instance->ssh_assert_script_run(
cmd => 'test -x /usr/lib/udev/write_net_rules',
fail_message => 'Executable "/usr/lib/udev/write_net_rules" '
. 'is required to persist network configuration but missing.'
);
}
# 75-persistent-net-generator.rules is usually a symlink to /dev/null in SLES 15+
if (is_sle('15+')) {
$instance->ssh_assert_script_run(
cmd => 'test -L /etc/udev/rules.d/75-persistent-net-generator.rules',
fail_message => 'File '
. '"/etc/udev/rules.d/75-persistent-net-generator.rules" should '
. 'be a symlink to "/dev/null" in SLES 15+.'
);
}

my $grep_cloudvm_ipv4_cmd =
'ip -4 addr show eth0 | grep -oP "^\s+inet\s(\d+\.){3}\d+" | '
. 'sed "s/ *inet //g"';
my $local_eth0_ip =
$instance->ssh_script_output(cmd => $grep_cloudvm_ipv4_cmd);
chomp($local_eth0_ip);

my $query_meta_ipv4_cmd =
'curl -H Metadata:true '
. '"http://169.254.169.254/metadata/instance/network/interface/0/ipv4/'
. 'ipAddress/0/privateIpAddress?api-version=2023-07-01&format=text"';
my $metadata_eth0_ip =
$instance->ssh_script_output(cmd => $query_meta_ipv4_cmd);
assert_equals($metadata_eth0_ip, $local_eth0_ip,
'Locally assigned IP does not equal the IP retrieved from CSP '
. ' metadata service.');
}
1;

0 comments on commit da5bb2a

Please sign in to comment.