File: 051-daemon-hook.t

package info (click to toggle)
libvirt-tck 0.1.0~2.git890d1c-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,128 kB
  • sloc: perl: 2,885; sh: 1,180; xml: 992; makefile: 6
file content (167 lines) | stat: -rw-r--r-- 4,854 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# -*- 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 invoked while
start, stop, or reload daemon.

=cut

use strict;
use warnings;

use Slurp;

use Sys::Virt::TCK;
use Sys::Virt::TCK::Hooks;

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');

    eval { $hook->prepare(); };
    BAIL_OUT "failed to setup hooks testing ENV: $@" if $@;

    diag "reload libvirtd for hooks scripts taking effect";
    $hook->action('reload');
    $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();
};