AFS-Command

 view release on metacpan or  search on metacpan

t/01vos_dumprestore.t  view on Meta::CPAN

#
# First, let's get all the config data we need.
#
my $volname_prefix = $AFS::Command::Tests::Config{AFS_COMMAND_VOLNAME_PREFIX} || do {
    print "not ok $TestCounter..$TestTotal\n";
    die "Missing configuration variable AFS_COMMAND_VOLNAME_PREFIX\n";
};

my $cell = $AFS::Command::Tests::Config{AFS_COMMAND_CELLNAME} || do {
    print "not ok $TestCounter..$TestTotal\n";
    die "Missing configuration variable AFS_COMMAND_CELLNAME\n";
};

my $partition_list = $AFS::Command::Tests::Config{AFS_COMMAND_PARTITION_LIST} || do {
    print "not ok $TestCounter..$TestTotal\n";
    die "Missing configuration variable AFS_COMMAND_PARTITION_LIST\n";
};

my $binary = $AFS::Command::Tests::Config{AFS_COMMAND_BINARY_VOS} || 'vos';

my %enabled =
  (
   gzip		=> $AFS::Command::Tests::Config{AFS_COMMAND_GZIP_ENABLED},
   bzip2	=> $AFS::Command::Tests::Config{AFS_COMMAND_BZIP2_ENABLED},
  );
$enabled{gunzip} = $enabled{gzip};
$enabled{bunzip2} = $enabled{bzip2};

my $dumpfilter = $AFS::Command::Tests::Config{AFS_COMMAND_DUMP_FILTER};
my $restorefilter = $AFS::Command::Tests::Config{AFS_COMMAND_RESTORE_FILTER};

my $tmproot = $AFS::Command::Tests::Config{AFS_COMMAND_TMP_ROOT};

my @servers 		= ();
my @partitions		= ();
my $server_primary 	= "";
my $partition_primary 	= "";

foreach my $serverpart ( split(/\s+/,$partition_list) ) {

    my ($server,$partition) = split(/:/,$serverpart);

    unless ( $server && $partition ) {
	print "not ok $TestCounter..$TestTotal\n";
	die "Invalid server:/partition specification: '$serverpart'\n";
    }

    $server_primary = $server unless $server_primary;
    $partition_primary = $partition unless $partition_primary;

    push(@servers,$server);
    push(@partitions,$partition);

}

#
# If the constructor fails, we're doomed.
#
my $vos = AFS::Command::VOS->new
  (
   command		=> $binary,
  );
if ( ref $vos && $vos->isa("AFS::Command::VOS") ) {
    print "ok $TestCounter\n";
    $TestCounter++;
} else {
    print "not ok $TestCounter..$TestTotal\n";
    die "Unable to instantiate AFS::Command::VOS object\n";
}

#
# Create a volume.
#
my $volname = $volname_prefix . $PID;

my $result = $vos->create
  (
   server		=> $server_primary,
   partition		=> $partition_primary,
   name			=> $volname,
   cell			=> $cell,
  );
if ( $result ) {
    print "ok $TestCounter\n";
    $TestCounter++;
    $Volnames{$volname}++;
} else {
    print "not ok $TestCounter..$TestTotal\n";
    die("Unable to create volume '$volname' on server '$server_primary:$partition_primary'" .
	"in cell '$cell'\n" . "Errors from vos command:\n" . $vos->errors());
}

#
# OK, let's create a few dump files, in different ways.
#
# First, a vanilla dump, nothing special.
#
my %files =
  (
   raw			=> "$tmproot/$volname.dump",
   gzip			=> "$tmproot/$volname.dump.gz",
   bzip2		=> "$tmproot/$volname.dump.bz2",
  );
$files{gunzip} = $files{gzip};
$files{bunzip2} = $files{bzip2};

$result = $vos->dump
  (
   id			=> $volname,
   time			=> 0,
   file			=> $files{raw},
   cell			=> $cell,
  );
if ( $result ) {
    print "ok $TestCounter\n";
} else {
    print "not ok $TestCounter\n";
    warn("Unable to dump volume '$volname' in cell '$cell' to file '$files{raw}':\n" .
	 $vos->errors());
}
$TestCounter++;

foreach my $ctype ( qw(gzip bzip2) ) {

    unless ( $enabled{$ctype} ) {
	for ( my $count = 0 ; $count < 3 ; $count++ ) {
	    print "ok $TestCounter # skip Compression support for $ctype disabled\n";
	    $TestCounter++;
	}
	next;
    }

    #
    # Now, with *implicit* use of gzip (via the filename)
    #
    $result = $vos->dump
      (
       id			=> $volname,
       time			=> 0,
       file			=> $files{$ctype},
       cell			=> $cell,
      );
    if ( $result ) {
	print "ok $TestCounter\n";
    } else {
	print "not ok $TestCounter\n";
	warn("Unable to dump volume '$volname' in cell '$cell' to file '$files{$ctype}':\n" .
	     $vos->errors());
    }
    $TestCounter++;



( run in 0.702 second using v1.01-cache-2.11-cpan-d8267643d1d )