Merge "Adding checking of host_status"
authorGerald Kunzmann <kunzmann@docomolab-euro.com>
Tue, 24 May 2016 07:29:04 +0000 (07:29 +0000)
committerGerrit Code Review <gerrit@172.30.200.206>
Tue, 24 May 2016 07:29:04 +0000 (07:29 +0000)
1  2 
tests/run.sh

diff --combined tests/run.sh
@@@ -17,6 -17,10 +17,10 @@@ VM_FLAVOR=m1.tin
  ALARM_NAME=doctor_alarm1
  INSPECTOR_PORT=12345
  CONSUMER_PORT=12346
+ TEST_USER=demo
+ TEST_PW=demo
+ TEST_TENANT=demo
+ TEST_ROLE=_member_
  
  SUPPORTED_INSTALLER_TYPES="apex local"
  INSTALLER_TYPE=${INSTALLER_TYPE:-apex}
@@@ -82,12 -86,33 +86,33 @@@ register_image() 
                          --file "$IMAGE_FILE"
  }
  
+ create_test_user() {
+     keystone user-list | grep -q "$TEST_USER" || {
+         keystone user-create --name "$TEST_USER" --pass "$TEST_PW"
+     }
+     keystone tenant-list | grep -q "$TEST_TENANT" || {
+         keystone tenant-create --name "$TEST_TENANT"
+     }
+     keystone user-role-list --user "$TEST_USER" --tenant "$TEST_TENANT" \
+     | grep -q "$TEST_ROLE" || {
+         keystone user-role-add --user "$TEST_USER" --role "$TEST_ROLE" \
+                            --tenant "$TEST_TENANT"
+     }
+ }
  boot_vm() {
      nova list | grep -q " $VM_NAME " && return 0
-     nova boot --flavor "$VM_FLAVOR" \
-               --image "$IMAGE_NAME" \
-               "$VM_NAME"
-     sleep 1
+     (
+         # 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_TENANT"
+         nova boot --flavor "$VM_FLAVOR" \
+                   --image "$IMAGE_NAME" \
+                   "$VM_NAME"
+         sleep 1
+     )
  }
  
  create_alarm() {
@@@ -151,7 -176,7 +176,7 @@@ inject_failure() 
      echo "disabling network of compute host [$COMPUTE_HOST] for 3 mins..."
      cat > disable_network.sh << 'END_TXT'
  #!/bin/bash -x
 -dev=$(ip route | awk '/^default/{print $5}')
 +dev=$(sudo ip route | awk '/^default/{print $5}')
  sleep 1
  sudo ip link set $dev down
  sleep 180
@@@ -170,6 -195,26 +195,26 @@@ calculate_notification_time() 
          awk '{d = $1 - $2; if (d < 1 && d > 0) print d " OK"; else print d " NG"}'
  }
  
+ check_host_status_down() {
+     (
+         # Switching to test user
+         export OS_USERNAME="$TEST_USER"
+         export OS_PASSWORD="$TEST_PW"
+         export OS_TENANT_NAME="$TEST_TENANT"
+         host_status_line=$(nova show $VM_NAME | grep "host_status")
+         [[ $? -ne 0 ]] && {
+             echo "ERROR: host_status not configured for owner in Nova policy.json"
+         }
+         host_status=$(echo $host_status_line | awk '{print $4}')
+         [[ "$host_status" == "DOWN" ]] && {
+             echo "$VM_NAME showing host_status: $host_status"
+         }
+         echo "ERROR: host_status not reported by: nova show $VM_NAME"
+     )
+ }
  cleanup() {
      set +e
      echo "cleanup..."
      image_id=$(glance image-list | grep " $IMAGE_NAME " | awk '{print $2}')
      sleep 1
      [ -n "$image_id" ] && glance image-delete "$image_id"
+     keystone user-role-remove --user "$TEST_USER" --role "$TEST_ROLE" \
+                               --tenant "$TEST_TENANT"
+     keystone tenant-remove --name "$TEST_TENANT"
+     keystone user-delete "$TEST_USER"
      #TODO: add host status check via nova admin api
      echo "waiting disabled compute host back to be enabled..."
      sleep 180
@@@ -211,6 -261,9 +261,9 @@@ start_monito
  start_inspector
  start_consumer
  
+ echo "creating test user..."
+ create_test_user
  echo "creating VM and alarm..."
  boot_vm
  create_alarm
@@@ -221,6 -274,7 +274,7 @@@ echo "injecting host failure...
  inject_failure
  sleep 10
  
+ check_host_status_down
  calculate_notification_time
  
  echo "done"