[libvirt] [PATCH] libvirt-tck: Update hook syntax for libvirt 0.9.0+

Starting with libvirt 0.9.0+, hook scripts can be called from several new locations. These locations must also be reflected in the expected logs of the hook tests. The final test in 052-domain-hook.t intentionally produces a failed start, which should show the first stage in the startup hook process, followed by all the stages in the destroy process. In addition to the above changes, libvirtd init scripts can return daemon status in several different ways (due to distribution differences, sysvinit vs. systemd, etc). This patch allows for 'running|active', and 'stopped|unused|inactive' responses which the hook tests rely on. --- lib/Sys/Virt/TCK/Hooks.pm | 17 ++++++++++++----- scripts/hooks/051-daemon-hook.t | 2 +- scripts/hooks/052-domain-hook.t | 6 +++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/Sys/Virt/TCK/Hooks.pm b/lib/Sys/Virt/TCK/Hooks.pm index 75f98e9..2ae2c2a 100644 --- a/lib/Sys/Virt/TCK/Hooks.pm +++ b/lib/Sys/Virt/TCK/Hooks.pm @@ -73,10 +73,10 @@ sub libvirtd_status { my $status = `service libvirtd status`; my $_ = $status; - if (/running/) { - $self->{libvirtd_status} = 'running'; - } elsif (/stopped/) { + if (/stopped|unused|inactive/) { $self->{libvirtd_status} = 'stopped'; + } elsif (/running|active/) { + $self->{libvirtd_status} = 'running'; } return $self; @@ -146,13 +146,20 @@ sub expect_log { } elsif ($self->{type} eq 'qemu' or $self->{type} eq 'lxc') { if ($domain_state eq &Sys::Virt::Domain::STATE_RUNNING) { if ($action eq 'destroy') { - $expect_log = "$hook $domain_name stopped end -"; + $expect_log = "$hook $domain_name stopped end -\n". + "$hook $domain_name release end -"; } else { die "hooks testing doesn't support $action running domain"; } } elsif ($domain_state eq &Sys::Virt::Domain::STATE_SHUTOFF) { if ($action eq 'start') { - $expect_log = "$hook $domain_name start begin -"; + $expect_log = "$hook $domain_name prepare begin -\n". + "$hook $domain_name start begin -\n". + "$hook $domain_name started begin -"; + } elsif ($action eq 'failstart') { + $expect_log = "$hook $domain_name prepare begin -\n". + "$hook $domain_name stopped end -\n". + "$hook $domain_name release end -"; } else { die "hooks testing doesn't support $action shutoff domain"; } diff --git a/scripts/hooks/051-daemon-hook.t b/scripts/hooks/051-daemon-hook.t index d9cfb3a..165cf4e 100644 --- a/scripts/hooks/051-daemon-hook.t +++ b/scripts/hooks/051-daemon-hook.t @@ -85,7 +85,7 @@ SKIP: { ok($hook->compare_log(), "$hook->{name} is invoked correctly while $hook->{action} libvirtd"); diag "check if libvirtd is stopped"; - ok(`service libvirtd status` =~ /stopped/, "libvirtd is stopped"); + ok(`service libvirtd status` =~ /stopped|unused|inactive/, "libvirtd is stopped"); # start libvirtd $hook->action('start'); diff --git a/scripts/hooks/052-domain-hook.t b/scripts/hooks/052-domain-hook.t index e3b55ec..90b8a48 100644 --- a/scripts/hooks/052-domain-hook.t +++ b/scripts/hooks/052-domain-hook.t @@ -90,7 +90,7 @@ SKIP: { ok(-f "$hook->{name}", "$hook->{name} is invoked"); my $actual_log_data = slurp($hook->{log_name}); - diag "acutal log: $hook->{log_name} '$actual_log_data'"; + diag "actual log: $hook->{log_name} '$actual_log_data'"; diag "expect log:\n $hook->{expect_log}"; @@ -147,7 +147,7 @@ SKIP: { $hook->domain_name($domain_name); $hook->domain_state($domain_state); - $hook->action('start'); + $hook->action('failstart'); $hook->expect_log(); diag "start $domain_name"; @@ -170,7 +170,7 @@ SKIP: { diag "expect log:\n $hook->{expect_log}"; diag "check if the actual log is same with expected log"; - ok($hook->compare_log, "$hook->{name} is invoked correctly while start $domain_name"); + ok($hook->compare_log, "$hook->{name} is invoked correctly while failing to start $domain_name"); # undefine domain diag "undefine $domain_name"; -- 1.8.4.5

On 07/03/14 00:27, Mike Latimer wrote:
Starting with libvirt 0.9.0+, hook scripts can be called from several new locations. These locations must also be reflected in the expected logs of the hook tests.
The final test in 052-domain-hook.t intentionally produces a failed start, which should show the first stage in the startup hook process, followed by all the stages in the destroy process.
In addition to the above changes, libvirtd init scripts can return daemon status in several different ways (due to distribution differences, sysvinit vs. systemd, etc). This patch allows for 'running|active', and 'stopped|unused|inactive' responses which the hook tests rely on.
--- lib/Sys/Virt/TCK/Hooks.pm | 17 ++++++++++++----- scripts/hooks/051-daemon-hook.t | 2 +- scripts/hooks/052-domain-hook.t | 6 +++--- 3 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/lib/Sys/Virt/TCK/Hooks.pm b/lib/Sys/Virt/TCK/Hooks.pm index 75f98e9..2ae2c2a 100644 --- a/lib/Sys/Virt/TCK/Hooks.pm +++ b/lib/Sys/Virt/TCK/Hooks.pm @@ -73,10 +73,10 @@ sub libvirtd_status { my $status = `service libvirtd status`; my $_ = $status;
- if (/running/) { - $self->{libvirtd_status} = 'running'; - } elsif (/stopped/) { + if (/stopped|unused|inactive/) { $self->{libvirtd_status} = 'stopped'; + } elsif (/running|active/) { + $self->{libvirtd_status} = 'running'; }
return $self; @@ -146,13 +146,20 @@ sub expect_log { } elsif ($self->{type} eq 'qemu' or $self->{type} eq 'lxc') { if ($domain_state eq &Sys::Virt::Domain::STATE_RUNNING) { if ($action eq 'destroy') { - $expect_log = "$hook $domain_name stopped end -"; + $expect_log = "$hook $domain_name stopped end -\n". + "$hook $domain_name release end -"; } else { die "hooks testing doesn't support $action running domain"; } } elsif ($domain_state eq &Sys::Virt::Domain::STATE_SHUTOFF) { if ($action eq 'start') { - $expect_log = "$hook $domain_name start begin -"; + $expect_log = "$hook $domain_name prepare begin -\n". + "$hook $domain_name start begin -\n". + "$hook $domain_name started begin -"; + } elsif ($action eq 'failstart') { + $expect_log = "$hook $domain_name prepare begin -\n". + "$hook $domain_name stopped end -\n". + "$hook $domain_name release end -"; } else { die "hooks testing doesn't support $action shutoff domain"; } diff --git a/scripts/hooks/051-daemon-hook.t b/scripts/hooks/051-daemon-hook.t index d9cfb3a..165cf4e 100644 --- a/scripts/hooks/051-daemon-hook.t +++ b/scripts/hooks/051-daemon-hook.t @@ -85,7 +85,7 @@ SKIP: { ok($hook->compare_log(), "$hook->{name} is invoked correctly while $hook->{action} libvirtd");
diag "check if libvirtd is stopped"; - ok(`service libvirtd status` =~ /stopped/, "libvirtd is stopped"); + ok(`service libvirtd status` =~ /stopped|unused|inactive/, "libvirtd is stopped");
# start libvirtd $hook->action('start'); diff --git a/scripts/hooks/052-domain-hook.t b/scripts/hooks/052-domain-hook.t index e3b55ec..90b8a48 100644 --- a/scripts/hooks/052-domain-hook.t +++ b/scripts/hooks/052-domain-hook.t @@ -90,7 +90,7 @@ SKIP: { ok(-f "$hook->{name}", "$hook->{name} is invoked");
my $actual_log_data = slurp($hook->{log_name}); - diag "acutal log: $hook->{log_name} '$actual_log_data'"; + diag "actual log: $hook->{log_name} '$actual_log_data'";
diag "expect log:\n $hook->{expect_log}";
@@ -147,7 +147,7 @@ SKIP: {
$hook->domain_name($domain_name); $hook->domain_state($domain_state); - $hook->action('start'); + $hook->action('failstart'); $hook->expect_log();
diag "start $domain_name"; @@ -170,7 +170,7 @@ SKIP: { diag "expect log:\n $hook->{expect_log}";
diag "check if the actual log is same with expected log"; - ok($hook->compare_log, "$hook->{name} is invoked correctly while start $domain_name"); + ok($hook->compare_log, "$hook->{name} is invoked correctly while failing to start $domain_name");
# undefine domain diag "undefine $domain_name";
ACK, but wondering why we didn't discover it, according to the log for the hook scripts have been changed. Osier

On Friday, March 07, 2014 05:02:00 PM Osier Yang wrote:
ACK, but wondering why we didn't discover it, according to the log for the hook scripts have been changed.
I'm not sure why this hasn't been seen before. The only thing that makes sense is that the hook tests haven't been tested since the changes in 0.9.0 - or people who have been running the tests have their own local patches that haven't been submitted upstream. -Mike

On 03/07/2014 02:02 AM, Osier Yang wrote:
On 07/03/14 00:27, Mike Latimer wrote:
Starting with libvirt 0.9.0+, hook scripts can be called from several new locations. These locations must also be reflected in the expected logs of the hook tests.
ACK, but wondering why we didn't discover it, according to the log for the hook scripts have been changed.
Pushed. Congrats on your first libvirt-related patch. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Friday, March 07, 2014 08:54:26 AM Eric Blake wrote:
On 03/07/2014 02:02 AM, Osier Yang wrote:
On 07/03/14 00:27, Mike Latimer wrote:
Starting with libvirt 0.9.0+, hook scripts can be called from several new locations. These locations must also be reflected in the expected logs of the hook tests.
ACK, but wondering why we didn't discover it, according to the log for the hook scripts have been changed.
Pushed. Congrats on your first libvirt-related patch.
Thank you. I look forward to contributing where I can. -Mike
participants (3)
-
Eric Blake
-
Mike Latimer
-
Osier Yang