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 => 46;
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 );
35 Amanda::Debug::dbopen("installcheck");
36 Installcheck::log_test_output();
38 $testconf = Installcheck::Run::setup();
41 config_init($CONFIG_INIT_EXPLICIT_NAME, "TESTCONF");
42 my ($cfgerr_level, @cfgerr_errors) = config_errors();
43 if ($cfgerr_level >= $CFGERR_WARNINGS) {
44 config_print_errors();
45 BAIL_OUT("config errors");
48 # label slot 2 with "MyTape", slot 3 with "TESTCONF13", and add
49 # 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");
64 $devdir = load_vtape(3);
65 $dev = Amanda::Device->new("file:$devdir");
66 ($dev && $dev->status == $DEVICE_STATUS_SUCCESS)
67 or BAIL_OUT("device error");
69 $dev->start($ACCESS_WRITE, "TESTCONF13", undef)
70 or BAIL_OUT("device error");
72 or BAIL_OUT("device error");
74 my $tlf = Amanda::Config::config_dir_relative(getconf($CNF_TAPELIST));
75 my $tl = Amanda::Tapelist->new($tlf, 1);
76 $tl->add_tapelabel("0", "TESTCONF13", "test tape");
80 like(run_err('amtape'),
82 "bare 'amtape' gives usage message");
84 # in general, output goes to stderr, so we can't use run_get. These checks
85 # accomplish two things: ensure that amtape can invoke the changer functions
86 # correctly (and not generate an error), and ensure that it gives the
87 # appropriate responses. It does not exercise the changer itself -- most
88 # of these operations are meaningless for vtapes, anyway.
92 ok(run('amtape', 'TESTCONF', 'reset'),
93 "'amtape TESTCONF reset'");
94 like($Installcheck::Run::stderr,
98 ok(run('amtape', 'TESTCONF', 'eject'),
99 "'amtape TESTCONF eject'");
100 like($Installcheck::Run::stderr,
104 # TODO: chg-disk doesn't support "clean"
106 ok(run('amtape', 'TESTCONF', 'slot', '2'),
107 "'amtape TESTCONF slot 2'");
108 like($Installcheck::Run::stderr,
109 qr/changed to slot 2/,
112 ok(run('amtape', 'TESTCONF', 'slot', 'current'),
113 "'amtape TESTCONF slot current'");
114 like($Installcheck::Run::stderr,
115 qr/changed to slot 2/,
118 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
119 "'amtape TESTCONF slot next'");
120 like($Installcheck::Run::stderr,
121 qr/changed to slot 3/,
124 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
125 "'amtape TESTCONF slot next'");
126 like($Installcheck::Run::stderr,
127 qr/changed to slot 1/, # loop around to slot 1
130 ok(run('amtape', 'TESTCONF', 'label', 'MyTape'),
131 "'amtape TESTCONF label MyTape'");
132 like($Installcheck::Run::stderr,
133 qr/slot +2:.*label MyTape/,
136 ok(run('amtape', 'TESTCONF', 'current'),
137 "'amtape TESTCONF current'");
138 like($Installcheck::Run::stderr,
139 qr/slot +2:.*label MyTape/,
142 ok(run('amtape', 'TESTCONF', 'update'),
143 "'amtape TESTCONF update'");
144 like($Installcheck::Run::stderr,
148 ok(run('amtape', 'TESTCONF', 'show'),
149 "'amtape TESTCONF show'");
150 like($Installcheck::Run::stderr,
151 qr/slot +2:.*label MyTape\nslot +3/,
152 "'amtape TESTCONF show' ..result correct");
154 ok(run('amtape', 'TESTCONF', 'show', '2'),
155 "'amtape TESTCONF show'");
156 like($Installcheck::Run::stderr,
157 qr/^slot +2:.*label MyTape$/,
158 "'amtape TESTCONF show 2' ..result correct");
160 ok(run('amtape', 'TESTCONF', 'show', '1,3'),
161 "'amtape TESTCONF show'");
162 like($Installcheck::Run::stderr,
163 qr/^slot +1: unlabeled volume\nslot +3: date \d{14} label TESTCONF13$/,
164 # qr/slot +1: unlabeled volume\nslot +3: date 20111121133419 label TESTCONF13/,
165 "'amtape TESTCONF show 1,3' ..result correct");
167 ok(run('amtape', 'TESTCONF', 'taper'),
168 "'amtape TESTCONF taper'");
169 like($Installcheck::Run::stderr,
170 qr/Will write to volume 'TESTCONF13' in slot 3/,
171 "'amtape TESTCONF taper' ..result correct");
174 ## shift to using the new Amanda::Changer::disk
176 $testconf->remove_param("tapedev");
177 $testconf->remove_param("tpchanger");
178 $testconf->add_param("tpchanger", "\"chg-disk:" . vtape_dir(). "\"");
183 ok(run('amtape', 'TESTCONF', 'reset'),
184 "'amtape TESTCONF reset'");
185 like($Installcheck::Run::stderr,
186 qr/changer is reset/,
189 ok(run('amtape', 'TESTCONF', 'slot', '2'),
190 "'amtape TESTCONF slot 2'");
191 like($Installcheck::Run::stderr,
192 qr/changed to slot 2/,
195 ok(run('amtape', 'TESTCONF', 'slot', 'current'),
196 "'amtape TESTCONF slot current'");
197 like($Installcheck::Run::stderr,
198 qr/changed to slot 2/,
201 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
202 "'amtape TESTCONF slot next'");
203 like($Installcheck::Run::stderr,
204 qr/changed to slot 3/,
207 ok(run('amtape', 'TESTCONF', 'label', 'MyTape'),
208 "'amtape TESTCONF label MyTape'");
209 like($Installcheck::Run::stderr,
210 qr/label MyTape is now loaded from slot 2/,
213 ok(run('amtape', 'TESTCONF', 'current'),
214 "'amtape TESTCONF current'");
215 like($Installcheck::Run::stderr,
216 qr/slot +2:.*label MyTape/,
219 like(run_err('amtape', 'TESTCONF', 'update'),
220 qr/does not support update/,
221 "'amtape TESTCONF update' fails gracefully");
223 ok(run('amtape', 'TESTCONF', 'show'),
224 "'amtape TESTCONF show'");
225 like($Installcheck::Run::stderr,
226 qr/slot +2:.*label MyTape\nslot +3/,
229 ok(run('amtape', 'TESTCONF', 'inventory'),
230 "'amtape TESTCONF inventory'");
231 like($Installcheck::Run::stdout,
232 qr/slot +1: blank\nslot +2: label MyTape \(current\)\nslot +3/,
235 ok(run('amtape', 'TESTCONF', 'taper'),
236 "'amtape TESTCONF taper'");
237 like($Installcheck::Run::stderr,
238 qr/Will write to volume 'TESTCONF13' in slot 3/,
239 "'amtape TESTCONF taper' ..result correct");
241 Installcheck::Run::cleanup();