3 # Copyright 2016 NEC Corporation.
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
17 #branch=$(git rev-parse --abbrev-ref HEAD)
20 IMAGE_URL=https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
22 IMAGE_FILE="${IMAGE_NAME}.img"
27 ALARM_NAME=doctor_alarm1
33 [ -e "$IMAGE_FILE" ] && return 0
34 wget "$IMAGE_URL" -o "$IMAGE_FILE"
38 glance image-list | grep -q " $IMAGE_NAME " && return 0
39 glance image-create --name "$IMAGE_NAME" \
41 --disk-format "$IMAGE_FORMAT" \
42 --container-format bare \
47 nova list | grep -q " $VM_NAME " && return 0
48 nova boot --flavor "$VM_FLAVOR" \
49 --image "$IMAGE_NAME" \
55 ceilometer alarm-list | grep -q " $ALARM_NAME " && return 0
56 vm_id=$(nova list | grep " $VM_NAME " | awk '{print $2}')
57 ceilometer alarm-event-create --name "$ALARM_NAME" \
58 --alarm-action "http://localhost:$CONSUMER_PORT/failure" \
59 --description "VM failure" \
61 --repeat-actions False \
62 --severity "moderate" \
63 --event-type compute.instance.update \
64 -q "traits.state=string::error; traits.instance_id=string::$vm_id"
68 pgrep -f "python monitor.py" && return 0
69 sudo python monitor.py "$COMPUTE_HOST" "http://127.0.0.1:$INSPECTOR_PORT/events" > monitor.log 2>&1 &
74 pgrep -f "python monitor.py" || return 0
75 sudo kill $(pgrep -f "python monitor.py")
80 pgrep -f "python inspector.py" && return 0
81 python inspector.py "$INSPECTOR_PORT" > inspector.log 2>&1 &
85 pgrep -f "python inspector.py" || return 0
86 kill $(pgrep -f "python inspector.py")
91 pgrep -f "python consumer.py" && return 0
92 python consumer.py "$CONSUMER_PORT" > consumer.log 2>&1 &
96 pgrep -f "python consumer.py" || return 0
97 kill $(pgrep -f "python consumer.py")
101 wait_for_vm_launch() {
102 echo "waiting for vm launch..."
105 state=$(nova list | grep " $VM_NAME " | awk '{print $6}')
106 [[ "$state" == "ACTIVE" ]] && return 0
113 echo ssh $COMPUTE_HOST "ip link set eno1 down"
116 calculate_notification_time() {
117 detect=$(grep "doctor monitor detected at" monitor.log | awk '{print $5}')
118 notified=$(grep "doctor consumer notified at" consumer.log | awk '{print $5}')
119 duration=$(echo "$notified $detect" | awk '{print $1 - $2 }')
120 echo "$notified $detect" | \
121 awk '{d = $1 - $2; if (d < 1 ) print d " OK"; else print d " NG"}'
124 # TODO(r-mibu): Make sure env params are set properly for OpenStack clients
125 # TODO(r-mibu): Make sure POD for doctor test is available in Pharos
127 echo "Note: doctor/tests/run.sh has been executed, "
128 echo " but skipping this test due to lack of available test env/deployment."
146 calculate_notification_time