2 ##############################################################################
3 # Copyright (c) 2016 NEC Corporation and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
11 #branch=$(git rev-parse --abbrev-ref HEAD)
14 IMAGE_URL=https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
16 IMAGE_FILE="${IMAGE_NAME}.img"
21 ALARM_NAME=doctor_alarm1
27 [ -e "$IMAGE_FILE" ] && return 0
28 wget "$IMAGE_URL" -o "$IMAGE_FILE"
32 glance image-list | grep -q " $IMAGE_NAME " && return 0
33 glance image-create --name "$IMAGE_NAME" \
35 --disk-format "$IMAGE_FORMAT" \
36 --container-format bare \
41 nova list | grep -q " $VM_NAME " && return 0
42 nova boot --flavor "$VM_FLAVOR" \
43 --image "$IMAGE_NAME" \
49 ceilometer alarm-list | grep -q " $ALARM_NAME " && return 0
50 vm_id=$(nova list | grep " $VM_NAME " | awk '{print $2}')
51 ceilometer alarm-event-create --name "$ALARM_NAME" \
52 --alarm-action "http://localhost:$CONSUMER_PORT/failure" \
53 --description "VM failure" \
55 --repeat-actions False \
56 --severity "moderate" \
57 --event-type compute.instance.update \
58 -q "traits.state=string::error; traits.instance_id=string::$vm_id"
62 pgrep -f "python monitor.py" && return 0
63 sudo python monitor.py "$COMPUTE_HOST" "http://127.0.0.1:$INSPECTOR_PORT/events" > monitor.log 2>&1 &
68 pgrep -f "python monitor.py" || return 0
69 sudo kill $(pgrep -f "python monitor.py")
74 pgrep -f "python inspector.py" && return 0
75 python inspector.py "$INSPECTOR_PORT" > inspector.log 2>&1 &
79 pgrep -f "python inspector.py" || return 0
80 kill $(pgrep -f "python inspector.py")
85 pgrep -f "python consumer.py" && return 0
86 python consumer.py "$CONSUMER_PORT" > consumer.log 2>&1 &
90 pgrep -f "python consumer.py" || return 0
91 kill $(pgrep -f "python consumer.py")
95 wait_for_vm_launch() {
96 echo "waiting for vm launch..."
99 state=$(nova list | grep " $VM_NAME " | awk '{print $6}')
100 [[ "$state" == "ACTIVE" ]] && return 0
107 echo ssh $COMPUTE_HOST "ip link set eno1 down"
110 calculate_notification_time() {
111 detect=$(grep "doctor monitor detected at" monitor.log | awk '{print $5}')
112 notified=$(grep "doctor consumer notified at" consumer.log | awk '{print $5}')
113 duration=$(echo "$notified $detect" | awk '{print $1 - $2 }')
114 echo "$notified $detect" | \
115 awk '{d = $1 - $2; if (d < 1 ) print d " OK"; else print d " NG"}'
118 # TODO(r-mibu): Make sure env params are set properly for OpenStack clients
119 # TODO(r-mibu): Make sure POD for doctor test is available in Pharos
121 echo "Note: doctor/tests/run.sh has been executed, "
122 echo " but skipping this test due to lack of available test env/deployment."
140 calculate_notification_time