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