fix bugs to get `CONSUMER_IP`
[doctor.git] / tests / run.sh
index 767a726..0bd9ee6 100755 (executable)
@@ -96,17 +96,12 @@ prepare_compute_ssh() {
 }
 
 get_consumer_ip() {
-    #get network of the compute_ip address
-    network_pre=${COMPUTE_IP%.*}
-    network=${network_pre}.0/24
+    CONSUMER_IP=$(ip route get $COMPUTE_IP | awk '/ src /{print $NF}')
 
-    #if there is a dedicated route, use it
-    dev=$(ip route |grep $network | awk '{print $3}' |head -n 1)
-
-    #if there is no route, use default route
-    [[ -z $dev ]] && dev=$(ip route |grep ^default | awk '{print $3}' |head -n 1)
-
-    CONSUMER_IP=$(ip addr show $dev |grep inet | grep $network_pre | awk '{print $2}' | cut -d'/' -f1)
+    if [[ -z "$CONSUMER_IP" ]]; then
+        echo "ERROR: Could not get CONSUMER_IP."
+        exit 1
+    fi
 }
 
 download_image() {
@@ -266,11 +261,11 @@ cleanup() {
     ssh $ssh_opts_cpu "$COMPUTE_USER@$COMPUTE_IP" \
         "[ -e disable_network.log ] && cat disable_network.log"
 
-    openstack $as_doctor_user server list | grep -q " $VM_NAME " && openstack server delete "$VM_NAME"
+    openstack $as_doctor_user server list | grep -q " $VM_NAME " && openstack $as_doctor_user server delete "$VM_NAME"
     sleep 1
-    alarm_id=$(ceilometer alarm-list | grep " $ALARM_NAME " | awk '{print $2}')
+    alarm_id=$(ceilometer $as_doctor_user alarm-list | grep " $ALARM_NAME " | awk '{print $2}')
     sleep 1
-    [ -n "$alarm_id" ] && ceilometer alarm-delete "$alarm_id"
+    [ -n "$alarm_id" ] && ceilometer $as_doctor_user alarm-delete "$alarm_id"
     sleep 1
 
     image_id=$(openstack image list | grep " $IMAGE_NAME " | awk '{print $2}')