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