1 # Copyright (c) 2008-2012 Zmanda, Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
20 use Test::More tests => 41;
24 use lib "@amperldir@";
26 use Amanda::Config qw( :init :getconf config_dir_relative );
27 use Amanda::Device qw( :constants );
30 use Installcheck::Config;
31 use Installcheck::Run qw(run run_err $diskname);
32 use Installcheck::Dumpcache;
34 Amanda::Debug::dbopen("installcheck");
35 Installcheck::log_test_output();
39 'stdout:', $Installcheck::Run::stdout, '',
40 'stderr:', $Installcheck::Run::stderr));
43 # note: assumes the config is already loaded and takes a config param
44 # to get as a directory and then count all the files in
46 my $conf_param = shift @_;
47 my $dir_name = getconf($conf_param);
53 return if -d $File::Find::name;
58 find($opts, $dir_name);
63 my ($idx_count_pre, $idx_count_post);
66 ## test config overrides
67 Installcheck::Dumpcache::load("notimestamps");
69 config_init($CONFIG_INIT_EXPLICIT_NAME, 'TESTCONF');
72 run(qw(amrmtape -o tapelist=/this/is/a/fake/tapelist TESTCONF TESTCONF01)),
73 "==", 1, "config override run"
77 $Installcheck::Run::stdout, "=~",
78 qr/label 'TESTCONF01' not found in \/this\/is\/a\/fake\/tapelist/,
79 "config overrides handled correctly"
84 Installcheck::Dumpcache::load("notimestamps");
86 config_init($CONFIG_INIT_EXPLICIT_NAME, 'TESTCONF');
87 my $tapelist = Amanda::Tapelist->new(config_dir_relative("tapelist"));
88 ok($tapelist->lookup_tapelabel('TESTCONF01'), "looked up tape after dump");
90 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
92 ok(run('amrmtape', 'TESTCONF', 'TESTCONF01'), "amrmtape runs successfully")
95 $idx_count_post = dir_file_count($CNF_INDEXDIR);
96 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
99 ok(!$tapelist->lookup_tapelabel('TESTCONF01'),
100 "should fail to look up tape that should has been removed");
102 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
104 ok($dev->start($ACCESS_READ, undef, undef),
105 "start device in read mode")
106 or diag($dev->error_or_status());
109 "finish device after starting")
110 or diag($dev->error_or_status());
114 Installcheck::Dumpcache::load("notimestamps");
116 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
118 ok(run('amrmtape', '--cleanup', 'TESTCONF', 'TESTCONF01'),
119 "amrmtape runs successfully with --cleanup")
122 $idx_count_post = dir_file_count($CNF_INDEXDIR);
123 isnt($idx_count_post, $idx_count_pre, "number of index files before and after is different");
126 ok(!$tapelist->lookup_tapelabel('TESTCONF01'),
127 "succesfully looked up tape that should have been removed after --cleanup");
129 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
131 ok($dev->start($ACCESS_READ, undef, undef),
132 "start device in read mode")
133 or diag($dev->error_or_status());
136 "finish device after starting")
137 or diag($dev->error_or_status());
141 Installcheck::Dumpcache::load("notimestamps");
143 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
145 ok(run('amrmtape', '--erase', 'TESTCONF', 'TESTCONF01'),
146 "amrmtape runs successfully with --erase")
149 $idx_count_post = dir_file_count($CNF_INDEXDIR);
150 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
153 ok(!$tapelist->lookup_tapelabel('TESTCONF01'),
154 "succesfully looked up tape that should have been removed after --erase");
156 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
158 ok(!$dev->start($ACCESS_READ, undef, undef),
159 "start device in read mode fails")
160 or diag($dev->error_or_status());
162 # just in case the above does start the device
164 "finish device (just in case)")
165 or diag($dev->error_or_status());
169 Installcheck::Dumpcache::load("notimestamps");
171 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
173 ok(run('amrmtape', '--keep-label', 'TESTCONF', 'TESTCONF01'),
174 "amrmtape runs successfully with --keep-label")
177 $idx_count_post = dir_file_count($CNF_INDEXDIR);
178 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
181 my $tape = $tapelist->lookup_tapelabel('TESTCONF01');
182 ok($tape, "succesfully looked up tape that should still be there");
183 is($tape->{'datestamp'}, "0", "datestamp was zeroed");
185 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
187 ok($dev->start($ACCESS_READ, undef, undef),
188 "start device in read mode")
189 or diag($dev->error_or_status());
192 "finish device after starting")
193 or diag($dev->error_or_status());
195 # test --keep-label --erase
197 Installcheck::Dumpcache::load("notimestamps");
199 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
201 ok(run('amrmtape', '--keep-label', '--erase', 'TESTCONF', 'TESTCONF01'),
202 "amrmtape runs successfully with --keep-label")
205 $idx_count_post = dir_file_count($CNF_INDEXDIR);
206 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
209 $tape = $tapelist->lookup_tapelabel('TESTCONF01');
210 ok($tape, "succesfully looked up tape that should still be there");
211 is($tape->{'datestamp'}, "0", "datestamp was zeroed");
213 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
216 ok(!($dev->status() & $DEVICE_STATUS_VOLUME_UNLABELED),
217 "tape still has label")
218 or diag($dev->error_or_status());
219 is($dev->volume_label, 'TESTCONF01', "label is correct");
221 # test --keep-label --erase
223 Installcheck::Dumpcache::load("notimestamps");
225 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
227 ok(run('amrmtape', '--keep-label', '--erase', 'TESTCONF', 'TESTCONF01'),
228 "amrmtape runs successfully with --keep-label")
231 $idx_count_post = dir_file_count($CNF_INDEXDIR);
232 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
235 $tape = $tapelist->lookup_tapelabel('TESTCONF01');
236 ok($tape, "succesfully looked up tape that should still be there");
237 is($tape->{'datestamp'}, "0", "datestamp was zeroed");
239 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
242 ok(!($dev->status() & $DEVICE_STATUS_VOLUME_UNLABELED),
243 "tape still has label")
244 or diag($dev->error_or_status());
245 is($dev->volume_label, 'TESTCONF01', "label is correct");
247 # test --dryrun --erase --cleanup
249 Installcheck::Dumpcache::load("notimestamps");
251 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
253 ok(run('amrmtape', '--dryrun', '--erase', '--cleanup', 'TESTCONF', 'TESTCONF01'),
254 "amrmtape runs successfully with --dryrun --erase --cleanup")
257 $idx_count_post = dir_file_count($CNF_INDEXDIR);
258 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
261 ok($tapelist->lookup_tapelabel('TESTCONF01'),
262 "succesfully looked up tape that should still be there");
264 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
266 ok($dev->start($ACCESS_READ, undef, undef),
267 "start device in read mode")
268 or diag($dev->error_or_status());
271 "finish device after starting")
272 or diag($dev->error_or_status());
274 Installcheck::Run::cleanup();