Dean Troyer | 10670d1 | 2012-01-24 11:26:15 -0600 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Test OpenStack client enviroment variable handling |
| 4 | |
| 5 | # Verify client workage |
| 6 | VERIFY=${1:-""} |
| 7 | |
| 8 | # Settings |
| 9 | # ======== |
| 10 | |
| 11 | # Use openrc + stackrc + localrc for settings |
| 12 | pushd $(cd $(dirname "$0")/.. && pwd) >/dev/null |
| 13 | source ./openrc |
| 14 | popd >/dev/null |
| 15 | |
| 16 | # Unset all of the known NOVA_ vars |
| 17 | unset NOVA_API_KEY |
| 18 | unset NOVA_ENDPOINT_NAME |
| 19 | unset NOVA_PASSWORD |
| 20 | unset NOVA_PROJECT_ID |
| 21 | unset NOVA_REGION_NAME |
| 22 | unset NOVA_URL |
| 23 | unset NOVA_USERNAME |
| 24 | unset NOVA_VERSION |
| 25 | |
| 26 | # Make sure we have the vars we are expecting |
| 27 | function is_set() { |
| 28 | local var=\$"$1" |
| 29 | eval echo $1=$var |
| 30 | if eval "[ -z $var ]"; then |
| 31 | return 1 |
| 32 | fi |
| 33 | return 0 |
| 34 | } |
| 35 | |
| 36 | for i in OS_TENANT_NAME OS_USERNAME OS_PASSWORD OS_AUTH_URL; do |
| 37 | is_set $i |
| 38 | if [[ $? -ne 0 ]]; then |
| 39 | ABORT=1 |
| 40 | fi |
| 41 | done |
| 42 | if [[ -n "$ABORT" ]]; then |
| 43 | exit 1 |
| 44 | fi |
| 45 | |
| 46 | # Set global return |
| 47 | RETURN=0 |
| 48 | |
| 49 | # Keystone client |
| 50 | # --------------- |
| 51 | if [[ "$ENABLED_SERVICES" =~ "key" ]]; then |
| 52 | if [[ "$SKIP_EXERCISES" =~ "key" ]] ; then |
| 53 | STATUS_KEYSTONE="Skipped" |
| 54 | else |
| 55 | if [[ -n "$VERIFY" ]]; then |
| 56 | # Save original environment |
| 57 | xOS_AUTH_URL=$OS_AUTH_URL |
| 58 | xOS_TENANT_NAME=$OS_TENANT_NAME |
| 59 | xOS_USERNAME=$OS_USERNAME |
| 60 | xOS_PASSWORD=$OS_PASSWORD |
| 61 | # keystone can't handle a trailing '/' |
| 62 | export OS_AUTH_URL=${OS_AUTH_URL%/} |
| 63 | # does any non-admin request work? |
| 64 | export OS_USERNAME=admin |
| 65 | export OS_TENANT_NAME=admin |
| 66 | fi |
| 67 | |
| 68 | echo -e "\nTest Keystone" |
| 69 | if keystone service-list; then |
| 70 | STATUS_KEYSTONE="Succeeded" |
| 71 | else |
| 72 | STATUS_KEYSTONE="Failed" |
| 73 | RETURN=1 |
| 74 | fi |
| 75 | if [[ -n "$VERIFY" ]]; then |
| 76 | # Save original environment |
| 77 | OS_AUTH_URL=$xOS_AUTH_URL |
| 78 | OS_TENANT_NAME=$xOS_TENANT_NAME |
| 79 | OS_USERNAME=$xOS_USERNAME |
| 80 | OS_PASSWORD=$xOS_PASSWORD |
| 81 | fi |
| 82 | fi |
| 83 | fi |
| 84 | |
| 85 | # Nova client |
| 86 | # ----------- |
| 87 | |
| 88 | if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then |
| 89 | if [[ "$SKIP_EXERCISES" =~ "n-api" ]] ; then |
| 90 | STATUS_NOVA="Skipped" |
| 91 | else |
| 92 | if [[ -n "$VERIFY" ]]; then |
| 93 | # Known novaclient breakage: |
| 94 | # NOVA_VERSION must be set or nova silently fails |
| 95 | export NOVA_VERSION=2 |
| 96 | fi |
| 97 | |
| 98 | echo -e "\nTest Nova" |
| 99 | if nova flavor-list; then |
| 100 | STATUS_NOVA="Succeeded" |
| 101 | else |
| 102 | STATUS_NOVA="Failed" |
| 103 | RETURN=1 |
| 104 | fi |
| 105 | fi |
| 106 | fi |
| 107 | |
| 108 | # Glance client |
| 109 | # ------------- |
| 110 | |
| 111 | if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then |
| 112 | if [[ "$SKIP_EXERCISES" =~ "g-api" ]] ; then |
| 113 | STATUS_GLANCE="Skipped" |
| 114 | else |
| 115 | if [[ -n "$VERIFY" ]]; then |
| 116 | # Known glance client differage: |
| 117 | export OS_AUTH_TENANT=$OS_TENANT_NAME |
| 118 | export OS_AUTH_USER=$OS_USERNAME |
| 119 | export OS_AUTH_KEY=$OS_PASSWORD |
| 120 | export OS_AUTH_STRATEGY=keystone |
| 121 | fi |
| 122 | |
| 123 | echo -e "\nTest Glance" |
| 124 | if glance index; then |
| 125 | STATUS_GLANCE="Succeeded" |
| 126 | else |
| 127 | STATUS_GLANCE="Failed" |
| 128 | RETURN=1 |
| 129 | fi |
| 130 | fi |
| 131 | fi |
| 132 | |
| 133 | # Swift client |
| 134 | # ------------ |
| 135 | |
| 136 | if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then |
| 137 | if [[ "$SKIP_EXERCISES" =~ "swift" ]] ; then |
| 138 | STATUS_SWIFT="Skipped" |
| 139 | else |
| 140 | echo -e "\nTest Swift" |
| 141 | # FIXME(dtroyer): implement swift test |
| 142 | if true; then |
| 143 | STATUS_SWIFT="Succeeded" |
| 144 | else |
| 145 | STATUS_SWIFT="Failed" |
| 146 | RETURN=1 |
| 147 | fi |
| 148 | fi |
| 149 | fi |
| 150 | |
| 151 | # Results |
| 152 | # ------- |
| 153 | |
| 154 | function report() { |
| 155 | if [[ -n "$2" ]]; then |
| 156 | echo "$1: $2" |
| 157 | fi |
| 158 | } |
| 159 | |
| 160 | echo -e "\n" |
| 161 | report "Keystone" $STATUS_KEYSTONE |
| 162 | report "Nova" $STATUS_NOVA |
| 163 | report "Glance" $STATUS_GLANCE |
| 164 | report "Swift" $STATUS_SWIFT |
| 165 | |
| 166 | exit $RETURN |