AFS-Command
view release on metacpan or search on metacpan
t/00vos_basic.t view on Meta::CPAN
use Data::Dumper;
use vars qw(
$TestCounter
$TestTotal
$Loaded
%Volnames
);
BEGIN {
require "./util/lib/parse_config";
}
BEGIN {
$| = 1;
if ( $AFS::Command::Tests::Config{AFS_COMMAND_DISABLE_TESTS} =~ /\bvos\b/ ) {
$TestTotal = 0;
} elsif ( $AFS::Command::Tests::Config{AFS_COMMAND_CELLNAME} eq 'your.cell.name' ) {
$TestTotal = 0;
} else {
$TestTotal = 77;
}
print "1..$TestTotal\n";
}
END {print "not ok 1\n" unless $Loaded;}
use AFS::Command::VOS 1.99;
$Loaded = 1;
$TestCounter = 1;
print "ok $TestCounter\n";
$TestCounter++;
exit 0 unless $TestTotal;
#
# 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 @servers = ();
my @partitions = ();
my $server_primary = "";
my $partition_primary = "";
#
# In order to have a predictable number of tests, we only use the
# first 2 server:/vicep* you specify.
#
foreach my $serverpart ( (split(/\s+/,$partition_list))[0..1] ) {
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 $volname_readonly = $volname . ".readonly";
$Volnames{$volname}++;
my $result = $vos->create
(
server => $server_primary,
partition => $partition_primary,
name => $volname,
cell => $cell,
);
if ( $result ) {
print "ok $TestCounter\n";
$TestCounter++;
} 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());
}
#
# Examine it.
t/00vos_basic.t view on Meta::CPAN
#
# Check the volume IDs. rwrite shold be numeric, ronly and
# backup should b e 0.
#
$rwrite = $header->rwrite();
if ( $rwrite =~ /^\d+$/ ) {
print "ok $TestCounter\n";
} else {
warn("Volume header 'rwrite' is '$rwrite', should be a numeric value\n");
print "not ok $TestCounter\n";
$errors++;
}
$TestCounter++;
if ( $header->ronly() == 0 ) {
print "ok $TestCounter\n";
} else {
warn("Volume header 'ronly' is '" .
$header->ronly() . "', should be zero\n");
print "not ok $TestCounter\n";
$errors++;
}
$TestCounter++;
if ( $header->backup() == 0 ) {
print "ok $TestCounter\n";
} else {
warn("Volume header 'backup' is '" .
$header->backup() . "', should be zero\n");
print "not ok $TestCounter\n";
$errors++;
}
$TestCounter++;
#
# This is a new volume, so access should be 0, and size 2
#
if ( $header->accesses() == 0 ) {
print "ok $TestCounter\n";
} else {
warn("Volume header 'accesses' is '" .
$header->access() . "', should be zero\n");
print "not ok $TestCounter\n";
$errors++;
}
$TestCounter++;
if ( $header->size() == 2 ) {
print "ok $TestCounter\n";
} else {
warn("Volume header 'size' is '" .
$header->size() . "', should be 2\n");
print "not ok $TestCounter\n";
$errors++;
}
$TestCounter++;
#
# Both the update and creation times should be ctime values.
# NOTE: This test may very well break if LANG is set, and
# affects vos output syntax. Note that in that case, we'll
# need code in VOS.pm to deal with more generic time strings.
#
foreach my $method ( qw( update creation ) ) {
if ( $header->$method() =~ /^\S+\s+\S+\s+\d+\s+\d{2}:\d{2}:\d{2}\s+\d{4}$/ ) {
print "ok $TestCounter\n";
} else {
warn("Volume header '$method' is '" .
$header->$method() . "', should be a ctime date value\n");
print "not ok $TestCounter\n";
$errors++;
}
$TestCounter++;
}
#
# Finally, maxauota must be numeric, and status should be
# 'online'
#
if ( $header->maxquota() =~ /^\d+$/ ) {
print "ok $TestCounter\n";
} else {
warn("Volume header 'maxquota' is '" .
$header->maxquota() . "', should be numeric\n");
print "not ok $TestCounter\n";
$errors++;
}
$TestCounter++;
if ( $header->status() eq 'online' ) {
print "ok $TestCounter\n";
} else {
warn("Volume header 'status' is '" .
$header->status() . "', should be 'online'\n");
print "not ok $TestCounter\n";
$errors++;
}
$TestCounter++;
} else {
warn("Invalid object -- getVolumeHeaders() did not return an " .
"AFS::Object::VolumeHeader object\n");
print "not ok $TestCounter\n";
$errors++;
}
#
# Second, we check the VLDB entry for this volume.
#
my $vldbentry = $result->getVLDBEntry();
if ( ref $vldbentry && $vldbentry->isa("AFS::Object::VLDBEntry") ) {
print "ok $TestCounter\n";
} else {
print "not ok $TestCounter..$TestTotal\n";
die("Invalid object type: getVLDBEntry() method call returned bogus data\n" .
Data::Dumper->Dump([$result],['result']));
}
$TestCounter++;
t/00vos_basic.t view on Meta::CPAN
} else {
print "not ok $TestCounter\n";
warn("Volume '$volname' on server '$servers[0]', " .
"partition '$partitions[0]', in cell '$cell' does not appear to be attached");
}
$TestCounter++;
}
} else {
for ( my $index = 0 ; $index <= 7 ; $index++ ) {
print "ok $TestCounter\n";
$TestCounter++;
}
}
$result = $vos->remove
(
id => $volname,
server => $servers[0],
partition => $partitions[0],
cell => $cell,
);
if ( $result ) {
print "ok $TestCounter\n";
delete $Volnames{$volname};
} else {
print "not ok $TestCounter..$TestTotal\n";
die("Unable to remove volume '$volname' from server '$servers[0]', " .
"partition '$partitions[0]', in cell '$cell':\n" .
$vos->errors());
}
$TestCounter++;
#
# Finally, one we *expect* to fail...
#
$result = $vos->examine
(
id => $volname,
cell => $cell,
);
if ( $result ) {
print "not ok $TestCounter..$TestTotal\n";
die("Volume '$volname' in cell '$cell', still exists after a successful vos remove!!\n");
} elsif ( $vos->errors() =~ /VLDB: no such entry/i ) {
print "ok $TestCounter\n";
} else {
print "not ok $TestCounter..$TestTotal\n";
die("Unexpected result from vos examine:\n" . $vos->errors());
}
$TestCounter++;
exit 0;
END {
#$TestCounter--;
#warn "Total number of tests == $TestCounter\n";
if ( %Volnames ) {
warn("The following temporary volumes were created, and may be left over:\n\t" .
join("\n\t",sort keys %Volnames) . "\n");
}
}
( run in 0.474 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )