From a91983520b6e85e7c0b5186e2cbe966630905da9 Mon Sep 17 00:00:00 2001 From: guoxuguang Date: Tue, 8 Aug 2023 18:57:50 +0200 Subject: [PATCH] [virt_autotest] Adapt SLE automation from monolithic to modular libvirt daemons on 15SP6 --- lib/virt_autotest/utils.pm | 79 ++++++++++++++----- lib/virt_autotest/virtual_network_utils.pm | 8 +- .../libvirt_host_bridge_virtual_network.pm | 12 +-- .../libvirt_isolated_virtual_network.pm | 16 +--- .../libvirt_nated_virtual_network.pm | 12 +-- .../libvirt_routed_virtual_network.pm | 12 +-- .../libvirt_virtual_network_init.pm | 18 +---- 7 files changed, 67 insertions(+), 90 deletions(-) diff --git a/lib/virt_autotest/utils.pm b/lib/virt_autotest/utils.pm index 515e2881214e..0572ab49b8e2 100644 --- a/lib/virt_autotest/utils.pm +++ b/lib/virt_autotest/utils.pm @@ -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. @@ -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; @@ -42,6 +42,24 @@ sub trim { return $text; } +#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; + } +} + +# Restart monolithic libvirt sub restart_libvirtd { if (is_sle('<12')) { assert_script_run('rclibvirtd restart', 180); @@ -55,13 +73,38 @@ sub restart_libvirtd { else { systemctl("restart libvirtd", timeout => 180); } - record_info("Libvirtd has been restarted!"); + record_info("Monolithic 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"); +# 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 = @_; + } + + 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: @@ -71,10 +114,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 = @_; @@ -85,7 +129,11 @@ 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 @@ -93,11 +141,12 @@ sub restart_modular_libvirt_daemons { # 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; } #return 1 if it is a VMware test judging by REGRESSION variable @@ -157,14 +206,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). diff --git a/lib/virt_autotest/virtual_network_utils.pm b/lib/virt_autotest/virtual_network_utils.pm index 6374aad58678..14d375c598ef 100644 --- a/lib/virt_autotest/virtual_network_utils.pm +++ b/lib/virt_autotest/virtual_network_utils.pm @@ -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: @@ -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 @@ -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}\'"; diff --git a/tests/virt_autotest/libvirt_host_bridge_virtual_network.pm b/tests/virt_autotest/libvirt_host_bridge_virtual_network.pm index edc62e9ac54c..e5d7994e03b1 100644 --- a/tests/virt_autotest/libvirt_host_bridge_virtual_network.pm +++ b/tests/virt_autotest/libvirt_host_bridge_virtual_network.pm @@ -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: @@ -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); } diff --git a/tests/virt_autotest/libvirt_isolated_virtual_network.pm b/tests/virt_autotest/libvirt_isolated_virtual_network.pm index c1ca7fd34b89..7a0ccb4bcd73 100644 --- a/tests/virt_autotest/libvirt_isolated_virtual_network.pm +++ b/tests/virt_autotest/libvirt_isolated_virtual_network.pm @@ -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: @@ -71,10 +71,6 @@ 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 { @@ -82,18 +78,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; diff --git a/tests/virt_autotest/libvirt_nated_virtual_network.pm b/tests/virt_autotest/libvirt_nated_virtual_network.pm index 455470fadeb9..858a847f3228 100644 --- a/tests/virt_autotest/libvirt_nated_virtual_network.pm +++ b/tests/virt_autotest/libvirt_nated_virtual_network.pm @@ -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: @@ -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; diff --git a/tests/virt_autotest/libvirt_routed_virtual_network.pm b/tests/virt_autotest/libvirt_routed_virtual_network.pm index 1cbfcb15a208..c55cf8dd2948 100644 --- a/tests/virt_autotest/libvirt_routed_virtual_network.pm +++ b/tests/virt_autotest/libvirt_routed_virtual_network.pm @@ -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: @@ -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; diff --git a/tests/virt_autotest/libvirt_virtual_network_init.pm b/tests/virt_autotest/libvirt_virtual_network_init.pm index c4c209d7cbc6..9664a825f4f9 100644 --- a/tests/virt_autotest/libvirt_virtual_network_init.pm +++ b/tests/virt_autotest/libvirt_virtual_network_init.pm @@ -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 @@ -99,10 +99,6 @@ 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 { @@ -110,18 +106,6 @@ 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;