From: Zane Bitter Date: Wed, 15 May 2013 20:26:09 +0000 (+0200) Subject: Clean up import of cinderclient exceptions X-Git-Tag: 2014.1~600^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=2bfd9c033cd21f24108e1f3e5b4834c23a516d34;p=openstack-build%2Fheat-build.git Clean up import of cinderclient exceptions Don't import a particular version of the cinderclient API - just import the client module and pass the version we want to the Client() constructor as is intended. This allows up to access the exceptions directly through client.exceptions, rather than having to do a separate import. Change-Id: Ic0e47506a51a572da01fdfdef0367cfdb3e34d54 --- diff --git a/heat/engine/clients.py b/heat/engine/clients.py index ae8a8e77..4b0fe29d 100644 --- a/heat/engine/clients.py +++ b/heat/engine/clients.py @@ -36,8 +36,7 @@ except ImportError: quantumclient = None logger.info('quantumclient not available') try: - from cinderclient.v1 import client as cinderclient - from cinderclient import exceptions as cinder_exceptions + from cinderclient import client as cinderclient except ImportError: cinderclient = None logger.info('cinderclient not available') @@ -186,7 +185,7 @@ class OpenStackClients(object): return None logger.debug('cinder args %s', args) - self._cinder = cinderclient.Client(**args) + self._cinder = cinderclient.Client('1', **args) if con.password is None and con.auth_token is not None: management_url = self.url_for(service_type='volume') self._cinder.client.auth_token = con.auth_token @@ -218,7 +217,7 @@ class OpenStackClients(object): try: vol = self.cinder().volumes.get(volume_id) - except cinder_exceptions.NotFound: + except cinderclient.exceptions.NotFound: logger.warning('Volume %s - not found' % (volume_id)) return @@ -242,7 +241,7 @@ class OpenStackClients(object): pass vol.get() logger.info('volume status of %s now %s' % (volume_id, vol.status)) - except cinder_exceptions.NotFound: + except cinderclient.exceptions.NotFound: logger.warning('Volume %s - not found' % (volume_id)) diff --git a/heat/engine/resources/volume.py b/heat/engine/resources/volume.py index 663ce56f..5b2ca708 100644 --- a/heat/engine/resources/volume.py +++ b/heat/engine/resources/volume.py @@ -105,7 +105,7 @@ class Volume(resource.Resource): raise exception.Error("Volume in use") self.cinder().volumes.delete(self.resource_id) - except clients.cinder_exceptions.NotFound: + except clients.cinderclient.exceptions.NotFound: pass if volume_backups is not None: diff --git a/heat/tests/test_volume.py b/heat/tests/test_volume.py index 4af4f7eb..3d4266c0 100644 --- a/heat/tests/test_volume.py +++ b/heat/tests/test_volume.py @@ -123,7 +123,7 @@ class VolumeTest(HeatTestCase): self.cinder_fc.volumes.delete('vol-123').AndReturn(None) self.cinder_fc.volumes.get('vol-123').AndRaise( - clients.cinder_exceptions.NotFound('Not found')) + clients.cinderclient.exceptions.NotFound('Not found')) self.m.ReplayAll() t = template_format.parse(volume_template)