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 Sep 9, 2023
1 parent 6f7f489 commit cdcaaee
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 109 deletions.
6 changes: 4 additions & 2 deletions lib/parallel_guest_migration_base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use List::MoreUtils qw(firstidx);
use List::Util 'first';
use version_utils qw(is_opensuse is_sle is_alp is_microos get_os_release);
use virt_utils qw(collect_host_and_guest_logs cleanup_host_and_guest_logs enable_debug_logging);
use virt_autotest::utils qw(is_kvm_host is_xen_host check_host_health check_guest_health is_fv_guest is_pv_guest add_guest_to_hosts parse_subnet_address_ipv4 check_port_state setup_common_ssh_config is_monolithic_libvirtd);
use virt_autotest::utils qw(is_kvm_host is_xen_host check_host_health check_guest_health is_fv_guest is_pv_guest add_guest_to_hosts parse_subnet_address_ipv4 check_port_state setup_common_ssh_config is_monolithic_libvirtd check_libvirtd check_modular_libvirt_daemons);
use virt_autotest::domain_management_utils qw(construct_uri create_guest remove_guest shutdown_guest show_guest check_guest_state);
use utils qw(zypper_call systemctl script_retry define_secret_variable);
use virt_autotest::common;
Expand Down Expand Up @@ -453,8 +453,10 @@ sub check_host_virtualization {
else {
systemctl("restart libvirtd");
}
systemctl("status libvirtd");
} else {
check_modular_libvirt_daemons;
}
check_libvirtd;
save_screenshot;
}

Expand Down
105 changes: 70 additions & 35 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 @@ -29,9 +29,9 @@ use Carp;
our @EXPORT = qw(is_vmware_virtualization is_hyperv_virtualization is_fv_guest is_pv_guest guest_is_sle is_guest_ballooned is_xen_host is_kvm_host reset_log_cursor check_failures_in_journal check_host_health check_guest_health
is_monolithic_libvirtd turn_on_libvirt_debugging_log
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
ensure_online add_guest_to_hosts restart_libvirtd check_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,62 +42,69 @@ sub trim {
return $text;
}

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");
#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 (!@daemons) {
@daemons = qw(network nodedev nwfilter secret storage proxy log lock);
(is_xen_host) ? push @daemons, 'xen' : push @daemons, 'qemu';
}
else {
systemctl("restart libvirtd", timeout => 180);

foreach my $daemon (@daemons) {
systemctl("status virt${daemon}d.service");
if (($daemon == 'lock') || ($daemon == 'log')) {
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, all active for", join(' ', @daemons));
}

# 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
sub restart_modular_libvirt_daemons {
my @daemons;
my @daemons = @_;

if (@_ == 0) {
if (is_xen_host) {
@daemons = qw(virtxend virtstoraged virtnetworkd virtnodedevd virtsecretd virtproxyd virtnwfilterd);
} else {
@daemons = qw(virtqemud virtstoraged virtnetworkd virtnodedevd virtsecretd virtproxyd virtnwfilterd);
}
} else {
@daemons = @_;
if (!@daemons) {
@daemons = qw(network nodedev nwfilter secret storage proxy log lock);
(is_xen_host) ? push @daemons, 'xen' : push @daemons, 'qemu';
}

if (is_alp) {
record_soft_failure("Restarting modular libvirt daemons has not been implemented in ALP. See poo#129086");
} else {
# Restart the sockets first
foreach my $daemon (@daemons) {
systemctl("restart $daemon\{,-ro,-admin\}.socket");
if (($daemon == 'lock') || ($daemon == 'log')) {
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;
script_retry("virsh list", delay => 10, retry => 1, die => 0) for (0 .. 4);

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

record_info("Libvirt daemons restarted", join(' ', @daemons));
record_info("Modular Libvirt daemons restarted, all active for", join(' ', @daemons));
}

#return 1 if it is a VMware test judging by REGRESSION variable
Expand Down Expand Up @@ -166,6 +173,34 @@ sub is_monolithic_libvirtd {
return 0;
}

# Restart libvirt daemon
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_monolithic_libvirtd) {
systemctl("restart libvirtd", timeout => 180);
} else {
restart_modular_libvirt_daemons;
}
save_screenshot;

record_info("Libvirtd Daemon has been restarted!");
}

# Check libvirt daemon
sub check_libvirtd {
is_monolithic_libvirtd ? systemctl("status libvirtd") : check_modular_libvirt_daemons;

record_info("Libvirtd Daemon has been checked!");
}

# 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 All @@ -192,7 +227,7 @@ sub turn_on_libvirt_debugging_log {
script_run "grep -e 'log_level.*=' -e 'log_outputs.*=' -e 'log_filters.*=' /etc/libvirt/*d.conf";
save_screenshot;

is_monolithic_libvirtd ? restart_libvirtd : restart_modular_libvirt_daemons;
restart_libvirtd;
}

# Reset journalctl cursor used by check_failures_in_journal() to skip already
Expand Down Expand Up @@ -514,7 +549,7 @@ sub ensure_online {
# Check also if name resolution works - restart libvirtd if not
if (script_run("ssh $guest ping -c 3 -w 120 $dns_host", timeout => 180) != 0) {
# Note: TBD for modular libvirt. See poo#129086 for detail.
restart_libvirtd if (is_monolithic_libvirtd and (is_xen_host || is_kvm_host));
restart_libvirtd;
die "name resolution failed for $guest" if (script_retry("ssh $guest ping -c 3 -w 120 $dns_host", delay => 1, retry => 10, timeout => 180) != 0);
}
}
Expand All @@ -531,7 +566,7 @@ sub upload_y2logs {
sub ensure_default_net_is_active {
if (script_run("virsh net-list --all | grep default | grep ' active'", 90) != 0) {
# Note: TBD for modular libvirt. See poo#129086 for detail.
restart_libvirtd if is_monolithic_libvirtd;
restart_libvirtd;
if (script_run("virsh net-list --all | grep default | grep ' active'", 90) != 0) {
assert_script_run "virsh net-start default";
}
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;
2 changes: 1 addition & 1 deletion tests/virt_autotest/virt_utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sub enable_debug_logging {
save_screenshot;

# enable qemu core dumps
my $qemu_conf_file = "/etc/libvirt/qemu.conf";
my $qemu_conf_file = is_monolithic_libvirtd ? "/etc/libvirt/qemu.conf" : "/etc/libvirt/virtqemud.conf";
if (!script_run "ls $qemu_conf_file") {
script_run "sed -i '/max_core *=/{h;s/^[# ]*max_core *=.*\$/max_core = \"unlimited\"/};\${x;/^\$/{s//max_core = \"unlimited\"/;H};x}' $qemu_conf_file";
script_run "grep max_core $qemu_conf_file";
Expand Down

0 comments on commit cdcaaee

Please sign in to comment.