From d4f57cb256542e42cfafd586b8c9ef025e6ef005 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Thu, 13 Oct 2016 15:29:35 +0200 Subject: Remove exits in OpenStack client utils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- utils/openstack_utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'utils/openstack_utils.py') diff --git a/utils/openstack_utils.py b/utils/openstack_utils.py index e0da7d97d..39594a2a9 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. -- cgit 1.2.3-korg