Browse code

Added functions for get a ip on an instance

The cause of some gating failure looks like
because of getting ip address on instance.
However current exercise didn't log the return value.
In this commit, we add get_instance_ip function with
error hanlding support, and apply it on the execise.

Change-Id: I8e17ba68093faafe58a98eb780a032368eea38aa

Nachi Ueno authored on 2013/08/13 10:18:56
Showing 5 changed files
... ...
@@ -174,7 +174,8 @@ if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | g
174 174
 fi
175 175
 
176 176
 # Get the instance IP
177
-IP=$(nova show $VM_UUID | grep "$PRIVATE_NETWORK_NAME" | get_field 2)
177
+IP=$(get_instance_ip $VM_UUID $PRIVATE_NETWORK_NAME)
178
+
178 179
 die_if_not_set $LINENO IP "Failure retrieving IP address"
179 180
 
180 181
 # Private IPs can be pinged in single node deployments
... ...
@@ -132,7 +132,7 @@ if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | g
132 132
 fi
133 133
 
134 134
 # Get the instance IP
135
-IP=$(nova show $VM_UUID | grep "$PRIVATE_NETWORK_NAME" | get_field 2)
135
+IP=$(get_instance_ip $VM_UUID $PRIVATE_NETWORK_NAME)
136 136
 die_if_not_set $LINENO IP "Failure retrieving IP address"
137 137
 
138 138
 # Private IPs can be pinged in single node deployments
... ...
@@ -272,12 +272,12 @@ function create_vms {
272 272
 }
273 273
 
274 274
 function ping_ip {
275
-   # Test agent connection.  Assumes namespaces are disabled, and
276
-   # that DHCP is in use, but not L3
277
-   local VM_NAME=$1
278
-   local NET_NAME=$2
279
-   IP=`nova show $VM_NAME | grep 'network' | awk '{print $5}'`
280
-   ping_check $NET_NAME $IP $BOOT_TIMEOUT
275
+     # Test agent connection.  Assumes namespaces are disabled, and
276
+     # that DHCP is in use, but not L3
277
+     local VM_NAME=$1
278
+     local NET_NAME=$2
279
+     IP=$(get_instance_ip $VM_NAME $NET_NAME)
280
+     ping_check $NET_NAME $IP $BOOT_TIMEOUT
281 281
 }
282 282
 
283 283
 function check_vm {
... ...
@@ -135,7 +135,8 @@ if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | g
135 135
 fi
136 136
 
137 137
 # Get the instance IP
138
-IP=$(nova show $VM_UUID | grep "$PRIVATE_NETWORK_NAME" | get_field 2)
138
+IP=$(get_instance_ip $VM_UUID $PRIVATE_NETWORK_NAME)
139
+
139 140
 die_if_not_set $LINENO IP "Failure retrieving IP address"
140 141
 
141 142
 # Private IPs can be pinged in single node deployments
... ...
@@ -1433,6 +1433,19 @@ function _ping_check_novanet() {
1433 1433
     fi
1434 1434
 }
1435 1435
 
1436
+# Get ip of instance
1437
+function get_instance_ip(){
1438
+    local vm_id=$1
1439
+    local network_name=$2
1440
+    local nova_result="$(nova show $vm_id)"
1441
+    local ip=$(echo "$nova_result" | grep "$network_name" | get_field 2)
1442
+    if [[ $ip = "" ]];then
1443
+        echo "$nova_result"
1444
+        die $LINENO "[Fail] Coudn't get ipaddress of VM"
1445
+        exit 1
1446
+    fi
1447
+    echo $ip
1448
+}
1436 1449
 
1437 1450
 # ssh check
1438 1451