----- "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