summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2016-10-13 15:29:35 +0200
committerJose Lausuch <jose.lausuch@ericsson.com>2016-10-18 14:00:23 +0000
commitd4f57cb256542e42cfafd586b8c9ef025e6ef005 (patch)
tree3769be46de872e1b46415e6c0fdd4b04b83d628e
parentee65be08012c74674ca7ba3261aaa6693f9773ba (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>
-rwxr-xr-xtestcases/Controllers/ODL/OpenDaylightTesting.py27
-rwxr-xr-xutils/openstack_utils.py12
2 files changed, 25 insertions, 14 deletions
diff --git a/testcases/Controllers/ODL/OpenDaylightTesting.py b/testcases/Controllers/ODL/OpenDaylightTesting.py
index 0ee37b64b..591faac5c 100755
--- a/testcases/Controllers/ODL/OpenDaylightTesting.py
+++ b/testcases/Controllers/ODL/OpenDaylightTesting.py
@@ -143,19 +143,19 @@ class ODLTestCases(TestCasesBase.TestCasesBase):
return self.EX_RUN_ERROR
def run(self):
- kclient = op_utils.get_keystone_client()
- keystone_url = kclient.service_catalog.url_for(
- service_type='identity', endpoint_type='publicURL')
- neutron_url = kclient.service_catalog.url_for(
- service_type='network', endpoint_type='publicURL')
- kwargs = {'keystoneip': urlparse.urlparse(keystone_url).hostname}
- kwargs['neutronip'] = urlparse.urlparse(neutron_url).hostname
- kwargs['odlip'] = kwargs['neutronip']
- kwargs['odlwebport'] = '8080'
- kwargs['odlrestconfport'] = '8181'
- kwargs['odlusername'] = 'admin'
- kwargs['odlpassword'] = 'admin'
try:
+ kclient = op_utils.get_keystone_client()
+ keystone_url = kclient.service_catalog.url_for(
+ service_type='identity', endpoint_type='publicURL')
+ neutron_url = kclient.service_catalog.url_for(
+ service_type='network', endpoint_type='publicURL')
+ kwargs = {'keystoneip': urlparse.urlparse(keystone_url).hostname}
+ kwargs['neutronip'] = urlparse.urlparse(neutron_url).hostname
+ kwargs['odlip'] = kwargs['neutronip']
+ kwargs['odlwebport'] = '8080'
+ kwargs['odlrestconfport'] = '8181'
+ kwargs['odlusername'] = 'admin'
+ kwargs['odlpassword'] = 'admin'
installer_type = os.environ['INSTALLER_TYPE']
kwargs['osusername'] = os.environ['OS_USERNAME']
kwargs['ostenantname'] = os.environ['OS_TENANT_NAME']
@@ -176,6 +176,9 @@ class ODLTestCases(TestCasesBase.TestCasesBase):
"Please check env var: "
"%s" % str(e))
return self.EX_RUN_ERROR
+ except Exception:
+ self.logger.exception("Cannot run ODL testcases.")
+ return self.EX_RUN_ERROR
return self.main(**kwargs)
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.