Imported Upstream version 3.3.3
[debian/amanda] / installcheck / pp-scripts.pl
1 # Copyright (c) 2008-2012 Zmanda, Inc.  All Rights Reserved.
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11 # for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19
20 use Test::More tests => 10;
21
22 use lib "@amperldir@";
23 use Cwd qw(abs_path getcwd);
24 use Installcheck;
25 use Installcheck::Dumpcache;
26 use Installcheck::Config;
27 use Installcheck::Run qw(run run_err $diskname amdump_diag);
28 use Amanda::Config qw( :init );
29 use Amanda::Paths;
30 use warnings;
31 use strict;
32
33 my $testconf;
34
35 # Run amdump with client- and server-side scripts
36
37 my $templog = $Installcheck::TMP . "/check-script." . $$;
38
39 sub verify_log {
40     my $msg = shift;
41     my @exp = @_;
42     my ($exp, $got);
43     my $logfile;
44
45     if (!open($logfile, "<", $templog)) {
46         fail($msg);
47         diag("Logfile '$templog' does not exist.");
48         return;
49     }
50
51     my $linenum = 1;
52     foreach $exp (@exp) {
53         chomp $exp;
54         $got = <$logfile>;
55         chomp $got;
56         if (!$got) {
57             fail($msg);
58             diag("    Line: $linenum");
59             diag("Expected: '$exp'");
60             diag("     Got: EOF");
61             diag($exp);
62             return;
63         }
64         $got =~ s/ *$//g;
65         if ($got ne $exp) {
66             fail($msg);
67             diag("    Line: $linenum");
68             diag("Expected: '$exp'");
69             diag("     Got: '$got'");
70             return;
71         }
72         $linenum++;
73     }
74     $got = <$logfile>;
75     if ($got) {
76         fail($msg);
77         diag("    Line: $linenum");
78         diag("Expected: EOF");
79         diag("     Got: '$got'");
80         diag($got);
81         return;
82     }
83     pass($msg);
84 };
85
86 # check script on client
87
88 $testconf = Installcheck::Run::setup();
89 $testconf->add_param('autolabel', '"TESTCONF%%" empty volume_error');
90
91 $testconf->add_dle(<<EODLE);
92 localhost diskname1 $diskname {
93     installcheck-test
94     program "APPLICATION"
95     application {
96         plugin "amgtar"
97         property "atime_preserve" "no" # note underscore
98     }
99     script {
100         plugin "amlog-script"
101         execute-where client
102         execute-on pre-dle-amcheck, post-dle-amcheck, pre-dle-estimate, post-dle-estimate, pre-dle-backup, post-dle-backup
103         property "logfile" "$templog"
104     }
105 }
106 EODLE
107 $testconf->write();
108
109 unlink $templog;
110 ok(run('amcheck', '-c', 'TESTCONF'), "amcheck runs successfully for client scripts.");
111
112 verify_log("amcheck invokes correct script commands",
113     "check TESTCONF pre-dle-amcheck client localhost diskname1 $diskname",
114     "check TESTCONF post-dle-amcheck client localhost diskname1 $diskname",
115 );
116
117 unlink $templog;
118 ok(run('amdump', 'TESTCONF'), "amdump runs successfully for client scripts.")
119     or amdump_diag();
120
121 verify_log("amdump invokes correct script commands",
122     "estimate TESTCONF pre-dle-estimate client localhost diskname1 $diskname 0",
123     "estimate TESTCONF post-dle-estimate client localhost diskname1 $diskname 0",
124     "backup TESTCONF pre-dle-backup client localhost diskname1 $diskname 0",
125     "backup TESTCONF post-dle-backup client localhost diskname1 $diskname 0",
126 );
127
128 Installcheck::Run::cleanup();
129
130 #check script on server
131 $testconf = Installcheck::Run::setup();
132 $testconf->add_param('autolabel', '"TESTCONF%%" empty volume_error');
133
134 $testconf->add_dle(<<EODLE);
135 localhost diskname2 $diskname {
136     installcheck-test
137     program "APPLICATION"
138     application {
139         plugin "amgtar"
140         property "atime-preserve" "no"
141     }
142     script {
143         plugin "amlog-script"
144         single-execution yes
145         execute-where server
146         execute-on pre-host-amcheck, post-host-amcheck, pre-host-estimate, post-host-estimate, pre-host-backup, post-host-backup
147         property "logfile" "$templog"
148     }
149 }
150 EODLE
151 $testconf->add_dle(<<EODLE);
152 localhost diskname3 $diskname {
153     installcheck-test
154     program "APPLICATION"
155     application {
156         plugin "amgtar"
157         property "atime-preserve" "no"
158     }
159     script {
160         plugin "amlog-script"
161         single-execution yes
162         execute-where server
163         execute-on pre-host-amcheck, post-host-amcheck, pre-host-estimate, post-host-estimate, pre-host-backup, post-host-backup
164         property "logfile" "$templog"
165     }
166 }
167 EODLE
168 $testconf->write();
169
170 unlink $templog;
171 ok(run('amcheck', '-c', 'TESTCONF'), "amcheck runs successfully for server scripts.");
172
173 verify_log("amcheck invokes correct script commands",
174     "check TESTCONF pre-host-amcheck server localhost diskname3 $diskname",
175     "check TESTCONF post-host-amcheck server localhost diskname3 $diskname",
176 );
177
178 unlink $templog;
179 ok(run('amdump', 'TESTCONF'), "amdump runs successfully for server scripts.")
180     or amdump_diag();
181
182 verify_log("amdump invokes correct script commands",
183     "estimate TESTCONF pre-host-estimate server localhost diskname3 $diskname",
184     "estimate TESTCONF post-host-estimate server localhost diskname3 $diskname",
185     "backup TESTCONF pre-host-backup server localhost diskname3 $diskname",
186     "backup TESTCONF post-host-backup server localhost diskname3 $diskname",
187 );
188
189 unlink $templog;
190 Installcheck::Run::cleanup();
191
192 #check order script
193 $testconf = Installcheck::Run::setup();
194 $testconf->add_param('autolabel', '"TESTCONF%%" empty volume_error');
195
196 $testconf->add_dle(<<EODLE);
197 localhost diskname2 $diskname {
198     installcheck-test
199     program "APPLICATION"
200     application {
201         plugin "amgtar"
202         property "atime-preserve" "no"
203     }
204     script {
205         plugin "amlog-script"
206         execute-where client
207         execute-on pre-host-amcheck
208         property "logfile" "$templog"
209         property "TEXT" "50"
210         order 50
211     }
212     script {
213         plugin "amlog-script"
214         execute-where client
215         execute-on pre-host-amcheck
216         property "logfile" "$templog"
217         property "TEXT" "60"
218         order 60
219     }
220     script {
221         plugin "amlog-script"
222         execute-where client
223         execute-on pre-host-amcheck
224         property "logfile" "$templog"
225         property "TEXT" "40"
226         order 40
227     }
228 }
229 EODLE
230 $testconf->write();
231
232 unlink $templog;
233 ok(run('amcheck', '-c', 'TESTCONF'), "amcheck runs successfully for ordered scripts.");
234
235 verify_log("amcheck invokes script in correct order",
236     "check TESTCONF pre-host-amcheck client localhost diskname2 $diskname  40",
237     "check TESTCONF pre-host-amcheck client localhost diskname2 $diskname  50",
238     "check TESTCONF pre-host-amcheck client localhost diskname2 $diskname  60",
239 );
240
241
242 unlink $templog;
243 Installcheck::Run::cleanup();