From 7654dbe5c215ca0649908c66c3c66e49199dbc8c Mon Sep 17 00:00:00 2001 From: "jose.lausuch" Date: Thu, 16 Jun 2016 14:21:00 +0200 Subject: Remove default values if the os credentials are not set If the creds are not sourced, then exit. Change-Id: I55c9cd3a5a0885b81df4ce14502ba816546bcbaa Signed-off-by: jose.lausuch --- utils/openstack_utils.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/utils/openstack_utils.py b/utils/openstack_utils.py index 4084e1fc..646df7ae 100644 --- a/utils/openstack_utils.py +++ b/utils/openstack_utils.py @@ -41,6 +41,14 @@ def get_credentials(service): requesting the credentials. """ creds = {} + + # Check that the env vars exists: + envvars = ('OS_USERNAME', 'OS_PASSWORD', 'OS_AUTH_URL', 'OS_TENANT_NAME') + for envvar in envvars: + if os.getenv(envvar) is None: + print("'%s' is not exported as an env variable." % envvar) + exit(-1) + # Unfortunately, each of the OpenStack client will request slightly # different entries in their credentials dict. if service.lower() in ("nova", "cinder"): @@ -53,11 +61,10 @@ def get_credentials(service): # The most common way to pass these info to the script is to do it through # environment variables. creds.update({ - "username": os.environ.get('OS_USERNAME', "admin"), - password: os.environ.get("OS_PASSWORD", 'admin'), - "auth_url": os.environ.get("OS_AUTH_URL", - "http://192.168.20.71:5000/v2.0"), - tenant: os.environ.get("OS_TENANT_NAME", "admin"), + "username": os.environ.get("OS_USERNAME"), + password: os.environ.get("OS_PASSWORD"), + "auth_url": os.environ.get("OS_AUTH_URL"), + tenant: os.environ.get("OS_TENANT_NAME") }) cacert = os.environ.get("OS_CACERT") if cacert is not None: -- cgit 1.2.3-korg