From 2bfd9c033cd21f24108e1f3e5b4834c23a516d34 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Wed, 15 May 2013 22:26:09 +0200 Subject: [PATCH] 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 --- heat/engine/clients.py | 9 ++++----- heat/engine/resources/volume.py | 2 +- heat/tests/test_volume.py | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) 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) -- 2.45.2