Imported Upstream version 3.1.0
[debian/amanda] / installcheck / pp-scripts.pl
1 # Copyright (c) 2008,2009 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         execute-where server
144         execute-on pre-host-amcheck, post-host-amcheck, pre-host-estimate, post-host-estimate, pre-host-backup, post-host-backup
145         property "logfile" "$templog"
146     }
147 }
148 EODLE
149 $testconf->write();
150
151 unlink $templog;
152 ok(run('amcheck', '-c', 'TESTCONF'), "amcheck runs successfully for server scripts.");
153
154 verify_log("amcheck invokes correct script commands",
155     "check TESTCONF pre-host-amcheck server localhost diskname2 $diskname",
156     "check TESTCONF post-host-amcheck server localhost diskname2 $diskname",
157 );
158
159 unlink $templog;
160 ok(run('amdump', 'TESTCONF'), "amdump runs successfully for server scripts.")
161     or amdump_diag();
162
163 verify_log("amdump invokes correct script commands",
164     "estimate TESTCONF pre-host-estimate server localhost diskname2 $diskname 0",
165     "estimate TESTCONF post-host-estimate server localhost diskname2 $diskname 0",
166     "backup TESTCONF pre-host-backup server localhost diskname2 $diskname",
167     "backup TESTCONF post-host-backup server localhost diskname2 $diskname",
168 );
169
170 unlink $templog;
171 Installcheck::Run::cleanup();
172
173 #check order script
174 $testconf = Installcheck::Run::setup();
175 $testconf->add_param('autolabel', '"TESTCONF%%" empty volume_error');
176
177 $testconf->add_dle(<<EODLE);
178 localhost diskname2 $diskname {
179     installcheck-test
180     program "APPLICATION"
181     application {
182         plugin "amgtar"
183         property "atime-preserve" "no"
184     }
185     script {
186         plugin "amlog-script"
187         execute-where client
188         execute-on pre-host-amcheck
189         property "logfile" "$templog"
190         property "TEXT" "50"
191         order 50
192     }
193     script {
194         plugin "amlog-script"
195         execute-where client
196         execute-on pre-host-amcheck
197         property "logfile" "$templog"
198         property "TEXT" "60"
199         order 60
200     }
201     script {
202         plugin "amlog-script"
203         execute-where client
204         execute-on pre-host-amcheck
205         property "logfile" "$templog"
206         property "TEXT" "40"
207         order 40
208     }
209 }
210 EODLE
211 $testconf->write();
212
213 unlink $templog;
214 ok(run('amcheck', '-c', 'TESTCONF'), "amcheck runs successfully for ordered scripts.");
215
216 verify_log("amcheck invokes script in correct order",
217     "check TESTCONF pre-host-amcheck client localhost diskname2 $diskname  40",
218     "check TESTCONF pre-host-amcheck client localhost diskname2 $diskname  50",
219     "check TESTCONF pre-host-amcheck client localhost diskname2 $diskname  60",
220 );
221
222
223 unlink $templog;
224 Installcheck::Run::cleanup();