Skip to content

Commit

Permalink
[virt_autotest] Adapt SLE automation from monolithic to modular libvi…
Browse files Browse the repository at this point in the history
…rt daemons on 15SP6
  • Loading branch information
guoxuguang committed Aug 17, 2023
1 parent e4729ec commit 808f8b6
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 102 deletions.
106 changes: 75 additions & 31 deletions lib/virt_autotest/utils.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SUSE's openQA tests
#
# Copyright 2020-2022 SUSE LLC
# Copyright 2020-2023 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

# Summary: virtualization test utilities.
Expand Down Expand Up @@ -31,7 +31,7 @@ our @EXPORT = qw(is_vmware_virtualization is_hyperv_virtualization is_fv_guest i
print_cmd_output_to_file ssh_setup ssh_copy_id create_guest import_guest install_default_packages upload_y2logs ensure_default_net_is_active ensure_guest_started
ensure_online add_guest_to_hosts restart_libvirtd remove_additional_disks remove_additional_nic collect_virt_system_logs shutdown_guests wait_guest_online start_guests restore_downloaded_guests save_original_guest_xmls restore_original_guests
is_guest_online wait_guests_shutdown remove_vm setup_common_ssh_config add_alias_in_ssh_config parse_subnet_address_ipv4 backup_file manage_system_service setup_rsyslog_host
check_port_state subscribe_extensions_and_modules download_script download_script_and_execute is_sev_es_guest upload_virt_logs recreate_guests download_vm_import_disks enable_nm_debug check_activate_network_interface set_host_bridge_interface_with_nm upload_nm_debug_log);
check_port_state subscribe_extensions_and_modules download_script download_script_and_execute is_sev_es_guest upload_virt_logs recreate_guests download_vm_import_disks enable_nm_debug check_activate_network_interface set_host_bridge_interface_with_nm upload_nm_debug_log restart_modular_libvirt_daemons check_modular_libvirt_daemons is_modular_libvirtd);

my %log_cursors;

Expand All @@ -42,26 +42,51 @@ sub trim {
return $text;
}

