Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add service check for libvirtd #12876

Merged
merged 1 commit into from Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/service_check.pm
Expand Up @@ -37,6 +37,7 @@ use services::users;
use autofs_utils;
use services::postfix;
use services::firewall;
use services::libvirtd;
use kdump_utils;
use version_utils 'is_sle';

Expand Down Expand Up @@ -180,6 +181,12 @@ our $default_services = {
support_ver => $support_ver_def,
service_check_func => \&full_kdump_check
},
libvirtd => {
srv_pkg_name => 'libvirtd',
srv_proc_name => 'libvirtd',
support_ver => $support_ver_def,
service_check_func => \&services::libvirtd::full_libvirtd_check
},
};

=head2 check_services
Expand Down
132 changes: 132 additions & 0 deletions lib/services/libvirtd.pm
@@ -0,0 +1,132 @@
# SUSE's openQA tests
#
# Copyright © 2021 SUSE LLC
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.

# Summary: Package for libvirtd service check tests for migration
#
# Maintainer: Wegao <wegao@suse.com>

package services::libvirtd;
use base 'opensusebasetest';
use testapi;
use utils;
use strict;
use warnings;

#default guest vm params
our %guest_params = (
name => 'nested_vm_test',
ram => '',
memory => '512',
vcpus => '',
'os-type' => '',
disk => 'none',
network => '',
graphics => 'vnc',
boot => 'cdrom',
);

sub remove_repo {
my $repo_max_num = script_output("zypper lr | tail -1 | cut -d' ' -f1");
zypper_call("lr -u");
for (my $i = 1; $i < $repo_max_num + 1; $i = $i + 1) {
zypper_call("rr 1");
}
script_run("zypper lr -u");
coolgw marked this conversation as resolved.
Show resolved Hide resolved
}
sub install_service {
if (get_var("DISTRI") eq "opensuse") {
remove_repo();
my $version = script_output("grep VERSION= /etc/os-release | cut -d'=' -f2 | cut -d' ' -f1 | sed 's/\"//g'");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wei, not a big deal, but you can take a look at "lsb_release -a" cmd
suse@localhost:~> lsb_release -a
LSB Version: n/a
Distributor ID: openSUSE
Description: openSUSE Leap 15.2
Release: 15.2
Codename: n/a

zypper_call("ar http://download.opensuse.org/distribution/leap/$version/repo/oss/ main");
zypper_call("ar http://download.opensuse.org/update/leap/$version/oss/ mainupdate");
Comment on lines +46 to +47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is meant to be a hardcoded test for leap right?, if so would you mind adding this for TW?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only find upgrade case from leap->TW in openqa.opensuse.org
I can not find any case for TW to TW, do we have this kind of check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was just a question, I don't think we have TW to TW for now we need to introduce within qe-core poo#16618 for that, I added the note, so that we enable it once poo#16618 is solved by us

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notify me or create ticket for me once TW to TW is ready, then we can integrate it.

zypper_call("ref");
zypper_call("lr -u");
}
zypper_call('in -t pattern kvm_server kvm_tools');
coolgw marked this conversation as resolved.
Show resolved Hide resolved
}

sub enable_service {
systemctl 'enable libvirtd';
}

sub start_service {
systemctl 'start libvirtd';
}

sub check_service {
systemctl 'is-enabled libvirtd.service';
systemctl 'is-active libvirtd';
}

sub initialize_virt_install_command {
my $virt_install_cmd = "virt-install";
foreach my $key (keys %guest_params) {
if ($guest_params{$key} ne "") {
$virt_install_cmd .= " " . "--" . $key . "=" . $guest_params{$key};
}
}
return $virt_install_cmd;
}

sub pre_guest_env {
my %hash = @_;
my $guest = $hash{name};
script_run("virsh net-start --network default");
script_run("virsh net-autostart --network default");
# start guest vm
my $virt_cmd = initialize_virt_install_command();
background_script_run($virt_cmd);
}

sub check_guest_status {
my %hash = @_;
my $guest = $hash{name};
my $status = $hash{status};
script_run("virsh list --all");
script_retry("virsh list --all | grep $guest | grep $status", delay => 5, retry => 10, die => 1);
}

sub shutdown_guest {
my %hash = @_;
my $guest = $hash{name};
#script_run("virsh shutdown $guest");
script_run("virsh destroy $guest");
# Wait until guests are terminated
script_retry("! virsh list --all | grep $guest | grep running", delay => 1, retry => 5, die => 1);
}

# check libvirt service before and after migration
# stage is 'before' or 'after' system migration.
sub full_libvirtd_check {
my (%hash) = @_;
my $stage = $hash{stage};
my $type = $hash{service_type};
my $pkg = $hash{srv_pkg_name};
if ($stage eq 'before') {
install_service();
common_service_action($pkg, $type, 'enable');
common_service_action($pkg, $type, 'start');
common_service_action($pkg, $type, 'status');
common_service_action($pkg, $type, 'is-active');
pre_guest_env(%guest_params);
check_guest_status(%guest_params, status => 'running');
shutdown_guest(%guest_params) if get_var("NESTED_VM_DOWN");
}

common_service_action($pkg, $type, 'is-enabled');
common_service_action($pkg, $type, 'is-active');

if ($stage eq 'after') {
script_run("virsh list --all");
# Since not set auto-start guest so guest status should be shut-down status after reboot/migration
check_guest_status(%guest_params, status => 'shut');
}
}

1;
23 changes: 23 additions & 0 deletions schedule/migration/nested_vm.yaml
@@ -0,0 +1,23 @@
name: nested_vm
description: >
This yaml file is used for check libvirt status in nested vm env during migration process
schedule:
- boot/boot_to_desktop
- console/consoletest_setup
- console/nested_vm
- installation/bootloader
- installation/welcome
- installation/upgrade_select
- installation/online_repos
- installation/resolve_dependency_issues
- installation/installation_overview
- installation/disable_grub_timeout
- installation/start_install
- installation/await_install
- installation/logs_from_installation_system
- installation/reboot_after_installation
- installation/grub_test
- installation/first_boot
- installation/opensuse_welcome
- console/system_prepare
- console/nested_vm
42 changes: 42 additions & 0 deletions tests/console/nested_vm.pm
@@ -0,0 +1,42 @@
# SUSE's openQA tests
#
# Copyright © 2021 SUSE LLC
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.

# Package: nest_vm
# Summary: Basics libvirtd test before and after migration, with a nested
# VM running or shutdown, performance of the nested vm is irrelevant as long
# as the service status is still enabled and active after migration.
# Maintainer: wegao@suse.com

use base 'consoletest';
use strict;
use warnings;
use testapi;
use utils;
use services::libvirtd;

sub run {
select_console 'root-console';
if (get_var('NESTED_VM_CHECK_BEFORE_MIGRATION')) {
my %hash = (stage => 'after', service_type => 'Systemd', srv_pkg_name => 'libvirtd');
services::libvirtd::full_libvirtd_check(%hash);
}
else {
my %hash = (stage => 'before', service_type => 'Systemd', srv_pkg_name => 'libvirtd');
services::libvirtd::full_libvirtd_check(%hash);
set_var('NESTED_VM_CHECK_BEFORE_MIGRATION', 1);
enter_cmd "reboot";
}
}

sub post_run_hook {
# Do nothing
}
coolgw marked this conversation as resolved.
Show resolved Hide resolved

1;