use specify host_ip in alarm_action 43/16743/3
authordongwenjuan <dong.wenjuan@zte.com.cn>
Tue, 12 Jul 2016 10:10:56 +0000 (18:10 +0800)
committerdongwenjuan <dong.wenjuan@zte.com.cn>
Fri, 22 Jul 2016 01:53:43 +0000 (09:53 +0800)
we can not use `localhost` in `--alarm-action`, it should be the IP
which the consumer started on.

Change-Id: I50b99e4ff7609c474fb569049b3b8cd216c9178b
Signed-off-by: dongwenjuan <dong.wenjuan@zte.com.cn>
tests/consumer.py
tests/run.sh

index ef4116a..6618f61 100644 (file)
@@ -29,13 +29,13 @@ def event_posted():
 def get_args():
     parser = argparse.ArgumentParser(description='Doctor Sample Consumer')
     parser.add_argument('port', metavar='PORT', type=int, nargs='?',
-                        help='a port for consumer')
+                        help='the port for consumer')
     return parser.parse_args()
 
 
 def main():
     args = get_args()
-    app.run(port=args.port, debug=True)
+    app.run(host="0.0.0.0", port=args.port)
 
 
 if __name__ == '__main__':
index 3e2fbab..4d9a5c7 100755 (executable)
@@ -29,6 +29,7 @@ SUPPORTED_INSTALLER_TYPES="apex local"
 INSTALLER_TYPE=${INSTALLER_TYPE:-apex}
 INSTALLER_IP=${INSTALLER_IP:-none}
 COMPUTE_USER=${COMPUTE_USER:-none}
+
 ssh_opts="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
 
 if [[ ! "$SUPPORTED_INSTALLER_TYPES" =~ "$INSTALLER_TYPE" ]] ; then
@@ -94,6 +95,20 @@ prepare_compute_ssh() {
     fi
 }
 
+get_consumer_ip() {
+    #get network of the compute_ip address
+    network_pre=${COMPUTE_IP%.*}
+    network=${network_pre}.0/24
+
+    #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)
+}
+
 download_image() {
     [ -e "$IMAGE_FILE" ] && return 0
     wget "$IMAGE_URL" -o "$IMAGE_FILE"
@@ -149,7 +164,7 @@ create_alarm() {
         ceilometer alarm-list | grep -q " $ALARM_NAME " && return 0
         vm_id=$(openstack server list | grep " $VM_NAME " | awk '{print $2}')
         ceilometer alarm-event-create --name "$ALARM_NAME" \
-            --alarm-action "http://localhost:$CONSUMER_PORT/failure" \
+            --alarm-action "http://$CONSUMER_IP:$CONSUMER_PORT/failure" \
             --description "VM failure" \
             --enabled True \
             --repeat-actions False \
@@ -275,7 +290,6 @@ cleanup() {
     check_host_status "UP"
     ssh $ssh_opts_cpu "$COMPUTE_USER@$COMPUTE_IP" \
         "[ -e disable_network.log ] && cat disable_network.log"
-    sleep 1
 
     (
         change_to_doctor_user
@@ -307,15 +321,18 @@ register_image
 echo "creating test user..."
 create_test_user
 
-echo "creating VM and alarm..."
+echo "creating VM..."
 boot_vm
 wait_for_vm_launch
-create_alarm
 
 echo "get computer host info and prepare to ssh..."
 get_compute_host_info
 prepare_compute_ssh
 
+echo "creating alarm..."
+get_consumer_ip
+create_alarm
+
 echo "starting doctor sample components..."
 start_monitor
 start_inspector