1 # Copyright (c) 2008,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 => 41;
21 use lib "@amperldir@";
23 use Amanda::Config qw( :init :getconf config_dir_relative );
24 use Amanda::Device qw( :constants );
27 use Installcheck::Config;
28 use Installcheck::Run qw(run run_err $diskname);
29 use Installcheck::Dumpcache;
31 Amanda::Debug::dbopen("installcheck");
32 Installcheck::log_test_output();
36 'stdout:', $Installcheck::Run::stdout, '',
37 'stderr:', $Installcheck::Run::stderr));
40 # note: assumes the config is already loaded and takes a config param
41 # to get as a directory and then count all the files in
43 my $conf_param = shift @_;
44 my $dir_name = getconf($conf_param);
50 return if -d $File::Find::name;
55 find($opts, $dir_name);
60 my ($idx_count_pre, $idx_count_post);
63 ## test config overrides
64 Installcheck::Dumpcache::load("notimestamps");
66 config_init($CONFIG_INIT_EXPLICIT_NAME, 'TESTCONF');
69 run(qw(amrmtape -o tapelist="/this/is/a/fake/tapelist" TESTCONF TESTCONF01)),
70 "==", 0, "config override run"
74 $Installcheck::Run::stderr, "=~",
75 qr/amrmtape: Could not read the tapelist/,
76 "config overrides handled correctly"
81 Installcheck::Dumpcache::load("notimestamps");
83 config_init($CONFIG_INIT_EXPLICIT_NAME, 'TESTCONF');
84 my $tapelist = Amanda::Tapelist::read_tapelist(config_dir_relative("tapelist"));
85 ok($tapelist->lookup_tapelabel('TESTCONF01'), "looked up tape after dump");
87 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
89 ok(run('amrmtape', 'TESTCONF', 'TESTCONF01'), "amrmtape runs successfully")
92 $idx_count_post = dir_file_count($CNF_INDEXDIR);
93 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
95 $tapelist = Amanda::Tapelist::read_tapelist(config_dir_relative("tapelist"));
96 ok(!$tapelist->lookup_tapelabel('TESTCONF01'),
97 "should fail to look up tape that should has been removed");
99 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
101 ok($dev->start($ACCESS_READ, undef, undef),
102 "start device in read mode")
103 or diag($dev->error_or_status());
106 "finish device after starting")
107 or diag($dev->error_or_status());
111 Installcheck::Dumpcache::load("notimestamps");
113 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
115 ok(run('amrmtape', '--cleanup', 'TESTCONF', 'TESTCONF01'),
116 "amrmtape runs successfully with --cleanup")
119 $idx_count_post = dir_file_count($CNF_INDEXDIR);
120 isnt($idx_count_post, $idx_count_pre, "number of index files before and after is different");
122 $tapelist = Amanda::Tapelist::read_tapelist(config_dir_relative("tapelist"));
123 ok(!$tapelist->lookup_tapelabel('TESTCONF01'),
124 "succesfully looked up tape that should have been removed after --cleanup");
126 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
128 ok($dev->start($ACCESS_READ, undef, undef),
129 "start device in read mode")
130 or diag($dev->error_or_status());
133 "finish device after starting")
134 or diag($dev->error_or_status());
138 Installcheck::Dumpcache::load("notimestamps");
140 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
142 ok(run('amrmtape', '--erase', 'TESTCONF', 'TESTCONF01'),
143 "amrmtape runs successfully with --erase")
146 $idx_count_post = dir_file_count($CNF_INDEXDIR);
147 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
149 $tapelist = Amanda::Tapelist::read_tapelist(config_dir_relative("tapelist"));
150 ok(!$tapelist->lookup_tapelabel('TESTCONF01'),
151 "succesfully looked up tape that should have been removed after --erase");
153 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
155 ok(!$dev->start($ACCESS_READ, undef, undef),
156 "start device in read mode fails")
157 or diag($dev->error_or_status());
159 # just in case the above does start the device
161 "finish device (just in case)")
162 or diag($dev->error_or_status());
166 Installcheck::Dumpcache::load("notimestamps");
168 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
170 ok(run('amrmtape', '--keep-label', 'TESTCONF', 'TESTCONF01'),
171 "amrmtape runs successfully with --keep-label")
174 $idx_count_post = dir_file_count($CNF_INDEXDIR);
175 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
177 $tapelist = Amanda::Tapelist::read_tapelist(config_dir_relative("tapelist"));
178 my $tape = $tapelist->lookup_tapelabel('TESTCONF01');
179 ok($tape, "succesfully looked up tape that should still be there");
180 is($tape->{'datestamp'}, "0", "datestamp was zeroed");
182 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
184 ok($dev->start($ACCESS_READ, undef, undef),
185 "start device in read mode")
186 or diag($dev->error_or_status());
189 "finish device after starting")
190 or diag($dev->error_or_status());
192 # test --keep-label --erase
194 Installcheck::Dumpcache::load("notimestamps");
196 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
198 ok(run('amrmtape', '--keep-label', '--erase', 'TESTCONF', 'TESTCONF01'),
199 "amrmtape runs successfully with --keep-label")
202 $idx_count_post = dir_file_count($CNF_INDEXDIR);
203 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
205 $tapelist = Amanda::Tapelist::read_tapelist(config_dir_relative("tapelist"));
206 $tape = $tapelist->lookup_tapelabel('TESTCONF01');
207 ok($tape, "succesfully looked up tape that should still be there");
208 is($tape->{'datestamp'}, "0", "datestamp was zeroed");
210 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
213 ok(!($dev->status() & $DEVICE_STATUS_VOLUME_UNLABELED),
214 "tape still has label")
215 or diag($dev->error_or_status());
216 is($dev->volume_label, 'TESTCONF01', "label is correct");
218 # test --keep-label --erase
220 Installcheck::Dumpcache::load("notimestamps");
222 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
224 ok(run('amrmtape', '--keep-label', '--erase', 'TESTCONF', 'TESTCONF01'),
225 "amrmtape runs successfully with --keep-label")
228 $idx_count_post = dir_file_count($CNF_INDEXDIR);
229 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
231 $tapelist = Amanda::Tapelist::read_tapelist(config_dir_relative("tapelist"));
232 $tape = $tapelist->lookup_tapelabel('TESTCONF01');
233 ok($tape, "succesfully looked up tape that should still be there");
234 is($tape->{'datestamp'}, "0", "datestamp was zeroed");
236 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
239 ok(!($dev->status() & $DEVICE_STATUS_VOLUME_UNLABELED),
240 "tape still has label")
241 or diag($dev->error_or_status());
242 is($dev->volume_label, 'TESTCONF01', "label is correct");
244 # test --dryrun --erase --cleanup
246 Installcheck::Dumpcache::load("notimestamps");
248 $idx_count_pre = dir_file_count($CNF_INDEXDIR);
250 ok(run('amrmtape', '--dryrun', '--erase', '--cleanup', 'TESTCONF', 'TESTCONF01'),
251 "amrmtape runs successfully with --dryrun --erase --cleanup")
254 $idx_count_post = dir_file_count($CNF_INDEXDIR);
255 is($idx_count_post, $idx_count_pre, "number of index files before and after is the same");
257 $tapelist = Amanda::Tapelist::read_tapelist(config_dir_relative("tapelist"));
258 ok($tapelist->lookup_tapelabel('TESTCONF01'),
259 "succesfully looked up tape that should still be there");
261 $dev = Amanda::Device->new('file:' . Installcheck::Run::vtape_dir());
263 ok($dev->start($ACCESS_READ, undef, undef),
264 "start device in read mode")
265 or diag($dev->error_or_status());
268 "finish device after starting")
269 or diag($dev->error_or_status());
271 Installcheck::Run::cleanup();