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