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 => 42;
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/,
153 ok(run('amtape', 'TESTCONF', 'taper'),
154 "'amtape TESTCONF taper'");
155 like($Installcheck::Run::stderr,
156 qr/Will write to volume TESTCONF13 in slot 3/,
160 ## shift to using the new Amanda::Changer::disk
162 $testconf->remove_param("tapedev");
163 $testconf->remove_param("tpchanger");
164 $testconf->add_param("tpchanger", "\"chg-disk:" . vtape_dir(). "\"");
169 ok(run('amtape', 'TESTCONF', 'reset'),
170 "'amtape TESTCONF reset'");
171 like($Installcheck::Run::stderr,
172 qr/changer is reset/,
175 ok(run('amtape', 'TESTCONF', 'slot', '2'),
176 "'amtape TESTCONF slot 2'");
177 like($Installcheck::Run::stderr,
178 qr/changed to slot 2/,
181 ok(run('amtape', 'TESTCONF', 'slot', 'current'),
182 "'amtape TESTCONF slot current'");
183 like($Installcheck::Run::stderr,
184 qr/changed to slot 2/,
187 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
188 "'amtape TESTCONF slot next'");
189 like($Installcheck::Run::stderr,
190 qr/changed to slot 3/,
193 ok(run('amtape', 'TESTCONF', 'label', 'MyTape'),
194 "'amtape TESTCONF label MyTape'");
195 like($Installcheck::Run::stderr,
196 qr/label MyTape is now loaded from slot 2/,
199 ok(run('amtape', 'TESTCONF', 'current'),
200 "'amtape TESTCONF current'");
201 like($Installcheck::Run::stderr,
202 qr/slot +2:.*label MyTape/,
205 like(run_err('amtape', 'TESTCONF', 'update'),
206 qr/does not support update/,
207 "'amtape TESTCONF update' fails gracefully");
209 ok(run('amtape', 'TESTCONF', 'show'),
210 "'amtape TESTCONF show'");
211 like($Installcheck::Run::stderr,
212 qr/slot +2:.*label MyTape\nslot +3/,
215 ok(run('amtape', 'TESTCONF', 'inventory'),
216 "'amtape TESTCONF inventory'");
217 like($Installcheck::Run::stdout,
218 qr/slot +1: blank\nslot +2: label MyTape \(current\)\nslot +3/,
221 ok(run('amtape', 'TESTCONF', 'taper'),
222 "'amtape TESTCONF taper'");
223 like($Installcheck::Run::stderr,
224 qr/Will write to volume TESTCONF13 in slot 3/,
227 Installcheck::Run::cleanup();