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 a397dd3
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 75 deletions.
41 changes: 37 additions & 4 deletions lib/virt_autotest/utils.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SUSE's openQA tests

Check failure on line 1 in lib/virt_autotest/utils.pm

View workflow job for this annotation

GitHub Actions / CI: Running static tests with perl v5.32

File lib/virt_autotest/utils.pm needs tidying
#
# 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);

my %log_cursors;

Expand All @@ -42,6 +42,7 @@ sub trim {
return $text;
}

# Restart monolithic libvirt
sub restart_libvirtd {
if (is_sle('<12')) {
assert_script_run('rclibvirtd restart', 180);
Expand All @@ -55,7 +56,7 @@ sub restart_libvirtd {
else {
systemctl("restart libvirtd", timeout => 180);
}
record_info("Libvirtd has been restarted!");
record_info("Monolithic Libvirtd has been restarted!");
save_screenshot;
}

Expand All @@ -64,6 +65,37 @@ sub is_xen_host {
return get_var("XEN") || check_var("SYSTEM_ROLE", "xen") || check_var("HOST_HYPERVISOR", "xen") || check_var("REGRESSION", "xen-hypervisor");
}

# 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 {
@daemons = qw(qemu network nodedev nwfilter secret storage);
push @daemons, 'qemu';
}
} else {
@daemons = @_;
}

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("Modular Libvirt daemons checked", join(' ', @daemons));
save_screenshot;
}

# Usage: restart_modular_libvirt_daemons([daemon1_name daemon2_name ...]). For example:
# to specify daemons which will be restarted: restart_modular_libvirt_daemons(virtqemud virtstoraged ...)
# to restart all modular daemons without any daemons passed
Expand Down Expand Up @@ -97,7 +129,8 @@ sub restart_modular_libvirt_daemons {
}
}

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

#return 1 if it is a VMware test judging by REGRESSION variable
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 a397dd3

Please sign in to comment.