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

Mike Latimer mlatimer at suse.com
Thu Mar 6 16:27:34 UTC 2014


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




More information about the libvir-list mailing list