Imported Upstream version 3.3.3
[debian/amanda] / installcheck / amtape.pl
1 # Copyright (c) 2009-2012 Zmanda, Inc.  All Rights Reserved.
2 #
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.
7 #
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
11 # for more details.
12 #
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
16 #
17 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19
20 use Test::More tests => 46;
21 use strict;
22 use warnings;
23
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 );
29 use Amanda::Paths;
30 use Amanda::Debug;
31 use Amanda::Tapelist;
32
33 my $testconf;
34
35 Amanda::Debug::dbopen("installcheck");
36 Installcheck::log_test_output();
37
38 $testconf = Installcheck::Run::setup();
39 $testconf->write();
40
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");
46 }
47
48 # label slot 2 with "MyTape", slot 3 with "TESTCONF13", and add
49 # the latter to the tapelist
50 sub setup_vtapes {
51     my ($devdir, $dev);
52
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");
57
58     $dev->start($ACCESS_WRITE, "MyTape", undef)
59         or BAIL_OUT("device error");
60     $dev->finish()
61         or BAIL_OUT("device error");
62
63
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");
68
69     $dev->start($ACCESS_WRITE, "TESTCONF13", undef)
70         or BAIL_OUT("device error");
71     $dev->finish()
72         or BAIL_OUT("device error");
73
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");
77     $tl->write($tlf);
78 }
79
80 like(run_err('amtape'),
81     qr/^Usage:/,
82     "bare 'amtape' gives usage message");
83
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.
89
90 setup_vtapes();
91
92 ok(run('amtape', 'TESTCONF', 'reset'),
93     "'amtape TESTCONF reset'");
94 like($Installcheck::Run::stderr,
95     qr/changer is reset/,
96     "..result correct");
97
98 ok(run('amtape', 'TESTCONF', 'eject'),
99     "'amtape TESTCONF eject'");
100 like($Installcheck::Run::stderr,
101     qr/drive ejected/,
102     "..result correct");
103
104 # TODO: chg-disk doesn't support "clean"
105
106 ok(run('amtape', 'TESTCONF', 'slot', '2'),
107     "'amtape TESTCONF slot 2'");
108 like($Installcheck::Run::stderr,
109     qr/changed to slot 2/,
110     "..result correct");
111
112 ok(run('amtape', 'TESTCONF', 'slot', 'current'),
113     "'amtape TESTCONF slot current'");
114 like($Installcheck::Run::stderr,
115     qr/changed to slot 2/,
116     "..result correct");
117
118 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
119     "'amtape TESTCONF slot next'");
120 like($Installcheck::Run::stderr,
121     qr/changed to slot 3/,
122     "..result correct");
123
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
128     "..result correct");
129
130 ok(run('amtape', 'TESTCONF', 'label', 'MyTape'),
131     "'amtape TESTCONF label MyTape'");
132 like($Installcheck::Run::stderr,
133     qr/slot +2:.*label MyTape/,
134     "..result correct");
135
136 ok(run('amtape', 'TESTCONF', 'current'),
137     "'amtape TESTCONF current'");
138 like($Installcheck::Run::stderr,
139     qr/slot +2:.*label MyTape/,
140     "..result correct");
141
142 ok(run('amtape', 'TESTCONF', 'update'),
143     "'amtape TESTCONF update'");
144 like($Installcheck::Run::stderr,
145     qr/update complete/,
146     "..result correct");
147
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");
153
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");
159
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");
166
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");
172
173 ###
174 ## shift to using the new Amanda::Changer::disk
175
176 $testconf->remove_param("tapedev");
177 $testconf->remove_param("tpchanger");
178 $testconf->add_param("tpchanger", "\"chg-disk:" . vtape_dir(). "\"");
179 $testconf->write();
180
181 setup_vtapes();
182
183 ok(run('amtape', 'TESTCONF', 'reset'),
184     "'amtape TESTCONF reset'");
185 like($Installcheck::Run::stderr,
186     qr/changer is reset/,
187     "..result correct");
188
189 ok(run('amtape', 'TESTCONF', 'slot', '2'),
190     "'amtape TESTCONF slot 2'");
191 like($Installcheck::Run::stderr,
192     qr/changed to slot 2/,
193     "..result correct");
194
195 ok(run('amtape', 'TESTCONF', 'slot', 'current'),
196     "'amtape TESTCONF slot current'");
197 like($Installcheck::Run::stderr,
198     qr/changed to slot 2/,
199     "..result correct");
200
201 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
202     "'amtape TESTCONF slot next'");
203 like($Installcheck::Run::stderr,
204     qr/changed to slot 3/,
205     "..result correct");
206
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/,
211     "..result correct");
212
213 ok(run('amtape', 'TESTCONF', 'current'),
214     "'amtape TESTCONF current'");
215 like($Installcheck::Run::stderr,
216     qr/slot +2:.*label MyTape/,
217     "..result correct");
218
219 like(run_err('amtape', 'TESTCONF', 'update'),
220     qr/does not support update/,
221     "'amtape TESTCONF update' fails gracefully");
222
223 ok(run('amtape', 'TESTCONF', 'show'),
224     "'amtape TESTCONF show'");
225 like($Installcheck::Run::stderr,
226     qr/slot +2:.*label MyTape\nslot +3/,
227     "..result correct");
228
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/,
233     "..result correct");
234
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");
240
241 Installcheck::Run::cleanup();