Blame installcheck/amflush.pl

Packit 23ab03
# Copyright (c) 2010-2012 Zmanda, Inc.  All Rights Reserved.
Packit 23ab03
# Copyright (c) 2013-2016 Carbonite, Inc.  All Rights Reserved.
Packit 23ab03
#
Packit 23ab03
# This program is free software; you can redistribute it and/or
Packit 23ab03
# modify it under the terms of the GNU General Public License
Packit 23ab03
# as published by the Free Software Foundation; either version 2
Packit 23ab03
# of the License, or (at your option) any later version.
Packit 23ab03
#
Packit 23ab03
# This program is distributed in the hope that it will be useful, but
Packit 23ab03
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit 23ab03
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit 23ab03
# for more details.
Packit 23ab03
#
Packit 23ab03
# You should have received a copy of the GNU General Public License along
Packit 23ab03
# with this program; if not, write to the Free Software Foundation, Inc.,
Packit 23ab03
# 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
Packit 23ab03
#
Packit 23ab03
# Contact information: Carbonite Inc., 756 N Pastoria Ave
Packit 23ab03
# Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
Packit 23ab03
Packit 23ab03
use Test::More tests => 4;
Packit 23ab03
use strict;
Packit 23ab03
use warnings;
Packit 23ab03
Packit 23ab03
use lib '@amperldir@';
Packit 23ab03
use File::Path;
Packit 23ab03
use Data::Dumper;
Packit 23ab03
use Installcheck;
Packit 23ab03
use Installcheck::Config;
Packit 23ab03
use Installcheck::Run qw(run run_err $diskname);
Packit 23ab03
use Amanda::Paths;
Packit 23ab03
use Amanda::Header;
Packit 23ab03
use Amanda::Debug;
Packit 23ab03
Packit 23ab03
Amanda::Debug::dbopen("installcheck");
Packit 23ab03
Installcheck::log_test_output();
Packit 23ab03
Packit 23ab03
my $testconf;
Packit 23ab03
my $vtape_dir;
Packit 23ab03
Packit 23ab03
# write a fake holding file to holding disk, for amflush to flush
Packit 23ab03
sub write_holding_file {
Packit 23ab03
    my ($host, $disk) = @_;
Packit 23ab03
Packit 23ab03
    my $datestamp = "20100102030405";
Packit 23ab03
    my $filename = "$Installcheck::Run::holdingdir/$datestamp/$host-somefile";
Packit 23ab03
Packit 23ab03
    my $hdr = Amanda::Header->new();
Packit 23ab03
    $hdr->{'type'} = $Amanda::Header::F_DUMPFILE;
Packit 23ab03
    $hdr->{'datestamp'} = $datestamp;
Packit 23ab03
    $hdr->{'dumplevel'} = 0;
Packit 23ab03
    $hdr->{'name'} = $host;
Packit 23ab03
    $hdr->{'disk'} = $disk;
Packit 23ab03
    $hdr->{'program'} = "INSTALLCHECK";
Packit 23ab03
Packit 23ab03
    mkpath($Installcheck::Run::holdingdir);
Packit 23ab03
    mkpath("$Installcheck::Run::holdingdir/$datestamp");
Packit 23ab03
    open(my $fh, ">", $filename) or die("opening '$filename': $!");
Packit 23ab03
    print $fh $hdr->to_string(32768,32768);
Packit 23ab03
    print $fh "some data!\n";
Packit 23ab03
    close($fh);
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
Installcheck::Run::cleanup();
Packit 23ab03
$testconf = Installcheck::Run::setup();
Packit 23ab03
$testconf->add_param("autolabel", '"TESTCONF%%" any');
Packit 23ab03
$testconf->add_dle("localhost $diskname installcheck-test");
Packit 23ab03
$testconf->write();
Packit 23ab03
Packit 23ab03
# add a holding file that's in the disklist
Packit 23ab03
write_holding_file("localhost", $Installcheck::Run::diskname);
Packit 23ab03
Packit 23ab03
ok(run("$sbindir/amflush", '-f', '-b', 'TESTCONF'),
Packit 23ab03
    "amflush runs successfully")
Packit 23ab03
    or diag($Installcheck::Run::stderr);
Packit 23ab03
Packit 23ab03
# check that there's a vtape file where we expect to see one
Packit 23ab03
$vtape_dir = Installcheck::Run::vtape_dir(1);
Packit 23ab03
ok(<$vtape_dir/00001.*>, "..and dump appears on vtapes");
Packit 23ab03
Packit 23ab03
Installcheck::Run::cleanup();
Packit 23ab03
$testconf = Installcheck::Run::setup();
Packit 23ab03
$testconf->add_param("autolabel", '"TESTCONF%%" any');
Packit 23ab03
# don't add anything to the disklist; it should still flush it
Packit 23ab03
$testconf->write();
Packit 23ab03
Packit 23ab03
# add a holding file that's not in the disklist
Packit 23ab03
write_holding_file("localhost", $Installcheck::Run::diskname);
Packit 23ab03
Packit 23ab03
ok(run("$sbindir/amflush", '-f', '-b', 'TESTCONF'),
Packit 23ab03
    "amflush runs successfully")
Packit 23ab03
    or diag($Installcheck::Run::stderr);
Packit 23ab03
Packit 23ab03
# check that there's a vtape file where we expect to see one
Packit 23ab03
$vtape_dir = Installcheck::Run::vtape_dir(1);
Packit 23ab03
ok(<$vtape_dir/00001.*>, "..and dump appears on vtapes");
Packit 23ab03
Packit 23ab03
#Installcheck::Run::cleanup();