Blame installcheck/dump-client-encrypt+amfetchdump.pl

Packit 23ab03
# Copyright (c) 2014-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;
Packit 23ab03
use File::Path;
Packit 23ab03
use strict;
Packit 23ab03
use warnings;
Packit 23ab03
Packit 23ab03
use lib '@amperldir@';
Packit 23ab03
use Installcheck;
Packit 23ab03
use Installcheck::Dumpcache;
Packit 23ab03
use Installcheck::Config;
Packit 23ab03
use Installcheck::Run qw(run run_err $diskname amdump_diag check_amreport check_amstatus);
Packit 23ab03
use Installcheck::Catalogs;
Packit 23ab03
use Amanda::Paths;
Packit 23ab03
use Amanda::Device qw( :constants );
Packit 23ab03
use Amanda::Debug;
Packit 23ab03
use Amanda::MainLoop;
Packit 23ab03
use Amanda::Config qw( :init :getconf config_dir_relative );
Packit 23ab03
use Amanda::Changer;
Packit 23ab03
use Cwd;
Packit 23ab03
Packit 23ab03
eval 'use Installcheck::Rest;';
Packit 23ab03
if ($@) {
Packit 23ab03
    plan skip_all => "Can't load Installcheck::Rest: $@";
Packit 23ab03
    exit 1;
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
eval "require Time::HiRes;";
Packit 23ab03
Packit 23ab03
# set up debugging so debug output doesn't interfere with test results
Packit 23ab03
Amanda::Debug::dbopen("installcheck");
Packit 23ab03
Installcheck::log_test_output();
Packit 23ab03
Packit 23ab03
# and disable Debug's die() and warn() overrides
Packit 23ab03
Amanda::Debug::disable_die_override();
Packit 23ab03
Packit 23ab03
my $rest = Installcheck::Rest->new();
Packit 23ab03
if ($rest->{'error'}) {
Packit 23ab03
   plan skip_all => "Can't start JSON Rest server: $rest->{'error'}: see " . Amanda::Debug::dbfn();
Packit 23ab03
   exit 1;
Packit 23ab03
}
Packit 23ab03
plan tests => 37;
Packit 23ab03
Packit 23ab03
my $reply;
Packit 23ab03
Packit 23ab03
my $config_dir = $Amanda::Paths::CONFIG_DIR;
Packit 23ab03
my $amperldir = $Amanda::Paths::amperldir;
Packit 23ab03
my $testconf;
Packit 23ab03
my $diskfile;
Packit 23ab03
my $infodir;
Packit 23ab03
my $timestamp;
Packit 23ab03
my $tracefile;
Packit 23ab03
my $logfile;
Packit 23ab03
my $hostname = `hostname`;
Packit 23ab03
chomp $hostname;
Packit 23ab03
Packit 23ab03
$testconf = Installcheck::Run::setup();
Packit 23ab03
$testconf->add_param('autolabel', '"TESTCONF%%" empty volume_error');
Packit 23ab03
$testconf->add_param('columnspec', '"Dumprate=1:-8:1,TapeRate=1:-8:1"');
Packit 23ab03
$testconf->add_dle(<
Packit 23ab03
localhost diskname2 $diskname {
Packit 23ab03
    installcheck-test
Packit 23ab03
    program "APPLICATION"
Packit 23ab03
#    compress client custom
Packit 23ab03
#    client-custom-compress  "$Amanda::Constants::COMPRESS_PATH"
Packit 23ab03
    encrypt client
Packit 23ab03
    client-encrypt  "$Amanda::Constants::COMPRESS_PATH"
Packit 23ab03
    client-decrypt-option "-d"
Packit 23ab03
    application {
Packit 23ab03
        plugin "amrandom"
Packit 23ab03
        property "SIZE" "262144"
Packit 23ab03
    }
Packit 23ab03
    holdingdisk never
Packit 23ab03
}
Packit 23ab03
EODLE
Packit 23ab03
$testconf->write();
Packit 23ab03
Packit 23ab03
config_init($CONFIG_INIT_EXPLICIT_NAME, "TESTCONF");
Packit 23ab03
$diskfile = Amanda::Config::config_dir_relative(getconf($CNF_DISKFILE));
Packit 23ab03
$infodir = getconf($CNF_INFOFILE);
Packit 23ab03
Packit 23ab03
$reply = $rest->post("http://localhost:5001/amanda/v1.0/configs/TESTCONF/runs/amdump","");
Packit 23ab03
foreach my $message (@{$reply->{'body'}}) {
Packit 23ab03
    if (defined $message and defined $message->{'code'}) {
Packit 23ab03
        if ($message->{'code'} == 2000003) {
Packit 23ab03
            $timestamp = $message->{'timestamp'};
Packit 23ab03
        }
Packit 23ab03
        if ($message->{'code'} == 2000001) {
Packit 23ab03
            $tracefile = $message->{'tracefile'};
Packit 23ab03
        }
Packit 23ab03
        if ($message->{'code'} == 2000000) {
Packit 23ab03
            $logfile = $message->{'logfile'};
Packit 23ab03
        }
Packit 23ab03
    }
Packit 23ab03
}
Packit 23ab03
#wait until it is done
Packit 23ab03
do {
Packit 23ab03
    Time::HiRes::sleep(0.5);
Packit 23ab03
    $reply = $rest->get("http://localhost:5001/amanda/v1.0/configs/TESTCONF/runs");
Packit 23ab03
    } while ($reply->{'body'}[0]->{'code'} == 2000004 and
Packit 23ab03
             $reply->{'body'}[0]->{'status'} ne 'done');
Packit 23ab03
Packit 23ab03
# get REST report
Packit 23ab03
$reply = $rest->get("http://localhost:5001/amanda/v1.0/configs/TESTCONF/report?logfile=$logfile");
Packit 23ab03
is($reply->{'body'}->[0]->{'severity'}, 'success', 'severity is success');
Packit 23ab03
is($reply->{'body'}->[0]->{'code'}, '1900001', 'code is 1900001');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'head'}->{'hostname'}, $hostname , 'hostname is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'head'}->{'exit_status'}, '0' , 'exit_status is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'head'}->{'status'}, 'done' , 'status is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'head'}->{'org'}, 'DailySet1' , 'org is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'head'}->{'config_name'}, 'TESTCONF' , 'config_name is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'head'}->{'timestamp'}, $timestamp , 'timestamp is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'notes'}->[1], '  planner: Adding new disk localhost:diskname2.' , 'notes[1] is correct') || diag("notes: " . Data::Dumper::Dumper($reply->{'body'}->[0]->{'report'}->{'notes'}));
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'notes'}->[2], '  taper: Slot 1 without label can be labeled' , 'notes[2] is correct') || diag("notes: " . Data::Dumper::Dumper($reply->{'body'}->[0]->{'report'}->{'notes'}));
Packit 23ab03
#is($reply->{'body'}->[0]->{'report'}->{'notes'}->[3], '  taper: tape TESTCONF01 kb 94 fm 1 [OK]' , 'notes[3] is correct') || diag("notes: " . Data::Dumper::Dumper($reply->{'body'}->[0]->{'report'}->{'notes'}));
Packit 23ab03
ok(!exists $reply->{'body'}->[0]->{'report'}->{'notes'}->[4], 'no notes[4]') || diag("notes: " . Data::Dumper::Dumper($reply->{'body'}->[0]->{'report'}->{'notes'}));
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'usage_by_tape'}->[0]->{'nb'}, '1' , 'one dle on tape 0');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'usage_by_tape'}->[0]->{'nc'}, '1' , 'one part on tape 0');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'usage_by_tape'}->[0]->{'tape_label'}, 'TESTCONF01' , 'label tape_label on tape 0');
Packit 23ab03
#is($reply->{'body'}->[0]->{'report'}->{'usage_by_tape'}->[0]->{'size'}, '94' , 'size 94  on tape 0');
Packit 23ab03
ok(!exists $reply->{'body'}->[0]->{'report'}->{'usage_by_tape'}->[1], 'only one tape');
Packit 23ab03
is_deeply($reply->{'body'}->[0]->{'report'}->{'tapeinfo'}->{'storage'}->{'TESTCONF'}->{'use'}, [ 'TESTCONF01'], 'use TESTCONF');
Packit 23ab03
#is_deeply($reply->{'body'}->[0]->{'report'}->{'statistic'}->{'tape_size'}, { 'full' => '94',
Packit 23ab03
#									     'total' => '94',
Packit 23ab03
#									     'incr' => '0' }, 'tape_size is correct');
Packit 23ab03
is_deeply($reply->{'body'}->[0]->{'report'}->{'statistic'}->{'parts_taped'}, { 'full' => '1',
Packit 23ab03
									       'total' => '1',
Packit 23ab03
									       'incr' => '0' }, 'parts_taped is correct');
