diff options
Diffstat (limited to 'tests/run.sh')
-rwxr-xr-x | tests/run.sh | 118 |
1 files changed, 67 insertions, 51 deletions
diff --git a/tests/run.sh b/tests/run.sh index d7240d24..76eaa8b6 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -19,10 +19,10 @@ VM_FLAVOR=m1.tiny ALARM_NAME=doctor_alarm1 INSPECTOR_PORT=12345 CONSUMER_PORT=12346 -TEST_USER=demo -TEST_PW=demo -TEST_PROJECT=demo -TEST_ROLE=_member_ +DOCTOR_USER=doctor +DOCTOR_PW=doctor +DOCTOR_PROJECT=doctor +DOCTOR_ROLE=_member_ SUPPORTED_INSTALLER_TYPES="apex local" INSTALLER_TYPE=${INSTALLER_TYPE:-apex} @@ -89,26 +89,31 @@ register_image() { } create_test_user() { - openstack user list | grep -q "$TEST_USER" || { - openstack user create "$TEST_USER" --password "$TEST_PW" + openstack user list | grep -q " $DOCTOR_USER " || { + openstack user create "$DOCTOR_USER" --password "$DOCTOR_PW" } - openstack project list | grep -q "$TEST_PROJECT" || { - openstack project create "$TEST_PROJECT" + openstack project list | grep -q " $DOCTOR_PROJECT " || { + openstack project create "$DOCTOR_PROJECT" } - openstack user role list "$TEST_USER" --project "$TEST_PROJECT" \ - | grep -q "$TEST_ROLE" || { - openstack role add "$TEST_ROLE" --user "$TEST_USER" \ - --project "$TEST_PROJECT" + openstack user role list "$DOCTOR_USER" --project "$DOCTOR_PROJECT" \ + | grep -q " $DOCTOR_ROLE " || { + openstack role add "$DOCTOR_ROLE" --user "$DOCTOR_USER" \ + --project "$DOCTOR_PROJECT" } } +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() { - nova list | grep -q " $VM_NAME " && return 0 ( # test VM done with test user, so can test non-admin - export OS_USERNAME="$TEST_USER" - export OS_PASSWORD="$TEST_PW" - export OS_TENANT_NAME="$TEST_PROJECT" + change_to_doctor_user + nova list | grep -q " $VM_NAME " && return 0 nova boot --flavor "$VM_FLAVOR" \ --image "$IMAGE_NAME" \ "$VM_NAME" @@ -118,18 +123,23 @@ boot_vm() { } create_alarm() { - ceilometer alarm-list | grep -q " $ALARM_NAME " && return 0 - vm_id=$(nova 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 + change_to_doctor_user + ceilometer alarm-list | grep -q " $ALARM_NAME " && return 0 + vm_id=$(nova 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" + ) } + start_monitor() { pgrep -f "python monitor.py" && return 0 sudo python monitor.py "$COMPUTE_HOST" "$COMPUTE_IP" \ @@ -166,17 +176,23 @@ stop_consumer() { wait_for_vm_launch() { echo "waiting for vm launch..." - count=0 - while [[ ${count} -lt 60 ]] - do - state=$(nova 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 + + ( + # get VM state as test user + change_to_doctor_user + + count=0 + while [[ ${count} -lt 60 ]] + do + state=$(nova 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() { @@ -204,10 +220,7 @@ calculate_notification_time() { check_host_status_down() { ( - # Switching to test user - export OS_USERNAME="$TEST_USER" - export OS_PASSWORD="$TEST_PW" - export OS_TENANT_NAME="$TEST_PROJECT" + change_to_doctor_user host_status_line=$(nova show $VM_NAME | grep "host_status") [[ $? -ne 0 ]] && { @@ -231,19 +244,22 @@ cleanup() { python ./nova_force_down.py "$COMPUTE_HOST" --unset sleep 1 - nova list | grep -q " $VM_NAME " && nova 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 + nova list | grep -q " $VM_NAME " && nova 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=$(glance image-list | grep " $IMAGE_NAME " | awk '{print $2}') sleep 1 [ -n "$image_id" ] && glance image-delete "$image_id" - openstack role remove "$TEST_ROLE" --user "$TEST_USER" \ - --project "$TEST_PROJECT" - openstack project delete "$TEST_PROJECT" - openstack user delete "$TEST_USER" + openstack role remove "$DOCTOR_ROLE" --user "$DOCTOR_USER" \ + --project "$DOCTOR_PROJECT" + openstack project delete "$DOCTOR_PROJECT" + openstack user delete "$DOCTOR_USER" #TODO: add host status check via nova admin api echo "waiting disabled compute host back to be enabled..." |