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