Imported Upstream version 2.6.1
[debian/amanda] / installcheck / amdevcheck.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 => 10;
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('amdevcheck'),
32     "'amdevcheck' with no arguments returns an error exit status");
33 like($Installcheck::Run::stdout, qr(\AUsage: )i, 
34     ".. and gives usage message on stdout");
35
36 like(run_err('amdevcheck', 'this-probably-doesnt-exist'), qr(could not open conf file)i, 
37     "if the configuration doesn't exist, fail with the correct message");
38
39 ##
40 # Next, work against a basically empty config
41
42 # this is re-created for each test
43 $testconf = Installcheck::Config->new();
44 $testconf->add_param("tapedev", '"/dev/null"');
45 $testconf->write();
46
47 # test some defaults
48 ok(run('amdevcheck', 'TESTCONF'), "run succeeds with a /dev/null tapedev");
49 is_deeply([ sort split "\n", $Installcheck::Run::stdout],
50           [ sort "MESSAGE File /dev/null is not a tape device", "DEVICE_ERROR"],
51           "Fail with correct message for a /dev/null tapedev");
52
53 ##
54 # Now use a config with a vtape
55
56 # this is re-created for each test
57 $testconf = Installcheck::Run::setup();
58 $testconf->add_param('label_new_tapes', '"TESTCONF%%"');
59 $testconf->add_dle("localhost $diskname installcheck-test");
60 $testconf->write();
61
62 ok(run('amdevcheck', 'TESTCONF'), "run succeeds with an unlabeled tape");
63 is_deeply([ sort split "\n", $Installcheck::Run::stdout],
64           [ sort "MESSAGE Error loading device header -- unlabeled volume?", "VOLUME_UNLABELED", "DEVICE_ERROR", "VOLUME_ERROR"],
65           "..and output is correct");
66
67 ok(run('amdevcheck', 'TESTCONF', "/dev/null"),
68     "can override device on the command line");
69 is_deeply([ sort split "\n", $Installcheck::Run::stdout],
70           [ sort "MESSAGE File /dev/null is not a tape device", "DEVICE_ERROR"],
71     ".. and produce a corresponding error message");
72
73 BAIL_OUT("amdump failed")
74     unless run('amdump', 'TESTCONF');
75
76 is_deeply([ sort split "\n", run_get('amdevcheck', 'TESTCONF') ],
77           [ sort "SUCCESS" ],
78     "used vtape described as SUCCESS");
79
80 Installcheck::Run::cleanup();