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

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

 



attach updated patch for daemon hook testing..

replaced "cat" with "slurp", corrected typos.

- Osier

----- "Osier" <jyang@xxxxxxxxxx> wrote:

> ----- "Daniel P. Berrange" <berrange@xxxxxxxxxx> wrote:
> 
> > On Mon, Oct 18, 2010 at 07:18:09AM +0800, Osier Yang wrote:
> > > 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@xxxxxxxxxx>
> > > +#
> > > +# 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}";
> > 
> > These 'cat' calls should all really be reported as diagnostics
> > rather than just sent to stdout directly. We should probably
> > just use the standard 'Slurp' module from CPAN.
> 
> yes, indeed.
> 
> > 
> > eg, put a 'use Slurp' at the top of the script then
> > replace those 2 lines with
> > 
> >    my $hookdata = slurp($hook->{name});
> >    diag "hook script: $hook->{name} '$hookdata'";
> > 
> 
> Thanks. will update.. think need to add it in 'Build.pl' as a
> requirement at the meantime.. 
> 
> > 
> > > +
> > > +sleep 3;
> > > +diag "check if $hook->{name} is invocated";
> > > +ok(-f "$hook->{name}", "$hook->{name} is invocated");
> > 
> > s/invocated/invoked/  (and in a few other places later)
> 
> yep, will update.
> 
> > 
> > > +
> > > +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;
> > 
> > As mentioned in the previous patch, it is probably best to wrap the
> > entire test block in a
> > 
> >   SKIP: {
> >      my $uri = $conn->get_uri();
> >      skip 12, "Not using QEMU/LXC driver" unless
> >           $uri eq "qemu:///system" or $uri eq "lxc:///";
> > 
> >      ....all test cases...
> >   }
> > 
> 
> As explained in previous mail. will not "SKIP" it. :-/
> 
> - Osier
> 
> > Regards,
> > Daniel
> > -- 
> > |: Red Hat, Engineering, London    -o-  
> > http://people.redhat.com/berrange/ :|
> > |: http://libvirt.org -o- http://virt-manager.org -o-
> > http://deltacloud.org :|
> > |: http://autobuild.org        -o-        
> > http://search.cpan.org/~danberr/ :|
> > |: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742
> 7D3B
> > 9505 :|
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list
>From 963158c860d5415117e70b67458745c2b4cf9c13 Mon Sep 17 00:00:00 2001
From: Osier Yang <jyang@xxxxxxxxxx>
Date: Tue, 19 Oct 2010 15:32:17 +0800
Subject: [libvirt-tck 4/4] Add test case for daemon hook testing

Validate daemon hook is invoked correctly while start, stop,
restart, reload libvirtd
---
 scripts/hooks/051-daemon-hook.t |  153 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 153 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..bc9714c
--- /dev/null
+++ b/scripts/hooks/051-daemon-hook.t
@@ -0,0 +1,153 @@
+# -*- perl -*-
+#
+# Copyright (C) 203 Red Hat, Inc.
+# Copyright (C) 203 Osier Yang <jyang@xxxxxxxxxx>
+#
+# 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 invoked while
+start, stop, or reload daemon.
+
+=cut
+
+use strict;
+use warnings;
+
+use Slurp;
+
+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;
+
+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");
+
+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 "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"); 
+
+# start libvirtd
+$hook->action('start');
+$hook->expect_log;
+
+diag "$hook->{action} libvirtd";
+$hook->service_libvirtd;
+
+$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");
+
+$actual_log_data = slurp($hook->{log_name});
+diag "actual log: $hook->{log_name} '$actual_log_data'";
+
+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 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;
+
+$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");
+
+$actual_log_data = slurp($hook->{log_name});
+diag "actual log: $hook->{log_name} '$actual_log_data'";
+
+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 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;
+
+$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");
+
+$actual_log_data = slurp($hook->{log_name});
+diag "actual log: $hook->{log_name} '$actual_log_data'";
+
+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 libvirtd is still running";
+ok(`service libvirtd status` =~ /running/, "libvirtd is running"); 
+
+$hook->cleanup;
+
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]