Imported Upstream version 3.3.2
[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 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. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
18
19 use Test::More tests => 10;
20
21 use lib "@amperldir@";
22 use Cwd qw(abs_path getcwd);
23 use Installcheck;
24 use Installcheck::Dumpcache;
25 use Installcheck::Config;
26 use Installcheck::Run qw(run run_err $diskname amdump_diag);
27 use Amanda::Config qw( :init );
28 use Amanda::Paths;
29 use warnings;
30 use strict;
31
32 my $testconf;
33
34 # Run amdump with client- and server-side scripts
35
36 my $templog = $Installcheck::TMP . "/check-script." . $$;
37
38 sub verify_log {
39     my $msg = shift;
40     my @exp = @_;
41     my ($exp, $got);
42     my $logfile;
43
44     if (!open($logfile, "<", $templog)) {
45         fail($msg);
46         diag("Logfile '$templog' does not exist.");
47         return;
48     }
49
50     my $linenum = 1;
51     foreach $exp (@exp) {
52         chomp $exp;
53         $got = <$logfile>;
54         chomp $got;
55         if (!$got) {
56             fail($msg);
57             diag("    Line: $linenum");
58             diag("Expected: '$exp'");
59             diag("     Got: EOF");
60             diag($exp);
61             return;
62         }
63         $got =~ s/ *$//g;
64         if ($got ne $exp) {
65             fail($msg);
66             diag("    Line: $linenum");
67             diag("Expected: '$exp'");
68             diag("     Got: '$got'");
69             return;
70         }
71         $linenum++;
72     }
73     $got = <$logfile>;
74     if ($got) {
75         fail($msg);
76         diag("    Line: $linenum");
77         diag("Expected: EOF");
78         diag("     Got: '$got'");
79         diag($got);
80         return;
81     }
82     pass($msg);
83 };
84
85 # check script on client
86
87 $testconf = Installcheck::Run::setup();
88 $testconf->add_param('autolabel', '"TESTCONF%%" empty volume_error');
89
90 $testconf->add_dle(<<EODLE);
91 localhost diskname1 $diskname {
92     installcheck-test
93     program "APPLICATION"
94     application {
95         plugin "amgtar"
96         property "atime_preserve" "no" # note underscore
97     }
98     script {
99         plugin "amlog-script"
100         execute-where client
101         execute-on pre-dle-amcheck, post-dle-amcheck, pre-dle-estimate, post-dle-estimate, pre-dle-backup, post-dle-backup
102         property "logfile" "$templog"
103     }
104 }
105 EODLE
106 $testconf->write();
107
108 unlink $templog;
109 ok(run('amcheck', '-c', 'TESTCONF'), "amcheck runs successfully for client scripts.");
110
111 verify_log("amcheck invokes correct script commands",
112     "check TESTCONF pre-dle-amcheck client localhost diskname1 $diskname",
113     "check TESTCONF post-dle-amcheck client localhost diskname1 $diskname",
114 );
115
116 unlink $templog;
117 ok(run('amdump', 'TESTCONF'), "amdump runs successfully for client scripts.")
118     or amdump_diag();
119
120 verify_log("amdump invokes correct script commands",
121     "estimate TESTCONF pre-dle-estimate client localhost diskname1 $diskname 0",
122     "estimate TESTCONF post-dle-estimate client localhost diskname1 $diskname 0",
123     "backup TESTCONF pre-dle-backup client localhost diskname1 $diskname 0",
124     "backup TESTCONF post-dle-backup client localhost diskname1 $diskname 0",
125 );
126
127 Installcheck::Run::cleanup();
128
129 #check script on server
130 $testconf = Installcheck::Run::setup();
131 $testconf->add_param('autolabel', '"TESTCONF%%" empty volume_error');
132
133 $testconf->add_dle(<<EODLE);
134 localhost diskname2 $diskname {
135     installcheck-test
136     program "APPLICATION"
137     application {
138         plugin "amgtar"
139         property "atime-preserve" "no"
140     }
141     script {
142         plugin "amlog-script"
143         single-execution yes
144         execute-where server
145         execute-on pre-host-amcheck, post-host-amcheck, pre-host-estimate, post-host-estimate, pre-host-backup, post-host-backup
146         property "logfile" "$templog"
147     }
148 }
149 EODLE
150 $testconf->add_dle(<<EODLE);
151 localhost diskname3 $diskname {
152     installcheck-test
153     program "APPLICATION"
154     application {
155         plugin "amgtar"
156         property "atime-preserve" "no"
157     }
158     script {
159         plugin "amlog-script"
160         single-execution yes
161         execute-where server
162         execute-on pre-host-amcheck, post-host-amcheck, pre-host-estimate, post-host-estimate, pre-host-backup, post-host-backup
163         property "logfile" "$templog"
164     }
165 }
166 EODLE
167 $testconf->write();
168
169 unlink $templog;
170 ok(run('amcheck', '-c', 'TESTCONF'), "amcheck runs successfully for server scripts.");
171
172 verify_log("amcheck invokes correct script commands",
173     "check TESTCONF pre-host-amcheck server localhost diskname3 $diskname",
174     "check TESTCONF post-host-amcheck server localhost diskname3 $diskname",
175 );
176
177 unlink $templog;
178 ok(run('amdump', 'TESTCONF'), "amdump runs successfully for server scripts.")
179     or amdump_diag();
180
181 verify_log("amdump invokes correct script commands",
182     "estimate TESTCONF pre-host-estimate server localhost diskname3 $diskname",
183     "estimate TESTCONF post-host-estimate server localhost diskname3 $diskname",
184     "backup TESTCONF pre-host-backup server localhost diskname3 $diskname",
185     "backup TESTCONF post-host-backup server localhost diskname3 $diskname",
186 );
187
188 unlink $templog;
189 Installcheck::Run::cleanup();
190
191 #check order script
192 $testconf = Installcheck::Run::setup();
193 $testconf->add_param('autolabel', '"TESTCONF%%" empty volume_error');
194
195 $testconf->add_dle(<<EODLE);
196 localhost diskname2 $diskname {
197     installcheck-test
198     program "APPLICATION"
199     application {
200         plugin "amgtar"
201         property "atime-preserve" "no"
202     }
203     script {
204         plugin "amlog-script"
205         execute-where client
206         execute-on pre-host-amcheck
207         property "logfile" "$templog"
208         property "TEXT" "50"
209         order 50
210     }
211     script {
212         plugin "amlog-script"
213         execute-where client
214         execute-on pre-host-amcheck
215         property "logfile" "$templog"
216         property "TEXT" "60"
217         order 60
218     }
219     script {
220         plugin "amlog-script"
221         execute-where client
222         execute-on pre-host-amcheck
223         property "logfile" "$templog"
224         property "TEXT" "40"
225         order 40
226     }
227 }
228 EODLE
229 $testconf->write();
230
231 unlink $templog;
232 ok(run('amcheck', '-c', 'TESTCONF'), "amcheck runs successfully for ordered scripts.");
233
234 verify_log("amcheck invokes script in correct order",
235     "check TESTCONF pre-host-amcheck client localhost diskname2 $diskname  40",
236     "check TESTCONF pre-host-amcheck client localhost diskname2 $diskname  50",
237     "check TESTCONF pre-host-amcheck client localhost diskname2 $diskname  60",
238 );
239
240
241 unlink $templog;
242 Installcheck::Run::cleanup();