c38550a11ecfddbd46a0ecaf0c7446ad669ed193
[debian/amanda] / installcheck / pp-scripts.pl
1 # Copyright (c) 2005-2008 Zmanda Inc.  All Rights Reserved.
2 #
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License version 2 as published
5 # by the Free Software Foundation.
6 #
7 # This program is distributed in the hope that it will be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
10 # for more details.
11 #
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 #
16 # Contact information: Zmanda Inc, 465 S Mathlida Ave, Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
18
19 use Test::More tests => 8;
20
21 use lib "@amperldir@";
22 use Cwd qw(abs_path getcwd);
23 use Installcheck::Config;
24 use Installcheck::Run qw(run run_err $diskname amdump_diag);
25 use Amanda::Config qw( :init );
26 use Amanda::Paths;
27 use warnings;
28 use strict;
29
30 my $testconf;
31
32 # Run amdump with client- and server-side scripts
33
34 my $templog = $Amanda::Paths::AMANDA_TMPDIR . "/check-script." . $$;
35
36 sub verify_log {
37     my $msg = shift;
38     my @exp = @_;
39     my ($exp, $got);
40     my $logfile;
41
42     if (!open($logfile, "<", $templog)) {
43         fail($msg);
44         diag("Logfile '$templog' does not exist.");
45         return;
46     }
47
48     my $linenum = 1;
49     foreach $exp (@exp) {
50         $got = <$logfile>;
51         if (!$got) {
52             fail($msg);
53             diag("    Line: $linenum");
54             diag("Expected: '$exp'");
55             diag("     Got: EOF");
56             diag($exp);
57             return;
58         }
59         chomp $got;
60         if ($got ne $exp) {
61             fail($msg);
62             diag("    Line: $linenum");
63             diag("Expected: '$exp'");
64             diag("     Got: '$got'");
65             return;
66         }
67         $linenum++;
68     }
69     $got = <$logfile>;
70     if ($got) {
71         fail($msg);
72         diag("    Line: $linenum");
73         diag("Expected: EOF");
74         diag("     Got: '$got'");
75         diag($got);
76         return;
77     }
78     pass($msg);
79 };
80
81 # check script on client
82
83 $testconf = Installcheck::Run::setup();
84 $testconf->add_param('label_new_tapes', '"TESTCONF%%"');
85
86 $testconf->add_dle(<<EODLE);
87 localhost diskname1 $diskname {
88     installcheck-test
89     program "APPLICATION"
90     application {
91         plugin "amgtar"
92         property "atime_preserve" "no" # note underscore
93     }
94     script {
95         plugin "amlog-script"
96         execute-where client
97         execute-on pre-dle-amcheck, post-dle-amcheck, pre-dle-estimate, post-dle-estimate, pre-dle-backup, post-dle-backup
98         property "logfile" "$templog"
99     }
100 }
101 EODLE
102 $testconf->write();
103
104 unlink $templog;
105 ok(run('amcheck', '-c', 'TESTCONF'), "amcheck runs successfully for client scripts.");
106
107 verify_log("amcheck invokes correct script commands",
108     "TESTCONF pre-dle-amcheck client localhost diskname1 $diskname ",
109     "TESTCONF post-dle-amcheck client localhost diskname1 $diskname ",
110 );
111
112 unlink $templog;
113 ok(run('amdump', 'TESTCONF'), "amdump runs successfully for client scripts.")
114     or amdump_diag();
115
116 verify_log("amdump invokes correct script commands",
117     "TESTCONF pre-dle-estimate client localhost diskname1 $diskname 0",
118     "TESTCONF post-dle-estimate client localhost diskname1 $diskname 0",
119     "TESTCONF pre-dle-backup client localhost diskname1 $diskname 0",
120     "TESTCONF post-dle-backup client localhost diskname1 $diskname 0",
121 );
122
123 Installcheck::Run::cleanup();
124
125 #check script on server
126 $testconf = Installcheck::Run::setup();
127 $testconf->add_param('label_new_tapes', '"TESTCONF%%"');
128
129 $testconf->add_dle(<<EODLE);
130 localhost diskname2 $diskname {
131     installcheck-test
132     program "APPLICATION"
133     application {
134         plugin "amgtar"
135         property "atime-preserve" "no"
136     }
137     script {
138         plugin "amlog-script"
139         execute-where server
140         execute-on pre-host-amcheck, post-host-amcheck, pre-host-estimate, post-host-estimate, pre-host-backup, post-host-backup
141         property "logfile" "$templog"
142     }
143 }
144 EODLE
145 $testconf->write();
146
147 unlink $templog;
148 ok(run('amcheck', '-c', 'TESTCONF'), "amcheck runs successfully for server scripts.");
149
150 verify_log("amcheck invokes correct script commands",
151     "TESTCONF pre-host-amcheck server localhost diskname2 $diskname ",
152     "TESTCONF post-host-amcheck server localhost diskname2 $diskname ",
153 );
154
155 unlink $templog;
156 ok(run('amdump', 'TESTCONF'), "amdump runs successfully for server scripts.")
157     or amdump_diag();
158
159 verify_log("amdump invokes correct script commands",
160     "TESTCONF pre-host-estimate server localhost diskname2 $diskname 0",
161     "TESTCONF post-host-estimate server localhost diskname2 $diskname 0",
162     "TESTCONF pre-host-backup server localhost diskname2 $diskname ",
163     "TESTCONF post-host-backup server localhost diskname2 $diskname ",
164 );
165
166 unlink $templog;
167 Installcheck::Run::cleanup();