Remove default values if the os credentials are not set 43/15743/3
authorjose.lausuch <jose.lausuch@ericsson.com>
Thu, 16 Jun 2016 12:21:00 +0000 (14:21 +0200)
committerjose.lausuch <jose.lausuch@ericsson.com>
Thu, 16 Jun 2016 12:45:47 +0000 (14:45 +0200)
If the creds are not sourced, then exit.

Change-Id: I55c9cd3a5a0885b81df4ce14502ba816546bcbaa
Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
utils/openstack_utils.py

index 4084e1f..646df7a 100644 (file)
@@ -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: