1 # Copyright (c) 2009 Zmanda, Inc. All Rights Reserved.
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.
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
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
16 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19 use Test::More tests => 31;
23 use lib "@amperldir@";
25 use Installcheck::Mock qw( setup_mock_mtx );
26 use Installcheck::Run qw( run run_get run_err );
28 my $vtape_root = "$Installcheck::TMP/mock_mtx_vtapes";
29 my $mtx_state_file = setup_mock_mtx (
38 vtape_root => $vtape_root,
45 unless(like(run_get('mock/mtx', '-f', $mtx_state_file, 'inquiry'),
46 qr/Product Type: Medium Changer/,
49 skip("mock/mtx seems broken; calling off the test early",
50 Test::More->builder->expected_tests-1);
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)");
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)");
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)");
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)");
79 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '1', '0'),
82 ok(-d "$vtape_root/drive0/data", "fake vfs drive loaded");
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");
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)");
100 ok(run('mock/mtx', '-f', $mtx_state_file, 'unload', '2', '0'),
103 ok(! -d "$vtape_root/drive0/data", "fake vfs drive unloaded");
104 ok(-d "$vtape_root/slot2/data", "fake vfs slot re-populated");
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");
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)");
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)");
126 ok(run('mock/mtx', '-f', $mtx_state_file, 'transfer', '2', '4'),
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");
144 # Without barcodes, with track orig
146 $mtx_state_file = setup_mock_mtx (
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)");
170 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '1', '0'),
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");
184 # Without barcodes, without track orig
186 $mtx_state_file = setup_mock_mtx (
200 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '1', '0'),
201 "mtx load 1 0 (-BARCODES, -TRACK ORIG)");
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");
214 # With barcodes, without track orig
216 $mtx_state_file = setup_mock_mtx (
230 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '2', '1'),
231 "mtx load 2 0 (+BARCODES, -TRACK ORIG)");
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");
244 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '4', '0'),
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");
259 # With barcodes, with weird track orig behavior
261 $mtx_state_file = setup_mock_mtx (
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)");
286 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '2', '1'),
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");
300 ok(run('mock/mtx', '-f', $mtx_state_file, 'load', '4', '0'),
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");