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 IMAGE_URL=https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
13 IMAGE_FILE="${IMAGE_NAME}.img"
17 ALARM_NAME=doctor_alarm1
21 # NOTE: You have to be changed these paramas depends on your machine,
22 # installer and configs.
23 COMPUTE_HOST='192.0.2.8'
24 SSH_TO_COMPUTE_HOST="ssh heat-admin@$COMPUTE_HOST"
28 [ -e "$IMAGE_FILE" ] && return 0
29 wget "$IMAGE_URL" -o "$IMAGE_FILE"
33 glance image-list | grep -q " $IMAGE_NAME " && return 0
34 glance image-create --name "$IMAGE_NAME" \
36 --disk-format "$IMAGE_FORMAT" \
37 --container-format bare \
42 nova list | grep -q " $VM_NAME " && return 0
43 nova boot --flavor "$VM_FLAVOR" \
44 --image "$IMAGE_NAME" \
50 ceilometer alarm-list | grep -q " $ALARM_NAME " && return 0
51 vm_id=$(nova list | grep " $VM_NAME " | awk '{print $2}')
52 ceilometer alarm-event-create --name "$ALARM_NAME" \
53 --alarm-action "http://localhost:$CONSUMER_PORT/failure" \
54 --description "VM failure" \
56 --repeat-actions False \
57 --severity "moderate" \
58 --event-type compute.instance.update \
59 -q "traits.state=string::error; traits.instance_id=string::$vm_id"
63 pgrep -f "python monitor.py" && return 0
64 sudo python monitor.py "$COMPUTE_HOST" "http://127.0.0.1:$INSPECTOR_PORT/events" > monitor.log 2>&1 &
69 pgrep -f "python monitor.py" || return 0
70 sudo kill $(pgrep -f "python monitor.py")
75 pgrep -f "python inspector.py" && return 0
76 python inspector.py "$INSPECTOR_PORT" > inspector.log 2>&1 &
80 pgrep -f "python inspector.py" || return 0
81 kill $(pgrep -f "python inspector.py")
86 pgrep -f "python consumer.py" && return 0
87 python consumer.py "$CONSUMER_PORT" > consumer.log 2>&1 &
91 pgrep -f "python consumer.py" || return 0
92 kill $(pgrep -f "python consumer.py")
96 wait_for_vm_launch() {
97 echo "waiting for vm launch..."
100 state=$(nova list | grep " $VM_NAME " | awk '{print $6}')
101 [[ "$state" == "ACTIVE" ]] && return 0
107 echo "disabling network of comupte host [$COMPUTE_HOST] for 3 mins..."
108 $SSH_TO_COMPUTE_HOST "
109 cat > disable_network.sh << 'END_TXT'
111 dev=\$(/usr/sbin/ip route | awk '/^default/{print \$5}')
113 echo sudo ip link set \$dev down
115 echo sudo ip link set \$dev up
118 chmod +x disable_network.sh
119 nohup ./disable_network.sh > c 2>&1 &"
122 calculate_notification_time() {
123 detect=$(grep "doctor monitor detected at" monitor.log | awk '{print $5}')
124 notified=$(grep "doctor consumer notified at" consumer.log | awk '{print $5}')
125 duration=$(echo "$notified $detect" | awk '{print $1 - $2 }')
126 echo "$notified $detect" | \
127 awk '{d = $1 - $2; if (d < 1 ) print d " OK"; else print d " NG"}'
130 # TODO(r-mibu): Make sure env params are set properly for OpenStack clients
131 # TODO(r-mibu): Make sure POD for doctor test is available in Pharos
133 echo "Note: doctor/tests/run.sh has been executed, "
134 echo " but skipping this test due to lack of available test env/deployment."
152 calculate_notification_time