1 # Copyright (c) 2009-2012 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 => 46;
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 );
34 Amanda::Debug::dbopen("installcheck");
35 Installcheck::log_test_output();
37 $testconf = Installcheck::Run::setup();
40 config_init($CONFIG_INIT_EXPLICIT_NAME, "TESTCONF");
41 my ($cfgerr_level, @cfgerr_errors) = config_errors();
42 if ($cfgerr_level >= $CFGERR_WARNINGS) {
43 config_print_errors();
44 BAIL_OUT("config errors");
47 # label slot 2 with "MyTape", slot 3 with "TESTCONF13", and add
48 # the latter to the tapelist
52 $devdir = load_vtape(2);
53 $dev = Amanda::Device->new("file:$devdir");
54 ($dev && $dev->status == $DEVICE_STATUS_SUCCESS)
55 or BAIL_OUT("device error");
57 $dev->start($ACCESS_WRITE, "MyTape", undef)
58 or BAIL_OUT("device error");
60 or BAIL_OUT("device error");
63 $devdir = load_vtape(3);
64 $dev = Amanda::Device->new("file:$devdir");
65 ($dev && $dev->status == $DEVICE_STATUS_SUCCESS)
66 or BAIL_OUT("device error");
68 $dev->start($ACCESS_WRITE, "TESTCONF13", undef)
69 or BAIL_OUT("device error");
71 or BAIL_OUT("device error");
73 my $tlf = Amanda::Config::config_dir_relative(getconf($CNF_TAPELIST));
74 my $tl = Amanda::Tapelist->new($tlf, 1);
75 $tl->add_tapelabel("0", "TESTCONF13", "test tape");
79 like(run_err('amtape'),
81 "bare 'amtape' gives usage message");
83 # in general, output goes to stderr, so we can't use run_get. These checks
84 # accomplish two things: ensure that amtape can invoke the changer functions
85 # correctly (and not generate an error), and ensure that it gives the
86 # appropriate responses. It does not exercise the changer itself -- most
87 # of these operations are meaningless for vtapes, anyway.
91 ok(run('amtape', 'TESTCONF', 'reset'),
92 "'amtape TESTCONF reset'");
93 like($Installcheck::Run::stderr,
97 ok(run('amtape', 'TESTCONF', 'eject'),
98 "'amtape TESTCONF eject'");
99 like($Installcheck::Run::stderr,
103 # TODO: chg-disk doesn't support "clean"
105 ok(run('amtape', 'TESTCONF', 'slot', '2'),
106 "'amtape TESTCONF slot 2'");
107 like($Installcheck::Run::stderr,
108 qr/changed to slot 2/,
111 ok(run('amtape', 'TESTCONF', 'slot', 'current'),
112 "'amtape TESTCONF slot current'");
113 like($Installcheck::Run::stderr,
114 qr/changed to slot 2/,
117 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
118 "'amtape TESTCONF slot next'");
119 like($Installcheck::Run::stderr,
120 qr/changed to slot 3/,
123 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
124 "'amtape TESTCONF slot next'");
125 like($Installcheck::Run::stderr,
126 qr/changed to slot 1/, # loop around to slot 1
129 ok(run('amtape', 'TESTCONF', 'label', 'MyTape'),
130 "'amtape TESTCONF label MyTape'");
131 like($Installcheck::Run::stderr,
132 qr/slot +2:.*label MyTape/,
135 ok(run('amtape', 'TESTCONF', 'current'),
136 "'amtape TESTCONF current'");
137 like($Installcheck::Run::stderr,
138 qr/slot +2:.*label MyTape/,
141 ok(run('amtape', 'TESTCONF', 'update'),
142 "'amtape TESTCONF update'");
143 like($Installcheck::Run::stderr,
147 ok(run('amtape', 'TESTCONF', 'show'),
148 "'amtape TESTCONF show'");
149 like($Installcheck::Run::stderr,
150 qr/slot +2:.*label MyTape\nslot +3/,
151 "'amtape TESTCONF show' ..result correct");
153 ok(run('amtape', 'TESTCONF', 'show', '2'),
154 "'amtape TESTCONF show'");
155 like($Installcheck::Run::stderr,
156 qr/^slot +2:.*label MyTape$/,
157 "'amtape TESTCONF show 2' ..result correct");
159 ok(run('amtape', 'TESTCONF', 'show', '1,3'),
160 "'amtape TESTCONF show'");
161 like($Installcheck::Run::stderr,
162 qr/^slot +1: unlabeled volume\nslot +3: date \d{14} label TESTCONF13$/,
163 # qr/slot +1: unlabeled volume\nslot +3: date 20111121133419 label TESTCONF13/,
164 "'amtape TESTCONF show 1,3' ..result correct");
166 ok(run('amtape', 'TESTCONF', 'taper'),
167 "'amtape TESTCONF taper'");
168 like($Installcheck::Run::stderr,
169 qr/Will write to volume 'TESTCONF13' in slot 3/,
170 "'amtape TESTCONF taper' ..result correct");
173 ## shift to using the new Amanda::Changer::disk
175 $testconf->remove_param("tapedev");
176 $testconf->remove_param("tpchanger");
177 $testconf->add_param("tpchanger", "\"chg-disk:" . vtape_dir(). "\"");
182 ok(run('amtape', 'TESTCONF', 'reset'),
183 "'amtape TESTCONF reset'");
184 like($Installcheck::Run::stderr,
185 qr/changer is reset/,
188 ok(run('amtape', 'TESTCONF', 'slot', '2'),
189 "'amtape TESTCONF slot 2'");
190 like($Installcheck::Run::stderr,
191 qr/changed to slot 2/,
194 ok(run('amtape', 'TESTCONF', 'slot', 'current'),
195 "'amtape TESTCONF slot current'");
196 like($Installcheck::Run::stderr,
197 qr/changed to slot 2/,
200 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
201 "'amtape TESTCONF slot next'");
202 like($Installcheck::Run::stderr,
203 qr/changed to slot 3/,
206 ok(run('amtape', 'TESTCONF', 'label', 'MyTape'),
207 "'amtape TESTCONF label MyTape'");
208 like($Installcheck::Run::stderr,
209 qr/label MyTape is now loaded from slot 2/,
212 ok(run('amtape', 'TESTCONF', 'current'),
213 "'amtape TESTCONF current'");
214 like($Installcheck::Run::stderr,
215 qr/slot +2:.*label MyTape/,
218 like(run_err('amtape', 'TESTCONF', 'update'),
219 qr/does not support update/,
220 "'amtape TESTCONF update' fails gracefully");
222 ok(run('amtape', 'TESTCONF', 'show'),
223 "'amtape TESTCONF show'");
224 like($Installcheck::Run::stderr,
225 qr/slot +2:.*label MyTape\nslot +3/,
228 ok(run('amtape', 'TESTCONF', 'inventory'),
229 "'amtape TESTCONF inventory'");
230 like($Installcheck::Run::stdout,
231 qr/slot +1: blank\nslot +2: label MyTape \(current\)\nslot +3/,
234 ok(run('amtape', 'TESTCONF', 'taper'),
235 "'amtape TESTCONF taper'");
236 like($Installcheck::Run::stderr,
237 qr/Will write to volume 'TESTCONF13' in slot 3/,
238 "'amtape TESTCONF taper' ..result correct");
240 Installcheck::Run::cleanup();