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