]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Clean up import of cinderclient exceptions
authorZane Bitter <zbitter@redhat.com>
Wed, 15 May 2013 20:26:09 +0000 (22:26 +0200)
committerZane Bitter <zbitter@redhat.com>
Thu, 16 May 2013 14:09:00 +0000 (16:09 +0200)
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
heat/engine/resources/volume.py
heat/tests/test_volume.py

index ae8a8e77bd2723409bcf70ee3ed0d89dacd377f5..4b0fe29d78543fc4780018aae2715191b9f16102 100644 (file)
@@ -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))
 
index 663ce56f8596fd9165ca180895afbf28418cabd5..5b2ca708af6bce646df658588d2319ec928f8178 100644 (file)
@@ -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:
index 4af4f7ebb5280e24672575e124d5d2b6d196d916..3d4266c03223c9bada9e67c771ee96bdc048b6f9 100644 (file)
@@ -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)