65919111ae49f191c7ee95402b78af17e8ae0c3d
[debian/amanda] / installcheck / amcheckdump.pl
1 # Copyright (c) 2005-2008 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 Mathlida Ave, Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
18
19 use Test::More tests => 9;
20
21 use lib "@amperldir@";
22 use Installcheck::Config;
23 use Installcheck::Run qw(run run_get run_err $diskname);
24 use Amanda::Paths;
25
26 my $testconf;
27
28 ##
29 # First, try amgetconf out without a config
30
31 ok(!run('amcheckdump'),
32     "amcheckdump with no arguments returns an error exit status");
33 like($Installcheck::Run::stdout, qr/\AUSAGE:/i, 
34     ".. and gives usage message");
35
36 like(run_err('amcheckdump', 'this-probably-doesnt-exist'), qr(could not open conf file)i, 
37     "run with non-existent config fails with an appropriate error message.");
38
39 ##
40 # Now use a config with a vtape and without usetimestamps
41
42 $testconf = Installcheck::Run::setup();
43 $testconf->add_param('label_new_tapes', '"TESTCONF%%"');
44 $testconf->add_param('usetimestamps', 'no');
45 $testconf->add_dle("localhost $diskname installcheck-test");
46 $testconf->write();
47
48 ok(run('amcheckdump', 'TESTCONF'),
49     "amcheckdump with a new config succeeds");
50 like($Installcheck::Run::stdout, qr(could not find)i,
51      "..but finds no dumps.");
52
53 BAIL_OUT("amdump failed")
54     unless run('amdump', 'TESTCONF');
55
56 like(run_get('amcheckdump', 'TESTCONF'), qr(Validating),
57     "amcheckdump succeeds, claims to validate something (usetimestamps=no)");
58
59 ##
60 # and check command-line handling
61
62 like(run_get('amcheckdump', 'TESTCONF', '-oorg=installcheck'), qr(Validating),
63     "amcheckdump accepts '-o' options on the command line");
64
65 ##
66 # And a config with usetimestamps enabled
67
68 $testconf = Installcheck::Run::setup();
69 $testconf->add_param('label_new_tapes', '"TESTCONF%%"');
70 $testconf->add_param('usetimestamps', 'yes');
71 $testconf->add_dle("localhost $diskname installcheck-test");
72 $testconf->write();
73
74 BAIL_OUT("amdump failed")
75     unless run('amdump', 'TESTCONF');
76
77 like(run_get('amcheckdump', 'TESTCONF'), qr(Validating),
78     "amcheckdump succeeds, claims to validate something (usetimestamps=yes)");
79
80 ##
81 # now try zeroing out the dumps
82
83 my $vtape1 = Installcheck::Run::vtape_dir(1);
84 opendir(my $vtape_dir, $vtape1) || die "can't opendir $vtape1: $!";
85 @dump1 = grep { /^0+1/ } readdir($vtape_dir);
86 closedir $vtape_dir;
87
88 for my $dumpfile (@dump1) {
89     open(my $dumpfh, "+<", "$vtape1/$dumpfile");
90     sysseek($dumpfh, 32768, 0); # jump past the header
91     syswrite($dumpfh, "\0" x 100); # and write some zeroes
92     close($dumpfh);
93 }
94
95 ok(!run('amcheckdump', 'TESTCONF'),
96     "amcheckdump detects a failure from a zeroed-out dumpfile");
97
98 Installcheck::Run::cleanup();