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