Imported Upstream version 3.2.0
[debian/amanda] / installcheck / mock_mtx.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 => 31;
20 use File::Path;
21 use strict;
22 use warnings;
23
24 use lib "@amperldir@";
25 use Installcheck;
26 use Installcheck::Mock qw( setup_mock_mtx );
27 use Installcheck::Run qw( run run_get run_err );
28
29 my $vtape_root = "$Installcheck::TMP/mock_mtx_vtapes";
30 my $mtx_state_file = setup_mock_mtx (
31          barcodes => 1,
32          track_orig => 1,
33          num_slots => 5,
34          num_drives => 2,
35          num_ie => 1,
36          first_slot => 1,
37          first_drive => 0,
38          first_ie => 6,
39          vtape_root => $vtape_root,
40          loaded_slots => {
41              1 => '023984',
42              3 => '978344',
43          },
44        );
45
46 unless(like(run_get('mock/mtx', '-f', $mtx_state_file, 'inquiry'),
47         qr/Product Type: Medium Changer/,
48         "mtx inquiry")) {
49   SKIP: {
50       skip("mock/mtx seems broken; calling off the test early",
51            Test::More->builder->expected_tests-1);
52     }
53     exit 0;
54 }
55
56 like(run_get('mock/mtx', '-f', $mtx_state_file, 'status'),
57     qr{  Storage Changer .*:2 Drives, 6 Slots \( 1 Import/Export \)
58 Data Transfer Element 0:Empty
59 Data Transfer Element 1:Empty
60       Storage Element 1:Full :VolumeTag=023984
61       Storage Element 2:Empty
62       Storage Element 3:Full :VolumeTag=978344
63       Storage Element 4:Empty
64       Storage Element 5:Empty
65       Storage Element 6 IMPORT/EXPORT:Empty},
66     "mtx status (+BARCODES, +TRACK ORIG)");
67
68 like(run_err('mock/mtx', '-f', $mtx_state_file, 'load', '2', '0'),
69     qr/source Element Address 2 is Empty/,
70     "mtx load 2 0 (slot empty)");
71
72 like(run_err('mock/mtx', '-f', $mtx_state_file, 'unload', '5', '1'),
73     qr/Unloading Data Transfer Element into Storage Element 5...source Element Address.*/,
74     "mtx unload 5 1 (drive empty)");
75
76 like(run_err('mock/mtx', '-f', $mtx_state_file, 'unload', '3', '0'),
77     qr/Storage Element 3 is Already Full/,
78     "mtx unload 5 1 (slot full)");
79
80 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '1', '0'),
81     "mtx load 1 0");
82
83 ok(-d "$vtape_root/drive0/data", "fake vfs drive loaded");
84
85 like(run_get('mock/mtx', '-f', $mtx_state_file, 'status'),
86     qr{  Storage Changer .*:2 Drives, 6 Slots \( 1 Import/Export \)
87 Data Transfer Element 0:Full \(Storage Element 1 Loaded\):VolumeTag=023984
88 Data Transfer Element 1:Empty
89       Storage Element 1:Empty
90       Storage Element 2:Empty
91       Storage Element 3:Full :VolumeTag=978344
92       Storage Element 4:Empty
93       Storage Element 5:Empty
94       Storage Element 6 IMPORT/EXPORT:Empty},
95     "mtx status shows results");
96
97 like(run_err('mock/mtx', '-f', $mtx_state_file, 'load', '3', '0'),
98     qr/Drive 0 Full \(Storage Element 1 Loaded\)/,
99     "mtx load 3 0 (drive full)");
100
101 ok(run('mock/mtx', '-f', $mtx_state_file, 'unload', '2', '0'),
102     "mtx unload 2 0");
103
104 ok(! -d "$vtape_root/drive0/data", "fake vfs drive unloaded");
105 ok(-d "$vtape_root/slot2/data", "fake vfs slot re-populated");
106
107 like(run_get('mock/mtx', '-f', $mtx_state_file, 'status'),
108     qr{  Storage Changer .*:2 Drives, 6 Slots \( 1 Import/Export \)
109 Data Transfer Element 0:Empty
110 Data Transfer Element 1:Empty
111       Storage Element 1:Empty
112       Storage Element 2:Full :VolumeTag=023984
113       Storage Element 3:Full :VolumeTag=978344
114       Storage Element 4:Empty
115       Storage Element 5:Empty
116       Storage Element 6 IMPORT/EXPORT:Empty},
117     "mtx status shows results");
118
119 like(run_err('mock/mtx', '-f', $mtx_state_file, 'transfer', '1', '4'),
120     qr/source Element Address 1 is Empty/,
121     "mtx transfer 1 4 (source empty)");
122
123 like(run_err('mock/mtx', '-f', $mtx_state_file, 'transfer', '2', '3'),
124     qr/destination Element Address 3 is Already Full/,
125     "mtx transfer 1 4 (dest full)");
126
127 ok(run('mock/mtx', '-f', $mtx_state_file, 'transfer', '2', '4'),
128     "mtx transfer 2 4");
129
130 like(run_get('mock/mtx', '-f', $mtx_state_file, 'status'),
131     qr{  Storage Changer .*:2 Drives, 6 Slots \( 1 Import/Export \)
132 Data Transfer Element 0:Empty
133 Data Transfer Element 1:Empty
134       Storage Element 1:Empty
135       Storage Element 2:Empty
136       Storage Element 3:Full :VolumeTag=978344
137       Storage Element 4:Full :VolumeTag=023984
138       Storage Element 5:Empty
139       Storage Element 6 IMPORT/EXPORT:Empty},
140     "mtx status shows results");
141
142 rmtree($vtape_root);
143
144 ##
145 # Without barcodes, with track orig
146
147 $mtx_state_file = setup_mock_mtx (
148          barcodes => 0,
149          track_orig => 1,
150          num_slots => 5,
151          num_drives => 1,
152          first_slot => 1,
153          first_drive => 0,
154          loaded_slots => {
155              1 => '023984',
156              2 => '376524',
157              3 => '983754',
158          },
159        );
160
161 like(run_get('mock/mtx', '-f', $mtx_state_file, 'status'),
162     qr{  Storage Changer .*:1 Drives, 5 Slots \( 0 Import/Export \)
163 Data Transfer Element 0:Empty
164       Storage Element 1:Full
165       Storage Element 2:Full
166       Storage Element 3:Full
167       Storage Element 4:Empty
168       Storage Element 5:Empty},
169     "mtx status (-BARCODES, +TRACK ORIG)");
170
171 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '1', '0'),
172     "mtx load 1 0");
173
174 like(run_get('mock/mtx', '-f', $mtx_state_file, 'status'),
175     qr{  Storage Changer .*:1 Drives, 5 Slots \( 0 Import/Export \)
176 Data Transfer Element 0:Full \(Storage Element 1 Loaded\)
177       Storage Element 1:Empty
178       Storage Element 2:Full
179       Storage Element 3:Full
180       Storage Element 4:Empty
181       Storage Element 5:Empty},
182     "mtx status shows results");
183
184 ##
185 # Without barcodes, without track orig
186
187 $mtx_state_file = setup_mock_mtx (
188          barcodes => 0,
189          track_orig => 0,
190          num_slots => 5,
191          num_drives => 1,
192          first_slot => 1,
193          first_drive => 0,
194          loaded_slots => {
195              1 => '023984',
196              2 => '376524',
197              3 => '983754',
198          },
199        );
200
201 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '1', '0'),
202     "mtx load 1 0 (-BARCODES, -TRACK ORIG)");
203
204 like(run_get('mock/mtx', '-f', $mtx_state_file, 'status'),
205     qr{  Storage Changer .*:1 Drives, 5 Slots \( 0 Import/Export \)
206 Data Transfer Element 0:Full
207       Storage Element 1:Empty
208       Storage Element 2:Full
209       Storage Element 3:Full
210       Storage Element 4:Empty
211       Storage Element 5:Empty},
212     "mtx status shows results");
213
214 ##
215 # With barcodes, without track orig
216
217 $mtx_state_file = setup_mock_mtx (
218          barcodes => 1,
219          track_orig => 0,
220          num_slots => 5,
221          num_drives => 2,
222          first_slot => 1,
223          first_drive => 0,
224          loaded_slots => {
225              2 => '023984',
226              3 => '376524',
227              4 => '983754',
228          },
229        );
230
231 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '2', '1'),
232     "mtx load 2 0 (+BARCODES, -TRACK ORIG)");
233
234 like(run_get('mock/mtx', '-f', $mtx_state_file, 'status'),
235     qr{  Storage Changer .*:2 Drives, 5 Slots \( 0 Import/Export \)
236 Data Transfer Element 0:Empty
237 Data Transfer Element 1:Full :VolumeTag=023984
238       Storage Element 1:Empty
239       Storage Element 2:Empty
240       Storage Element 3:Full :VolumeTag=376524
241       Storage Element 4:Full :VolumeTag=983754
242       Storage Element 5:Empty},
243     "mtx status shows results");
244
245 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '4', '0'),
246     "mtx load 2 0");
247
248 like(run_get('mock/mtx', '-f', $mtx_state_file, 'status'),
249     qr{  Storage Changer .*:2 Drives, 5 Slots \( 0 Import/Export \)
250 Data Transfer Element 0:Full :VolumeTag=983754
251 Data Transfer Element 1:Full :VolumeTag=023984
252       Storage Element 1:Empty
253       Storage Element 2:Empty
254       Storage Element 3:Full :VolumeTag=376524
255       Storage Element 4:Empty
256       Storage Element 5:Empty},
257     "mtx status shows results");
258
259 ##
260 # With barcodes, with weird track orig behavior
261
262 $mtx_state_file = setup_mock_mtx (
263          barcodes => 1,
264          track_orig => -1,
265          num_slots => 5,
266          num_drives => 2,
267          first_slot => 1,
268          first_drive => 0,
269          loaded_slots => {
270              2 => '023984',
271              3 => '376524',
272              4 => '983754',
273          },
274        );
275
276 like(run_get('mock/mtx', '-f', $mtx_state_file, 'status'),
277     qr{  Storage Changer .*:2 Drives, 5 Slots \( 0 Import/Export \)
278 Data Transfer Element 0:Empty
279 Data Transfer Element 1:Empty
280       Storage Element 1:Empty
281       Storage Element 2:Full :VolumeTag=023984
282       Storage Element 3:Full :VolumeTag=376524
283       Storage Element 4:Full :VolumeTag=983754
284       Storage Element 5:Empty},
285     "mtx status (+BARCODES, IMAGINED TRACK ORIG)");
286
287 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '2', '1'),
288     "mtx load 2 0");
289
290 like(run_get('mock/mtx', '-f', $mtx_state_file, 'status'),
291     qr{  Storage Changer .*:2 Drives, 5 Slots \( 0 Import/Export \)
292 Data Transfer Element 0:Empty
293 Data Transfer Element 1:Full \(Storage Element 1 Loaded\):VolumeTag=023984
294       Storage Element 1:Empty
295       Storage Element 2:Empty
296       Storage Element 3:Full :VolumeTag=376524
297       Storage Element 4:Full :VolumeTag=983754
298       Storage Element 5:Empty},
299     "mtx status shows results");
300
301 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '4', '0'),
302     "mtx load 2 0");
303
304 like(run_get('mock/mtx', '-f', $mtx_state_file, 'status'),
305     qr{  Storage Changer .*:2 Drives, 5 Slots \( 0 Import/Export \)
306 Data Transfer Element 0:Full \(Storage Element 1 Loaded\):VolumeTag=983754
307 Data Transfer Element 1:Full \(Storage Element 2 Loaded\):VolumeTag=023984
308       Storage Element 1:Empty
309       Storage Element 2:Empty
310       Storage Element 3:Full :VolumeTag=376524
311       Storage Element 4:Empty
312       Storage Element 5:Empty},
313     "mtx status shows results");