Added ping_check and ssh_check functions and use it in exercise.sh
Change-Id: I69d41c9db527f60f250b6af36b2d8e9d0dd39684
diff --git a/exercises/boot_from_volume.sh b/exercises/boot_from_volume.sh
index 183efa6..460b50c 100755
--- a/exercises/boot_from_volume.sh
+++ b/exercises/boot_from_volume.sh
@@ -139,16 +139,10 @@
nova add-floating-ip $VOL_VM_UUID $FLOATING_IP
# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
-if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
- echo "Couldn't ping volume-backed server with floating ip"
- exit 1
-fi
+ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
# Make sure our volume-backed instance launched
-if ! timeout $ACTIVE_TIMEOUT sh -c "while ! ssh -o StrictHostKeyChecking=no -i $KEY_FILE ${DEFAULT_INSTANCE_USER}@$FLOATING_IP echo success ; do sleep 1; done"; then
- echo "server didn't become ssh-able!"
- exit 1
-fi
+ssh_check "$PUBLIC_NETWORK_NAME" $KEY_FILE $FLOATING_IP $DEFAULT_INSTANCE_USER $ACTIVE_TIMEOUT
# Remove floating ip from volume-backed instance
nova remove-floating-ip $VOL_VM_UUID $FLOATING_IP
diff --git a/exercises/euca.sh b/exercises/euca.sh
index 58b5d91..b121493 100755
--- a/exercises/euca.sh
+++ b/exercises/euca.sh
@@ -130,10 +130,7 @@
die "Failure authorizing rule in $SECGROUP"
# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
-if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
- echo "Couldn't ping server with floating ip"
- exit 1
-fi
+ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
# Revoke pinging
euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
diff --git a/exercises/floating_ips.sh b/exercises/floating_ips.sh
index 77f020e..6787878 100755
--- a/exercises/floating_ips.sh
+++ b/exercises/floating_ips.sh
@@ -118,23 +118,10 @@
fi
# get the IP of the server
-IP=`nova show $VM_UUID | grep "private network" | get_field 2`
+IP=`nova show $VM_UUID | grep "$PRIVATE_NETWORK_NAME" | get_field 2`
die_if_not_set IP "Failure retrieving IP address"
-# for single node deployments, we can ping private ips
-MULTI_HOST=`trueorfalse False $MULTI_HOST`
-if [ "$MULTI_HOST" = "False" ]; then
- # sometimes the first ping fails (10 seconds isn't enough time for the VM's
- # network to respond?), so let's ping for a default of 15 seconds with a
- # timeout of a second for each ping.
- if ! timeout $BOOT_TIMEOUT sh -c "while ! ping -c1 -w1 $IP; do sleep 1; done"; then
- echo "Couldn't ping server"
- exit 1
- fi
-else
- # On a multi-host system, without vm net access, do a sleep to wait for the boot
- sleep $BOOT_TIMEOUT
-fi
+ping_check "$PRIVATE_NETWORK_NAME" $IP $BOOT_TIMEOUT
# Security Groups & Floating IPs
# ------------------------------
@@ -166,10 +153,7 @@
die "Failure adding floating IP $FLOATING_IP to $NAME"
# test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
-if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
- echo "Couldn't ping server with floating ip"
- exit 1
-fi
+ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
# Allocate an IP from second floating pool
TEST_FLOATING_IP=`nova floating-ip-create $TEST_FLOATING_POOL | grep $TEST_FLOATING_POOL | get_field 1`
@@ -187,19 +171,16 @@
# FIXME (anthony): make xs support security groups
if [ "$VIRT_DRIVER" != "xenserver" -a "$VIRT_DRIVER" != "openvz" ]; then
# test we can aren't able to ping our floating ip within ASSOCIATE_TIMEOUT seconds
- if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
- print "Security group failure - ping should not be allowed!"
- echo "Couldn't ping server with floating ip"
- exit 1
- fi
+ ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
fi
-# de-allocate the floating ip
-nova floating-ip-delete $FLOATING_IP || die "Failure deleting floating IP $FLOATING_IP"
-
# Delete second floating IP
nova floating-ip-delete $TEST_FLOATING_IP || die "Failure deleting floating IP $TEST_FLOATING_IP"
+
+# de-allocate the floating ip
+nova floating-ip-delete $FLOATING_IP || die "Failure deleting floating IP $FLOATING_IP"
+
# Shutdown the server
nova delete $VM_UUID || die "Failure deleting instance $NAME"
diff --git a/exercises/volumes.sh b/exercises/volumes.sh
index ffa12c4..1c73786 100755
--- a/exercises/volumes.sh
+++ b/exercises/volumes.sh
@@ -119,23 +119,11 @@
fi
# get the IP of the server
-IP=`nova show $VM_UUID | grep "private network" | get_field 2`
+IP=`nova show $VM_UUID | grep "$PRIVATE_NETWORK_NAME" | get_field 2`
die_if_not_set IP "Failure retrieving IP address"
# for single node deployments, we can ping private ips
-MULTI_HOST=`trueorfalse False $MULTI_HOST`
-if [ "$MULTI_HOST" = "False" ]; then
- # sometimes the first ping fails (10 seconds isn't enough time for the VM's
- # network to respond?), so let's ping for a default of 15 seconds with a
- # timeout of a second for each ping.
- if ! timeout $BOOT_TIMEOUT sh -c "while ! ping -c1 -w1 $IP; do sleep 1; done"; then
- echo "Couldn't ping server"
- exit 1
- fi
-else
- # On a multi-host system, without vm net access, do a sleep to wait for the boot
- sleep $BOOT_TIMEOUT
-fi
+ping_check "$PRIVATE_NETWORK_NAME" $IP $BOOT_TIMEOUT
# Volumes
# -------