From 10670d1bad6b4afd3dce9af61d22c8cd5eeded59 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Tue, 24 Jan 2012 11:26:15 -0600 Subject: [PATCH] Add support for OS_* environment vars Add the OS_* env variables to mirror the NOVA_* vars; example: setting OS_USERNAME will override NOVA_USERNAME in the clients and tools, but if left unset it defaults to NOVA_USERNAME. Adds exercises/client-env.sh to test operation of command-line clients with only the OS_* variables set Addresses bug 897304, http://wiki.openstack.org/CLIAuth Change-Id: I72450153541072fe8026a82748cfcd1cf5ed31d8 --- exercises/client-env.sh | 166 ++++++++++++++++++++++++++++++++++++++ exercises/floating_ips.sh | 2 +- exercises/volumes.sh | 2 +- openrc | 10 ++- 4 files changed, 177 insertions(+), 3 deletions(-) create mode 100755 exercises/client-env.sh diff --git a/exercises/client-env.sh b/exercises/client-env.sh new file mode 100755 index 0000000000..f4172bcb9d --- /dev/null +++ b/exercises/client-env.sh @@ -0,0 +1,166 @@ +#!/usr/bin/env bash + +# Test OpenStack client enviroment variable handling + +# Verify client workage +VERIFY=${1:-""} + +# Settings +# ======== + +# Use openrc + stackrc + localrc for settings +pushd $(cd $(dirname "$0")/.. && pwd) >/dev/null +source ./openrc +popd >/dev/null + +# Unset all of the known NOVA_ vars +unset NOVA_API_KEY +unset NOVA_ENDPOINT_NAME +unset NOVA_PASSWORD +unset NOVA_PROJECT_ID +unset NOVA_REGION_NAME +unset NOVA_URL +unset NOVA_USERNAME +unset NOVA_VERSION + +# Make sure we have the vars we are expecting +function is_set() { + local var=\$"$1" + eval echo $1=$var + if eval "[ -z $var ]"; then + return 1 + fi + return 0 +} + +for i in OS_TENANT_NAME OS_USERNAME OS_PASSWORD OS_AUTH_URL; do + is_set $i + if [[ $? -ne 0 ]]; then + ABORT=1 + fi +done +if [[ -n "$ABORT" ]]; then + exit 1 +fi + +# Set global return +RETURN=0 + +# Keystone client +# --------------- +if [[ "$ENABLED_SERVICES" =~ "key" ]]; then + if [[ "$SKIP_EXERCISES" =~ "key" ]] ; then + STATUS_KEYSTONE="Skipped" + else + if [[ -n "$VERIFY" ]]; then + # Save original environment + xOS_AUTH_URL=$OS_AUTH_URL + xOS_TENANT_NAME=$OS_TENANT_NAME + xOS_USERNAME=$OS_USERNAME + xOS_PASSWORD=$OS_PASSWORD + # keystone can't handle a trailing '/' + export OS_AUTH_URL=${OS_AUTH_URL%/} + # does any non-admin request work? + export OS_USERNAME=admin + export OS_TENANT_NAME=admin + fi + + echo -e "\nTest Keystone" + if keystone service-list; then + STATUS_KEYSTONE="Succeeded" + else + STATUS_KEYSTONE="Failed" + RETURN=1 + fi + if [[ -n "$VERIFY" ]]; then + # Save original environment + OS_AUTH_URL=$xOS_AUTH_URL + OS_TENANT_NAME=$xOS_TENANT_NAME + OS_USERNAME=$xOS_USERNAME + OS_PASSWORD=$xOS_PASSWORD + fi + fi +fi + +# Nova client +# ----------- + +if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then + if [[ "$SKIP_EXERCISES" =~ "n-api" ]] ; then + STATUS_NOVA="Skipped" + else + if [[ -n "$VERIFY" ]]; then + # Known novaclient breakage: + # NOVA_VERSION must be set or nova silently fails + export NOVA_VERSION=2 + fi + + echo -e "\nTest Nova" + if nova flavor-list; then + STATUS_NOVA="Succeeded" + else + STATUS_NOVA="Failed" + RETURN=1 + fi + fi +fi + +# Glance client +# ------------- + +if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then + if [[ "$SKIP_EXERCISES" =~ "g-api" ]] ; then + STATUS_GLANCE="Skipped" + else + if [[ -n "$VERIFY" ]]; then + # Known glance client differage: + export OS_AUTH_TENANT=$OS_TENANT_NAME + export OS_AUTH_USER=$OS_USERNAME + export OS_AUTH_KEY=$OS_PASSWORD + export OS_AUTH_STRATEGY=keystone + fi + + echo -e "\nTest Glance" + if glance index; then + STATUS_GLANCE="Succeeded" + else + STATUS_GLANCE="Failed" + RETURN=1 + fi + fi +fi + +# Swift client +# ------------ + +if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then + if [[ "$SKIP_EXERCISES" =~ "swift" ]] ; then + STATUS_SWIFT="Skipped" + else + echo -e "\nTest Swift" + # FIXME(dtroyer): implement swift test + if true; then + STATUS_SWIFT="Succeeded" + else + STATUS_SWIFT="Failed" + RETURN=1 + fi + fi +fi + +# Results +# ------- + +function report() { + if [[ -n "$2" ]]; then + echo "$1: $2" + fi +} + +echo -e "\n" +report "Keystone" $STATUS_KEYSTONE +report "Nova" $STATUS_NOVA +report "Glance" $STATUS_GLANCE +report "Swift" $STATUS_SWIFT + +exit $RETURN diff --git a/exercises/floating_ips.sh b/exercises/floating_ips.sh index 8afa3ccdb5..c1cffa4a73 100755 --- a/exercises/floating_ips.sh +++ b/exercises/floating_ips.sh @@ -55,7 +55,7 @@ TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test} # returns a token and catalog of endpoints. We use python to parse the token # and save it. -TOKEN=`curl -s -d "{\"auth\":{\"passwordCredentials\": {\"username\": \"$NOVA_USERNAME\", \"password\": \"$NOVA_PASSWORD\"}}}" -H "Content-type: application/json" http://$HOST_IP:5000/v2.0/tokens | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['access']['token']['id'];"` +TOKEN=`curl -s -d "{\"auth\":{\"passwordCredentials\": {\"username\": \"$OS_USERNAME\", \"password\": \"$OS_PASSWORD\"}}}" -H "Content-type: application/json" ${OS_AUTH_URL%/}/tokens | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['access']['token']['id'];"` # Launching a server # ================== diff --git a/exercises/volumes.sh b/exercises/volumes.sh index 3f7548393a..1f7c25f5b1 100755 --- a/exercises/volumes.sh +++ b/exercises/volumes.sh @@ -41,7 +41,7 @@ DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami} # returns a token and catalog of endpoints. We use python to parse the token # and save it. -TOKEN=`curl -s -d "{\"auth\":{\"passwordCredentials\": {\"username\": \"$NOVA_USERNAME\", \"password\": \"$NOVA_PASSWORD\"}}}" -H "Content-type: application/json" http://$HOST_IP:5000/v2.0/tokens | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['access']['token']['id'];"` +TOKEN=`curl -s -d "{\"auth\":{\"passwordCredentials\": {\"username\": \"$OS_USERNAME\", \"password\": \"$OS_PASSWORD\"}}}" -H "Content-type: application/json" ${OS_AUTH_URL%/}/tokens | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['access']['token']['id'];"` # Launching a server # ================== diff --git a/openrc b/openrc index 195a8fe897..4c4b1d31fa 100644 --- a/openrc +++ b/openrc @@ -12,20 +12,27 @@ SERVICE_HOST=${SERVICE_HOST:-$HOST_IP} # should be listening on HOST_IP. If its running elsewhere, it can be set here GLANCE_HOST=${GLANCE_HOST:-$HOST_IP} +# novaclient now supports the new OS_* configuration variables in addition to +# the older NOVA_* variables. Set them both for now... + # Nova original used project_id as the *account* that owned resources (servers, # ip address, ...) With the addition of Keystone we have standardized on the # term **tenant** as the entity that owns the resources. **novaclient** still # uses the old deprecated terms project_id. Note that this field should now be # set to tenant_name, not tenant_id. export NOVA_PROJECT_ID=${TENANT:-demo} +export OS_TENANT_NAME=${NOVA_PROJECT_ID} # In addition to the owning entity (tenant), nova stores the entity performing # the action as the **user**. export NOVA_USERNAME=${USERNAME:-demo} +export OS_USERNAME=${NOVA_USERNAME} # With Keystone you pass the keystone password instead of an api key. -# The most recent versions of novaclient use NOVA_PASSWORD instead of NOVA_API_KEY +# Recent versions of novaclient use NOVA_PASSWORD instead of NOVA_API_KEY +# The most recent versions of novaclient use OS_PASSWORD in addition to NOVA_PASSWORD export NOVA_PASSWORD=${ADMIN_PASSWORD:-secrete} +export OS_PASSWORD=${NOVA_PASSWORD} # With the addition of Keystone, to use an openstack cloud you should # authenticate against keystone, which returns a **Token** and **Service @@ -36,6 +43,7 @@ export NOVA_PASSWORD=${ADMIN_PASSWORD:-secrete} # *NOTE*: Using the 2.0 *auth api* does not mean that compute api is 2.0. We # will use the 1.1 *compute api* export NOVA_URL=${NOVA_URL:-http://$SERVICE_HOST:5000/v2.0/} +export OS_AUTH_URL=${NOVA_URL} # Currently novaclient needs you to specify the *compute api* version. This # needs to match the config of your catalog returned by Keystone.