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 => 24;
23 use lib "@amperldir@";
24 use Installcheck::Config;
25 use Installcheck::Run qw(run run_err run_get load_vtape vtape_dir);
26 use Amanda::Device qw( :constants );
27 use Amanda::Config qw( :init :getconf );
30 use Amanda::Constants;
35 Amanda::Debug::dbopen("installcheck");
36 Installcheck::log_test_output();
38 $testconf = Installcheck::Run::setup(1, 4);
39 $testconf->add_param('autolabel', '"TESTCONF%%" any');
42 config_init($CONFIG_INIT_EXPLICIT_NAME, "TESTCONF");
43 my ($cfgerr_level, @cfgerr_errors) = config_errors();
44 if ($cfgerr_level >= $CFGERR_WARNINGS) {
45 config_print_errors();
46 BAIL_OUT("config errors");
49 # label slot 2 with "MyTape", slot 3 with "TESTCONF13", and add
50 # the latter to the tapelist
53 $devdir = load_vtape(2);
54 $dev = Amanda::Device->new("file:$devdir");
55 ($dev && $dev->status == $DEVICE_STATUS_SUCCESS)
56 or BAIL_OUT("device error");
58 $dev->start($ACCESS_WRITE, "MyTape", undef)
59 or BAIL_OUT("device error");
61 or BAIL_OUT("device error");
63 my $tlf = Amanda::Config::config_dir_relative(getconf($CNF_TAPELIST));
64 my $tl = Amanda::Tapelist->new($tlf, 1);
65 $tl->add_tapelabel("0", "TESTCONF13", "test tape");
68 like(run_err('amlabel'),
70 "bare 'amlabel' gives usage message");
72 like(run_get('amlabel', '--version'),
73 qr/^amlabel-\Q$Amanda::Constants::VERSION\E/,
74 "'amlabel --version' gives version");
76 like(run_get('amlabel', 'TESTCONF', 'TESTCONF92'),
77 qr/Writing label 'TESTCONF92'/,
78 "amlabel labels the current slot by default");
81 is_deeply($tl->{'tles'}->[0], {
87 'label' => 'TESTCONF92',
90 "tapelist correctly updated");
92 $devdir = load_vtape(1);
93 $dev = Amanda::Device->new("file:$devdir");
94 die "read_label failed" unless $dev->read_label() == $DEVICE_STATUS_SUCCESS;
95 is($dev->volume_label, "TESTCONF92", "volume is actually labeled");
97 ok(!run('amlabel', 'TESTCONF', 'TESTCONF93'),
98 "amlabel refuses to re-label a labeled volume");
99 like($Installcheck::Run::stdout,
100 qr/Volume with label 'TESTCONF92' is active and contains data from this configuration/,
101 "with correct message");
103 ok(!run('amlabel', 'TESTCONF', 'SomeTape'),
104 "amlabel refuses to write a non-matching label");
105 like($Installcheck::Run::stderr,
106 qr/Label 'SomeTape' doesn't match labelstr '.*'/,
107 "with correct message on stderr");
109 ok(!run('amlabel', '-f', 'TESTCONF', 'SomeTape'),
110 "amlabel will not write a non-matching label even with -f");
112 ok(!run('amlabel', 'TESTCONF', 'TESTCONF13', 'slot', '3'),
113 "amlabel refuses to write a label already in the tapelist (and recognizes 'slot xx')");
114 like($Installcheck::Run::stderr,
115 qr/Label 'TESTCONF13' already on a volume/,
116 "with correct message on stderr");
118 ok(run('amlabel', '-f', 'TESTCONF', 'TESTCONF13', 'slot', '3'),
119 "amlabel will write a label already in the tapelist with -f");
120 like($Installcheck::Run::stdout,
121 qr/Writing label 'TESTCONF13'/,
122 "with correct message on stdout");
124 ok(!run('amlabel', 'TESTCONF', 'TESTCONF88', 'slot', '2'),
125 "amlabel refuses to overwrite a non-matching label");
126 like($Installcheck::Run::stdout,
127 qr/Found label 'MyTape', but it is not from configuration 'TESTCONF'\./,
128 "with correct message on stdout");
130 ok(run('amlabel', '-f', 'TESTCONF', 'TESTCONF88', 'slot', '2'),
131 "amlabel will overwrite a non-matching label with -f");
132 like($Installcheck::Run::stdout,
133 qr/Found label 'MyTape', but it is not from configuration 'TESTCONF'\.
134 Writing label 'TESTCONF88'/,
135 "with correct message on stdout");
137 ok(run('amlabel', 'TESTCONF', 'TESTCONF88', '-f', 'slot', '2'),
138 "-f option doesn't have to follow 'amlabel'");
140 ok(run('amlabel', 'TESTCONF', 'TESTCONF88', '--meta', 'meta-01', '--barcode', 'bar-01', '--assign'),
144 is_deeply($tl->{'tles'}->[0], {
146 'barcode' => 'bar-01',
150 'label' => 'TESTCONF88',
153 "tapelist correctly updated after --assign");
155 ok(run('amlabel', 'TESTCONF', 'slot', '4'),
156 "amlabel works without a label");
157 like($Installcheck::Run::stdout,
158 qr/Reading label\.\.\.
159 Found an empty tape\.
160 Writing label 'TESTCONF01'\.\.\.
163 "amlabel without label use autolabel");
166 is_deeply($tl->{'tles'}->[0], {
172 'label' => 'TESTCONF01',
175 "tapelist correctly updated after autolabel");