X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=installcheck%2Famcheckdump.pl;h=65919111ae49f191c7ee95402b78af17e8ae0c3d;hb=2627875b7d18858bc1f9f7652811e4d8c15a23eb;hp=ff6a150cfdd62b3f2dcfbcb221f6667850634ff7;hpb=fb2bd066c2f8b34addafe48d62550e3033a59431;p=debian%2Famanda diff --git a/installcheck/amcheckdump.pl b/installcheck/amcheckdump.pl index ff6a150..6591911 100644 --- a/installcheck/amcheckdump.pl +++ b/installcheck/amcheckdump.pl @@ -1,34 +1,98 @@ -use Test::More qw( no_plan ); +# Copyright (c) 2005-2008 Zmanda Inc. All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Contact information: Zmanda Inc, 465 S Mathlida Ave, Suite 300 +# Sunnyvale, CA 94086, USA, or: http://www.zmanda.com -use Amconfig; +use Test::More tests => 9; use lib "@amperldir@"; +use Installcheck::Config; +use Installcheck::Run qw(run run_get run_err $diskname); use Amanda::Paths; -sub amcheckdump { - my $cmd = "$sbindir/amcheckdump " . join(" ", @_) . " 2>&1"; - my $result = `$cmd`; - chomp $result; - return $result; -} - my $testconf; ## # First, try amgetconf out without a config -like(amcheckdump(), qr/\AUSAGE:/i, - "bare 'amcheckdump' gives usage message"); -like(amcheckdump("this-probably-doesnt-exist"), qr(could not open conf file)i, - "error message when configuration parameter doesn't exist"); +ok(!run('amcheckdump'), + "amcheckdump with no arguments returns an error exit status"); +like($Installcheck::Run::stdout, qr/\AUSAGE:/i, + ".. and gives usage message"); + +like(run_err('amcheckdump', 'this-probably-doesnt-exist'), qr(could not open conf file)i, + "run with non-existent config fails with an appropriate error message."); ## -# Now use a config with a vtape +# Now use a config with a vtape and without usetimestamps -# this is re-created for each test -$testconf = Amconfig->new(); -$testconf->setup_vtape(); +$testconf = Installcheck::Run::setup(); +$testconf->add_param('label_new_tapes', '"TESTCONF%%"'); +$testconf->add_param('usetimestamps', 'no'); +$testconf->add_dle("localhost $diskname installcheck-test"); $testconf->write(); -like(amcheckdump("TESTCONF"), qr(could not find)i, - "'amcheckdump' on a brand-new config finds no dumps."); +ok(run('amcheckdump', 'TESTCONF'), + "amcheckdump with a new config succeeds"); +like($Installcheck::Run::stdout, qr(could not find)i, + "..but finds no dumps."); + +BAIL_OUT("amdump failed") + unless run('amdump', 'TESTCONF'); + +like(run_get('amcheckdump', 'TESTCONF'), qr(Validating), + "amcheckdump succeeds, claims to validate something (usetimestamps=no)"); + +## +# and check command-line handling + +like(run_get('amcheckdump', 'TESTCONF', '-oorg=installcheck'), qr(Validating), + "amcheckdump accepts '-o' options on the command line"); + +## +# And a config with usetimestamps enabled + +$testconf = Installcheck::Run::setup(); +$testconf->add_param('label_new_tapes', '"TESTCONF%%"'); +$testconf->add_param('usetimestamps', 'yes'); +$testconf->add_dle("localhost $diskname installcheck-test"); +$testconf->write(); + +BAIL_OUT("amdump failed") + unless run('amdump', 'TESTCONF'); + +like(run_get('amcheckdump', 'TESTCONF'), qr(Validating), + "amcheckdump succeeds, claims to validate something (usetimestamps=yes)"); + +## +# now try zeroing out the dumps + +my $vtape1 = Installcheck::Run::vtape_dir(1); +opendir(my $vtape_dir, $vtape1) || die "can't opendir $vtape1: $!"; +@dump1 = grep { /^0+1/ } readdir($vtape_dir); +closedir $vtape_dir; + +for my $dumpfile (@dump1) { + open(my $dumpfh, "+<", "$vtape1/$dumpfile"); + sysseek($dumpfh, 32768, 0); # jump past the header + syswrite($dumpfh, "\0" x 100); # and write some zeroes + close($dumpfh); +} + +ok(!run('amcheckdump', 'TESTCONF'), + "amcheckdump detects a failure from a zeroed-out dumpfile"); + +Installcheck::Run::cleanup();