diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-09-20 17:30:47 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-09-20 17:30:47 +0000 |
| commit | fbdaa960d9abfada9cabd4764b11eaaed15b19df (patch) | |
| tree | 2e64939fc3d1cb4d1aca5d0ba933a2ba599df878 | |
| parent | ad4503d8340f0ef147d03ca789438067345e332e (diff) | |
| parent | a7a0705699662ec3a604126eec868c673cd5328e (diff) | |
| download | nova-fbdaa960d9abfada9cabd4764b11eaaed15b19df.tar.gz nova-fbdaa960d9abfada9cabd4764b11eaaed15b19df.tar.xz nova-fbdaa960d9abfada9cabd4764b11eaaed15b19df.zip | |
Merge "Raise NotFound for non-existent volume snapshot create"
| -rw-r--r-- | nova/api/openstack/volume/snapshots.py | 7 | ||||
| -rw-r--r-- | nova/tests/api/openstack/fakes.py | 2 | ||||
| -rw-r--r-- | nova/tests/api/openstack/volume/test_snapshots.py | 14 |
3 files changed, 21 insertions, 2 deletions
diff --git a/nova/api/openstack/volume/snapshots.py b/nova/api/openstack/volume/snapshots.py index bba3b0ced..74c5f75e6 100644 --- a/nova/api/openstack/volume/snapshots.py +++ b/nova/api/openstack/volume/snapshots.py @@ -151,7 +151,12 @@ class SnapshotsController(wsgi.Controller): snapshot = body['snapshot'] volume_id = snapshot['volume_id'] - volume = self.volume_api.get(context, volume_id) + + try: + volume = self.volume_api.get(context, volume_id) + except exception.VolumeNotFound as err: + raise exc.HTTPNotFound(explanation=unicode(err)) + force = snapshot.get('force', False) msg = _("Create snapshot from volume %s") LOG.audit(msg, volume_id, context=context) diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py index dc9ccc5f3..fb7a7183c 100644 --- a/nova/tests/api/openstack/fakes.py +++ b/nova/tests/api/openstack/fakes.py @@ -567,7 +567,7 @@ def stub_volume_get(self, context, volume_id): def stub_volume_get_notfound(self, context, volume_id): - raise exc.NotFound + raise exc.VolumeNotFound(volume_id=volume_id) def stub_volume_get_all(context, search_opts=None): diff --git a/nova/tests/api/openstack/volume/test_snapshots.py b/nova/tests/api/openstack/volume/test_snapshots.py index 66f8cddc3..c6e703f83 100644 --- a/nova/tests/api/openstack/volume/test_snapshots.py +++ b/nova/tests/api/openstack/volume/test_snapshots.py @@ -124,6 +124,20 @@ class SnapshotApiTest(test.TestCase): req, body) + def test_snapshot_create_nonexistent_volume_id(self): + self.stubs.Set(volume.api.API, 'get', fakes.stub_volume_get_notfound) + + snapshot = {"volume_id": 13, + "force": False, + "display_name": "Snapshot Test Name", + "display_description": "Snapshot Test Desc"} + body = dict(snapshot=snapshot) + req = fakes.HTTPRequest.blank('/v1/snapshots') + self.assertRaises(webob.exc.HTTPNotFound, + self.controller.create, + req, + body) + def test_snapshot_delete(self): self.stubs.Set(volume.api.API, "get_snapshot", stub_snapshot_get) self.stubs.Set(volume.api.API, "delete_snapshot", stub_snapshot_delete) |
