Blame installcheck/amflush.pl

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