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 package Installcheck::Dumpcache;
23 Installcheck::Dumpcache - manage a cached amdump run, to avoid the need to run
24 amdump repeatedly just to test other applications
28 use Installcheck::Dumpcache;
30 Installcheck::Dumpcache::load("basic");
34 This single function will make an amdump run, or at least make it look like one
35 has been done by restoring a cached tarball of a previous run. This saves the
36 time of repeated slow 'amdump' invocations to test functionality that requires
39 The dump cache captures everything: vtapes, curinfo, indexes, trace logs,
40 tapelist, timestamp, and configuration. When a flavor is loaded, the timestamp
41 for all runs are available in the package variable C<@timestamps>.
43 The function C<create_all> is called by the special installcheck '=setupcache',
50 Basic runs a single amdump with the default L<Installcheck::Run> configuration,
51 to which has been added:
53 $testconf->add_dle("localhost $diskname installcheck-test");
55 and a few basic configuration parameters listed below.
59 Like 'basic', but with "usetimestamps" set to "no".
63 Like 'basic', but with an NDMP device. You will need to use
64 L<Installcheck::Mock>'s C<edit_config> to use this.
68 A single multi-part dump with nine parts (using a fallback_splitsize of 128k).
72 A single dump of C<$diskname> with server-side compression enabled. This
76 This flavor runs three dumps of two DLEs (C<$diskname> and C<$diskname/dir>).
77 The first two dumps run normally, while the third is in degraded mode (the
83 use Installcheck::Run qw(run $diskname $taperoot amdump_diag);
84 use Installcheck::Mock;
87 use Amanda::Constants;
88 use File::Path qw( mkpath rmtree );
90 use Cwd qw(abs_path getcwd);
95 my $tarballdir = "$Installcheck::TMP/dumpcache";
101 $testconf->add_param('autolabel', '"TESTCONF%%" EMPTY VOLUME_ERROR');
102 $testconf->add_param('amrecover_changer', '"changer"');
105 sub use_new_chg_disk {
108 $testconf->remove_param('tapedev');
109 $testconf->remove_param('tpchanger');
110 $testconf->add_param('tpchanger', "\"chg-disk:$taperoot\"");
113 $flavors{'basic'} = sub {
114 my $testconf = Installcheck::Run::setup();
115 basic_settings($testconf);
116 use_new_chg_disk($testconf);
117 $testconf->add_dle("localhost $diskname installcheck-test");
120 ok(Installcheck::Run::run('amdump', 'TESTCONF'), "amdump for 'basic'"),
121 or amdump_diag("Amdump run failed for 'basic'");
124 $flavors{'notimestamps'} = sub {
125 my $testconf = Installcheck::Run::setup();
126 basic_settings($testconf);
127 use_new_chg_disk($testconf);
128 $testconf->add_dle("localhost $diskname installcheck-test");
129 $testconf->add_param('usetimestamps', 'no');
132 ok(Installcheck::Run::run('amdump', 'TESTCONF'), "amdump for 'notimestamps'"),
133 or amdump_diag("Amdump run failed for 'notimestamps'");
136 $flavors{'multi'} = sub {
137 my $stuff = "abcdefghijkl" x 512;
138 my $append_stuff = sub {
139 open(my $fh, ">>", "$diskname/extrastuff");
140 print $fh $stuff, $stuff;
143 open($fh, ">>", "$diskname/dir/extrastuff");
144 print $fh $stuff, $stuff;
148 my $testconf = Installcheck::Run::setup();
149 basic_settings($testconf);
150 use_new_chg_disk($testconf);
151 $testconf->add_dle("localhost $diskname installcheck-test");
152 $testconf->add_dle("localhost $diskname/dir installcheck-test");
153 # do the smallest dumps first -- $diskname/dir in particular should
154 # be smaller than $diskname
155 $testconf->add_param("dumporder", '"ssssssssss"');
158 ok(Installcheck::Run::run('amdump', 'TESTCONF'), "amdump for 'multi' step 1"),
159 or amdump_diag("Amdump run failed for 'multi' step 1");
163 # XXX note that Amanda will not bump $diskname to level 1 here; other installchecks
164 # may depend on this behavior
165 ok(Installcheck::Run::run('amdump', 'TESTCONF'), "amdump for 'multi' step 2"),
166 or amdump_diag("Amdump run failed for 'multi' step 2");
170 ok(Installcheck::Run::run('amdump', 'TESTCONF', '-otpchanger=', '-otapedev='),
171 "amdump for 'multi' step 3 (degraded mode)"),
172 or amdump_diag("Amdump run failed for 'multi' step 3 (degraded mode)");
174 # we made a mess of $diskname, so invalidate it
178 $flavors{'parts'} = sub {
179 my $testconf = Installcheck::Run::setup();
180 basic_settings($testconf);
181 use_new_chg_disk($testconf);
182 $testconf->add_tapetype("TEST-TAPE", [
185 "part_cache_type", "memory",
187 $testconf->add_dle("localhost $diskname installcheck-test");
190 ok(Installcheck::Run::run('amdump', 'TESTCONF'), "amdump for 'parts'"),
191 or amdump_diag("Amdump run failed for 'part'");
194 $flavors{'compress'} = sub {
195 my $testconf = Installcheck::Run::setup();
196 basic_settings($testconf);
197 use_new_chg_disk($testconf);
198 $testconf->add_dumptype("installcheck-test-comp", [
199 "installcheck-test", "",
200 "compress", "server fast",
202 $testconf->add_dle("localhost $diskname installcheck-test-comp");
205 # add some compressible data to the dump
206 open(my $fh, ">>", "$diskname/compressible");
207 my $stuff = <<EOLOREM;
208 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
209 incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
210 nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
211 Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
212 fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
213 culpa qui officia deserunt mollit anim id est laborum.
215 for my $i (1 .. 100) {
216 print $fh $stuff, $stuff;
220 ok(Installcheck::Run::run('amdump', 'TESTCONF'), "amdump for 'compress'"),
221 or amdump_diag("Amdump run failed for 'part'");
223 # we made a mess of $diskname, so invalidate it
227 if (Amanda::Util::built_with_component("server")
228 and Amanda::Util::built_with_component("ndmp")) {
230 $flavors{'ndmp'} = sub {
231 my $testconf = Installcheck::Run::setup();
232 basic_settings($testconf);
233 use_new_chg_disk($testconf);
234 $testconf->add_dle("localhost $diskname installcheck-test");
235 my $ndmp = Installcheck::Mock::NdmpServer->new();
236 $ndmp->config($testconf);
239 ok(Installcheck::Run::run('amdump', 'TESTCONF'), "amdump for 'ndmp'"),
240 or amdump_diag("Amdump run failed for 'ndmp'");
244 sub generate_and_store {
247 if (exists $flavors{$flavor}) {
248 $flavors{$flavor}->();
250 die("Invalid flavor '$flavor'");
253 # now package that up as a tarball
255 my $tmp_tarball = "$tarballdir/$flavor-tmp.tgz";
256 my $conf_tarball = "$tarballdir/$flavor-conf.tgz";
258 if (system("$Amanda::Constants::GNUTAR",
259 "-C", "$Installcheck::TMP",
260 "-zcf", "$tmp_tarball",
263 diag("Error caching dump results (ignored): $?");
267 if (system("$Amanda::Constants::GNUTAR",
269 "-zcf", "$conf_tarball",
271 diag("Error caching dump results (ignored): $?");
281 croak("Invalid flavor '$flavor'") unless (exists $flavors{$flavor});
283 # clean up any remnants first
284 Installcheck::Run::cleanup();
286 my $tmp_tarball = "$tarballdir/$flavor-tmp.tgz";
287 my $conf_tarball = "$tarballdir/$flavor-conf.tgz";
289 if (! -f $tmp_tarball || ! -f $conf_tarball) {
290 die "Cached dump '$flavor' is not available. Re-run the '=setupcache' check";
292 if (system("$Amanda::Constants::GNUTAR",
293 "-zxf", "$tmp_tarball",
294 "-C", "$Installcheck::TMP")) {
295 die("Error untarring dump results: $?");
298 if (system("$Amanda::Constants::GNUTAR",
299 "-zxf", "$conf_tarball",
300 "-C", "$CONFIG_DIR")) {
301 die("Error untarring dump results: $?");
304 # calculate the timestamps for this run
305 my @logfiles = glob "$CONFIG_DIR/TESTCONF/log/log.*";
306 my %timestamps = map { my ($ts) = ($_ =~ /log\.(\d+)\./); $ts?($ts, 1):() } @logfiles;
307 @timestamps = keys %timestamps; # set package variable
311 for my $flavor (keys %flavors) {
312 ok(generate_and_store($flavor), "cached flavor '$flavor'") or return;
316 Installcheck::Run::cleanup();