]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Handle NotFound exception in snapshots API code
authorjohn-griffith <john.griffith@solidfire.com>
Wed, 27 Nov 2013 21:02:48 +0000 (14:02 -0700)
committerjohn-griffith <john.griffith@solidfire.com>
Wed, 27 Nov 2013 21:02:48 +0000 (14:02 -0700)
Passing tests in the gate leave unhandled trace/error messages
for a VolumeNotFound issue.

These are caused by the test_volumes_snapshots_negative test
which requests a non-existent volume and the tests pass however
the log files are a bit messed up due to the unhandled exception.

This change just adds a try/catch block around the volume get calls
in the snapshot modules and raises HTTPNotFound as appropriate.

Change-Id: I2096f2da7c68ef7924fc8e69b2d5c2afea578512
Closes-Bug: #1255214

cinder/api/v1/snapshots.py
cinder/api/v2/snapshots.py

index 08d87afbf6ee81d8a70e995ab0a9c4aaf4408b3b..1e441114341468e6c7ba3a2f77ff8272c62e6458 100644 (file)
@@ -173,7 +173,11 @@ class SnapshotsController(wsgi.Controller):
             msg = _("'volume_id' must be specified")
             raise exc.HTTPBadRequest(explanation=msg)
 
-        volume = self.volume_api.get(context, volume_id)
+        try:
+            volume = self.volume_api.get(context, volume_id)
+        except exception.NotFound:
+            raise exc.HTTPNotFound()
+
         force = snapshot.get('force', False)
         msg = _("Create snapshot from volume %s")
         LOG.audit(msg, volume_id, context=context)
index 24703317a8c6daf153edf89155339ec94413b458..bc74d58fdfe9609b96a14582d650db1ea7025232 100644 (file)
@@ -184,7 +184,11 @@ class SnapshotsController(wsgi.Controller):
             msg = _("'volume_id' must be specified")
             raise exc.HTTPBadRequest(explanation=msg)
 
-        volume = self.volume_api.get(context, volume_id)
+        try:
+            volume = self.volume_api.get(context, volume_id)
+        except exception.NotFound:
+            msg = _("Volume could not be found")
+            raise exc.HTTPNotFound(explanation=msg)
         force = snapshot.get('force', False)
         msg = _("Create snapshot from volume %s")
         LOG.audit(msg, volume_id, context=context)