Imported Upstream version 3.1.0
[debian/amanda] / installcheck / amdevcheck.pl
1 # Copyright (c) 2007, 2008, 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 => 17;
20
21 use lib "@amperldir@";
22 use Installcheck::Config;
23 use Installcheck::Run qw(run run_get run_err $diskname);
24 use Installcheck::Dumpcache;
25 use Amanda::Paths;
26
27 my $testconf;
28
29 ##
30 # First, try amgetconf out without a config
31
32 ok(!run('amdevcheck'),
33     "'amdevcheck' with no arguments returns an error exit status");
34 like($Installcheck::Run::stdout, qr(\AUsage: )i, 
35     ".. and gives usage message on stdout");
36
37 like(run_err('amdevcheck', 'this-probably-doesnt-exist'), qr(could not open conf file)i, 
38     "if the configuration doesn't exist, fail with the correct message");
39
40 ##
41 # Next, work against a basically empty config
42
43 # this is re-created for each test
44 $testconf = Installcheck::Config->new();
45 $testconf->add_param("tapedev", '"/dev/null"');
46 $testconf->write();
47
48 # test some defaults
49 ok(run('amdevcheck', 'TESTCONF'), "run succeeds with a /dev/null tapedev");
50 is_deeply([ sort split "\n", $Installcheck::Run::stdout],
51           [ sort "MESSAGE File /dev/null is not a tape device", "DEVICE_ERROR"],
52           "Fail with correct message for a /dev/null tapedev");
53
54 ##
55 # Now use a config with a vtape
56
57 # this is re-created for each test
58 $testconf = Installcheck::Run::setup();
59 $testconf->add_param('autolabel', '"TESTCONF%%" empty volume_error');
60 $testconf->add_dle("localhost $diskname installcheck-test");
61 $testconf->write();
62
63 ok(run('amdevcheck', 'TESTCONF'), "run succeeds with an unlabeled tape");
64 is_deeply([ sort split "\n", $Installcheck::Run::stdout],
65           [ sort "MESSAGE Error loading device header -- unlabeled volume?", "VOLUME_UNLABELED", "DEVICE_ERROR", "VOLUME_ERROR"],
66           "..and output is correct");
67
68 ok(run('amdevcheck', 'TESTCONF', "--properties"),
69     "can list properties with --properties option");
70
71 ok(run('amdevcheck', 'TESTCONF', "--properties", "BLOCK_SIZE"),
72     "check block_size property value");
73 is_deeply([ sort split "\n", $Installcheck::Run::stdout],
74           [ sort "BLOCK_SIZE=32768"],
75     ".. and confirm it is default value");
76
77 ok(run('amdevcheck', 'TESTCONF', "--properties", "CANONICAL_NAME"),
78     "check canonical_name property value");
79 is_deeply([ sort split "\n", $Installcheck::Run::stdout],
80           [ sort "CANONICAL_NAME=file:" . Installcheck::Run::vtape_dir() ],
81     ".. and confirm it is set to default value");
82
83 ok(run('amdevcheck', 'TESTCONF', "--properties", "BLOCK_SIZE,CANONICAL_NAME"),
84     "check a list of properties");
85 is_deeply([ sort split "\n", $Installcheck::Run::stdout],
86           [ sort "BLOCK_SIZE=32768",
87                  "CANONICAL_NAME=file:" . Installcheck::Run::vtape_dir() ],
88     ".. with correct results");
89
90 ok(run('amdevcheck', 'TESTCONF', '/dev/null'),
91     "can override device on the command line");
92 is_deeply([ sort split "\n", $Installcheck::Run::stdout],
93           [ sort "MESSAGE File /dev/null is not a tape device", "DEVICE_ERROR"],
94     ".. and produce a corresponding error message");
95
96 Installcheck::Dumpcache::load("basic");
97
98 # the 'basic' dumpcache uses a changer, not a tapedev, and amdevcheck doesn't
99 # understand that, so we have to give an explicit device here
100 is_deeply([ sort split "\n",
101             run_get('amdevcheck', 'TESTCONF', 'file:'.$Installcheck::Run::taperoot) ],
102           [ sort "SUCCESS" ],
103     "used vtape described as SUCCESS");
104
105 Installcheck::Run::cleanup();