1
0
mirror of synced 2026-01-30 13:06:30 +00:00

2006-06-19 20:39:21 by steve

Updated test to do more work, and removed extraneous cruft.
This commit is contained in:
steve
2006-06-19 20:39:21 +00:00
parent 8c0a4ac329
commit 7e9bd2eae3

View File

@@ -5,7 +5,7 @@
#
# Steve
# --
# $Id: xt-create-xen-config.t,v 1.1 2006-06-19 14:03:52 steve Exp $
# $Id: xt-create-xen-config.t,v 1.2 2006-06-19 20:39:21 steve Exp $
#
@@ -15,28 +15,119 @@ use File::Temp;
#
# Look for mention of DHCP when setting up DHCP.
# What we basically do here is setup a collection of environmental
# variables, and then call the script. We then make a couple of simple
# tests against the output file which is written.
#
#
runCommand( "dhcp", memory => 128, dhcp => 1, dir => '/tmp' );
#
# Look for an IP address when specifying one.
# Look for mention of DHCP when setting up DHCP, this conflicts with
# a static IP address.
#
runCommand( "ip=192.168.1.1", memory => 128, ip1 => '192.168.1.1', dir => '/tmp' );
#
# Look for SDA + HDA
#
runCommand( "sda1", memory => 128, ip1 => '192.168.1.1', dir => '/tmp' );
runCommand( "sda2", memory => 128, ip1 => '192.168.1.1', dir => '/tmp' );
runCommand( "hda1", memory => 128, ip1 => '192.168.1.1', dir => '/tmp', ide => 1 );
runCommand( "hda2", memory => 128, ip1 => '192.168.1.1', dir => '/tmp', ide => 1 );
testOutputContains( "dhcp",
memory => 128, dhcp => 1, dir => '/tmp' );
noMentionOf( "ip=",
memory => 128, dhcp => 1, dir => '/tmp' );
sub runCommand
#
# Look for an IP address when specifying one, and make sure there
# is no mention of DHCP.
#
testOutputContains( "ip=192.168.1.1",
memory => 128, ip1 => '192.168.1.1', dir => '/tmp' );
noMentionOf( "dhcp",
memory => 128, ip1 => '192.168.1.1', dir => '/tmp' );
#
# SCSI based systems:
#
testOutputContains( "sda1",
memory => 128, ip1 => '192.168.1.1', dir => '/tmp' );
testOutputContains( "/dev/sda1 ro",
memory => 128, ip1 => '192.168.1.1', dir => '/tmp' );
testOutputContains( "sda2",
memory => 128, ip1 => '192.168.1.1', dir => '/tmp' );
noMentionOf( "hda1",
memory => 128, ip1 => '192.168.1.1', dir => '/tmp' );
noMentionOf( "hda2",
memory => 128, ip1 => '192.168.1.1', dir => '/tmp' );
#
# IDE based systems
#
testOutputContains( "hda1",
memory => 128, ip1 => '192.168.1.1', dir => '/tmp', ide => 1 );
testOutputContains( "/dev/hda1 ro",
memory => 128, ip1 => '192.168.1.1', dir => '/tmp', ide => 1 );
noMentionOf( "sda1",
memory => 128, ip1 => '192.168.1.1', dir => '/tmp', ide => 1 );
testOutputContains( "hda2",
memory => 128, ip1 => '192.168.1.1', dir => '/tmp', ide => 1 );
noMentionOf( "sda2",
memory => 128, ip1 => '192.168.1.1', dir => '/tmp', ide => 1 );
#
# Test memory size.
#
testOutputContains( "128",
memory => 128, dhcp => 1, dir => '/tmp' );
testOutputContains( "211",
memory => 211, dhcp => 1, dir => '/tmp' );
testOutputContains( "912",
memory => 912, dhcp => 1, lvm => 'skx-vg0' );
#
# Test LVM stuff.
#
testOutputContains( "phy:",
memory => 128, dhcp => 1, lvm => 'skx-vg0' );
testOutputContains( "skx-vg0",
memory => 128, dhcp => 1, lvm => 'skx-vg0' );
noMentionOf( "/tmp",
memory => 128, dhcp => 1, lvm => 'skx-vg0' );
noMentionOf( "domains",
memory => 128, dhcp => 1, lvm => 'skx-vg0' );
#
# Now test the loopback devices.
#
testOutputContains( "/tmp",
memory => 128, dhcp => 1, dir => '/tmp' );
testOutputContains( "/tmp/domains",
memory => 128, dhcp => 1, dir => '/tmp' );
testOutputContains( "/tmp/domains/foo.my.flat",
memory => 128, dhcp => 1, dir => '/tmp' );
noMentionOf( "phy:",
memory => 128, dhcp => 1, dir => '/tmp' );
=head2 runCreateCommand
Run the xt-create-xen-config command and return the output.
This involves setting up the environment and running the command,
once complete return the text which has been written to the xen
configuration file.
=cut
sub runCreateCommand
{
my ($text, %params ) = ( @_ );
my ( %params ) = ( @_ );
#
# Force a hostname
@@ -46,8 +137,8 @@ sub runCommand
#
# Create a temporary directory, and make sure it is present.
#
my $dir = File::Temp::tempdir( CLEANUP => 1 );
ok ( -d $dir, "The temporary directory was created: $dir" );
my $dir = File::Temp::tempdir( CLEANUP => 1 );
ok ( -d $dir, "The temporary directory was created." );
#
# Save the environment.
@@ -75,30 +166,68 @@ sub runCommand
#
# See if we found the output we wanted.
# Read the Xen configuration file which the xt-creaat...
# command wrote and return it to the caller.
#
open( OUTPUT, "<", $dir . "/foo.my.flat.cfg" );
my @LINES = <OUTPUT>;
close( OUTPUT );
return( join( "\n", @LINES ) );
}
=head2 testOutputContains
Run the xt-create-xen-config and ensure that the output
contains the text we're looking for.
=cut
sub testOutputContains
{
my ( $text, %params ) = ( @_ );
# Get the output of running the command.
my $output = runCreateCommand( %params );
#
# Look to see if we got the text.
#
my $found = 0;
my $match = '';
open( OUTPUT, "<", $dir . "/foo.my.flat.cfg" );
foreach my $line ( <OUTPUT> )
if ( $output =~ /\Q$text\E/ )
{
if ( $line =~ /\Q$text\E/ )
{
$found += 1;
$match = $line;
}
$found += 1;
}
ok( $found > 0, "We found the output we wanted" );
ok( $found > 0, "We found the output we wanted: $text" );
}
=head2 noMentionOf
Make sure that the creation of a given Xen configuration
file contains no mention of the given string.
=cut
sub noMentionOf
{
my ( $text, %params ) = ( @_ );
# Get the output of running the command.
my $output = runCreateCommand( %params );
#
# Look to see if we got the text.
#
my $found = 0;
if ( $output =~ /\Q$text\E/ )
{
$found += 1;
}
ok( $found == 0, "The output didn't contain the excluded text: $text" );
}
exit;
#
# Create a temporary directory, and make sure it is present.
#
my $dir = File::Temp::tempdir( CLEANUP => 1 );
ok ( -d $dir, "The temporary directory was created: $dir" );