From a0469e6b2e9bfe32b72134e76b78cc6974498c21 Mon Sep 17 00:00:00 2001 From: chamarty Date: Tue, 14 Mar 2017 21:53:45 +0000 Subject: [PATCH] Fix access to openstack if cinder is not present Change-Id: I20b32565c39a5ffaea29bf508e93e62af71197ab Signed-off-by: chamarty --- .../rift/rwcal/openstack/cinder/cinder_drv.py | 13 ++++++++++++- .../rift/rwcal/openstack/openstack_drv.py | 10 +++++++--- rwcal/test/test_rwcal_openstack.py | 17 +++++++++++++---- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/rwcal/plugins/vala/rwcal_openstack/rift/rwcal/openstack/cinder/cinder_drv.py b/rwcal/plugins/vala/rwcal_openstack/rift/rwcal/openstack/cinder/cinder_drv.py index 76bc8fe0..5bb5cc4a 100644 --- a/rwcal/plugins/vala/rwcal_openstack/rift/rwcal/openstack/cinder/cinder_drv.py +++ b/rwcal/plugins/vala/rwcal_openstack/rift/rwcal/openstack/cinder/cinder_drv.py @@ -18,6 +18,7 @@ import logging from cinderclient import client as ciclient import cinderclient.exceptions as CinderException +import keystoneauth1 class CinderAPIVersionException(Exception): @@ -29,12 +30,16 @@ class CinderAPIVersionException(Exception): return self.__repr__() def __repr__(self): - msg = "{} : Following Exception(s) have occured during Neutron API discovery".format(self.__class__) + msg = "{} : Following Exception(s) have occured during Cinder API discovery".format(self.__class__) for n,e in enumerate(self.errors): msg += "\n" msg += " {}: {}".format(n, str(e)) return msg +class CinderEndpointException(Exception): + "Cinder Endpoint is absent" + pass + class CinderDriver(object): """ CinderDriver Class for image management @@ -89,6 +94,12 @@ class CinderDriver(object): else: raise CinderAPIVersionException(errors) + try: + self._ci_drv.client.get_endpoint() + except keystoneauth1.exceptions.catalog.EndpointNotFound: + self.log.info("Cinder endpoint not found") + raise CinderEndpointException() + @property def cinder_endpoint(self): return self._ci_drv.client.get_endpoint() diff --git a/rwcal/plugins/vala/rwcal_openstack/rift/rwcal/openstack/openstack_drv.py b/rwcal/plugins/vala/rwcal_openstack/rift/rwcal/openstack/openstack_drv.py index c7ed119c..6ee2cb6d 100644 --- a/rwcal/plugins/vala/rwcal_openstack/rift/rwcal/openstack/openstack_drv.py +++ b/rwcal/plugins/vala/rwcal_openstack/rift/rwcal/openstack/openstack_drv.py @@ -132,10 +132,13 @@ class OpenstackDriver(object): self.glance_drv = gl_drv.GlanceDriver(self.sess_drv, region_name = region, logger = self.log) - - self.cinder_drv = ci_drv.CinderDriver(self.sess_drv, + + try: + self.cinder_drv = ci_drv.CinderDriver(self.sess_drv, region_name = region, logger = self.log) + except Exception as e: + self.cinder_drv = None self.ceilo_drv = ce_drv.CeilometerDriver(self.sess_drv, region_name = region, @@ -247,7 +250,8 @@ class OpenstackDriver(object): def build_cinder_resource_cache(self): self.log.info("Building cinder resource cache") - self._build_cinder_volume_list() + if self.cinder_drv is not None: + self._build_cinder_volume_list() def build_glance_resource_cache(self): self.log.info("Building glance resource cache") diff --git a/rwcal/test/test_rwcal_openstack.py b/rwcal/test/test_rwcal_openstack.py index 339a2b4d..8278a5e1 100644 --- a/rwcal/test/test_rwcal_openstack.py +++ b/rwcal/test/test_rwcal_openstack.py @@ -43,10 +43,10 @@ ssh_pwauth: True # Important information about openstack installation. This needs to be manually verified # openstack_info = { - 'username' : 'xxxxxx', + 'username' : 'xxxx', 'password' : 'xxxxxx', - 'auth_url' : 'http://10.66.4.102:5000/v2.0/', - 'project_name' : 'xxxxxx', + 'auth_url' : 'http://10.66.4.19:5000/v2.0/', + 'project_name' : 'xxxxx', 'mgmt_network' : 'private', 'reserved_flavor' : 'm1.medium', 'reserved_image' : 'Fedora-x86_64-20-20131211.1-sda-ping.qcow2', @@ -1103,7 +1103,7 @@ class OpenStackTest(unittest.TestCase): self.assertEqual(found, True) logger.info("Openstack-CAL-Test: Passed VDU list" ) - #@unittest.skip("Skipping test_create_delete_virtual_link_and_vdu") + @unittest.skip("Skipping test_create_delete_virtual_link_and_vdu") def test_create_delete_virtual_link_and_vdu(self): """ Test to create VDU @@ -1303,6 +1303,15 @@ class OpenStackTest(unittest.TestCase): self.assertEqual(found, True) logger.info("Openstack-CAL-Test: Passed VDU list" ) + @unittest.skip("Skipping test_validate_creds") + def test_validate_creds(self): + """ + Test validate creds + """ + logger.info("Openstack-CAL-Test: Test validate creds") + status = self.cal.validate_cloud_creds(self._acct) + logger.info("Openstack-CAL-Test: Passed validate creds") + class VmData(object): """A convenience class that provides all the stats and EPA Attributes from the VM provided -- 2.25.1