>From 8d2a62528a7820939c4d7c86dd10cbf16ea5d751 Mon Sep 17 00:00:00 2001
From: Osier Yang <jyang@redhat.com>
Date: Fri, 22 Oct 2010 14:40:13 +0800
Subject: [TCK] Skip daemon hook testing if URI is not qemu:///system or lxc:///
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Skip the case execution if Sys::Virt::TCK connection object is
not qemu:///system or lxc:///
---
 scripts/hooks/051-daemon-hook.t |  178 +++++++++++++++++++++------------------
 1 files changed, 96 insertions(+), 82 deletions(-)

diff --git a/scripts/hooks/051-daemon-hook.t b/scripts/hooks/051-daemon-hook.t
index bc9714c..c378bd0 100644
--- a/scripts/hooks/051-daemon-hook.t
+++ b/scripts/hooks/051-daemon-hook.t
@@ -30,124 +30,138 @@ use warnings;
 
 use Slurp;
 
-use Test::More tests => 12;
+use Sys::Virt::TCK;
 use Sys::Virt::TCK::Hooks;
 
-my $hook = Sys::Virt::TCK::Hooks->new(type => 'daemon',
-                                      conf_dir => '/etc/libvirt/hooks',
-                                      log_name => '/tmp/daemon.log');
+use Test::More tests => 12;
+
+my $tck = Sys::Virt::TCK->new();
+my $conn = eval { $tck->setup(); };
+BAIL_OUT "failed to setup test harness: $@" if $@;
+END { $tck->cleanup if $tck; }
+
+SKIP: {
+    my $uri = $conn->get_uri();
+    
+    skip 12, "NOT using QEMU/LXC driver" unless
+        $uri eq "qemu:///system" or $uri eq "lxc:///";
+
+    my $hook = Sys::Virt::TCK::Hooks->new(type => 'daemon',
+                                          conf_dir => '/etc/libvirt/hooks',
+                                          log_name => '/tmp/daemon.log');
 
-$hook->libvirtd_status;
-BAIL_OUT "libvirtd is not running, Exit..." 
-    if ($hook->{libvirtd_status} eq 'stopped');
+    $hook->libvirtd_status;
+    BAIL_OUT "libvirtd is not running, Exit..." 
+        if ($hook->{libvirtd_status} eq 'stopped');
 
-eval { $hook->prepare; };
-BAIL_OUT "failed to setup hooks testing ENV: $@" if $@;
+    eval { $hook->prepare; };
+    BAIL_OUT "failed to setup hooks testing ENV: $@" if $@;
 
-diag "restart libvirtd for hooks scripts taking effect";
-$hook->action('restart');
-$hook->service_libvirtd;
-unlink $hook->{log_name} unless -f $hook->{log_name};
+    diag "restart libvirtd for hooks scripts taking effect";
+    $hook->action('restart');
+    $hook->service_libvirtd;
+    unlink $hook->{log_name} unless -f $hook->{log_name};
 
-# stop libvirtd
-$hook->action('stop');
-$hook->expect_log;
+    # stop libvirtd
+    $hook->action('stop');
+    $hook->expect_log;
 
-diag "$hook->{action} libvirtd";
-$hook->service_libvirtd;
+    diag "$hook->{action} libvirtd";
+    $hook->service_libvirtd;
 
-my $hook_data = slurp($hook->{name});
-diag "hook script: $hook->{name} '$hook_data'";
+    my $hook_data = slurp($hook->{name});
+    diag "hook script: $hook->{name} '$hook_data'";
 
-sleep 3;
-diag "check if $hook->{name} is invoked";
-ok(-f "$hook->{name}", "$hook->{name} is invoked");
+    sleep 3;
+    diag "check if $hook->{name} is invoked";
+    ok(-f "$hook->{name}", "$hook->{name} is invoked");
 
-my $actual_log_data = slurp($hook->{log_name});
-diag "actual log: $hook->{log_name} '$actual_log_data'";
+    my $actual_log_data = slurp($hook->{log_name});
+    diag "actual log: $hook->{log_name} '$actual_log_data'";
 
-diag "expected log:\n$hook->{expect_log}";
+    diag "expected 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 $hook->{action} libvirtd");
+    diag "check if the actual log is same with expected log";
+    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"); 
+    diag "check if libvirtd is stopped";
+    ok(`service libvirtd status` =~ /stopped/, "libvirtd is stopped"); 
 
-# start libvirtd
-$hook->action('start');
-$hook->expect_log;
+    # start libvirtd
+    $hook->action('start');
+    $hook->expect_log;
 
-diag "$hook->{action} libvirtd";
-$hook->service_libvirtd;
+    diag "$hook->{action} libvirtd";
+    $hook->service_libvirtd;
 
