Browse code

Added ping_check and ssh_check functions and use it in exercise.sh

Change-Id: I69d41c9db527f60f250b6af36b2d8e9d0dd39684

Nachi Ueno authored on 2012/10/25 09:26:02
Showing 8 changed files
... ...
@@ -139,16 +139,10 @@ fi
139 139
 nova add-floating-ip $VOL_VM_UUID $FLOATING_IP
140 140
 
141 141
 # Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
142
-if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
143
-    echo "Couldn't ping volume-backed server with floating ip"
144
-    exit 1
145
-fi
142
+ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
146 143
 
147 144
 # Make sure our volume-backed instance launched
148
-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
149
-    echo "server didn't become ssh-able!"
150
-    exit 1
151
-fi
145
+ssh_check "$PUBLIC_NETWORK_NAME" $KEY_FILE $FLOATING_IP $DEFAULT_INSTANCE_USER $ACTIVE_TIMEOUT
152 146
 
153 147
 # Remove floating ip from volume-backed instance
154 148
 nova remove-floating-ip $VOL_VM_UUID $FLOATING_IP
... ...
@@ -130,10 +130,7 @@ euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
130 130
     die "Failure authorizing rule in $SECGROUP"
131 131
 
132 132
 # Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
133
-if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
134
-    echo "Couldn't ping server with floating ip"
135
-    exit 1
136
-fi
133
+ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
137 134
 
138 135
 # Revoke pinging
139 136
 euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
... ...
@@ -118,23 +118,10 @@ if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | g
118 118
 fi
119 119
 
120 120
 # get the IP of the server
121
-IP=`nova show $VM_UUID | grep "private network" | get_field 2`
121
+IP=`nova show $VM_UUID | grep "$PRIVATE_NETWORK_NAME" | get_field 2`
122 122
 die_if_not_set IP "Failure retrieving IP address"
123 123
 
124
-# for single node deployments, we can ping private ips
125
-MULTI_HOST=`trueorfalse False $MULTI_HOST`
126
-if [ "$MULTI_HOST" = "False" ]; then
127
-    # sometimes the first ping fails (10 seconds isn't enough time for the VM's
128
-    # network to respond?), so let's ping for a default of 15 seconds with a
129
-    # timeout of a second for each ping.
130
-    if ! timeout $BOOT_TIMEOUT sh -c "while ! ping -c1 -w1 $IP; do sleep 1; done"; then
131
-        echo "Couldn't ping server"
132
-        exit 1
133
-    fi
134
-else
135
-    # On a multi-host system, without vm net access, do a sleep to wait for the boot
136
-    sleep $BOOT_TIMEOUT
137
-fi
124
+ping_check "$PRIVATE_NETWORK_NAME" $IP $BOOT_TIMEOUT
138 125
 
139 126
 # Security Groups & Floating IPs
140 127
 # ------------------------------
... ...
@@ -166,10 +153,7 @@ nova add-floating-ip $VM_UUID $FLOATING_IP || \
166 166
     die "Failure adding floating IP $FLOATING_IP to $NAME"
167 167
 
168 168
 # test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
169
-if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
170
-    echo "Couldn't ping server with floating ip"
171
-    exit 1
172
-fi
169
+ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
173 170
 
174 171
 # Allocate an IP from second floating pool
175 172
 TEST_FLOATING_IP=`nova floating-ip-create $TEST_FLOATING_POOL | grep $TEST_FLOATING_POOL | get_field 1`
... ...
@@ -187,19 +171,16 @@ nova secgroup-delete-rule $SECGROUP icmp -1 -1 0.0.0.0/0 || die "Failure deletin
187 187
 # FIXME (anthony): make xs support security groups
188 188
 if [ "$VIRT_DRIVER" != "xenserver" -a "$VIRT_DRIVER" != "openvz" ]; then
189 189
     # test we can aren't able to ping our floating ip within ASSOCIATE_TIMEOUT seconds
190
-    if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
191
-        print "Security group failure - ping should not be allowed!"
192
-        echo "Couldn't ping server with floating ip"
193
-        exit 1
194
-    fi
190
+    ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
195 191
 fi
196 192
 
