1 # Copyright (c) 2009-2012 Zmanda, Inc. All Rights Reserved.
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.
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
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
17 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
20 use Test::More tests => 24;
24 use lib "@amperldir@";
25 use Installcheck::Config;
26 use Installcheck::Run qw(run run_err run_get load_vtape vtape_dir);
27 use Amanda::Device qw( :constants );
28 use Amanda::Config qw( :init :getconf );
31 use Amanda::Constants;
36 Amanda::Debug::dbopen("installcheck");
37 Installcheck::log_test_output();
39 $testconf = Installcheck::Run::setup(1, 4);
40 $testconf->add_param('autolabel', '"TESTCONF%%" any');
43 config_init($CONFIG_INIT_EXPLICIT_NAME, "TESTCONF");
44 my ($cfgerr_level, @cfgerr_errors) = config_errors();
45 if ($cfgerr_level >= $CFGERR_WARNINGS) {
46 config_print_errors();
47 BAIL_OUT("config errors");
50 # label slot 2 with "MyTape", slot 3 with "TESTCONF13", and add
51 # the latter to the tapelist
54 $devdir = load_vtape(2);
55 $dev = Amanda::Device->new("file:$devdir");
56 ($dev && $dev->status == $DEVICE_STATUS_SUCCESS)
57 or BAIL_OUT("device error");
59 $dev->start($ACCESS_WRITE, "MyTape", undef)
60 or BAIL_OUT("device error");
62 or BAIL_OUT("device error");
64 my $tlf = Amanda::Config::config_dir_relative(getconf($CNF_TAPELIST));
65 my $tl = Amanda::Tapelist->new($tlf, 1);
66 $tl->add_tapelabel("0", "TESTCONF13", "test tape");
69 like(run_err('amlabel'),
71 "bare 'amlabel' gives usage message");
73 like(run_get('amlabel', '--version'),
74 qr/^amlabel-\Q$Amanda::Constants::VERSION\E/,
75 "'amlabel --version' gives version");
77 like(run_get('amlabel', 'TESTCONF', 'TESTCONF92'),
78 qr/Writing label 'TESTCONF92'/,
79 "amlabel labels the current slot by default");
82 is_deeply($tl->{'tles'}->[0], {
89 'label' => 'TESTCONF92',
92 "tapelist correctly updated");
94 $devdir = load_vtape(1);
95 $dev = Amanda::Device->new("file:$devdir");
96 die "read_label failed" unless $dev->read_label() == $DEVICE_STATUS_SUCCESS;
97 is($dev->volume_label, "TESTCONF92", "volume is actually labeled");
99 ok(!run('amlabel', 'TESTCONF', 'TESTCONF93'),
100 "amlabel refuses to re-label a labeled volume");
101 like($Installcheck::Run::stdout,
102 qr/Volume with label 'TESTCONF92' is active and contains data from this configuration/,
103 "with correct message");
105 ok(!run('amlabel', 'TESTCONF', 'SomeTape'),
106 "amlabel refuses to write a non-matching label");
107 like($Installcheck::Run::stderr,
108 qr/Label 'SomeTape' doesn't match labelstr '.*'/,
109 "with correct message on stderr");
111 ok(!run('amlabel', '-f', 'TESTCONF', 'SomeTape'),
112 "amlabel will not write a non-matching label even with -f");
114 ok(!run('amlabel', 'TESTCONF', 'TESTCONF13', 'slot', '3'),
115 "amlabel refuses to write a label already in the tapelist (and recognizes 'slot xx')");
116 like($Installcheck::Run::stderr,
117 qr/Label 'TESTCONF13' already on a volume/,
118 "with correct message on stderr");
120 ok(run('amlabel', '-f', 'TESTCONF', 'TESTCONF13', 'slot', '3'),
121 "amlabel will write a label already in the tapelist with -f");
122 like($Installcheck::Run::stdout,
123 qr/Writing label 'TESTCONF13'/,
124 "with correct message on stdout");
126 ok(!run('amlabel', 'TESTCONF', 'TESTCONF88', 'slot', '2'),
127 "amlabel refuses to overwrite a non-matching label");
128 like($Installcheck::Run::stdout,
129 qr/Found label 'MyTape', but it is not from configuration 'TESTCONF'\./,
130 "with correct message on stdout");
132 ok(run('amlabel', '-f', 'TESTCONF', 'TESTCONF88', 'slot', '2'),
133 "amlabel will overwrite a non-matching label with -f");
134 like($Installcheck::Run::stdout,
135 qr/Found label 'MyTape', but it is not from configuration 'TESTCONF'\.
136 Writing label 'TESTCONF88'/,
137 "with correct message on stdout");
139 ok(run('amlabel', 'TESTCONF', 'TESTCONF88', '-f', 'slot', '2'),
140 "-f option doesn't have to follow 'amlabel'");
142 ok(run('amlabel', 'TESTCONF', 'TESTCONF88', '--meta', 'meta-01', '--barcode', 'bar-01', '--assign'),
146 is_deeply($tl->{'tles'}->[0], {
148 'barcode' => 'bar-01',
150 'blocksize' => undef,
153 'label' => 'TESTCONF88',
156 "tapelist correctly updated after --assign");
158 ok(run('amlabel', 'TESTCONF', 'slot', '4'),
159 "amlabel works without a label");
160 like($Installcheck::Run::stdout,
161 qr/Reading label\.\.\.
162 Found an empty tape\.
163 Writing label 'TESTCONF01'\.\.\.
166 "amlabel without label use autolabel");
169 is_deeply($tl->{'tles'}->[0], {
176 'label' => 'TESTCONF01',
179 "tapelist correctly updated after autolabel");