sub restart_libvirtd {
if (is_sle('<12')) {
assert_script_run('rclibvirtd restart', 180);
#return 1 if test is expected to run on XEN hypervisor
sub is_xen_host {
return get_var("XEN") || check_var("SYSTEM_ROLE", "xen") || check_var("HOST_HYPERVISOR", "xen") || check_var("REGRESSION", "xen-hypervisor");
}

#Setup modular libvrit daemons as the default in SLE15SP6, refer to PED-4804 to get more details
sub is_modular_libvirtd {
return 0 if is_sle(">=15-sp6");
}

#retrun 1 if libvirt 9.0- is running which monolithic libvirtd is the default service
sub is_monolithic_libvirtd {
unless (is_alp) {
return 1 if script_run('rpm -q libvirt-libs | grep -e "libs-9\.0" -e "libs-[1-8]\."') == 0;
}
elsif (is_alp) {
my $_libvirtd_pid = script_output(q@ps -ef |grep [l]ibvirtd | gawk '{print $2;}'@);
my $_libvirtd_cmd = script_output("ps -o command $_libvirtd_pid | tail -1");
assert_script_run("kill -9 $_libvirtd_pid");
assert_script_run("$_libvirtd_cmd");
}

# Usage: check_modular_libvirt_daemons([daemon1_name daemon2_name ...]). For example:
# to specify daemons which will be checked: check_modular_libvirt_daemons(qemu storage ...)
# to check all required modular daemons without any daemons passed
sub check_modular_libvirt_daemons {
my @daemons;

if (@_ == 0) {
@daemons = qw(network nodedev nwfilter secret storage proxy log lock);
if (is_xen_host) {
push @daemons, 'xen';
} else {
push @daemons, 'qemu';
}
} else {
@daemons = @_;
}
else {
systemctl("restart libvirtd", timeout => 180);

foreach my $daemon (@daemons) {
systemctl("status virt${daemon}d.service");
if ($daemon == 'lock') {
systemctl("status virt${daemon}d\{,-admin\}.socket");
} else {
systemctl("status virt${daemon}d\{,-ro,-admin\}.socket");
}
}
record_info("Libvirtd has been restarted!");
save_screenshot;
}

#return 1 if test is expected to run on XEN hypervisor
sub is_xen_host {
return get_var("XEN") || check_var("SYSTEM_ROLE", "xen") || check_var("HOST_HYPERVISOR", "xen") || check_var("REGRESSION", "xen-hypervisor");
record_info("Modular Libvirt daemons checked", join(' ', @daemons));
save_screenshot;
}

# Usage: restart_modular_libvirt_daemons([daemon1_name daemon2_name ...]). For example:
Expand All @@ -71,10 +96,11 @@ sub restart_modular_libvirt_daemons {
my @daemons;

if (@_ == 0) {
@daemons = qw(network nodedev nwfilter secret storage proxy log lock);
if (is_xen_host) {
@daemons = qw(virtxend virtstoraged virtnetworkd virtnodedevd virtsecretd virtproxyd virtnwfilterd);
push @daemons, 'xen';
} else {
@daemons = qw(virtqemud virtstoraged virtnetworkd virtnodedevd virtsecretd virtproxyd virtnwfilterd);
push @daemons, 'qemu';
}
} else {
@daemons = @_;
Expand All @@ -85,19 +111,45 @@ sub restart_modular_libvirt_daemons {
} else {
# Restart the sockets first
foreach my $daemon (@daemons) {
systemctl("restart $daemon\{,-ro,-admin\}.socket");
if ($daemon == 'lock') {
systemctl("restart virt${daemon}d\{,-admin\}.socket");
} else {
systemctl("restart virt${daemon}d\{,-ro,-admin\}.socket");
}
}

# Introduce idle time here (e.g., sleep 5) if necessary
sleep 5;

# Restart the services after a brief idle time
foreach my $daemon (@daemons) {
systemctl("restart $daemon.service");
systemctl("restart virt${daemon}d.service");
}
}

record_info("Libvirt daemons restarted", join(' ', @daemons));
record_info("Modular Libvirt daemons restarted", join(' ', @daemons));
check_modular_libvirt_daemons;
}

# Restart monolithic libvirt
sub restart_libvirtd {
if (is_sle('<12')) {
assert_script_run('rclibvirtd restart', 180);
}
elsif (is_alp) {
my $_libvirtd_pid = script_output(q@ps -ef |grep [l]ibvirtd | gawk '{print $2;}'@);
my $_libvirtd_cmd = script_output("ps -o command $_libvirtd_pid | tail -1");
assert_script_run("kill -9 $_libvirtd_pid");
assert_script_run("$_libvirtd_cmd");
}
elsif (is_modular_libvirtd) {
restart_modular_libvirt_daemons;
}
else {
systemctl("restart libvirtd", timeout => 180);
}
record_info("Monolithic Libvirtd has been restarted!");
save_screenshot;
}

#return 1 if it is a VMware test judging by REGRESSION variable
Expand Down Expand Up @@ -157,14 +209,6 @@ sub is_kvm_host {
return check_var("SYSTEM_ROLE", "kvm") || check_var("HOST_HYPERVISOR", "kvm") || check_var("REGRESSION", "qemu-hypervisor");
}

#retrun 1 if libvirt 9.0- is running which monolithic libvirtd is the default service
sub is_monolithic_libvirtd {
unless (is_alp) {
return 1 if script_run('rpm -q libvirt-libs | grep -e "libs-9\.0" -e "libs-[1-8]\."') == 0;
}
return 0;
}

# For legacy libvird, set debug level logging for libvirtd services
# For modular libvirt, do the same settings to /etc/libvirt/virt{qemu,xen,driver}d.conf.
# virt{qemu,xen}d daemons provide the most important libvirt log(sufficient for most issues).
Expand Down
8 changes: 2 additions & 6 deletions lib/virt_autotest/virtual_network_utils.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SUSE's openQA tests
#
# Copyright 2019-2022 SUSE LLC
# Copyright 2019-2023 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

# Summary: virtual_network_utils:
Expand All @@ -26,7 +26,7 @@ use version_utils qw(is_sle is_alp);
use virt_autotest::utils;

our @EXPORT
= qw(download_network_cfg prepare_network restore_standalone destroy_standalone restart_network
= qw(download_network_cfg prepare_network restore_standalone destroy_standalone
restore_guests restore_network destroy_vir_network restore_libvirt_default pload_debug_log
check_guest_status check_guest_module check_guest_ip save_guest_ip test_network_interface hosts_backup
hosts_restore get_free_mem get_active_pool_and_available_space clean_all_virt_networks setup_vm_simple_dns_with_ip
Expand Down Expand Up @@ -255,10 +255,6 @@ sub destroy_standalone {
assert_script_run("source $cleanup_path", 60) if (script_run("[[ -f $cleanup_path ]]") == 0);
}

sub restart_network {
is_sle('=11-sp4') ? script_run("service network restart") : systemctl 'restart network';
}

sub restore_guests {
return if get_var('INCIDENT_ID'); # QAM does not recreate guests every time
my $get_vm_hostnames = "virsh list --all | grep -e sles -e opensuse -e alp -i | awk \'{print \$2}\'";
Expand Down
12 changes: 1 addition & 11 deletions tests/virt_autotest/libvirt_host_bridge_virtual_network.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SUSE's openQA tests
#
# Copyright 2019-2022 SUSE LLC
# Copyright 2019-2023 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

# Summary: HOST bridge virtual network test:
Expand Down Expand Up @@ -89,19 +89,9 @@ sub post_fail_hook {

$self->SUPER::post_fail_hook;

#Restart libvirtd service
# Note: TBD for modular libvirt. See poo#129086 for detail.
virt_autotest::utils::restart_libvirtd() if is_monolithic_libvirtd;

#Destroy created virtual networks
virt_autotest::virtual_network_utils::destroy_vir_network();

#Restore br123 for virt_autotest
virt_autotest::virtual_network_utils::restore_standalone();

#Restore Guest systems
virt_autotest::virtual_network_utils::restore_guests();

#Restore Network setting
virt_autotest::virtual_network_utils::restore_network($virt_host_bridge, $based_guest_dir);
}
Expand Down
16 changes: 1 addition & 15 deletions tests/virt_autotest/libvirt_isolated_virtual_network.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SUSE's openQA tests
#
# Copyright 2019-2022 SUSE LLC
# Copyright 2019-2023 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

# Summary: Isolated virtual network test:
Expand Down Expand Up @@ -71,29 +71,15 @@ sub run_test {

#After finished all virtual network test, need to restore file /etc/hosts from backup
virt_autotest::virtual_network_utils::hosts_restore();

#Skip restart network service due to bsc#1166570
#Restart network service
#virt_autotest::virtual_network_utils::restart_network();
}

sub post_fail_hook {
my ($self) = @_;

$self->SUPER::post_fail_hook;

#Restart libvirtd service
# Note: TBD for modular libvirt. See poo#129086 for detail.
virt_autotest::utils::restart_libvirtd() if is_monolithic_libvirtd;

#Destroy created virtual networks
virt_autotest::virtual_network_utils::destroy_vir_network();

#Restore br123 for virt_autotest
virt_autotest::virtual_network_utils::restore_standalone();

#Restore Guest systems
virt_autotest::virtual_network_utils::restore_guests();
}

1;
12 changes: 1 addition & 11 deletions tests/virt_autotest/libvirt_nated_virtual_network.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SUSE's openQA tests
#
# Copyright 2019-2022 SUSE LLC
# Copyright 2019-2023 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

# Summary: NAT based virtual network test:
Expand Down Expand Up @@ -75,21 +75,11 @@ sub post_fail_hook {

$self->SUPER::post_fail_hook;

#Restart libvirtd service
# Note: TBD for modular libvirt. See poo#129086 for detail.
virt_autotest::utils::restart_libvirtd() if is_monolithic_libvirtd;

#Destroy created virtual networks
virt_autotest::virtual_network_utils::destroy_vir_network();

#Restore default(NATed Network)
virt_autotest::virtual_network_utils::restore_libvirt_default();

#Restore br123 for virt_autotest
virt_autotest::virtual_network_utils::restore_standalone();

#Restore Guest systems
virt_autotest::virtual_network_utils::restore_guests();
}

1;
12 changes: 1 addition & 11 deletions tests/virt_autotest/libvirt_routed_virtual_network.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SUSE's openQA tests
#
# Copyright 2019-2022 SUSE LLC
# Copyright 2019-2023 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

# Summary: Routed virtual network test:
Expand Down Expand Up @@ -113,18 +113,8 @@ sub post_fail_hook {

$self->SUPER::post_fail_hook;

#Restart libvirtd service
# Note: TBD for modular libvirt. See poo#129086 for detail.
virt_autotest::utils::restart_libvirtd() if is_monolithic_libvirtd;

#Destroy created virtual networks
virt_autotest::virtual_network_utils::destroy_vir_network();

#Restore br123 for virt_autotest
virt_autotest::virtual_network_utils::restore_standalone();

#Restore Guest systems
virt_autotest::virtual_network_utils::restore_guests();
}

1;
18 changes: 1 addition & 17 deletions tests/virt_autotest/libvirt_virtual_network_init.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SUSE's openQA tests
#
# Copyright 2019-2022 SUSE LLC
# Copyright 2019-2023 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Summary: Initialize testing environment for Libvirt Virtual Networks
Expand Down Expand Up @@ -99,29 +99,13 @@ sub run_test {
assert_script_run("time ssh -v root\@$guest systemctl restart wickedd", 120);
}
}

#Skip restart network service due to bsc#1166570
#Restart network service
#virt_autotest::virtual_network_utils::restart_network();
}

sub post_fail_hook {
my ($self) = @_;

$self->SUPER::post_fail_hook;

#Restart libvirtd service
# Note: TBD for modular libvirt. See poo#129086 for detail.
virt_autotest::utils::restart_libvirtd() if is_monolithic_libvirtd;

#Destroy created virtual networks
virt_autotest::virtual_network_utils::destroy_vir_network();

#Restore br123 for virt_autotest
virt_autotest::virtual_network_utils::restore_standalone();

#Restore Guest systems
virt_autotest::virtual_network_utils::restore_guests();
}

1;

0 comments on commit 808f8b6

Please sign in to comment.