exercise using timeouts instead of sleeping
| ... | ... |
@@ -82,11 +82,11 @@ nova boot --flavor $FLAVOR --image $IMAGE $NAME --security_groups=$SECGROUP |
| 82 | 82 |
# Waiting for boot |
| 83 | 83 |
# ---------------- |
| 84 | 84 |
|
| 85 |
-# let's give it 10 seconds to launch |
|
| 86 |
-sleep 10 |
|
| 87 |
- |
|
| 88 |
-# check that the status is active |
|
| 89 |
-nova show $NAME | grep status | grep -q ACTIVE |
|
| 85 |
+# check that the status is active within 10 seconds |
|
| 86 |
+if ! timeout 10 sh -c "while ! nova show $NAME | grep status | grep -q ACTIVE; do sleep 1; done"; then |
|
| 87 |
+ echo "server didn't become active!" |
|
| 88 |
+ exit 1 |
|
| 89 |
+fi |
|
| 90 | 90 |
|
| 91 | 91 |
# get the IP of the server |
| 92 | 92 |
IP=`nova show $NAME | grep "private network" | cut -d"|" -f3` |
| ... | ... |
@@ -94,14 +94,13 @@ IP=`nova show $NAME | grep "private network" | cut -d"|" -f3` |
| 94 | 94 |
# for single node deployments, we can ping private ips |
| 95 | 95 |
MULTI_HOST=${MULTI_HOST:-0}
|
| 96 | 96 |
if [ "$MULTI_HOST" = "0" ]; then |
| 97 |
- # ping it once (timeout of a second) |
|
| 98 |
- ping -c1 -w1 $IP || true |
|
| 99 |
- |
|
| 100 | 97 |
# sometimes the first ping fails (10 seconds isn't enough time for the VM's |
| 101 |
- # network to respond?), so let's wait 5 seconds and really test ping |
|
| 102 |
- sleep 5 |
|
| 103 |
- |
|
| 104 |
- ping -c1 -w1 $IP |
|
| 98 |
+ # network to respond?), so let's ping for 15 seconds with a timeout |
|
| 99 |
+ # of a second. |
|
| 100 |
+ if ! timeout 15 sh -c "while ! ping -c1 -w1 $IP; do sleep 1; done"; then |
|
| 101 |
+ echo "Couldn't ping server" |
|
| 102 |
+ exit 1 |
|
| 103 |
+ fi |
|
| 105 | 104 |
fi |
| 106 | 105 |
|
| 107 | 106 |
# Security Groups & Floating IPs |
| ... | ... |
@@ -122,21 +121,19 @@ FLOATING_IP=`nova floating-ip-list | grep None | head -1 | cut -d '|' -f2 | sed |
| 122 | 122 |
# add floating ip to our server |
| 123 | 123 |
nova add-floating-ip $NAME $FLOATING_IP |
| 124 | 124 |
|
| 125 |
-# sleep for a smidge |
|
| 126 |
-sleep 5 |
|
| 127 |
- |
|
| 128 |
-# ping our floating ip |
|
| 129 |
-ping -c1 -w1 $FLOATING_IP |
|
| 125 |
+# test we can ping our floating ip within 10 seconds |
|
| 126 |
+if ! timeout 10 sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then |
|
| 127 |
+ echo "Couldn't ping server with floating ip" |
|
| 128 |
+ exit 1 |
|
| 129 |
+fi |
|
| 130 | 130 |
|
| 131 | 131 |
# dis-allow icmp traffic (ping) |
| 132 | 132 |
nova secgroup-delete-rule $SECGROUP icmp -1 -1 0.0.0.0/0 |
| 133 | 133 |
|
| 134 |
-# sleep for a smidge |
|
| 135 |
-sleep 5 |
|
| 136 |
- |
|
| 137 |
-# ping our floating ip |
|
| 138 |
-if ( ping -c1 -w1 $FLOATING_IP ); then |
|
| 134 |
+# test we can aren't able to ping our floating ip within 10 seconds |
|
| 135 |
+if ! timeout 10 sh -c "while ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then |
|
| 139 | 136 |
print "Security group failure - ping should not be allowed!" |
| 137 |
+ echo "Couldn't ping server with floating ip" |
|
| 140 | 138 |
exit 1 |
| 141 | 139 |
fi |
| 142 | 140 |
|