197
-# de-allocate the floating ip
198
-nova floating-ip-delete $FLOATING_IP || die "Failure deleting floating IP $FLOATING_IP"
199
-
200 193
 # Delete second floating IP
201 194
 nova floating-ip-delete $TEST_FLOATING_IP || die "Failure deleting floating IP $TEST_FLOATING_IP"
202 195
 
196
+
197
+# de-allocate the floating ip
198
+nova floating-ip-delete $FLOATING_IP || die "Failure deleting floating IP $FLOATING_IP"
199
+
203 200
 # Shutdown the server
204 201
 nova delete $VM_UUID || die "Failure deleting instance $NAME"
205 202
 
... ...
@@ -119,23 +119,11 @@ if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | g
119 119
 fi
120 120
 
121 121
 # get the IP of the server
122
-IP=`nova show $VM_UUID | grep "private network" | get_field 2`
122
+IP=`nova show $VM_UUID | grep "$PRIVATE_NETWORK_NAME" | get_field 2`
123 123
 die_if_not_set IP "Failure retrieving IP address"
124 124
 
125 125
 # for single node deployments, we can ping private ips
126
-MULTI_HOST=`trueorfalse False $MULTI_HOST`
127
-if [ "$MULTI_HOST" = "False" ]; then
128
-    # sometimes the first ping fails (10 seconds isn't enough time for the VM's
129
-    # network to respond?), so let's ping for a default of 15 seconds with a
130
-    # timeout of a second for each ping.
131
-    if ! timeout $BOOT_TIMEOUT sh -c "while ! ping -c1 -w1 $IP; do sleep 1; done"; then
132
-        echo "Couldn't ping server"
133
-        exit 1
134
-    fi
135
-else
136
-    # On a multi-host system, without vm net access, do a sleep to wait for the boot
137
-    sleep $BOOT_TIMEOUT
138
-fi
126
+ping_check "$PRIVATE_NETWORK_NAME" $IP $BOOT_TIMEOUT
139 127
 
140 128
 # Volumes
141 129
 # -------
... ...
@@ -849,6 +849,42 @@ function yum_install() {
849 849
         yum install -y "$@"
850 850
 }
851 851
 
852
+# ping check
853
+# Uses globals ``ENABLED_SERVICES``
854
+function ping_check() {
855
+    _ping_check_novanet "$1" $2 $3
856
+}
857
+
858
+# ping check for nova
859
+# Uses globals ``MULTI_HOST``, ``PRIVATE_NETWORK``
860
+function _ping_check_novanet() {
861
+    local from_net=$1
862
+    local ip=$2
863
+    local boot_timeout=$3
864
+    MULTI_HOST=`trueorfalse False $MULTI_HOST`
865
+    if [[ "$MULTI_HOST" = "True" && "$from_net" = "$PRIVATE_NETWORK_NAME" ]]; then
866
+        sleep $boot_timeout
867
+        return
868
+    fi
869
+    if ! timeout $boot_timeout sh -c "while ! ping -c1 -w1 $ip; do sleep 1; done"; then
870
+        echo "Couldn't ping server"
871
+        exit 1
872
+    fi
873
+}
874
+
875
+# ssh check
876
+function ssh_check() {
877
+    local NET_NAME=$1
878
+    local KEY_FILE=$2
879
+    local FLOATING_IP=$3
880
+    local DEFAULT_INSTANCE_USER=$4
881
+    local ACTIVE_TIMEOUT=$5
882
+    local probe_cmd = ""
883
+    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
884
+        echo "server didn't become ssh-able!"
885
+        exit 1
886
+    fi
887
+}
852 888
 
853 889
 # Restore xtrace
854 890
 $XTRACE
... ...
@@ -72,3 +72,6 @@ export COMPUTE_API_VERSION=${COMPUTE_API_VERSION:-$NOVA_VERSION}
72 72
 # set log level to DEBUG (helps debug issues)
73 73
 # export KEYSTONECLIENT_DEBUG=1
74 74
 # export NOVACLIENT_DEBUG=1
75
+
76
+# set qunatum debug command
77
+export TEST_CONFIG_FILE=/etc/quantum/debug.ini
... ...
@@ -1950,14 +1950,14 @@ if is_service_enabled q-svc; then
1950 1950
     # Create a small network