-$hook_data = slurp($hook->{name});
-diag "hook script: $hook->{name} '$hook_data'";
+    $hook_data = slurp($hook->{name});
+    diag "hook script: $hook->{name} '$hook_data'";
 
-sleep 3;
-diag "check if $hook->{name} is invoked";
-ok(-f "$hook->{name}", "$hook->{name} is invoked");
+    sleep 3;
+    diag "check if $hook->{name} is invoked";
+    ok(-f "$hook->{name}", "$hook->{name} is invoked");
 
-$actual_log_data = slurp($hook->{log_name});
-diag "actual log: $hook->{log_name} '$actual_log_data'";
+    $actual_log_data = slurp($hook->{log_name});
+    diag "actual log: $hook->{log_name} '$actual_log_data'";
 
-diag "expected log: \n$hook->{expect_log}";
+    diag "expected 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 $hook->{action} libvirtd");
+    diag "check if the actual log is same with expected log";
+    ok($hook->compare_log, "$hook->{name} is invoked correctly while $hook->{action} libvirtd");
 
-diag "check if libvirtd is still running";
-ok(`service libvirtd status` =~ /running/, "libvirtd is running"); 
+    diag "check if libvirtd is still running";
+    ok(`service libvirtd status` =~ /running/, "libvirtd is running"); 
 
-# restart libvirtd
-$hook->action('restart');
-$hook->expect_log;
+    # restart libvirtd
+    $hook->action('restart');
+    $hook->expect_log;
 
-diag "$hook->{action} libvirtd";
-$hook->service_libvirtd;
+    diag "$hook->{action} libvirtd";
+    $hook->service_libvirtd;
 
-$hook_data = slurp($hook->{name});
-diag "hook script: $hook->{name} '$hook_data'";
+    $hook_data = slurp($hook->{name});
+    diag "hook script: $hook->{name} '$hook_data'";
 
-sleep 3;
-diag "check if $hook->{name} is invoked";
-ok(-f "$hook->{name}", "$hook->{name} is invoked");
+    sleep 3;
+    diag "check if $hook->{name} is invoked";
+    ok(-f "$hook->{name}", "$hook->{name} is invoked");
 
-$actual_log_data = slurp($hook->{log_name});
-diag "actual log: $hook->{log_name} '$actual_log_data'";
+    $actual_log_data = slurp($hook->{log_name});
+    diag "actual log: $hook->{log_name} '$actual_log_data'";
 
-diag "expected log: \n$hook->{expect_log}";
+    diag "expected 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 $hook->{action} libvirtd");
+    diag "check if the actual log is same with expected log";
+    ok($hook->compare_log, "$hook->{name} is invoked correctly while $hook->{action} libvirtd");
 
-diag "check if libvirtd is still running";
-ok(`service libvirtd status` =~ /running/, "libvirtd is running"); 
+    diag "check if libvirtd is still running";
+    ok(`service libvirtd status` =~ /running/, "libvirtd is running"); 
 
-# reload libvirtd
-$hook->action('reload');
-$hook->expect_log;
+    # reload libvirtd
+    $hook->action('reload');
+    $hook->expect_log;
 
-diag "$hook->{action} libvirtd";
-$hook->service_libvirtd;
+    diag "$hook->{action} libvirtd";
+    $hook->service_libvirtd;
 
-$hook_data = slurp($hook->{name});
-diag "hook script: $hook->{name} '$hook_data'";
+    $hook_data = slurp($hook->{name});
+    diag "hook script: $hook->{name} '$hook_data'";
 
-sleep 3;
-diag "check if $hook->{name} is invoked";
-ok(-f "$hook->{name}", "$hook->{name} is invoked");
+    sleep 3;
+    diag "check if $hook->{name} is invoked";
+    ok(-f "$hook->{name}", "$hook->{name} is invoked");
 
-$actual_log_data = slurp($hook->{log_name});
-diag "actual log: $hook->{log_name} '$actual_log_data'";
+    $actual_log_data = slurp($hook->{log_name});
+    diag "actual log: $hook->{log_name} '$actual_log_data'";
 
-diag "expected log: \n$hook->{expect_log}";
+    diag "expected 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 $hook->{action} libvirtd");
+    diag "check if the actual log is same with expected log";
+    ok($hook->compare_log, "$hook->{name} is invoked correctly while $hook->{action} libvirtd");
 
-diag "check if libvirtd is still running";
-ok(`service libvirtd status` =~ /running/, "libvirtd is running"); 
+    diag "check if libvirtd is still running";
+    ok(`service libvirtd status` =~ /running/, "libvirtd is running"); 
 
-$hook->cleanup;
+    $hook->cleanup;
+};
 
-- 
1.7.1

