Imported Upstream version 3.3.3
[debian/amanda] / installcheck / amflush.pl
1 # Copyright (c) 2010-2012 Zmanda, Inc.  All Rights Reserved.
2 #
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.
7 #
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
11 # for more details.
12 #
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
16 #
17 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19
20 use Test::More tests => 4;
21 use strict;
22 use warnings;
23
24 use lib "@amperldir@";
25 use File::Path;
26 use Data::Dumper;
27 use Installcheck;
28 use Installcheck::Config;
29 use Installcheck::Run qw(run run_err $diskname);
30 use Amanda::Paths;
31 use Amanda::Header;
32 use Amanda::Debug;
33
34 Amanda::Debug::dbopen("installcheck");
35
36 my $testconf;
37 my $vtape_dir;
38
39 # write a fake holding file to holding disk, for amflush to flush
40 sub write_holding_file {
41     my ($host, $disk) = @_;
42
43     my $datestamp = "20100102030405";
44     my $filename = "$Installcheck::Run::holdingdir/$datestamp/$host-somefile";
45
46     my $hdr = Amanda::Header->new();
47     $hdr->{'type'} = $Amanda::Header::F_DUMPFILE;
48     $hdr->{'datestamp'} = $datestamp;
49     $hdr->{'dumplevel'} = 0;
50     $hdr->{'name'} = $host;
51     $hdr->{'disk'} = $disk;
52     $hdr->{'program'} = "INSTALLCHECK";
53
54     mkpath($Installcheck::Run::holdingdir);
55     mkpath("$Installcheck::Run::holdingdir/$datestamp");
56     open(my $fh, ">", $filename) or die("opening '$filename': $!");
57     print $fh $hdr->to_string(32768,32768);
58     print $fh "some data!\n";
59     close($fh);
60 }
61
62 Installcheck::Run::cleanup();
63 $testconf = Installcheck::Run::setup();
64 $testconf->add_param("autolabel", '"TESTCONF%%" any');
65 $testconf->add_dle("localhost $diskname installcheck-test");
66 $testconf->write();
67
68 # add a holding file that's in the disklist
69 write_holding_file("localhost", $Installcheck::Run::diskname);
70
71 ok(run("$sbindir/amflush", '-f', '-b', 'TESTCONF'),
72     "amflush runs successfully")
73     or diag($Installcheck::Run::stderr);
74
75 # check that there's a vtape file where we expect to see one
76 $vtape_dir = Installcheck::Run::vtape_dir(1);
77 ok(<$vtape_dir/00001.*>, "..and dump appears on vtapes");
78
79 Installcheck::Run::cleanup();
80 $testconf = Installcheck::Run::setup();
81 $testconf->add_param("autolabel", '"TESTCONF%%" any');
82 # don't add anything to the disklist; it should still flush it
83 $testconf->write();
84
85 # add a holding file that's not in the disklist
86 write_holding_file("localhost", $Installcheck::Run::diskname);
87
88 ok(run("$sbindir/amflush", '-f', '-b', 'TESTCONF'),
89     "amflush runs successfully")
90     or diag($Installcheck::Run::stderr);
91
92 # check that there's a vtape file where we expect to see one
93 $vtape_dir = Installcheck::Run::vtape_dir(1);
94 ok(<$vtape_dir/00001.*>, "..and dump appears on vtapes");
95
96 #Installcheck::Run::cleanup();