1 # Copyright (c) 2008, 2009, 2010 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 => 41;
23 use lib "@amperldir@";
25 use Amanda::Config qw( :init :getconf config_dir_relative );
26 use Amanda::Device qw( :constants );
29 use Installcheck::Config;
30 use Installcheck::Run qw(run run_err $diskname);
31 use Installcheck::Dumpcache;
33 Amanda::Debug::dbopen("installcheck");
34 Installcheck::log_test_output();
38 'stdout:', $Installcheck::Run::stdout, '',
39 'stderr:', $Installcheck::Run::stderr));
42 # note: assumes the config is already loaded and takes a config param
43 # to get as a directory and then count all the files in
45 my $conf_param = shift @_;
46 my $dir_name = getconf($conf_param);
52 return if -d $File::Find::name;
57 find($opts, $dir_name);
62 my ($idx_count_pre, $idx_count_post);
65 ## test config overrides
66 Installcheck::Dumpcache::load("notimestamps");
68 config_init($CONFIG_INIT_EXPLICIT_NAME, 'TESTCONF');
71 run(qw(amrmtape -o tapelist=/this/is/a/fake/tapelist TESTCONF TESTCONF01)),
72 "==", 1, "config override run"
76 $Installcheck::Run::stdout, "=~",
77 qr/label 'TESTCONF01' not found in \/this\/is\/a\/fake\/tapelist/,
78 "config overrides handled correctly"
83 Installcheck::Dumpcache::load("notimestamps");
85 config_init($CONFIG_INIT_EXPLICIT_NAME, 'TESTCONF');
86 my $tapelist = Amanda::Tapelist->new(config_dir_relative("tapelist"));
87 ok($tapelist->lookup_tapelabel('TESTCONF01'), "looked up tape after dump");
89 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
91 ok(run('amrmtape', 'TESTCONF', 'TESTCONF01'), "amrmtape runs successfully")
94 $idx_count_post = dir_file_count($CNF_INDEXDIR);
95 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
98 ok(!$tapelist->lookup_tapelabel('TESTCONF01'),
99 "should fail to look up tape that should has been removed");
101 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
103 ok($dev->start($ACCESS_READ, undef, undef),
104 "start device in read mode")
105 or diag($dev->error_or_status());
108 "finish device after starting")
109 or diag($dev->error_or_status());
113 Installcheck::Dumpcache::load("notimestamps");
115 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
117 ok(run('amrmtape', '--cleanup', 'TESTCONF', 'TESTCONF01'),
118 "amrmtape runs successfully with --cleanup")
121 $idx_count_post = dir_file_count($CNF_INDEXDIR);
122 isnt($idx_count_post, $idx_count_pre, "number of index files before and after is different");
125 ok(!$tapelist->lookup_tapelabel('TESTCONF01'),
126 "succesfully looked up tape that should have been removed after --cleanup");
128 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
130 ok($dev->start($ACCESS_READ, undef, undef),
131 "start device in read mode")
132 or diag($dev->error_or_status());
135 "finish device after starting")
136 or diag($dev->error_or_status());
140 Installcheck::Dumpcache::load("notimestamps");
142 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
144 ok(run('amrmtape', '--erase', 'TESTCONF', 'TESTCONF01'),
145 "amrmtape runs successfully with --erase")
148 $idx_count_post = dir_file_count($CNF_INDEXDIR);
149 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
152 ok(!$tapelist->lookup_tapelabel('TESTCONF01'),
153 "succesfully looked up tape that should have been removed after --erase");
155 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
157 ok(!$dev->start($ACCESS_READ, undef, undef),
158 "start device in read mode fails")
159 or diag($dev->error_or_status());
161 # just in case the above does start the device
163 "finish device (just in case)")
164 or diag($dev->error_or_status());
168 Installcheck::Dumpcache::load("notimestamps");
170 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
172 ok(run('amrmtape', '--keep-label', 'TESTCONF', 'TESTCONF01'),
173 "amrmtape runs successfully with --keep-label")
176 $idx_count_post = dir_file_count($CNF_INDEXDIR);
177 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
180 my $tape = $tapelist->lookup_tapelabel('TESTCONF01');
181 ok($tape, "succesfully looked up tape that should still be there");
182 is($tape->{'datestamp'}, "0", "datestamp was zeroed");
184 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
186 ok($dev->start($ACCESS_READ, undef, undef),
187 "start device in read mode")
188 or diag($dev->error_or_status());
191 "finish device after starting")
192 or diag($dev->error_or_status());
194 # test --keep-label --erase
196 Installcheck::Dumpcache::load("notimestamps");
198 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
200 ok(run('amrmtape', '--keep-label', '--erase', 'TESTCONF', 'TESTCONF01'),
201 "amrmtape runs successfully with --keep-label")
204 $idx_count_post = dir_file_count($CNF_INDEXDIR);
205 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
208 $tape = $tapelist->lookup_tapelabel('TESTCONF01');
209 ok($tape, "succesfully looked up tape that should still be there");
210 is($tape->{'datestamp'}, "0", "datestamp was zeroed");
212 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
215 ok(!($dev->status() & $DEVICE_STATUS_VOLUME_UNLABELED),
216 "tape still has label")
217 or diag($dev->error_or_status());
218 is($dev->volume_label, 'TESTCONF01', "label is correct");
220 # test --keep-label --erase
222 Installcheck::Dumpcache::load("notimestamps");
224 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
226 ok(run('amrmtape', '--keep-label', '--erase', 'TESTCONF', 'TESTCONF01'),
227 "amrmtape runs successfully with --keep-label")
230 $idx_count_post = dir_file_count($CNF_INDEXDIR);
231 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
234 $tape = $tapelist->lookup_tapelabel('TESTCONF01');
235 ok($tape, "succesfully looked up tape that should still be there");
236 is($tape->{'datestamp'}, "0", "datestamp was zeroed");
238 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
241 ok(!($dev->status() & $DEVICE_STATUS_VOLUME_UNLABELED),
242 "tape still has label")
243 or diag($dev->error_or_status());
244 is($dev->volume_label, 'TESTCONF01', "label is correct");
246 # test --dryrun --erase --cleanup
248 Installcheck::Dumpcache::load("notimestamps");
250 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
252 ok(run('amrmtape', '--dryrun', '--erase', '--cleanup', 'TESTCONF', 'TESTCONF01'),
253 "amrmtape runs successfully with --dryrun --erase --cleanup")
256 $idx_count_post = dir_file_count($CNF_INDEXDIR);
257 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
260 ok($tapelist->lookup_tapelabel('TESTCONF01'),
261 "succesfully looked up tape that should still be there");
263 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
265 ok($dev->start($ACCESS_READ, undef, undef),
266 "start device in read mode")
267 or diag($dev->error_or_status());
270 "finish device after starting")
271 or diag($dev->error_or_status());
273 Installcheck::Run::cleanup();