From e6a1ba529172b14eed6f611a1d6a09e673176dfd Mon Sep 17 00:00:00 2001 From: john-griffith Date: Wed, 27 Nov 2013 14:02:48 -0700 Subject: [PATCH] Handle NotFound exception in snapshots API code 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 | 6 +++++- cinder/api/v2/snapshots.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cinder/api/v1/snapshots.py b/cinder/api/v1/snapshots.py index 08d87afbf..1e4411143 100644 --- a/cinder/api/v1/snapshots.py +++ b/cinder/api/v1/snapshots.py @@ -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) diff --git a/cinder/api/v2/snapshots.py b/cinder/api/v2/snapshots.py index 24703317a..bc74d58fd 100644 --- a/cinder/api/v2/snapshots.py +++ b/cinder/api/v2/snapshots.py @@ -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) -- 2.45.2