3a2beadb5be8a804de72e40e26e8f468fc5244d6
[debian/amanda] / installcheck / amtape.pl
1 # Copyright (c) 2009 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
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 );
26 use Amanda::Paths;
27 use Amanda::Debug;
28 use Amanda::Tapelist;
29
30 my $testconf;
31
32 Amanda::Debug::dbopen("installcheck");
33 Installcheck::log_test_output();
34
35 $testconf = Installcheck::Run::setup();
36 $testconf->write();
37
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");
43 }
44
45 # label slot 2 with "MyTape", slot 3 with "TESTCONF13", and add
46 # the latter to the tapelist
47 sub setup_vtapes {
48     my ($devdir, $dev);
49
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");
54
55     $dev->start($ACCESS_WRITE, "MyTape", undef)
56         or BAIL_OUT("device error");
57     $dev->finish()
58         or BAIL_OUT("device error");
59
60
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");
65
66     $dev->start($ACCESS_WRITE, "TESTCONF13", undef)
67         or BAIL_OUT("device error");
68     $dev->finish()
69         or BAIL_OUT("device error");
70
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");
74     $tl->write($tlf);
75 }
76
77 like(run_err('amtape'),
78     qr/^Usage:/,
79     "bare 'amtape' gives usage message");
80
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.
86
87 setup_vtapes();
88
89 ok(run('amtape', 'TESTCONF', 'reset'),
90     "'amtape TESTCONF reset'");
91 like($Installcheck::Run::stderr,
92     qr/changer is reset/,
93     "..result correct");
94
95 ok(run('amtape', 'TESTCONF', 'eject'),
96     "'amtape TESTCONF eject'");
97 like($Installcheck::Run::stderr,
98     qr/drive ejected/,
99     "..result correct");
100
101 # TODO: chg-disk doesn't support "clean"
102
103 ok(run('amtape', 'TESTCONF', 'slot', '2'),
104     "'amtape TESTCONF slot 2'");
105 like($Installcheck::Run::stderr,
106     qr/changed to slot 2/,
107     "..result correct");
108
109 ok(run('amtape', 'TESTCONF', 'slot', 'current'),
110     "'amtape TESTCONF slot current'");
111 like($Installcheck::Run::stderr,
112     qr/changed to slot 2/,
113     "..result correct");
114
115 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
116     "'amtape TESTCONF slot next'");
117 like($Installcheck::Run::stderr,
118     qr/changed to slot 3/,
119     "..result correct");
120
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
125     "..result correct");
126
127 ok(run('amtape', 'TESTCONF', 'label', 'MyTape'),
128     "'amtape TESTCONF label MyTape'");
129 like($Installcheck::Run::stderr,
130     qr/slot +2:.*label MyTape/,
131     "..result correct");
132
133 ok(run('amtape', 'TESTCONF', 'current'),
134     "'amtape TESTCONF current'");
135 like($Installcheck::Run::stderr,
136     qr/slot +2:.*label MyTape/,
137     "..result correct");
138
139 ok(run('amtape', 'TESTCONF', 'update'),
140     "'amtape TESTCONF update'");
141 like($Installcheck::Run::stderr,
142     qr/update complete/,
143     "..result correct");
144
145 ok(run('amtape', 'TESTCONF', 'show'),
146     "'amtape TESTCONF show'");
147 like($Installcheck::Run::stderr,
148     qr/slot +2:.*label MyTape\nslot +3/,
149     "..result correct");
150
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/,
155     "..result correct");
156
157 ###
158 ## shift to using the new Amanda::Changer::disk
159
160 $testconf->remove_param("tapedev");
161 $testconf->remove_param("tpchanger");
162 $testconf->add_param("tpchanger", "\"chg-disk:" . vtape_dir(). "\"");
163 $testconf->write();
164
165 setup_vtapes();
166
167 ok(run('amtape', 'TESTCONF', 'reset'),
168     "'amtape TESTCONF reset'");
169 like($Installcheck::Run::stderr,
170     qr/changer is reset/,
171     "..result correct");
172
173 ok(run('amtape', 'TESTCONF', 'slot', '2'),
174     "'amtape TESTCONF slot 2'");
175 like($Installcheck::Run::stderr,
176     qr/changed to slot 2/,
177     "..result correct");
178
179 ok(run('amtape', 'TESTCONF', 'slot', 'current'),
180     "'amtape TESTCONF slot current'");
181 like($Installcheck::Run::stderr,
182     qr/changed to slot 2/,
183     "..result correct");
184
185 ok(run('amtape', 'TESTCONF', 'slot', 'next'),
186     "'amtape TESTCONF slot next'");
187 like($Installcheck::Run::stderr,
188     qr/changed to slot 3/,
189     "..result correct");
190
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/,
195     "..result correct");
196
197 ok(run('amtape', 'TESTCONF', 'current'),
198     "'amtape TESTCONF current'");
199 like($Installcheck::Run::stderr,
200     qr/slot +2:.*label MyTape/,
201     "..result correct");
202
203 like(run_err('amtape', 'TESTCONF', 'update'),
204     qr/does not support update/,
205     "'amtape TESTCONF update' fails gracefully");
206
207 ok(run('amtape', 'TESTCONF', 'show'),
208     "'amtape TESTCONF show'");
209 like($Installcheck::Run::stderr,
210     qr/slot +2:.*label MyTape\nslot +3/,
211     "..result correct");
212
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/,
217     "..result correct");
218
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/,
223     "..result correct");
224
225 Installcheck::Run::cleanup();