1951 1951
     # Since quantum command is executed in admin context at this point,
1952 1952
     # ``--tenant_id`` needs to be specified.
1953
-    NET_ID=$(quantum net-create --tenant_id $TENANT_ID net1 | grep ' id ' | get_field 2)
1953
+    NET_ID=$(quantum net-create --tenant_id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
1954 1954
     SUBNET_ID=$(quantum subnet-create --tenant_id $TENANT_ID --ip_version 4 --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
1955 1955
     if is_service_enabled q-l3; then
1956 1956
         # Create a router, and add the private subnet as one of its interfaces
1957 1957
         ROUTER_ID=$(quantum router-create --tenant_id $TENANT_ID router1 | grep ' id ' | get_field 2)
1958 1958
         quantum router-interface-add $ROUTER_ID $SUBNET_ID
1959 1959
         # Create an external network, and a subnet. Configure the external network as router gw
1960
-        EXT_NET_ID=$(quantum net-create ext_net -- --router:external=True | grep ' id ' | get_field 2)
1960
+        EXT_NET_ID=$(quantum net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
1961 1961
         EXT_GW_IP=$(quantum subnet-create --ip_version 4 $EXT_NET_ID $FLOATING_RANGE -- --enable_dhcp=False | grep 'gateway_ip' | get_field 2)
1962 1962
         quantum router-gateway-set $ROUTER_ID $EXT_NET_ID
1963 1963
         if is_quantum_ovs_base_plugin "$Q_PLUGIN" && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
... ...
@@ -1975,10 +1975,10 @@ if is_service_enabled q-svc; then
1975 1975
 
1976 1976
 elif is_service_enabled mysql && is_service_enabled nova; then
1977 1977
     # Create a small network
1978
-    $NOVA_BIN_DIR/nova-manage network create private $FIXED_RANGE 1 $FIXED_NETWORK_SIZE $NETWORK_CREATE_ARGS
1978
+    $NOVA_BIN_DIR/nova-manage network create "$PRIVATE_NETWORK_NAME" $FIXED_RANGE 1 $FIXED_NETWORK_SIZE $NETWORK_CREATE_ARGS
1979 1979
 
1980 1980
     # Create some floating ips
1981
-    $NOVA_BIN_DIR/nova-manage floating create $FLOATING_RANGE
1981
+    $NOVA_BIN_DIR/nova-manage floating create $FLOATING_RANGE --pool=$PUBLIC_NETWORK
1982 1982
 
1983 1983
     # Create a second pool
1984 1984
     $NOVA_BIN_DIR/nova-manage floating create --ip_range=$TEST_FLOATING_RANGE --pool=$TEST_FLOATING_POOL
... ...
@@ -136,10 +136,10 @@ fi
136 136
 #IMAGE_URLS="http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img" # cirros full disk image
137 137
 
138 138
 # Set default image based on ``VIRT_DRIVER`` and ``LIBVIRT_TYPE``, either of
139
-# which may be set in ``localrc``.  Also allow ``DEFAULT_IMAGE_NAME`` and 
139
+# which may be set in ``localrc``.  Also allow ``DEFAULT_IMAGE_NAME`` and
140 140
 # ``IMAGE_URLS`` to be set directly in ``localrc``.
141 141
 case "$VIRT_DRIVER" in
142
-    openvz) 
142
+    openvz)
143 143
         DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ubuntu-11.10-x86_64}
144 144
         IMAGE_URLS=${IMAGE_URLS:-"http://download.openvz.org/template/precreated/ubuntu-11.10-x86_64.tar.gz"};;
145 145
     libvirt)
... ...
@@ -159,3 +159,6 @@ esac
159 159
 
160 160
 # 5Gb default volume backing file size
161 161
 VOLUME_BACKING_FILE_SIZE=${VOLUME_BACKING_FILE_SIZE:-5130M}
162
+
163
+PRIVATE_NETWORK_NAME=${PRIVATE_NETWORK_NAME:-"private"}
164
+PUBLIC_NETWORK_NAME=${PUBLIC_NETWORK_NAME:-"nova"}