diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/consumer.py | 4 | ||||
-rw-r--r-- | tests/monitor.py | 2 | ||||
-rwxr-xr-x | tests/run.sh | 164 |
3 files changed, 80 insertions, 90 deletions
diff --git a/tests/consumer.py b/tests/consumer.py index ef4116a9..6618f615 100644 --- a/tests/consumer.py +++ b/tests/consumer.py @@ -29,13 +29,13 @@ def event_posted(): def get_args(): parser = argparse.ArgumentParser(description='Doctor Sample Consumer') parser.add_argument('port', metavar='PORT', type=int, nargs='?', - help='a port for consumer') + help='the port for consumer') return parser.parse_args() def main(): args = get_args() - app.run(port=args.port, debug=True) + app.run(host="0.0.0.0", port=args.port) if __name__ == '__main__': diff --git a/tests/monitor.py b/tests/monitor.py index bc22b1ea..9e489865 100644 --- a/tests/monitor.py +++ b/tests/monitor.py @@ -31,7 +31,7 @@ class DoctorMonitorSample(object): self.ip_addr = args.ip or socket.gethostbyname(self.hostname) def start_loop(self): - print "start ping to host %(h)s (ip=$(i)s)" % {'h': self.hostname, + print "start ping to host %(h)s (ip=%(i)s)" % {'h': self.hostname, 'i': self.ip_addr} sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP) diff --git a/tests/run.sh b/tests/run.sh index 3e2fbab5..0d9e08a0 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -28,8 +28,10 @@ DOCTOR_ROLE=admin SUPPORTED_INSTALLER_TYPES="apex local" INSTALLER_TYPE=${INSTALLER_TYPE:-apex} INSTALLER_IP=${INSTALLER_IP:-none} -COMPUTE_USER=${COMPUTE_USER:-none} + ssh_opts="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" +as_doctor_user="--os-username $DOCTOR_USER --os-password $DOCTOR_PW + --os-tenant-name $DOCTOR_PROJECT" if [[ ! "$SUPPORTED_INSTALLER_TYPES" =~ "$INSTALLER_TYPE" ]] ; then echo "ERROR: INSTALLER_TYPE=$INSTALLER_TYPE is not supported." @@ -37,14 +39,14 @@ if [[ ! "$SUPPORTED_INSTALLER_TYPES" =~ "$INSTALLER_TYPE" ]] ; then fi get_compute_host_info() { - ( - change_to_doctor_user - - # get computer host info which VM boot in - export COMPUTE_HOST=$(openstack server show $VM_NAME | \ - grep "OS-EXT-SRV-ATTR:host" | awk '{ print $4 }' | - awk -F '.' '{print $1}') - ) + # get computer host info which VM boot in + COMPUTE_HOST=$(openstack $as_doctor_user server show $VM_NAME | + grep "OS-EXT-SRV-ATTR:host" | awk '{ print $4 }' | + awk -F '.' '{print $1}') + if [[ -z "$COMPUTE_HOST" ]] ; then + echo "ERROR: failed to get compute hostname" + exit 1 + fi if [[ "$INSTALLER_TYPE" == "apex" ]] ; then COMPUTE_USER=${COMPUTE_USER:-heat-admin} if [[ "$INSTALLER_IP" == "none" ]] ; then @@ -94,6 +96,20 @@ prepare_compute_ssh() { fi } +get_consumer_ip() { + #get network of the compute_ip address + network_pre=${COMPUTE_IP%.*} + network=${network_pre}.0/24 + + #if there is a dedicated route, use it + dev=$(ip route |grep $network | awk '{print $3}' |head -n 1) + + #if there is no route, use default route + [[ -z $dev ]] && dev=$(ip route |grep ^default | awk '{print $3}' |head -n 1) + + CONSUMER_IP=$(ip addr show $dev |grep inet | grep $network_pre | awk '{print $2}' | cut -d'/' -f1) +} + download_image() { [ -e "$IMAGE_FILE" ] && return 0 wget "$IMAGE_URL" -o "$IMAGE_FILE" @@ -122,41 +138,27 @@ create_test_user() { } } -change_to_doctor_user() { - export OS_USERNAME="$DOCTOR_USER" - export OS_PASSWORD="$DOCTOR_PW" - export OS_PROJECT_NAME="$DOCTOR_PROJECT" - export OS_TENANT_NAME="$DOCTOR_PROJECT" -} - boot_vm() { - ( - # test VM done with test user, so can test non-admin - change_to_doctor_user - openstack server list | grep -q " $VM_NAME " && return 0 - openstack server create --flavor "$VM_FLAVOR" \ - --image "$IMAGE_NAME" \ - "$VM_NAME" - sleep 1 - ) - + # test VM done with test user, so can test non-admin + openstack $as_doctor_user server list | grep -q " $VM_NAME " && return 0 + openstack $as_doctor_user server create --flavor "$VM_FLAVOR" \ + --image "$IMAGE_NAME" \ + "$VM_NAME" + sleep 1 } create_alarm() { - ( - # get vm_id as test user - change_to_doctor_user - ceilometer alarm-list | grep -q " $ALARM_NAME " && return 0 - vm_id=$(openstack server list | grep " $VM_NAME " | awk '{print $2}') - ceilometer alarm-event-create --name "$ALARM_NAME" \ - --alarm-action "http://localhost:$CONSUMER_PORT/failure" \ - --description "VM failure" \ - --enabled True \ - --repeat-actions False \ - --severity "moderate" \ - --event-type compute.instance.update \ - -q "traits.state=string::error; traits.instance_id=string::$vm_id" - ) + # get vm_id as test user + ceilometer $as_doctor_user alarm-list | grep -q " $ALARM_NAME " && return 0 + vm_id=$(openstack $as_doctor_user server list | grep " $VM_NAME " | awk '{print $2}') + ceilometer $as_doctor_user alarm-event-create --name "$ALARM_NAME" \ + --alarm-action "http://$CONSUMER_IP:$CONSUMER_PORT/failure" \ + --description "VM failure" \ + --enabled True \ + --repeat-actions False \ + --severity "moderate" \ + --event-type compute.instance.update \ + -q "traits.state=string::error; traits.instance_id=string::$vm_id" } @@ -197,22 +199,17 @@ stop_consumer() { wait_for_vm_launch() { echo "waiting for vm launch..." - ( - # get VM state as test user - change_to_doctor_user - - count=0 - while [[ ${count} -lt 60 ]] - do - state=$(openstack server list | grep " $VM_NAME " | awk '{print $6}') - [[ "$state" == "ACTIVE" ]] && return 0 - [[ "$state" == "ERROR" ]] && echo "vm state is ERROR" && exit 1 - count=$(($count+1)) - sleep 1 - done - echo "ERROR: time out while waiting for vm launch" - exit 1 - ) + count=0 + while [[ ${count} -lt 60 ]] + do + state=$(openstack $as_doctor_user server list | grep " $VM_NAME " | awk '{print $6}') + [[ "$state" == "ACTIVE" ]] && return 0 + [[ "$state" == "ERROR" ]] && echo "vm state is ERROR" && exit 1 + count=$(($count+1)) + sleep 1 + done + echo "ERROR: time out while waiting for vm launch" + exit 1 } inject_failure() { @@ -239,27 +236,20 @@ calculate_notification_time() { } check_host_status() { - expect_state=$1 - ( - change_to_doctor_user - - host_status_line=$(openstack --os-compute-api-version 2.16 server show $VM_NAME | grep "host_status") - if [[ $? -ne 0 ]] ; then - echo "ERROR: host_status not configured for owner in Nova policy.json" - exit 1 - fi + expected_state=$1 - host_status=$(echo $host_status_line | awk '{print $4}') - if [ -z "$host_status" ] ; then - echo "ERROR: host_status not reported by: nova show $VM_NAME" - exit 1 - elif [[ "$host_status" != "$expect_state" ]] ; then - echo "ERROR: host_status:$host_status not equal to expect_state: $expect_state" - exit 1 - else - echo "$VM_NAME showing host_status: $host_status" - fi - ) + host_status_line=$(openstack $as_doctor_user --os-compute-api-version 2.16 \ + server show $VM_NAME | grep "host_status") + host_status=$(echo $host_status_line | awk '{print $4}') + if [ -z "$host_status" ] ; then + echo "ERROR: host_status not reported by: nova show $VM_NAME" + exit 1 + elif [[ "$host_status" != "$expected_state" ]] ; then + echo "ERROR: host_status:$host_status not equal to expected_state: $expected_state" + exit 1 + else + echo "$VM_NAME showing host_status: $host_status" + fi } cleanup() { @@ -275,17 +265,14 @@ cleanup() { check_host_status "UP" ssh $ssh_opts_cpu "$COMPUTE_USER@$COMPUTE_IP" \ "[ -e disable_network.log ] && cat disable_network.log" + + openstack $as_doctor_user server list | grep -q " $VM_NAME " && openstack server delete "$VM_NAME" + sleep 1 + alarm_id=$(ceilometer alarm-list | grep " $ALARM_NAME " | awk '{print $2}') + sleep 1 + [ -n "$alarm_id" ] && ceilometer alarm-delete "$alarm_id" sleep 1 - ( - change_to_doctor_user - openstack server list | grep -q " $VM_NAME " && openstack server delete "$VM_NAME" - sleep 1 - alarm_id=$(ceilometer alarm-list | grep " $ALARM_NAME " | awk '{print $2}') - sleep 1 - [ -n "$alarm_id" ] && ceilometer alarm-delete "$alarm_id" - sleep 1 - ) image_id=$(openstack image list | grep " $IMAGE_NAME " | awk '{print $2}') sleep 1 [ -n "$image_id" ] && openstack image delete "$image_id" @@ -307,15 +294,18 @@ register_image echo "creating test user..." create_test_user -echo "creating VM and alarm..." +echo "creating VM..." boot_vm wait_for_vm_launch -create_alarm echo "get computer host info and prepare to ssh..." get_compute_host_info prepare_compute_ssh +echo "creating alarm..." +get_consumer_ip +create_alarm + echo "starting doctor sample components..." start_monitor start_inspector |