2006-01-07 17:12:57 by steve
Test that the xen-delete-image script deletes disk + swap images correctly.
This commit is contained in:
parent
0c7a7e8f94
commit
f912baa6ae
94
tests/xen-delete-image.t
Normal file
94
tests/xen-delete-image.t
Normal file
@ -0,0 +1,94 @@
|
||||
#!/usr/bin/perl -w
|
||||
#
|
||||
# Test that the xen-delete-image script will delete an images
|
||||
# contents correctly.
|
||||
#
|
||||
# Steve
|
||||
# --
|
||||
# $Id: xen-delete-image.t,v 1.1 2006-01-07 17:12:57 steve Exp $
|
||||
#
|
||||
|
||||
|
||||
use strict;
|
||||
use Test::More qw( no_plan );
|
||||
use File::Temp;
|
||||
|
||||
|
||||
#
|
||||
# Create a temporary directory.
|
||||
#
|
||||
my $dir = File::Temp::tempdir( CLEANUP => 1 );
|
||||
my $domains = $dir . "/domains";
|
||||
|
||||
#
|
||||
# Test that we can make the directory.
|
||||
#
|
||||
ok ( -d $dir, "The temporary directory was created: $dir" );
|
||||
|
||||
#
|
||||
# Create the domains directory.
|
||||
#
|
||||
ok ( ! -d $domains, "The temp directory doesn't have a domains directory." );
|
||||
mkdir( $domains, 0777 );
|
||||
ok ( -d $domains, "The temp directory now has a domains directory." );
|
||||
|
||||
|
||||
#
|
||||
# Generate a random hostname.
|
||||
#
|
||||
my $hostname = join ( '', map {('a'..'z')[rand 26]} 0..17 );
|
||||
ok( ! -d $domains . "/" . $hostname, "The virtual hostname doesnt exist." );
|
||||
|
||||
#
|
||||
# Make the hostname directory
|
||||
#
|
||||
mkdir( $domains . "/" . $hostname, 0777 );
|
||||
ok( -d $domains . "/" . $hostname, "The virtual hostname now exists." );
|
||||
|
||||
|
||||
#
|
||||
# Create a stub disk image
|
||||
#
|
||||
open( IMAGE, ">", $domains . "/" . $hostname . "/" . "disk.img" )
|
||||
or warn "Failed to open disk image : $!";
|
||||
print IMAGE "Test";
|
||||
close( IMAGE );
|
||||
|
||||
|
||||
#
|
||||
# Create a stub swap image
|
||||
#
|
||||
open( IMAGE, ">", $domains . "/" . $hostname . "/" . "swap.img" )
|
||||
or warn "Failed to open swap image : $!";
|
||||
print IMAGE "Test";
|
||||
close( IMAGE );
|
||||
|
||||
|
||||
#
|
||||
# Now we have :
|
||||
#
|
||||
# $dir/
|
||||
# $dir/domains/
|
||||
# $dir/domains/$hostname
|
||||
# $dir/domains/$hostname/disk.img
|
||||
# $dir/domains/$hostname/swap.img
|
||||
#
|
||||
# So we need to run the deletion script and verify the images
|
||||
# are removed correctly.
|
||||
#
|
||||
`./xen-delete-image --dir=$dir $hostname`;
|
||||
|
||||
|
||||
#
|
||||
# If the deletion worked our images are gone.
|
||||
#
|
||||
ok( ! -e $domains . "/" . $hostname . "/" . "disk.img",
|
||||
"Disk image deleted successfully." );
|
||||
ok( ! -e $domains . "/" . $hostname . "/" . "swap.img",
|
||||
"Swap image deleted successfully." );
|
||||
|
||||
#
|
||||
# And the hostname directory should have gone too.
|
||||
#
|
||||
ok( ! -d $domains . "/" . $hostname,
|
||||
"The hostname directory was removed" );
|
||||
@ -59,7 +59,7 @@ Show the version number and exit.
|
||||
--
|
||||
http://www.steve.org.uk/
|
||||
|
||||
$Id: xen-delete-image,v 1.11 2006-01-06 14:44:54 steve Exp $
|
||||
$Id: xen-delete-image,v 1.12 2006-01-07 17:12:57 steve Exp $
|
||||
|
||||
=cut
|
||||
|
||||
@ -121,13 +121,11 @@ if ( $EFFECTIVE_USER_ID != 0 )
|
||||
{
|
||||
print <<E_O_ROOT;
|
||||
|
||||
In order to use this script you must be running with root privileges.
|
||||
|
||||
(This is necessary to remove the Xen configuration file beneath /etc/xen.)
|
||||
This script is not running with root privileges, so the configuration
|
||||
file(s) beneath /etc/xen will not be removed.
|
||||
|
||||
E_O_ROOT
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
@ -234,7 +232,7 @@ sub parseCommandLineArguments
|
||||
|
||||
if ( $VERSION )
|
||||
{
|
||||
my $REVISION = '$Id: xen-delete-image,v 1.11 2006-01-06 14:44:54 steve Exp $';
|
||||
my $REVISION = '$Id: xen-delete-image,v 1.12 2006-01-07 17:12:57 steve Exp $';
|
||||
$VERSION = join (' ', (split (' ', $REVISION))[2]);
|
||||
$VERSION =~ s/,v\b//;
|
||||
$VERSION =~ s/(\S+)$/$1/;
|
||||
@ -275,7 +273,6 @@ sub deleteXenImage
|
||||
unlink( $CONFIG{'dir'} . "/domains/" . $hostname . "/swap.img" );
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Now the disk image
|
||||
#
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user