Darryl L. Pierce
2009-Apr-24 13:56 UTC
[Ovirt-devel] [PATCH node-image] Added new autotests and refactored the autotest script.
Completely reworked the tests so that it would be easier to add or
extend tests. Added commandline arguments to enable debugging of tests,
open virt-viewer on a test vm while it's running. specify different ISOs
to test, run just a single or small set of tests, and to make the script
itself more robust.
Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
autotest.sh | 706 +++++++++++++++++++++++++++++------------------------------
1 files changed, 349 insertions(+), 357 deletions(-)
diff --git a/autotest.sh b/autotest.sh
index 6cba9fa..6b4496e 100755
--- a/autotest.sh
+++ b/autotest.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
#
# oVirt node image autotest script
#
@@ -36,53 +36,201 @@
# This will, for each module whose autobuild.sh is run, to have a matching
# autotest.sh to run as well.
#
-# To run the test locally, all that's needed is for an ISO file named
ovirt-node-image.iso
-# be present in the local directory. This will then be put through its paces
with test
-# results being send to stdout.
+# To run these tests locally, you will need to open port 69 TCP and UDP and
have
+# an ISO file.
ME=$(basename "$0")
warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
die() { warn "$*"; exit 1; }
+debug() { if $debugging; then log "[DEBUG] %s" "$*"; fi }
-# trap '__st=$?; stop_log; exit $__st' 0
-trap '__st=$?; log "Exiting normally."; cleanup; exit $__st'
0
-trap '__st=$?; log "Dying a horrible death."; cleanup; exit
$__st' 1 2 13 15
+trap '__st=$?; cleanup_after_testing; exit $__st' 0
+trap '__st=$?; log "Dying a horrible death.";
cleanup_after_testing; exit $__st' 1 2 13 15
-test -n "$1" && RESULTS=$1 || RESULTS=autotest.log
+set -e
+set -u
-echo "Running oVirt node image Autotest"
+log () {
+ date=$(date)
+ printf "${date} $*\n"
+}
-# BZ#495954 needs to be fixed to uncomment this
-# set -e
-# set -v
+usage () {
+ cat <<EOF
+Usage: $ME [-n test_name] [LOGFILE]
+ -i: set the ISO filename (defualt: ovirt-node-image.iso)
+ -n: the name of the specific autotest to run (default: run all autotests)
+ -d: enable more verbose output (default: disabled)
+ -v: enable tracing (default: disabled)
+ -w: launch virt-viewer for each VM (default: no window shown)
+ -h: display this help and exit
+EOF
+}
-OVIRT_NODE_IMAGE_ISO=$PWD/ovirt-node-image.iso
+# $1 - the test function to call
+execute_test () {
+ local testname=$1
-if [ ! -f $OVIRT_NODE_IMAGE_ISO ]; then
- die "Missing ovirt-node-image.iso file!"
-fi
+ if [ -z $testname ]; then die "Missing test name"; fi
-log () {
- local text="`date` $*"
- printf "${text}\n"
- # sudo bash -c "printf \"[$$] ${text}\n\" >>
${RESULTS}"
+ log "Executing test: $testname"
+
+ eval $testname
+
+ rc=$?
+ log "Completed test: $testname [result=$rc]"
+
+ return $rc
}
-cleanup () {
- log "CLEANING UP"
+# setup a node for pxeboot
+# $1 - the working directory
+# $2 - kernel arguments; if present then they replace all default flags
+setup_pxeboot () {
+ local workdir=${1-}
+ local kernelargs=${2-}
+ local pxedefault=$workdir/tftpboot/pxelinux.cfg/default
+
+ debug "setup for pxeboot: isofile=${isofile} workdir=${workdir}
kernelargs='${kernelargs}' pxedefault=${pxedefault}"
+ (cd $workdir && sudo livecd-iso-to-pxeboot $isofile) > /dev/null
2>&1
+ sudo chmod -R 777 $workdir
+
+ # set default kernel arguments if none were provided
+ # the defaults boot in standalone mode
+ if [ -z "$kernelargs" ]; then
+ kernelargs="ovirt_standalone"
+ fi
+
+ local definition="DEFAULT pxeboot"
+ definition="${definition}\nTIMEOUT 20"
+ definition="${definition}\nPROMPT 0"
+ definition="${definition}\nLABEL pxeboot"
+ definition="${definition}\n KERNEL vmlinuz0"
+ definition="${definition}\n IPAPPEND 2"
+ definition="${definition}\n APPEND rootflags=loop
initrd=initrd0.img root=/${isoname} rootfstype=auto console=tty0 check
console=ttyS0,115200n8 $kernelargs"
+
+ debug "pxeboot definition=\n${definition}"
+ sudo bash -c "printf \"${definition}\" >
$pxedefault"
+}
+
+# Starts a simple instance of dnsmasq.
+# $1 - the iface on which dnsmasq works
+# $2 - the root for tftp files
+# $3 - the mac address for the node (ignored if blank)
+# $4 - the nodename
+start_dnsmasq () {
+ local iface=$1
+ local tftproot=$2
+ local macaddress=$3
+ local nodename=$4
+ local pidfile=$2/dnsmasq.pid
+
stop_dnsmasq
- destroy_test_iface
+ debug "Starting dnsmasq"
+ dns_startup="sudo /usr/sbin/dnsmasq --read-ethers
+
--dhcp-range=${NETWORK}.100,${NETWORK}.254,255.255.255.0,24h
+ --interface=${iface}
+ --bind-interfaces
+ --except-interface=lo
+ --dhcp-boot=tftpboot/pxelinux.0
+ --enable-tftp
+ --tftp-root=${tftproot}
+
--log-facility=/tmp/dnsmasq-${nodename}.log
+ --log-queries
+ --log-dhcp
+ --pid-file=${pidfile}"
+ if [ -n "$macaddress" ]; then
+ dns_startup="${dns_startup}
--dhcp-host=${macaddress},${NODE_ADDRESS}"
+ fi
+ # start dnsmasq
+ eval $dns_startup
+ debug "pidfile=$pidfile"
+ DNSMASQ_PID=$(sudo cat $pidfile)
+ debug "DNSMASQ_PID=${DNSMASQ_PID}"
}
-# Creates a HD disk file.
+# Kills the running instance of dnsmasq.
+stop_dnsmasq () {
+ if [ -n "${DNSMASQ_PID-}" -a "${DNSMASQ_PID-}" !=
"0" ]; then
+ local check=$(ps -ef | awk "/${DNSMASQ_PID}/"' { if ($2 ~
'"${DNSMASQ_PID}"') print $2 }')
+
+ if [[ "${check}" == "${DNSMASQ_PID}" ]]; then
+ debug "Killing dnsmasq: DNSMASQ_PID=${DNSMASQ_PID}"
+ sudo kill -9 $DNSMASQ_PID
+ return
+ fi
+ fi
+ DNSMASQ_PID="0"
+}
+
+# Creates a virt network.
+# $1 - the network interface name
+# $2 - use DHCP (any value)
+create_test_iface () {
+ local name=$1
+ local dhcp=$2
+ local definition=$(mktemp)
+ local network=$NETWORK
+ local definition=""
+ local xmlfile=$(mktemp)
+
+ debug "Creating network interface: $name"
+ destroy_test_iface $name
+ NETWORK_NAME=$name
+
+
definition="<network>\n<name>${name}</name>\n<forward
mode='nat' />\n<bridge name='${name}' stp='on'
forwardDelay='0' />"
+ definition="${definition}\n<ip address='${network}.1'
netmask='255.255.255.0'>"
+ if [ -n "$dhcp" ]; then
+ debug "Test networking is using DHCP."
+ definition="${definition}\n<dhcp>\n<range
start='${network}.100' end='${network}.199'
/>\n</dhcp>"
+ fi
+ definition="${definition}\n</ip>\n</network>"
+
+ debug "Saving network definition file to: ${xmlfile}\n"
+ sudo printf "${definition}" > $xmlfile
+ sudo virsh net-define $xmlfile > /dev/null 2>&1
+ debug "Starting network."
+ sudo virsh net-start $name > /dev/null 2>&1
+}
+
+# Destroys the test network interface
+# $1 - the network name
+destroy_test_iface () {
+ local networkname=${1-}
+
+ # if no network was supplied, then check for the global network
+ if [ -z "$networkname" ]; then
+ networkname=${NETWORK_NAME-}
+ fi
+
+ if [ -n "${networkname}" ]; then
+ debug "Destroying network interface: ${networkname}"
+ check=$(sudo virsh net-list --all)
+ if [[ "${check}" =~ "${networkname}" ]]; then
+ if [[ "{$check}" =~ active ]]; then
+ sudo virsh net-destroy $networkname > /dev/null 2>&1
+ fi
+ sudo virsh net-undefine $networkname > /dev/null 2>&1
+ fi
+
+ # ensure the bridge interface was destroyed
+ check=$(sudo /sbin/ifconfig)
+ if [[ "${check}" =~ "${networkname}" ]]; then
+ sudo /sbin/ifconfig $networkname down
+ fi
+ fi
+}
+
+# creates a HD disk file
# $1 - filename for disk file
-# $2 - size
+# $2 - size, in MB
create_hard_disk () {
local filename=$1
local size=$2
- sudo qemu-img create -f raw $filename $size
- sudo chcon -t virt_image_t $filename
+ debug "Creating hard disk: filename=${filename} size=${size}M"
+ sudo qemu-img create -f raw $filename "${size}M" > /dev/null
2>&1
+ sudo chcon -t virt_image_t $filename > /dev/null 2>&1
}
# Creates the XML for a virtual machine.
@@ -111,11 +259,19 @@ define_node () {
local vncport="-1"
local bootdev='hd'
+ # first destroy the node
+ destroy_node $nodename
+
# if a cdrom was defined, then assume it's the boot device
if [ -n "$cddrive" ]; then bootdev='cdrom'; fi
if [ -n "$options" ]; then eval "$options"; fi
+ debug "Defining virtual machine"
+ for var in filename nodename memory harddrive cddrive bridge options arch
emulator serial vncport bootdev; do
+ eval debug "$var: \$$var"
+ done
+
result="<domain
type='kvm'>\n<name>${nodename}</name>\n<memory>${memory}</memory>\n
<vcpu>1</vcpu>"
# begin the os section
@@ -139,6 +295,7 @@ define_node () {
result="${result}\n<emulator>${emulator}</emulator>"
# inject the hard disk if defined
if [ -n "$harddrive" ]; then
+ debug "Adding a hard drive to the node"
result="${result}\n<disk type='file'
device='disk'>"
result="${result}\n<source file='$harddrive' />"
result="${result}\n<target dev='vda' bus='virtio'
/>"
@@ -146,6 +303,7 @@ define_node () {
fi
# inject the cdrom drive if defined
if [ -n "$cddrive" ]; then
+ debug "Adding a CDROM drive to the node"
result="${result}\n<disk type='file'
device='cdrom'>"
result="${result}\n<source file='${cddrive}' />"
result="${result}\n<target dev='hdc' bus='ide'
/>"
@@ -169,398 +327,232 @@ define_node () {
result="${result}\n</domain>"
- log "Saving node definition to file: ${filename}"
+ debug "Node definition: ${filename}"
sudo printf "$result" > $filename
# now define the vm
- sudo virsh define $filename
+ sudo virsh define $filename > /dev/null 2>&1
if [ $? != 0 ]; then die "Unable to define virtual machine:
$nodename"; fi
}
-# Returns the mac address for the given node.
-# $1 - the node name
-# $2 - the variable name to set
-get_mac_address () {
- local nodename=$1
- local varname=$2
-
- if [ -z "$nodename" ]; then die "Cannot get mac address for
node with a name"; fi
-
- address=$(sudo virsh dumpxml $nodename|awk '/<mac address/ {
- match($0,"mac
address='"'"'(.*)'"'"'",data);
print data[1]}')
-
- if [ -z "$varname" ]; then die "Cannot set unnamed
varilable"; fi
- eval $varname="$address"
-}
-
-# Starts the named node.
-# $1 - the node name
-start_node () {
- local nodename=$1
-
- if [ -z "$nodename" ]; then die "Cannot start node without a
name"; fi
-
- sudo virsh start $nodename
-}
-
# Destroys any existing instance of the given node.
# $1 - the node name
destroy_node () {
local nodename=$1
if [ -n "${nodename}" ]; then
- log "Destroying VM: ${nodename}"
check=$(sudo virsh list --all)
if [[ "${check}" =~ "${nodename}" ]]; then
if [[ "${check}" =~ running ]]; then
- sudo virsh destroy $nodename
+ debug "Destroying node: $nodename"
+ sudo virsh destroy $nodename > /dev/null 2>&1
fi
- sudo virsh undefine $nodename
+ debug "Undefining node: $nodename"
+ sudo virsh undefine $nodename > /dev/null 2>&1
fi
fi
}
-# PXE boots a node.
-# $1 - the ISO file
-# $2 - the working directory
-# $3 - kernel arguments; if present then they replace all default flags
-setup_pxeboot () {
- local isofile=$1
- local workdir=$2
- local kernelargs=$3
- local pxedefault=$workdir/tftpboot/pxelinux.cfg/default
-
- (cd $workdir && sudo livecd-iso-to-pxeboot $isofile)
- sudo chmod -R 777 $workdir
-
- # set default kernel arguments if none were provided
- # the defaults boot in standalone mode
- if [ -z "$kernelargs" ]; then
- kernelargs="ovirt_standalone"
- fi
-
- local definition="DEFAULT pxeboot\nTIMEOUT 20\nPROMPT 0\nLABEL
pxeboot\n KERNEL vmlinuz0\n IPAPPEND 2\n APPEND rootflags=loop
BOOTIF=link|eth*|<MAC> initrd=initrd0.img root=/ovirt-node-image.iso
rootfstype=auto console=ttyS0,115200n8 $kernelargs\n"
+# for each test created, add it to the follow array:
+tests=''; testcount=0;
- sudo bash -c "printf \"${definition}\" >
$pxedefault"
+# $1 - test name
+add_test () {
+ tests[$testcount]=$1
+ testcount=$testcount+1
}
-# Launches the node as a virtual machine.
-# $1 - the node name
-# $2 - the ISO filename
-# $3 - the hard disk file
-# $4 - the memory size (in MB)
-# $5 - the network bridge to use
-# $6 - kernel arguments
-# $7 - verification method
-pxeboot_node_vm () {
- local nodename=$1
- local isofile=$2
- local diskfile=$3
- local memsize=$4
- local bridge=$5
- local kernel_args=$6
- local verify_method=$7
- local xmlfile=$(mktemp)
- local tftproot=$(mktemp -d)
- local node_mac_address=""
- local return_code=0
-
- destroy_node $nodename
+# $1 - the node's name
+# $2 - hard disk size (no disk if blank)
+# $3 - script to verify the node
+# $4 - kernel arguments
+boot_with_pxe () {
+ local workdir=$(mktemp -d)
+ local nodename=${1-}
+ local disksize=${2-}
+ local script=${3-}
+ local kernel_args=${4-}
+ local diskfile=$workdir/ovirt-harddisk.img
+ local nodefile=$workdir/ovirt-node.xml
- log "Beginning pxeboot for $nodename"
- # setup the dnsmasq instance with the iso setup
- setup_pxeboot "$isofile" "$tftproot"
"$kernel_args"
- create_test_iface $bridge
- define_node $xmlfile $nodename $memsize "$diskfile" ""
$bridge "local bootdev='network'; local noapic='yes'"
- get_mac_address $nodename "node_mac_address"
- start_dnsmasq $bridge $tftproot $node_mac_address $nodename
- start_node $nodename
- if [ -n "$verify_method" ]; then
- eval $verify_method
- return_code=$?
+ setup_pxeboot $workdir "${kernel_args}"
+ if [ -n "${disksize}" ]; then
+ create_hard_disk $diskfile $disksize
+ else
+ diskfile=""
fi
- destroy_node $nodename
- stop_dnsmasq
- destroy_test_iface $bridge
- log "Finished pxeboot for $nodename (RC=${return_code})"
- if [ $return_code != 0 ]; then
- log "Test ended in failure"
+ create_test_iface $IFACE_NAME ""
+ start_dnsmasq $IFACE_NAME $workdir "" "${nodename}"
+ define_node $nodefile $nodename 524288 "${diskfile}" ""
$IFACE_NAME "local bootdev='network'; local
noapic='yes'"
+ debug "Starting node: $nodename"
+ sudo virsh start $nodename # > /dev/null 2>&1
+ if $show_viewer; then
+ sudo virt-viewer $nodename > /dev/null 2>&1&
fi
- test $return_code == 0 && return 0 || return 1
-}
-
-# Launches the node as a virtual machine with a CDROM.
-# $1 - the node name
-# $2 - the ISO filename
-# $3 - the disk file to use
-# $4 - the memory size (in MB)
-# $5 - the network bridge
-cdrom_boot_node_vm () {
- local nodename=$1
- local isofile=$2
- local diskfile=$3
- local memsize=$4
- local bridge=$5
- local xmlfile=$(mktemp)
+ result=0
+ if [ -n "${script}" ]; then
+ debug "script=${script}"
+ expect -c "${script}"
+ result=$?
+ debug "result=$result"
+ read -ep "Press ENTER To Continue: "
+ else
+ read -ep "Press ENTER To Continue: "
+ fi
destroy_node $nodename
+ stop_dnsmasq
+ destroy_test_iface $IFACE_NAME
- log "Beginning cdrom boot for $nodename"
- create_test_iface $bridge "yes"
- define_node $xmlfile $nodename $memsize "$diskfile"
"$isofile" $bridge
- start_node $nodename
- # TODO make sure the node's booted
- sleep 300
- # TODO verify the node's running
- destroy_node $nodename
- destroy_test_iface $bridge
- log "Finished cdrom booting for $nodename"
+ return $result
}
-# Creates a virt network.
-# $1 - the network interface name
-# $2 - use DHCP (any value)
-create_test_iface () {
- local name=$1
- local dhcp=$2
- local definition=$(mktemp)
- local network=$NETWORK
- local definition=""
- local xmlfile=$(mktemp)
+STATELESS_PXE_NOHD_SCRIPT="set timeout 120
+log_file -noappend expect.log
- destroy_test_iface $name
- NETWORK_NAME=$name
+spawn sudo virsh console stateless-pxe-nohd
- log "Creating network definition file: $definition"
-
definition="<network>\n<name>${name}</name>\n<forward
mode='nat' />\n<bridge name='${name}' stp='on'
forwardDelay='0' />"
- definition="${definition}\n<ip address='${network}.1'
netmask='255.255.255.0'>"
- if [ -n "$dhcp" ]; then
- definition="${definition}\n<dhcp>\n<range
start='${network}.100' end='${network}.199'
/>\n</dhcp>"
- fi
- definition="${definition}\n</ip>\n</network>"
-
- printf "Saving network definition file to: ${xmlfile}\n"
- sudo printf "${definition}" > $xmlfile
- sudo virsh net-define $xmlfile
- log "Starting network"
- sudo virsh net-start $name
+expect {
+ -exact \"Linux version\" { send_log \"\\n\\nMarker
1\\n\\n\"; exp_continue }
+ -exact \"Starting ovirt-early:\" { send_log \"\\n\\nMarker
2\\n\\n\"; exp_continue }
+ -exact \"Starting ovirt:\" { send_log \"\\n\\nMarker
3\\n\\n\"; exp_continue }
+ -exact \"Starting ovirt-post:\" { send_log \"\\n\\nMarker
4\\n\\n\"; exp_continue }
+ -exact \"login:\" { send_log \"\\n\\nMarker
5\\n\\n\"; exit }
+ timeout {
+ send_user \"\\nMarker not found.\\n\\n\"
+ exit 1
+ } eof {
+ send_user \"Unexpected end of file.\"
+ exit 2
+ }
}
-# Destroys the test network interface
-# $1 - the network name
-destroy_test_iface () {
- local networkname=$1
-
- # if no network was supplied, then check for the global network
- if [ -z "$networkname" ]; then
- networkname=$NETWORK_NAME
- fi
-
- if [ -n "${networkname}" ]; then
- log "Destroying network interface: ${networkname}"
- check=$(sudo virsh net-list --all)
- if [[ "${check}" =~ "${networkname}" ]]; then
- log "- found existing instance"
- if [[ "{$check}" =~ active ]]; then
- log "- shutting down current instance"
- sudo virsh net-destroy $networkname
- fi
- log "- undefining previous instance"
- sudo virsh net-undefine $networkname
- fi
+send_log \"\\n\\nUnexpected end of interaction.\\n\\n\"
+exit 3"
- # ensure the bridge interface was destroyed
- check=$(sudo /sbin/ifconfig)
- if [[ "${check}" =~ "${networkname}" ]]; then
- sudo /sbin/ifconfig $networkname down
- fi
- fi
+add_test "test_stateless_pxe_with_nohd"
+test_stateless_pxe_with_nohd () {
+ boot_with_pxe "stateless-pxe-nohd" ""
"${STATELESS_PXE_NOHD_SCRIPT}" "ovirt_firstboot=yes"
}
-# Starts a simple instance of dnsmasq.
-# $1 - the iface on which dnsmasq works
-# $2 - the root for tftp files
-# $3 - the mac address for the node (ignored if blank)
-# $4 - the nodename
-start_dnsmasq () {
- local iface=$1
- local tftproot=$2
- local macaddress=$3
- local nodename=$4
- local pidfile=$2/dnsmasq.pid
-
- stop_dnsmasq
- log "Starting dnsmasq"
- dns_startup="sudo /usr/sbin/dnsmasq --read-ethers
-
--dhcp-range=${NETWORK}.100,${NETWORK}.254,255.255.255.0,24h
- --interface=${iface}
- --bind-interfaces
- --except-interface=lo
- --dhcp-boot=tftpboot/pxelinux.0
- --enable-tftp
- --tftp-root=${tftproot}
-
--log-facility=/tmp/dnsmasq-${nodename}.log
- --log-queries
- --log-dhcp
- --pid-file=${pidfile}"
- if [ -n "$macaddress" ]; then
- dns_startup="${dns_startup}
--dhcp-host=${macaddress},${NODE_ADDRESS}"
- fi
- # start dnsmasq
- eval $dns_startup
- DNSMASQ_PID=$(sudo cat $pidfile)
- log "dnsmasq start: PID=${DNSMASQ_PID}"
-}
+STATELESS_PXE_SCRIPT="set timeout 120
+log_file -noappend expect.log
-# Kills the running instance of dnsmasq.
-stop_dnsmasq () {
- log "Killing dnsmasq: DNSMASQ_PID=${DNSMASQ_PID}"
- if [ -n "$DNSMASQ_PID" -a "$DNSMASQ_PID" !=
"0" ]; then
- local check=$(ps -ef | awk "/${DNSMASQ_PID}/"' { if ($2 ~
'"${DNSMASQ_PID}"') print $2 }')
+spawn sudo virsh console stateless-pxe
- if [[ "${check}" == "${DNSMASQ_PID}" ]]; then
- log "Killing dnsmasq"
- sudo kill -9 $DNSMASQ_PID
- return
- fi
- fi
- log "No running instance of dnsmasq found."
- DNSMASQ_PID="0"
+expect {
+ -exact \"Linux version\" { send_log \"\\n\\nMarker
1\\n\\n\"; exp_continue }
+ -exact \"Starting ovirt-early:\" { send_log \"\\n\\nMarker
2\\n\\n\"; exp_continue }
+ -exact \"Starting ovirt:\" { send_log \"\\n\\nMarker
3\\n\\n\"; exp_continue }
+ -exact \"Starting ovirt-post:\" { send_log \"\\n\\nMarker
4\\n\\n\"; exp_continue }
+ -re \"localhost.*login:\" { send_log \"\\n\\nMarker
5\\n\\n\"; exit }
+ timeout {
+ send_user \"\\nMarker not found.\\n\\n\"
+ exit 1
+ } eof {
+ send_user \"Unexpected end of file.\"
+ exit 2
+ }
}
-# Boots a node via CDROM.
-# $1 - the node name
-# $2 - the network to use
-# $3 - the working directory
-# $4 - the ISO file to use as CDROM
-cdrom_boot () {
- local nodename=$1
- local network=$2
- local workdir=$3
- local isofile=$4
- local diskfile=$workdir/ovirt-harddisk.img
+send_log \"\\n\\nUnexpected end of interaction.\\n\\n\"
+exit 3"
- create_hard_disk $diskfile "10G"
- cdrom_boot_node_vm $nodename $isofile $diskfile "512" $network
+add_test "test_stateless_pxe"
+test_stateless_pxe () {
+ boot_with_pxe "stateless-pxe" "10000"
"${STATELESS_PXE_SCRIPT}" "ovirt_firstboot=yes"
}
-# verify that a node has booted properly
-# $1 - the node's name
-# $2 - the logfile to use
-verify_pxeboot_stateless_standalone () {
- local nodename=$1
- local port=$(sudo virsh ttyconsole $nodename)
- local logfile=$2
+STATEFUL_PXE_SCRIPT="set timeout 120
+log_file -noappend expect.log
+
+spawn sudo virsh console stateful-pxe
- log "Verifying ${nodename} is booted correctly"
- local script='
-log_file -noappend '"${logfile}"'
-set timeout 60
-expect {
- "Linux version" {send_log "\n\n***\nGot first boot
marker\n\n"}
- timeout {send_log "\n\n***\nDid not receive in time\n\n"
- exit 1}
-}
expect {
- -re "Kernel command line.*ovirt_standalone" {send_log
"\n\n***\nGot kernel arguments marker\n\n"}
+ -exact \"Linux version\" { send_log
\"\\n\\nMarker 1\\n\\n\"; exp_continue }
+ -exact \"Starting ovirt-early:\" { send_log
\"\\n\\nMarker 2\\n\\n\"; exp_continue }
+ -exact \"Starting ovirt:\" { send_log
\"\\n\\nMarker 3\\n\\n\"; exp_continue }
+ -exact \"Starting ovirt-post:\" { send_log
\"\\n\\nMarker 4\\n\\n\"; exp_continue }
+ -exact \"Starting ovirt-firstpost:\" { send_log
\"\\n\\nMarker 5\\n\\n\"; exp_continue }
+ -exact \"Starting partitioning of /dev/vda\" { send_log
\"\\n\\nMarker 6\\n\\n\"; exp_continue }
+ -exact \"Restarting system\" { send_log
\"\\n\\nMarker 7\\n\\n\"; exit }
timeout {
- send_log "\n\n***\nDid not receive in time\n\n"
- exit 2
+ send_user \"\\nMarker not found.\\n\\n\"
+ exit 1
+ } eof {
+ send_user \"Unexpected end of file.\"
+ exit 2
}
}
-expect {
- "Starting ovirt-early:" {send_log "\n\n***\nGot ovirt-early
marker\n\n"}
- timeout {send_log "\n\n***\nDid not receive in time\n\n"
- exit 3}
-}
-expect {
- "Starting ovirt:" {send_log "\n\n***\nGot ovirt
marker\n\n"}
- timeout {send_log "\n\n***\nDid not receive in time\n\n"
- exit 4}
-}
-expect {
- "Starting ovirt-post:" {send_log "\n\n***\nGot ovirt-post
marker\n\n"}
- timeout {send_log "\n\n***\nDid not receive in time\n\n"
- exit 5}
-}
-expect {
- "Starting ovirt-firstboot:" {send_log "\n\n***\nGot
ovirt-firstboot marker\n\n"}
- timeout {send_log "\n\n***\nDid not receive in time\n\n"
- exit 6}
-}'
-
- sudo bash -c "/usr/bin/expect -c '${script}' <
${port}"
- result=$?
- printf "result=${result}\n"
-}
-
-# Verify that a stateful node has booted properly.
-# $1 - the node's name
-# $2 - the logfile for recording the transcript
-verify_pxeboot_stateful_standalone () {
- local nodename=$1
- local port=$(sudo virsh ttyconsole $nodename)
- local logfile=$2
-
- # leverage the existing stateless test
- verify_pxeboot_stateless_standalone $nodename
- log "Verifying ${nodename} is booted correctly"
- local script='
-log_file -noappend '"${logfile}"'
-set timeout 180
-expect {
- -re "login:$" {send_log "\n\n***\nGot login
prompt!\n\n"}
- timeout {send_log "\n\n***\nDid not receive in time\n\n"
- exit 7}
-}'
- sudo bash -c "/usr/bin/expect -c '${script}' <
${port}"
-}
-# TEST: Performs a PXE boot of the node as a standalone, stateless instance.
-test_pxeboot_stateless_standalone () {
- local nodename="pxe_stateless_standalone-$$"
- local hdfile=$(mktemp)
+send_log \"\\n\\nUnexpected end of interaction.\\n\\n\"
+exit 3"
- log "TEST: Booting a stateless standalone node via PXE."
- create_hard_disk $hdfile "10G"
- pxeboot_node_vm $nodename $OVIRT_NODE_IMAGE_ISO "${hdfile}"
"524288" \
- $IFACE_NAME "ovirt_standalone OVIRT_FIRSTBOOT=no" \
- "verify_pxeboot_stateless_standalone $nodename
'pxeboot_stateless_standalone.log'"
+# add_test "test_stateful_pxe"
+test_stateful_pxe () {
+ boot_with_pxe "stateful-pxe" "10000"
"${STATEFUL_PXE_SCRIPT}" "ovirt_standalone ovirt_init=/dev/vda
ovirt_local_boot"
}
-# TEST: Performs a PXE boot of the node as a standalone instance. The node then
performs a full install
-test_pxeboot_stateful_standalone () {
- local nodename="pxe_stateful_standalone-$$"
- local hdfile=$(mktemp)
-
- log "TEST: Installing a stateful standalone node via PXE."
- create_hard_disk $hdfile "10G"
- pxeboot_node_vm $nodename $OVIRT_NODE_IMAGE_ISO "${hdfile}"
"524288" \
- $IFACE_NAME "ovirt_standalone OVIRT_FIRSTBOOT=no
ovirt_init=/dev/vda" \
- "verify_pxeboot_stateful_standalone $nodename
'pxeboot_stateful_standalone.log'"
+# configures the environment for testing
+setup_for_testing () {
+ debug "isofile=${isofile}"
+ debug "isoname=${isoname}"
+ IFACE_NAME=testbr$$
+ debug "IFACE_NAME=${IFACE_NAME}"
+ NETWORK=192.168.$(echo "scale=0; print $$ % 255" | bc -l)
+ debug "NETWORK=${NETWORK}"
+ NODE_ADDRESS=$NETWORK.100
+ debug "NODE_ADDRESS=${NODE_ADDRESS}"
+ DNSMASQ_PID=0
}
-# TEST: Performs a CDROM boot of the node as a standalone, stateless instance
-test_cdrom_stateless_standalone () {
- local nodename="stateless_cdrom_standalone-$$"
-
- log "TEST: Booting a stateless node from CDROM."
- cdrom_boot $nodename "$IFACE_NAME" "$TFTP_ROOT_DIR"
"$OVIRT_NODE_IMAGE_ISO"
+# cleans up any loose ends
+cleanup_after_testing () {
+ stop_dnsmasq
+ destroy_test_iface
}
-# automated testing entry points
+# check commandline options
+test=''
+debugging=false
+isofile="${PWD}/ovirt-node-image.iso"
+show_viewer=false
+
+while getopts di:n:vwh c; do
+ case $c in
+ d) debugging=true;;
+ i) isofile=($OPTARG);;
+ n) tests=($OPTARG);;
+ v) set -v;;
+ w) show_viewer=true;;
+ h) usage; exit 0;;
+ '?') die "invalid option \`-$OPTARG'";;
+ :) die "missing argument to \`-$OPTARG' option";;
+ *) die "internal error";;
+ esac
+done
+
+isoname=$(basename $isofile)
+isofile="$(cd dirname $isofile; pwd)/${isoname}"
+
+shift $(($OPTIND - 1))
+
+set +u
+if [ $# -gt 0 -a -n "${1-}" ]; then RESULTS=$1; else
RESULTS=autotest.log; fi
+set -u
+
+log "Logging results to file: ${RESULTS}"
{
- IFACE_NAME=testbr$$
- NETWORK=192.168.$(echo "scale=0; print $$ % 255" | bc -l)
- NODE_ADDRESS=$NETWORK.100
- DNSMASQ_PID=0
+ setup_for_testing
+
+ log "Begin Testing: RHEV-H"
- log "Starting tests"
- log "Using network: ${NETWORK}.0"
+ for test in ${tests[@]}; do
+ execute_test $test
+ done
- test_pxeboot_stateless_standalone
- test_pxeboot_stateful_standalone
+ log "End Testing: RHEV-H"
} | sudo tee --append $RESULTS
--
1.6.0.6