diff options
author | 2016-10-13 15:29:35 +0200 | |
---|---|---|
committer | 2016-10-18 14:00:23 +0000 | |
commit | d4f57cb256542e42cfafd586b8c9ef025e6ef005 (patch) | |
tree | 3769be46de872e1b46415e6c0fdd4b04b83d628e /utils | |
parent | ee65be08012c74674ca7ba3261aaa6693f9773ba (diff) |
Remove exits in OpenStack client utils
It prevents openstack_utils from exiting when the mandatory env vars
are unset. Every testcase is now in charge of handling the exception
MissingEnvVar.
JIRA: FUNCTEST-438
Change-Id: I0e321b544a470c1f2f2fa62b3e061fe5f938e112
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/openstack_utils.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/utils/openstack_utils.py b/utils/openstack_utils.py index e0da7d97..39594a2a 100755 --- a/utils/openstack_utils.py +++ b/utils/openstack_utils.py @@ -28,6 +28,15 @@ logger = ft_logger.Logger("openstack_utils").getLogger() # ********************************************* # CREDENTIALS # ********************************************* +class MissingEnvVar(Exception): + + def __init__(self, var): + self.var = var + + def __str__(self): + return str.format("Please set the mandatory env var: {}", self.var) + + def check_credentials(): """ Check if the OpenStack credentials (openrc) are sourced @@ -51,8 +60,7 @@ def get_credentials(service): envvars = ('OS_USERNAME', 'OS_PASSWORD', 'OS_AUTH_URL', 'OS_TENANT_NAME') for envvar in envvars: if os.getenv(envvar) is None: - logger.error("'%s' is not exported as an env variable." % envvar) - exit(-1) + raise MissingEnvVar(envvar) # Unfortunately, each of the OpenStack client will request slightly # different entries in their credentials dict. |