Imported Upstream version 3.2.0
[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 => 42;
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     "..result correct");
152
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/,
157     "..result correct");
158
159 ###
160 ## shift to using the new Amanda::Changer::disk
161
162 $testconf->remove_param("tapedev");
163 $testconf->remove_param("tpchanger");
164 $testconf->add_param("tpchanger", "\"chg-disk:" . vtape_dir(). "\"");
165 $testconf->write();
166
167 setup_vtapes();
168
169 ok(run('amtape', 'TESTCONF', 'reset'),
170     "'amtape TESTCONF reset'");
171 like($Installcheck::Run::stderr,
172     qr/changer is reset/,
173     "..result correct");
174
175 ok(run('amtape', 'TESTCONF', 'slot', '2'),
176     "'amtape TESTCONF slot 2'");
177 like($Installcheck::Run::stderr,
178     qr/changed to slot 2/,
179     "..result correct");
180
181 ok(run('amtape', 'TESTCONF', 'slot', 'current'),
182     "'amtape TESTCONF slot current'");
183 like($Installcheck::Run::stderr,
184     qr/changed to slot 2/,
185     "..result correct");
186
187 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
188     "'amtape TESTCONF slot next'");
189 like($Installcheck::Run::stderr,
190     qr/changed to slot 3/,
191     "..result correct");
192
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/,
197     "..result correct");
198
199 ok(run('amtape', 'TESTCONF', 'current'),
200     "'amtape TESTCONF current'");
201 like($Installcheck::Run::stderr,
202     qr/slot +2:.*label MyTape/,
203     "..result correct");
204
205 like(run_err('amtape', 'TESTCONF', 'update'),
206     qr/does not support update/,
207     "'amtape TESTCONF update' fails gracefully");
208
209 ok(run('amtape', 'TESTCONF', 'show'),
210     "'amtape TESTCONF show'");
211 like($Installcheck::Run::stderr,
212     qr/slot +2:.*label MyTape\nslot +3/,
213     "..result correct");
214
215 ok(run('amtape', 'TESTCONF', 'inventory'),
216     "'amtape TESTCONF inventory'");
217 like($Installcheck::Run::stdout,
218     qr/slot +1: blank\nslot +2: label MyTape\nslot +3/,
219     "..result correct");
220
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/,
225     "..result correct");
226
227 Installcheck::Run::cleanup();