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 INSTALLER_TYPE=${INSTALLER_TYPE:-apex}
22 INSTALLER_IP=${INSTALLER_IP:-none}
23 COMPUTE_HOST=${COMPUTE_HOST:-overcloud-novacompute-0}
24 COMPUTE_IP=${COMPUTE_IP:-none}
25 ssh_opts="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
27 if [[ "$INSTALLER_TYPE" != "apex" ]] ; then
28 echo "ERROR: INSTALLER_TYPE=$INSTALLER_TYPE is not supported."
32 if [[ "$INSTALLER_IP" == "none" ]] ; then
33 instack_mac=$(sudo virsh domiflist instack | awk '/default/{print $5}')
34 INSTALLER_IP=$(/usr/sbin/arp -e | grep ${instack_mac} | awk '{print $1}')
37 if [[ "$COMPUTE_IP" == "none" ]] ; then
38 COMPUTE_IP=$(sudo ssh $ssh_opts $INSTALLER_IP \
40 nova show $COMPUTE_HOST \
41 | awk '/ ctlplane network /{print \$5}'")
45 [ -e "$IMAGE_FILE" ] && return 0
46 wget "$IMAGE_URL" -o "$IMAGE_FILE"
50 glance image-list | grep -q " $IMAGE_NAME " && return 0
51 glance image-create --name "$IMAGE_NAME" \
53 --disk-format "$IMAGE_FORMAT" \
54 --container-format bare \
59 nova list | grep -q " $VM_NAME " && return 0
60 nova boot --flavor "$VM_FLAVOR" \
61 --image "$IMAGE_NAME" \
67 ceilometer alarm-list | grep -q " $ALARM_NAME " && return 0
68 vm_id=$(nova list | grep " $VM_NAME " | awk '{print $2}')
69 ceilometer alarm-event-create --name "$ALARM_NAME" \
70 --alarm-action "http://localhost:$CONSUMER_PORT/failure" \
71 --description "VM failure" \
73 --repeat-actions False \
74 --severity "moderate" \
75 --event-type compute.instance.update \
76 -q "traits.state=string::error; traits.instance_id=string::$vm_id"
80 pgrep -f "python monitor.py" && return 0
81 sudo python monitor.py "$COMPUTE_HOST" "$COMPUTE_IP" \
82 "http://127.0.0.1:$INSPECTOR_PORT/events" > monitor.log 2>&1 &
86 pgrep -f "python monitor.py" || return 0
87 sudo kill $(pgrep -f "python monitor.py")
92 pgrep -f "python inspector.py" && return 0
93 python inspector.py "$INSPECTOR_PORT" > inspector.log 2>&1 &
97 pgrep -f "python inspector.py" || return 0
98 kill $(pgrep -f "python inspector.py")
103 pgrep -f "python consumer.py" && return 0
104 python consumer.py "$CONSUMER_PORT" > consumer.log 2>&1 &
108 pgrep -f "python consumer.py" || return 0
109 kill $(pgrep -f "python consumer.py")
113 wait_for_vm_launch() {
114 echo "waiting for vm launch..."
117 state=$(nova list | grep " $VM_NAME " | awk '{print $6}')
118 [[ "$state" == "ACTIVE" ]] && return 0
124 echo "disabling network of comupte host [$COMPUTE_HOST] for 3 mins..."
125 cat > disable_network.sh << 'END_TXT'
127 dev=$(/usr/sbin/ip route | awk '/^default/{print $5}')
129 echo sudo ip link set $dev down
131 echo sudo ip link set $dev up
134 chmod +x disable_network.sh
135 sudo scp $ssh_opts disable_network.sh $INSTALLER_IP:
136 ssh_opts_cpu="$ssh_opts -i /home/stack/.ssh/id_rsa"
137 sudo ssh $ssh_opts $INSTALLER_IP \
138 "scp $ssh_opts_cpu disable_network.sh heat-admin@$COMPUTE_HOST: && \
139 ssh $ssh_opts_cpu 'nohup ./disable_network.sh > c 2>&1 &'"
142 calculate_notification_time() {
143 detect=$(grep "doctor monitor detected at" monitor.log | awk '{print $5}')
144 notified=$(grep "doctor consumer notified at" consumer.log | awk '{print $5}')
145 duration=$(echo "$notified $detect" | awk '{print $1 - $2 }')
146 echo "$notified $detect" | \
147 awk '{d = $1 - $2; if (d < 1 ) print d " OK"; else print d " NG"}'
157 nova service-force-down --unset "$COMPUTE_HOST" nova-compute
159 nova delete "$VM_NAME"
161 alarm_id=$(ceilometer alarm-list | grep " $ALARM_NAME " | awk '{print $2}')
163 [ -n "$alarm_id" ] && ceilometer alarm-delete "$alarm_id"
165 image_id=$(glance image-list | grep " $IMAGE_NAME " | awk '{print $2}')
167 [ -n "$image_id" ] && glance image-delete "$image_id"
168 #TODO: add host status check via nova admin api
169 echo "waiting disabled compute host back to be enabled..."
174 echo "Note: doctor/tests/run.sh has been executed."
176 ping -c 1 "$COMPUTE_IP"
180 echo "preparing VM image..."
184 echo "starting doctor sample components..."
189 echo "creating VM and alarm..."
195 echo "injecting host failure..."
199 calculate_notification_time