Packit 23ab03
is_deeply($reply->{'body'}->[0]->{'report'}->{'statistic'}->{'dles_taped'}, { 'full' => '1',
Packit 23ab03
									      'total' => '1',
Packit 23ab03
									      'incr' => '0' }, 'dles_taped is correct');
Packit 23ab03
is_deeply($reply->{'body'}->[0]->{'report'}->{'statistic'}->{'dles_dumped'}, { 'full' => '1',
Packit 23ab03
									       'total' => '1',
Packit 23ab03
									       'incr' => '0' }, 'dles_dumped is correct');
Packit 23ab03
is_deeply($reply->{'body'}->[0]->{'report'}->{'statistic'}->{'original_size'}, { 'full' => '256',
Packit 23ab03
									         'total' => '256',
Packit 23ab03
									         'incr' => '0' }, 'original_size is correct');
Packit 23ab03
#is_deeply($reply->{'body'}->[0]->{'report'}->{'statistic'}->{'output_size'}, { 'full' => '94',
Packit 23ab03
#									       'total' => '94',
Packit 23ab03
#									       'incr' => '0' }, 'output_size is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'statistic'}->{'dumpdisks'}, '', 'dumpdisks is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'statistic'}->{'tapedisks'}, '', 'tapedisks is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'statistic'}->{'tapeparts'}, '', 'tapeparts is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'summary'}->[0]->{'backup_level'}, '0', 'backup_level is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'summary'}->[0]->{'disk_name'}, 'diskname2', 'disk_name is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'summary'}->[0]->{'hostname'}, 'localhost', 'hostname is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'summary'}->[0]->{'dump_orig_kb'}, '256', 'dump_orig_kb is correct');
Packit 23ab03
#is($reply->{'body'}->[0]->{'report'}->{'summary'}->[0]->{'dump_out_kb'}, '94', 'dump_out_kb is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'report'}->{'summary'}->[0]->{'dle_status'}, 'full', 'dle_status is correct');
Packit 23ab03
ok(!exists $reply->{'body'}->[0]->{'report'}->{'summary'}->[1], 'Only one summary');
Packit 23ab03
Packit 23ab03
$reply = $rest->get("http://localhost:5001/amanda/v1.0/configs/TESTCONF/status?tracefile=$tracefile");
Packit 23ab03
is($reply->{'body'}->[0]->{'severity'}, 'info', 'severity is info');
Packit 23ab03
is($reply->{'body'}->[0]->{'code'}, '1800000', 'code is 1800000');
Packit 23ab03
is($reply->{'body'}->[0]->{'status'}->{'dead_run'}, '1', 'dead_run is correct');
Packit 23ab03
is($reply->{'body'}->[0]->{'status'}->{'exit_status'}, '0', 'exit_status is correct');
Packit 23ab03
$reply->{'body'}->[0]->{'status'}->{'dles'}->{'localhost'}->{'diskname2'}->{$timestamp}->{'chunk_time'} = undef;
Packit 23ab03
$reply->{'body'}->[0]->{'status'}->{'dles'}->{'localhost'}->{'diskname2'}->{$timestamp}->{'dump_time'} = undef;
Packit 23ab03
$reply->{'body'}->[0]->{'status'}->{'dles'}->{'localhost'}->{'diskname2'}->{$timestamp}->{'storage'}->{'TESTCONF'}->{'taper_time'} = undef;
Packit 23ab03
is($reply->{'body'}->[0]->{'status'}->{'dles'}->{'localhost'}->{'diskname2'}->{$timestamp}->{'status'}, '21', 'status 21 is good');
Packit 23ab03
is($reply->{'body'}->[0]->{'status'}->{'dles'}->{'localhost'}->{'diskname2'}->{$timestamp}->{'storage'}->{'TESTCONF'}->{'status'}, '21', 'storage status 21 is good');
Packit 23ab03
Packit 23ab03
$rest->stop();
Packit 23ab03
Packit 23ab03
my $testdir = "$Installcheck::TMP/amfetchdump-installcheck/files";
Packit 23ab03
rmtree($testdir);
Packit 23ab03
mkpath($testdir);
Packit 23ab03
Packit 23ab03
my $origdir = getcwd;
Packit 23ab03
chdir($testdir);
Packit 23ab03
Packit 23ab03
ok(run('amfetchdump', 'TESTCONF', 'localhost'),
Packit 23ab03
    "amfetchdump restore a client compressed dump");
Packit 23ab03
Packit 23ab03
ok(-f "$testdir/localhost.diskname2.$timestamp.0", "file exists");
Packit 23ab03
Packit 23ab03
chdir("$origdir");
Packit 23ab03
rmtree($testdir);
Packit 23ab03
Packit 23ab03
Installcheck::Run::cleanup();