[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [libvirt-tck 3/3] Add test case for daemon hook testing



Validate daemon hook is invocated correctly while start, restart,
stop, reload libvirtd
---
 scripts/hooks/051-daemon-hook.t |  156 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 156 insertions(+), 0 deletions(-)
 create mode 100644 scripts/hooks/051-daemon-hook.t

diff --git a/scripts/hooks/051-daemon-hook.t b/scripts/hooks/051-daemon-hook.t
new file mode 100644
index 0000000..2d44e45
--- /dev/null
+++ b/scripts/hooks/051-daemon-hook.t
@@ -0,0 +1,156 @@
+# -*- perl -*-
+#
+# Copyright (C) 203 Red Hat, Inc.
+# Copyright (C) 203 Osier Yang <jyang redhat com>
+#
+# This program is free software; You can redistribute it and/or modify
+# it under the GNU General Public License as published by the Free
+# Software Foundation; either version 2, or (at your option) any
+# later version
+#
+# The file "LICENSE" distributed along with this file provides full
+# details of the terms and conditions
+#
+
+=pod
+
+=head1 NAME
+
+domain/051-start-daemon.t - hooks testing for daemon 
+
+=head1 DESCRIPTION
+
+The test case validates that the hook script is invocated while
+start, stop, or reload daemon.
+
+=cut
+
+use strict;
+use warnings;
+
+use Test::More tests => 12;
+
+use Sys::Virt::TCK::Hooks;
+
+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');
+
+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};
+
+# stop libvirtd
+$hook->action('stop');
+$hook->expect_log;
+
+diag "$hook->{action} libvirtd";
+$hook->service_libvirtd;
+
+diag "hook script: $hook->{name}";
+system "cat $hook->{name}";
+
+sleep 3;
+diag "check if $hook->{name} is invocated";
+ok(-f "$hook->{name}", "$hook->{name} is invocated");
+
+diag "actual log: $hook->{log_name}";
+system "cat $hook->{log_name}";
+
+diag "expected log:";
+print $hook->{expect_log}."\n";
+
+diag "check if the actual log is same with expected log";
+ok($hook->compare_log, "$hook->{name} is invocated correctly while $hook->{action} libvirtd");
+
+diag "check if libvirtd is stopped";
+ok(`service libvirtd status` =~ /stopped/, "libvirtd is stopped"); 
+
+# start libvirtd
+$hook->action('start');
+$hook->expect_log;
+
+diag "$hook->{action} libvirtd";
+$hook->service_libvirtd;
+
+diag "hook script: $hook->{name}";
+system "cat $hook->{name}";
+
+sleep 3;
+diag "check if $hook->{name} is invocated";
+ok(-f "$hook->{name}", "$hook->{name} is invocated");
+
+diag "actual log: $hook->{log_name}";
+system "cat $hook->{log_name}";
+
+diag "expected log:";
+print $hook->{expect_log}."\n";
+
+diag "check if the actual log is same with expected log";
+ok($hook->compare_log, "$hook->{name} is invocated correctly while $hook->{action} libvirtd");
+
+diag "check if libvirtd is still running";
+ok(`service libvirtd status` =~ /running/, "libvirtd is running"); 
+
+# restart libvirtd
+$hook->action('restart');
+$hook->expect_log;
+
+diag "$hook->{action} libvirtd";
+$hook->service_libvirtd;
+
+diag "hook script: $hook->{name}";
+system "cat $hook->{name}";
+
+sleep 3;
+diag "check if $hook->{name} is invocated";
+ok(-f "$hook->{name}", "$hook->{name} is invocated");
+
+diag "actual log: $hook->{log_name}";
+system "cat $hook->{log_name}";
+
+diag "expected log:";
+print $hook->{expect_log}."\n";
+
+diag "check if the actual log is same with expected log";
+ok($hook->compare_log, "$hook->{name} is invocated correctly while $hook->{action} libvirtd");
+
+diag "check if libvirtd is still running";
+ok(`service libvirtd status` =~ /running/, "libvirtd is running"); 
+
+# reload libvirtd
+$hook->action('reload');
+$hook->expect_log;
+
+diag "$hook->{action} libvirtd";
+$hook->service_libvirtd;
+
+diag "hook script: $hook->{name}";
+system "cat $hook->{name}";
+
+sleep 3;
+diag "check if $hook->{name} is invocated";
+ok(-f "$hook->{name}", "$hook->{name} is invocated");
+
+diag "actual log: $hook->{log_name}";
+system "cat $hook->{log_name}";
+
+diag "expected log:";
+print $hook->{expect_log}."\n";
+
+diag "check if the actual log is same with expected log";
+ok($hook->compare_log, "$hook->{name} is invocated correctly while $hook->{action} libvirtd");
+
+diag "check if libvirtd is still running";
+ok(`service libvirtd status` =~ /running/, "libvirtd is running"); 
+
+$hook->cleanup;
+
-- 
1.7.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]