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