Imported Upstream version 3.2.0
[debian/amanda] / installcheck / amreport.pl
1 # Copyright (c) 2009, 2010 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 => 166;
20
21 use strict;
22 use warnings;
23 use Cwd qw(abs_path);
24 use lib "@amperldir@";
25
26 use Installcheck;
27 use Installcheck::Run qw( run run_get run_err );
28 use Installcheck::Catalogs;
29 use Amanda::Paths;
30 use Amanda::Constants;
31 use Amanda::Util qw( slurp burp );
32 use Amanda::Debug;
33 use Amanda::Config qw ( :init :getconf );
34
35 # easy knob to twiddle to check amreport_new instead
36 my $amreport = "amreport";
37
38 Amanda::Debug::dbopen("installcheck");
39 Installcheck::log_test_output();
40
41 # we use Text::Diff for diagnostics if it's installed
42 my $have_text_diff;
43 BEGIN {
44     eval "use Text::Diff;";
45     if ($@) {
46         $have_text_diff = 0;
47     } else {
48         $have_text_diff = 1;
49     }
50 }
51
52 # set up a fake "printer" for postscript output
53 my $printer_output = "$Installcheck::TMP/postscript-output";
54 $ENV{'INSTALLCHECK_MOCK_LPR_OUTPUT'} = $printer_output;
55 $ENV{'INSTALLCHECK_MOCK_LPR'} = abs_path("mock") . "/lpr";
56
57 # and a fake template
58 my $ps_template = "$Installcheck::TMP/postscript-template";
59 burp($ps_template, "--PS-TEMPLATE--\n");
60
61 # and a fake "mail" for email output
62 my $mail_output = "$Installcheck::TMP/mail-output";
63 $ENV{'INSTALLCHECK_MOCK_MAIL_OUTPUT'} = $mail_output;
64 my $mail_mock = abs_path("mock") . "/mail";
65
66 my $cat;
67 my $alternate_log_filename="$Installcheck::TMP/installcheck-log";
68 my $current_log_filename="$Installcheck::CONFIG_DIR/TESTCONF/log/log";
69 my $out_filename="$Installcheck::TMP/installcheck-amreport-output";
70
71 sub setup_config {
72     my %params = @_;
73     my $testconf = Installcheck::Run::setup();
74
75     cleanup();
76
77     my $mailer =
78         $params{want_mailer}  ? "\"$mail_mock\""
79       : $params{bogus_mailer} ? "\"$mail_mock.bogus\""
80       :                         '""';                    #default
81
82     $testconf->add_param('mailer', $mailer);
83     $testconf->add_param('mailto',
84         $params{want_mailto} ? '"nobody\@localhost"' : '""');
85
86     $testconf->add_tapetype('TEST-TAPE-TEMPLATE', [
87         'length' => '30 mbytes',
88         'filemark' => '4 kbytes',
89         $params{'want_template'}? ('lbl_templ' => "\"$ps_template\""):(),
90     ]);
91     $testconf->add_param('tapetype', "\"TEST-TAPE-TEMPLATE\"");
92
93     $testconf->remove_param('send_amreport_on');
94     $testconf->add_param('send_amreport_on',
95         exists $params{send_amreport} ? uc($params{send_amreport}) : "ALL"
96     );
97
98     if (defined $params{'runtapes'}) {
99         $testconf->remove_param('runtapes');
100         $testconf->add_param('runtapes', $params{'runtapes'});
101     }
102     if (defined $params{'tapecycle'}) {
103         $testconf->remove_param('tapecycle');
104         $testconf->add_param('tapecycle', $params{'tapecycle'});
105     }
106
107     $testconf->write();
108
109     undef $cat;
110     if ($params{'catalog'}) {
111         $cat = Installcheck::Catalogs::load($params{'catalog'});
112         $cat->install();
113     }
114 }
115
116 sub cleanup {
117     unlink $out_filename;
118     unlink $mail_output;
119     unlink $printer_output;
120     unlink $alternate_log_filename;
121 }
122
123 # compare two multiline strings, giving a diff if they do not match
124 sub results_match
125 {
126     my ( $a_filename, $b, $msg ) = @_;
127
128     if ($a_filename eq 'stdout') {
129         $a = $Installcheck::Run::stdout;
130         if (!$a) {
131             diag("stdout is empty");
132             fail($msg);
133             return;
134         }
135     } else {
136         if (!-f $a_filename) {
137             diag("'$a_filename' does not exist");
138             fail($msg);
139             return;
140         }
141         $a = slurp($a_filename);
142     }
143
144     my $is_ps = ($b =~ m/^--PS-TEMPLATE--/);
145
146     my $cleanup = sub {
147         my $str = shift;
148         chomp $str;
149
150         # strip out special characters
151         $str =~ tr{\f}{};
152
153         if ($is_ps) {
154             # old amreport underquotes the postscript strings
155             $str =~ s{\\\(}{(}mgx;
156             $str =~ s{\\\)}{)}mgx;
157         } else {
158             # make human report insensitive to whitespace differences
159             $str =~ s{[\t ]+}{ }mgx;
160             $str =~ s{\s*\n[\n ]*\s*}{\n}mgx;
161         }
162
163         # chomp the version lines
164         $str =~ s{\n\(brought to you by Amanda version .*$}{\n<versioninfo>}g;
165         $str =~ s{\(Amanda Version .*\) DrawVers}{(Amanda Version x.y.z) DrawVers}g;
166
167         return $str;
168     };
169
170     $a = $cleanup->($a);
171     $b = $cleanup->($b);
172
173     if ( $a eq $b ) {
174         pass($msg);
175     } else {
176         my $diff;
177         if ($have_text_diff) {
178             $diff = diff( \$a, \$b, { 'STYLE' => "Unified" } );
179         } else {
180             $diff = "---- GOT: ----\n$a\n---- EXPECTED: ----\n$b\n---- ----";
181         }
182         fail($msg);
183         diag($diff);
184     }
185 }
186
187 # convert a regular report into what we expect to see in a mail
188 sub make_mail {
189     my ($report, $config, $error, $date, $addr) = @_;
190     my $error_msg ="";
191     $error_msg = " FAIL:" if $error;
192     return <<EOF . $report;
193 \$ARGS = ['-s','$config${error_msg} AMANDA MAIL REPORT FOR $date','$addr'];
194 EOF
195 }
196
197 ## try a few various options with a pretty normal logfile.  Note that
198 ## these tests all use amreport's script mode
199
200 setup_config(catalog => 'normal',
201     want_mailer => 1, want_mailto => 1, want_template => 1);
202
203 like(run_err($amreport, 'TESTCONF-NOSUCH'),
204     qr/could not open conf/,
205     "amreport with bogus config exits with error status and error message");
206
207 ok(!run($amreport, 'TESTCONF-NOSUCH', '--help'),
208     "amreport --help exits with status 1");
209 like($Installcheck::Run::stdout,
210     qr/Usage: amreport conf/,
211     "..and prints usage message");
212
213 like(run_get($amreport, 'TESTCONF-NOSUCH', '--version'),
214     qr/^amreport-.*/,
215     "amreport --version gives version");
216
217 ok(run($amreport, 'TESTCONF', '--from-amdump'),
218     "amreport, as run from amdump, with mailer, mailto, and a template")
219     or diag($Installcheck::Run::stderr);
220
221 is($Installcheck::Run::stdout, "", "..produces no output");
222 results_match($mail_output,
223     make_mail($cat->get_text('rpt1'), "DailySet1", 0, "February 25, 2009", "nobody\@localhost"),
224     "..mail matches");
225
226 results_match($printer_output,
227     $cat->get_text('postscript'),
228     "..printer output matches");
229
230 ok(run($amreport, 'TESTCONF', '--from-amdump', '/garbage/directory/'),
231     "amreport, as run from amdump, with mailer, mailto, and a template, and  bogus option")
232     or diag($Installcheck::Run::stderr);
233 is($Installcheck::Run::stdout, "", "..produces no output");
234 results_match($mail_output,
235     make_mail($cat->get_text('rpt1'), "DailySet1", 0, "February 25, 2009", "nobody\@localhost"),
236     "..mail matches");
237 results_match($printer_output,
238     $cat->get_text('postscript'),
239     "..printer output matches");
240
241 cleanup();
242
243 ok(run($amreport, 'TESTCONF', '-M', 'somebody@localhost'),
244     "amreport -M, with mailer, mailto, and a template")
245     or diag($Installcheck::Run::stderr);
246 is($Installcheck::Run::stdout, "", "..produces no output");
247 results_match($mail_output,
248     make_mail($cat->get_text('rpt1'), "DailySet1", 0, "February 25, 2009", "somebody\@localhost"),
249     "..mail matches");
250 results_match($printer_output,
251     $cat->get_text('postscript'),
252     "..printer output matches");
253
254 cleanup();
255
256 ok(run($amreport, 'TESTCONF', '-i'),
257     "amreport -i, with mailer, mailto, and a template => no error");
258 ok(! -f $mail_output,
259     "..doesn't mail");
260 ok(! -f $printer_output,
261     "..doesn't print");
262
263 cleanup();
264
265 ok(run($amreport, 'TESTCONF', '-p', $out_filename),
266     "amreport -p, with mailer, mailto, and a template")
267     or diag($Installcheck::Run::stderr);
268 is($Installcheck::Run::stdout, "", "..produces no output");
269 results_match($mail_output,
270     make_mail($cat->get_text('rpt1'), "DailySet1", 0, "February 25, 2009", "nobody\@localhost"),
271     "..mail matches");
272 ok(! -f $printer_output,
273     "..doesn't print");
274 results_match($out_filename, $cat->get_text('postscript'), "..postscript file matches");
275
276 # test a bare 'amreport', which should now output to stdout
277 cleanup();
278
279 ok(run($amreport, 'TESTCONF'),
280     "amreport with no other options outputs to stdout for user convenience")
281   or diag($Installcheck::Run::stderr);
282 results_match('stdout', $cat->get_text('rpt1'),
283     "..output matches");
284 ok(!-f $printer_output, "..no printer output")
285   or diag("error: printer output!:\n" . burp($printer_output));
286 ok(!-f $mail_output, "..no mail output")
287   or diag("error: mail output!:\n" . burp($printer_output));
288
289 # test long-form file option
290 cleanup();
291
292 ok(run($amreport, 'TESTCONF', "--text=$out_filename"),
293     "amreport --text=foo, no other options")
294   or diag($Installcheck::Run::stderr);
295 results_match($out_filename, $cat->get_text('rpt1'),
296     "..output matches");
297 ok(!-f $printer_output, "..no printer output")
298   or diag("error: printer output!:\n" . burp($printer_output));
299 ok(!-f $mail_output, "..no mail output")
300   or diag("error: mail output!:\n" . burp($printer_output));
301
302 # test long form postscript option
303 cleanup();
304
305 ok(
306     run($amreport, 'TESTCONF', '--ps', $out_filename),
307     "amreport --ps foo, no other options"
308 );
309 results_match($out_filename, $cat->get_text('postscript'), '..results match');
310 ok(!-f $printer_output, "..no printer output");
311 ok(!-f $mail_output, "..no mail output");
312
313 cleanup();
314
315 # test new mail option, using config mailto
316 setup_config(catalog => 'normal',
317              want_mailer => 1, want_mailto => 1, want_template => 1);
318
319 ok(run($amreport, 'TESTCONF', '--mail-text'),
320     "amreport --mail-text, no other options, built-in mailto");
321 results_match(
322     $mail_output,
323     make_mail(
324         $cat->get_text('rpt1'), "DailySet1", 0,
325         "February 25, 2009",   "nobody\@localhost"
326     ),
327     "..mail matches"
328 );
329 ok(!-f $printer_output, "..no printer output");
330 ok(!-f $out_filename,   "..no file output");
331
332 cleanup();
333
334 # test new mail option, using passed mailto
335 ok(run($amreport, 'TESTCONF', '--mail-text=somebody@localhost',),
336     'amreport --mail-text=somebody\@localhost, no other options');
337 results_match(
338     $mail_output,
339     make_mail(
340         $cat->get_text('rpt1'), "DailySet1", 0,
341         "February 25, 2009",   "somebody\@localhost"
342     ),
343     "..mail matches"
344 );
345 ok(!-f $printer_output, "..no printer output");
346 ok(!-f $out_filename, "..no file output");
347
348 cleanup();
349
350 # test long-form log option
351 burp($alternate_log_filename, $cat->get_file('log/log'));
352 ok(
353     run($amreport, 'TESTCONF', '--log', $alternate_log_filename),
354     "amreport --log with old log, no other config options"
355 );
356 results_match('stdout', $cat->get_text('rpt1'),
357     '..stdout output matches');
358 ok(!-f $mail_output, "..no mail output");
359 ok(!-f $out_filename, "..no file output");
360 ok(!-f $printer_output, "..no printer output");
361
362 cleanup();
363
364 # test long-form print option, without specified printer
365 setup_config(catalog => 'normal', want_template => 1);
366 ok(run($amreport, 'TESTCONF', '--print'),
367     'amreport --print, no other options');
368 results_match(
369     $printer_output,
370     $cat->get_text('postscript'),
371     "..printer output matches"
372 );
373 ok(!-f $mail_output,  "..no mail output");
374 ok(!-f $out_filename, "..no file output");
375
376 cleanup();
377
378 setup_config(catalog => 'normal',
379     want_mailer => 1, want_mailto => 1, want_template => 1);
380 ok(run($amreport, 'TESTCONF', '-i', '-p', $out_filename),
381     "amreport -i -p, with mailer, mailto, and a template")
382     or diag($Installcheck::Run::stderr);
383 is($Installcheck::Run::stdout, "", "..produces no output");
384 ok(! -f $mail_output,
385     "..produces no mail");
386 ok(! -f $printer_output,
387     "..doesn't print");
388 results_match($out_filename,
389     $cat->get_text('postscript'),
390     "..postscript output in -p file matches");
391
392 cleanup();
393
394 ok(run($amreport, 'TESTCONF', '-i', '-f', $out_filename),
395     "amreport -i -f, with mailer, mailto, and a template")
396     or diag($Installcheck::Run::stderr);
397 is($Installcheck::Run::stdout, "", "..produces no output");
398 ok(! -f $mail_output,
399     "..produces no mail");
400 results_match($printer_output,
401     $cat->get_text('postscript'),
402     "..printer output matches");
403 results_match($out_filename,
404     $cat->get_text('rpt1'),
405     "..report output in -f file matches");
406
407 cleanup();
408
409 burp($alternate_log_filename, $cat->get_file('log/log'));
410 ok(run($amreport, 'TESTCONF', '-l', $alternate_log_filename),
411     "amreport -l, with mailer, mailto, and a template")
412     or diag($Installcheck::Run::stderr);
413 is($Installcheck::Run::stdout, "", "..produces no output");
414 results_match($mail_output,
415     make_mail($cat->get_text('rpt1'), "DailySet1", 0, "February 25, 2009", "nobody\@localhost"),
416     "..mail matches");
417 results_match($printer_output,
418     $cat->get_text('postscript'),
419     "..printer output matches");
420
421 setup_config(catalog => 'normal',
422     want_mailer => 1);
423
424 ok(run($amreport, 'TESTCONF', '--from-amdump'),
425     "amreport --from-amdump, with mailer but no mailto and no template => exit==0");
426 ok(! -f $mail_output, "..doesn't mail");
427 ok(! -f $printer_output, "..doesn't print");
428
429 cleanup();
430
431 ok(run($amreport, 'TESTCONF', '--from-amdump', '-o', 'mailto=hello'),
432     "amreport -o to set mailto, with mailer but no mailto and no template")
433     or diag($Installcheck::Run::stderr);
434 is($Installcheck::Run::stdout, "", "..produces no output");
435 results_match($mail_output,
436     make_mail($cat->get_text('rpt1'), "DailySet1", 0, "February 25, 2009", "hello"),
437     "..mail matches");
438 ok(! -f $printer_output,
439     "..doesn't print");
440
441 cleanup();
442
443 like(run_err($amreport, 'TESTCONF', '--from-amdump', '-o', 'mailto=ill\egal'),
444     qr/mail addresses have invalid characters/,
445     "amreport with illegal email in -o, with mailer but no mailto and no template, errors out");
446
447 setup_config(catalog => 'normal',
448     want_mailer => 1, want_template => 1);
449
450 ok(run($amreport, 'TESTCONF', '--from-amdump'),
451     "no-args amreport with mailer, no mailto, and a template does nothing even though it could "
452         . "print a label"); # arguably a bug, but we'll keep it for now
453 ok(! -f $mail_output, "..doesn't mail");
454 ok(! -f $printer_output, "..doesn't print");
455
456 cleanup();
457
458 ok(run($amreport, 'TESTCONF', '--from-amdump', '-o', 'mailto=dustin'),
459     "amreport with mailer, no mailto, and a template, but mailto in config override works")
460     or diag($Installcheck::Run::stderr);
461 is($Installcheck::Run::stdout, "", "..produces no output");
462 results_match($mail_output,
463     make_mail($cat->get_text('rpt1'), "DailySet1", 0, "February 25, 2009", "dustin"),
464     "..mail matches");
465 results_match($printer_output,
466     $cat->get_text('postscript'),
467     "..printer output matches");
468
469 ok(run($amreport, 'TESTCONF', '-M', 'pcmantz'),
470     "amreport with mailer, no mailto, and a template, but mailto in -M works")
471     or diag($Installcheck::Run::stderr);
472 is($Installcheck::Run::stdout, "", "..produces no output");
473 results_match($mail_output,
474     make_mail($cat->get_text('rpt1'), "DailySet1", 0, "February 25, 2009", "pcmantz"),
475     "..mail matches");
476 results_match($printer_output,
477     $cat->get_text('postscript'),
478     "..printer output matches");
479
480 setup_config(catalog => 'normal', want_template => 1);
481
482 like(run_get($amreport, 'TESTCONF', '-M', 'martineau'),
483     qr/Warning: a mailer is not defined/,
484     "amreport with no mailer, no mailto, and a template, but mailto in -M fails with "
485         . "warning, but exit==0");
486 ok(! -f $mail_output, "..doesn't mail");
487 ok(! -f $printer_output, "..doesn't print");
488
489 setup_config(catalog => 'normal',
490         want_mailer => 1, want_mailto => 1);
491
492 ok(run($amreport, 'TESTCONF', '-p', $out_filename), # XXX another probable bug
493     "amreport with mailer, mailto, but no template, ignores -p option ")
494     or diag($Installcheck::Run::stderr);
495 is($Installcheck::Run::stdout, "", "..produces no output");
496 results_match($mail_output,
497     make_mail($cat->get_text('rpt1'), "DailySet1", 0, "February 25, 2009", "nobody\@localhost"),
498     "..mail matches");
499 ok(! -f $printer_output,
500     "..doesn't print");
501
502 cleanup();
503
504 ok(run($amreport, 'TESTCONF', '-o', "tapetype:TEST-TAPE-TEMPLATE:lbl_templ=$ps_template",
505                                             '-p', $out_filename),
506     "amreport with mailer, mailto, but no template, minds -p option if template given via -o")
507     or diag($Installcheck::Run::stderr);
508 is($Installcheck::Run::stdout, "", "..produces no output");
509 results_match($mail_output,
510     make_mail($cat->get_text('rpt1'), "DailySet1", 0, "February 25, 2009", "nobody\@localhost"),
511     "..mail matches");
512 results_match($out_filename,
513     $cat->get_text('postscript'),
514     "..printer output matches");
515
516 setup_config(catalog => 'normal',
517         bogus_mailer => 1, want_mailto => 1, want_template => 1);
518
519 ok(run($amreport, 'TESTCONF', '--from-amdump'),
520     "amreport with bogus mailer; doesn't mail, still prints")
521   or diag($Installcheck::Run::stderr);
522 ok(!-f $mail_output, "..produces no mail output");
523 is($Installcheck::Run::stdout, "", "..produces no stdout output");
524 results_match(
525     $printer_output,
526     $cat->get_text('postscript'),
527     "..printer output matches"
528 );
529
530 setup_config(
531     catalog => 'normal',
532     want_mailer   => 1,
533     want_mailto   => 1,
534     want_template => 1,
535     send_amreport => 'error'
536 );
537
538 ok(
539     run($amreport, 'TESTCONF', '--from-amdump'),
540 "amreport with CNF_SEND_AMREPORT_ON set to errors only, no mail, still prints"
541 ) or diag($Installcheck::Run::stderr);
542 ok(!-f $mail_output, "..produces no mail output") or diag(slurp $mail_output);
543 is($Installcheck::Run::stdout, "", "..produces no stdout output")
544   or diag($Installcheck::Run::stdout);
545 results_match(
546     $printer_output,
547     $cat->get_text('postscript'),
548     "..printer output matches"
549 );
550
551 ## test columnspec adjustments, etc.
552
553 setup_config(catalog => 'normal');
554
555 ok(run($amreport, 'TESTCONF', '-f', $out_filename, '-o', 'columnspec=OrigKB=::2'),
556     "amreport with OrigKB=::2");
557 results_match($out_filename, $cat->get_text('rpt2'),
558     "..result matches");
559
560 ok(run($amreport, 'TESTCONF', '-f', $out_filename, '-o', 'columnspec=OrigKB=:5'),
561     "amreport with OrigKB=:5");
562 results_match($out_filename, $cat->get_text('rpt3'),
563     "..result matches");
564
565 ok(run($amreport, 'TESTCONF', '-f', $out_filename, '-o', 'columnspec=OrigKB=:5:6'),
566     "amreport with OrigKB=:5:6");
567 results_match($out_filename, $cat->get_text('rpt4'),
568     "..result matches");
569
570 ok(run($amreport, 'TESTCONF', '-f', $out_filename, '-o', 'displayunit=m'),
571     "amreport with displayunit=m");
572 results_match($out_filename, $cat->get_text('rpt5'),
573     "..result matches");
574
575 setup_config(catalog => 'doublefailure',
576     want_mailer => 1, want_template => 1);
577
578 ok(!run($amreport, 'TESTCONF', '-M', 'dustin'),
579     "amreport with log in error")
580     or diag($Installcheck::Run::stderr);
581 is($Installcheck::Run::stdout, "", "..produces no output");
582 results_match($mail_output,
583     make_mail($cat->get_text('report'), "DailySet1", 1, "March 26, 2009", "dustin"),
584     "..mail matches");
585
586 ## some (anonymized) real logfiles, for regression testing
587
588 setup_config(catalog => 'strontium', want_template => 1);
589
590 ok(run($amreport, 'TESTCONF', '-f', $out_filename),
591     "amreport with strontium logfile (simple example with multiple levels)");
592 results_match($out_filename, $cat->get_text('report'),
593     "..result matches");
594 results_match($printer_output,
595     $cat->get_text('postscript'),
596     "..printer output matches");
597
598 setup_config(catalog => 'amflush', want_template => 1);
599
600 ok(run($amreport, 'TESTCONF', '-f', $out_filename),
601     "amreport with amflush logfile (regression check for flush-related DUMP STATUS)");
602 results_match($out_filename, $cat->get_text('report'),
603     "..result matches");
604 results_match($printer_output,
605     $cat->get_text('postscript'),
606     "..printer output matches");
607
608 setup_config(catalog => 'resultsmissing', want_template => 1);
609
610 run($amreport, 'TESTCONF', '-f', $out_filename);
611 is($Installcheck::Run::exit_code, 12,
612     "amreport with resultsmissing logfile ('RESULTS MISSING') exit==12");
613 results_match($out_filename, $cat->get_text('report'),
614     "..result matches");
615 results_match($printer_output,
616     $cat->get_text('postscript'),
617     "..printer output matches");
618
619 setup_config(catalog => 'shortstrange', want_template => 1);
620
621 run($amreport, 'TESTCONF', '-f', $out_filename);
622 is($Installcheck::Run::exit_code, 2,
623     "amreport with shortstrange logfile exit==2");
624 results_match($out_filename, $cat->get_text('report'),
625     "..result matches");
626 results_match($printer_output,
627     $cat->get_text('postscript'),
628     "..printer output matches");
629
630 setup_config(catalog => 'longstrange', want_template => 1);
631
632 run($amreport, 'TESTCONF', '-f', $out_filename);
633 is($Installcheck::Run::exit_code, 2,
634     "amreport with longstrange logfile exit==2");
635 results_match($out_filename, $cat->get_text('report'),
636     "..result matches");
637
638 setup_config(catalog => 'doublefailure', want_template => 1);
639
640 run($amreport, 'TESTCONF', '-f', $out_filename);
641 is($Installcheck::Run::exit_code, 4,
642     "amreport with doublefailure logfile exit==4");
643 results_match($out_filename, $cat->get_text('report'),
644     "..result matches");
645 results_match($printer_output,
646     $cat->get_text('postscript'),
647     "..printer output matches");
648
649 setup_config(catalog => 'bigestimate', want_template => 1);
650
651 run($amreport, 'TESTCONF', '-f', $out_filename);
652 is($Installcheck::Run::exit_code, 0,
653     "amreport with bigestimate logfile exit==0");
654 results_match($out_filename, $cat->get_text('report'),
655     "..result matches");
656 results_match($printer_output,
657     $cat->get_text('postscript'),
658     "..printer output matches");
659
660 setup_config(catalog => 'retried', want_template => 1);
661
662 run($amreport, 'TESTCONF', '-f', $out_filename);
663 is($Installcheck::Run::exit_code, 4,
664     "amreport with retried logfile exit==4");
665 results_match($out_filename, $cat->get_text('report'),
666     "..result matches");
667 results_match($printer_output,
668     $cat->get_text('postscript'),
669     "..printer output matches");
670
671 setup_config(catalog => 'retried-strange');
672
673 run($amreport, 'TESTCONF', '-f', $out_filename);
674 is($Installcheck::Run::exit_code, 6,
675     "amreport with retried logfile, with strange exit==6");
676 results_match($out_filename, $cat->get_text('report'),
677     "..result matches");
678
679 setup_config(catalog => 'retried-nofinish', want_template => 1);
680
681 run($amreport, 'TESTCONF', '-f', $out_filename);
682 is($Installcheck::Run::exit_code, 4,
683     "amreport with retried logfile where driver did not finish exit==4");
684 results_match($out_filename, $cat->get_text('report'),
685     "..result matches");
686
687 setup_config(catalog => 'taperr', want_template => 1);
688
689 run($amreport, 'TESTCONF', '-f', $out_filename);
690 is($Installcheck::Run::exit_code, 16,
691     "amreport with taperr logfile exit==16");
692 results_match($out_filename, $cat->get_text('report-holding'),
693     "..result matches");
694 ok((-f $printer_output and -z $printer_output),
695     "..printer output exists but is empty");
696
697 burp($alternate_log_filename, $cat->get_file('log/log'));
698
699 # use an explicit -l here so amreport doesn't try to look at the holding disk
700 run($amreport, 'TESTCONF', '-f', $out_filename, '-l', $alternate_log_filename);
701 is($Installcheck::Run::exit_code, 16,
702     "amreport with taperr logfile specified explicitly exit==16");
703 results_match($out_filename, $cat->get_text('report-noholding'),
704     "..result matches");
705
706 setup_config(catalog => 'spanned', want_template => 1);
707
708 run($amreport, 'TESTCONF', '-f', $out_filename);
709 is($Installcheck::Run::exit_code, 0,
710     "amreport with spanned logfile");
711 results_match($out_filename, $cat->get_text('report'),
712     "..result matches");
713 results_match($printer_output,
714     $cat->get_text('postscript'),
715     "..printer output matches");
716
717 setup_config(catalog => 'fatal', want_template => 1);
718
719 run($amreport, 'TESTCONF', '-f', $out_filename);
720 is($Installcheck::Run::exit_code, 5,
721     "amreport with fatal logfile");
722 results_match($out_filename, $cat->get_text('report'),
723     "..result matches");
724 ok(-f $printer_output && -z $printer_output,
725     "..printer output is empty (no dumps, no tapes)");
726
727 setup_config(catalog => 'flush-origsize', want_template => 1);
728
729 run($amreport, 'TESTCONF', '-f', $out_filename);
730 is($Installcheck::Run::exit_code, 0,
731     "amreport with flush-origsize");
732 results_match($out_filename, $cat->get_text('report'),
733     "..result matches");
734
735 setup_config(catalog => 'flush-noorigsize', want_template => 1);
736
737 run($amreport, 'TESTCONF', '-f', $out_filename);
738 is($Installcheck::Run::exit_code, 0,
739     "amreport with flush-noorigsize");
740 results_match($out_filename, $cat->get_text('report'),
741     "..result matches");
742
743 setup_config(catalog => 'plannerfail', want_template => 1);
744
745 run($amreport, 'TESTCONF', '-f', $out_filename);
746 is($Installcheck::Run::exit_code, 4,
747     "amreport with a planner failure (failed)");
748 results_match($out_filename, $cat->get_text('report'),
749     "..result matches");
750
751 setup_config(catalog => 'skipped', want_template => 1);
752
753 run($amreport, 'TESTCONF', '-f', $out_filename);
754 is($Installcheck::Run::exit_code, 0,
755     "amreport with a planner skipped dump (success)");
756 results_match($out_filename, $cat->get_text('report'),
757     "..result matches");
758
759 setup_config(catalog => 'filesystemstaped', want_template => 1, runtapes => 3, tapecycle => 5);
760
761 run($amreport, 'TESTCONF', '-f', $out_filename);
762 is($Installcheck::Run::exit_code, 0,
763     "amreport correctly report filesystem taped (success)");
764 results_match($out_filename, $cat->get_text('report'),
765     "..result matches");
766
767 setup_config(catalog => 'multi-taper', want_template => 0);
768
769 config_init($CONFIG_INIT_EXPLICIT_NAME, "TESTCONF");
770 my $logdir = getconf($CNF_LOGDIR);
771 my $logfile = $logdir . "/log.20100908110856.0";
772 run($amreport, 'TESTCONF', '-l', $logfile, '-f', $out_filename, '-o', 'TAPETYPE:TEST-TAPE-TEMPLATE:length=41m');
773 is($Installcheck::Run::exit_code, 0,
774     "amreport correctly report multi-taper (success)");
775 results_match($out_filename, $cat->get_text('report'),
776     "..result matches");
777
778 cleanup();