1 # Copyright (c) 2009, 2010 Zmanda, Inc. All Rights Reserved.
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.
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
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
16 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19 use Test::More tests => 19;
21 use lib "@amperldir@";
22 use Installcheck::Config;
23 use Installcheck::Run qw(run run_err run_get load_vtape vtape_dir);
24 use Amanda::Device qw( :constants );
25 use Amanda::Config qw( :init :getconf );
28 use Amanda::Constants;
33 Amanda::Debug::dbopen("installcheck");
34 Installcheck::log_test_output();
36 $testconf = Installcheck::Run::setup();
39 config_init($CONFIG_INIT_EXPLICIT_NAME, "TESTCONF");
40 my ($cfgerr_level, @cfgerr_errors) = config_errors();
41 if ($cfgerr_level >= $CFGERR_WARNINGS) {
42 config_print_errors();
43 BAIL_OUT("config errors");
46 # label slot 2 with "MyTape", slot 3 with "TESTCONF13", and add
47 # the latter to the tapelist
50 $devdir = load_vtape(2);
51 $dev = Amanda::Device->new("file:$devdir");
52 ($dev && $dev->status == $DEVICE_STATUS_SUCCESS)
53 or BAIL_OUT("device error");
55 $dev->start($ACCESS_WRITE, "MyTape", undef)
56 or BAIL_OUT("device error");
58 or BAIL_OUT("device error");
60 my $tlf = Amanda::Config::config_dir_relative(getconf($CNF_TAPELIST));
61 my $tl = Amanda::Tapelist::read_tapelist($tlf);
62 $tl->add_tapelabel("0", "TESTCONF13", "test tape");
65 like(run_err('amlabel'),
67 "bare 'amlabel' gives usage message");
69 like(run_get('amlabel', '--version'),
70 qr/^amlabel-\Q$Amanda::Constants::VERSION\E/,
71 "'amlabel --version' gives version");
73 like(run_get('amlabel', 'TESTCONF', 'TESTCONF92'),
74 qr/Writing label 'TESTCONF92'/,
75 "amlabel labels the current slot by default");
77 $tl = Amanda::Tapelist::read_tapelist($tlf);
82 'label' => 'TESTCONF92',
85 "tapelist correctly updated");
87 $devdir = load_vtape(1);
88 $dev = Amanda::Device->new("file:$devdir");
89 die "read_label failed" unless $dev->read_label() == $DEVICE_STATUS_SUCCESS;
90 is($dev->volume_label, "TESTCONF92", "volume is actually labeled");
92 ok(!run('amlabel', 'TESTCONF', 'TESTCONF93'),
93 "amlabel refuses to re-label a labeled volume");
94 like($Installcheck::Run::stdout,
95 qr/Volume with label 'TESTCONF92' is active and contains data from this configuration/,
96 "with correct message");
98 ok(!run('amlabel', 'TESTCONF', 'SomeTape'),
99 "amlabel refuses to write a non-matching label");
100 like($Installcheck::Run::stderr,
101 qr/Label 'SomeTape' doesn't match labelstr '.*'/,
102 "with correct message on stderr");
104 ok(!run('amlabel', '-f', 'TESTCONF', 'SomeTape'),
105 "amlabel will not write a non-matching label even with -f");
107 ok(!run('amlabel', 'TESTCONF', 'TESTCONF13', 'slot', '3'),
108 "amlabel refuses to write a label already in the tapelist (and recognizes 'slot xx')");
109 like($Installcheck::Run::stderr,
110 qr/Label 'TESTCONF13' already on a volume/,
111 "with correct message on stderr");
113 ok(run('amlabel', '-f', 'TESTCONF', 'TESTCONF13', 'slot', '3'),
114 "amlabel will write a label already in the tapelist with -f");
115 like($Installcheck::Run::stdout,
116 qr/Writing label 'TESTCONF13'/,
117 "with correct message on stdout");
119 ok(!run('amlabel', 'TESTCONF', 'TESTCONF88', 'slot', '2'),
120 "amlabel refuses to overwrite a non-matching label");
121 like($Installcheck::Run::stdout,
122 qr/Found label 'MyTape', but it is not from configuration 'TESTCONF'\./,
123 "with correct message on stdout");
125 ok(run('amlabel', '-f', 'TESTCONF', 'TESTCONF88', 'slot', '2'),
126 "amlabel will overwrite a non-matching label with -f");
127 like($Installcheck::Run::stdout,
128 qr/Found label 'MyTape', but it is not from configuration 'TESTCONF'\.
129 Writing label 'TESTCONF88'/,
130 "with correct message on stdout");
132 ok(run('amlabel', 'TESTCONF', 'TESTCONF88', '-f', 'slot', '2'),
133 "-f option doesn't have to follow 'amlabel'");