1 # Copyright (c) 2009 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;
21 use lib "@amperldir@";
22 use Installcheck::Config;
23 use Installcheck::Run qw(run run_err run_get load_vtape vtape_dir);
24 use Amanda::Device qw( :constants );
25 use Amanda::Config qw( :init :getconf );
32 Amanda::Debug::dbopen("installcheck");
33 Installcheck::log_test_output();
35 $testconf = Installcheck::Run::setup();
38 config_init($CONFIG_INIT_EXPLICIT_NAME, "TESTCONF");
39 my ($cfgerr_level, @cfgerr_errors) = config_errors();
40 if ($cfgerr_level >= $CFGERR_WARNINGS) {
41 config_print_errors();
42 BAIL_OUT("config errors");
45 # label slot 2 with "MyTape", slot 3 with "TESTCONF13", and add
46 # the latter to the tapelist
50 $devdir = load_vtape(2);
51 $dev = Amanda::Device->new("file:$devdir");
52 ($dev && $dev->status == $DEVICE_STATUS_SUCCESS)
53 or BAIL_OUT("device error");
55 $dev->start($ACCESS_WRITE, "MyTape", undef)
56 or BAIL_OUT("device error");
58 or BAIL_OUT("device error");
61 $devdir = load_vtape(3);
62 $dev = Amanda::Device->new("file:$devdir");
63 ($dev && $dev->status == $DEVICE_STATUS_SUCCESS)
64 or BAIL_OUT("device error");
66 $dev->start($ACCESS_WRITE, "TESTCONF13", undef)
67 or BAIL_OUT("device error");
69 or BAIL_OUT("device error");
71 my $tlf = Amanda::Config::config_dir_relative(getconf($CNF_TAPELIST));
72 my $tl = Amanda::Tapelist::read_tapelist($tlf);
73 $tl->add_tapelabel("0", "TESTCONF13", "test tape");
77 like(run_err('amtape'),
79 "bare 'amtape' gives usage message");
81 # in general, output goes to stderr, so we can't use run_get. These checks
82 # accomplish two things: ensure that amtape can invoke the changer functions
83 # correctly (and not generate an error), and ensure that it gives the
84 # appropriate responses. It does not exercise the changer itself -- most
85 # of these operations are meaningless for vtapes, anyway.
89 ok(run('amtape', 'TESTCONF', 'reset'),
90 "'amtape TESTCONF reset'");
91 like($Installcheck::Run::stderr,
95 ok(run('amtape', 'TESTCONF', 'eject'),
96 "'amtape TESTCONF eject'");
97 like($Installcheck::Run::stderr,
101 # TODO: chg-disk doesn't support "clean"
103 ok(run('amtape', 'TESTCONF', 'slot', '2'),
104 "'amtape TESTCONF slot 2'");
105 like($Installcheck::Run::stderr,
106 qr/changed to slot 2/,
109 ok(run('amtape', 'TESTCONF', 'slot', 'current'),
110 "'amtape TESTCONF slot current'");
111 like($Installcheck::Run::stderr,
112 qr/changed to slot 2/,
115 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
116 "'amtape TESTCONF slot next'");
117 like($Installcheck::Run::stderr,
118 qr/changed to slot 3/,
121 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
122 "'amtape TESTCONF slot next'");
123 like($Installcheck::Run::stderr,
124 qr/changed to slot 1/, # loop around to slot 1
127 ok(run('amtape', 'TESTCONF', 'label', 'MyTape'),
128 "'amtape TESTCONF label MyTape'");
129 like($Installcheck::Run::stderr,
130 qr/slot +2:.*label MyTape/,
133 ok(run('amtape', 'TESTCONF', 'current'),
134 "'amtape TESTCONF current'");
135 like($Installcheck::Run::stderr,
136 qr/slot +2:.*label MyTape/,
139 ok(run('amtape', 'TESTCONF', 'update'),
140 "'amtape TESTCONF update'");
141 like($Installcheck::Run::stderr,
145 ok(run('amtape', 'TESTCONF', 'show'),
146 "'amtape TESTCONF show'");
147 like($Installcheck::Run::stderr,
148 qr/slot +2:.*label MyTape\nslot +3/,
151 ok(run('amtape', 'TESTCONF', 'taper'),
152 "'amtape TESTCONF taper'");
153 like($Installcheck::Run::stderr,
154 qr/Will write to volume TESTCONF13 in slot 3/,
158 ## shift to using the new Amanda::Changer::disk
160 $testconf->remove_param("tapedev");
161 $testconf->remove_param("tpchanger");
162 $testconf->add_param("tpchanger", "\"chg-disk:" . vtape_dir(). "\"");
167 ok(run('amtape', 'TESTCONF', 'reset'),
168 "'amtape TESTCONF reset'");
169 like($Installcheck::Run::stderr,
170 qr/changer is reset/,
173 ok(run('amtape', 'TESTCONF', 'slot', '2'),
174 "'amtape TESTCONF slot 2'");
175 like($Installcheck::Run::stderr,
176 qr/changed to slot 2/,
179 ok(run('amtape', 'TESTCONF', 'slot', 'current'),
180 "'amtape TESTCONF slot current'");
181 like($Installcheck::Run::stderr,
182 qr/changed to slot 2/,
185 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
186 "'amtape TESTCONF slot next'");
187 like($Installcheck::Run::stderr,
188 qr/changed to slot 3/,
191 ok(run('amtape', 'TESTCONF', 'label', 'MyTape'),
192 "'amtape TESTCONF label MyTape'");
193 like($Installcheck::Run::stderr,
194 qr/label MyTape is now loaded from slot 2/,
197 ok(run('amtape', 'TESTCONF', 'current'),
198 "'amtape TESTCONF current'");
199 like($Installcheck::Run::stderr,
200 qr/slot +2:.*label MyTape/,
203 like(run_err('amtape', 'TESTCONF', 'update'),
204 qr/does not support update/,
205 "'amtape TESTCONF update' fails gracefully");
207 ok(run('amtape', 'TESTCONF', 'show'),
208 "'amtape TESTCONF show'");
209 like($Installcheck::Run::stderr,
210 qr/slot +2:.*label MyTape\nslot +3/,
213 ok(run('amtape', 'TESTCONF', 'inventory'),
214 "'amtape TESTCONF inventory'");
215 like($Installcheck::Run::stdout,
216 qr/slot +1: blank\nslot +2: label MyTape\nslot +3/,
219 ok(run('amtape', 'TESTCONF', 'taper'),
220 "'amtape TESTCONF taper'");
221 like($Installcheck::Run::stderr,
222 qr/Will write to volume TESTCONF13 in slot 3/,
225 Installcheck::Run::cleanup();