Raise exception if volume snapshot id not found instead of return
In V2 API, if show or delete a snapshot with an unknown id, exception will be returned instead of raised. Even though correct error will be returned to client, it's not aligned to other API layer code, this patch modify it by raise exception instead of return. Change-Id: I22d4565ca08e1c0ed5041ce903bf6ba918c14cfd Closes-Bug: #1279189
This commit is contained in:
@@ -817,6 +817,21 @@ class UnprocessableSnapshotTestCase(CommonUnprocessableEntityTestCase,
|
||||
controller_cls = volumes.SnapshotController
|
||||
|
||||
|
||||
class ShowSnapshotTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(ShowSnapshotTestCase, self).setUp()
|
||||
self.controller = volumes.SnapshotController()
|
||||
self.req = fakes.HTTPRequest.blank('/v2/fake/os-snapshots')
|
||||
self.req.method = 'GET'
|
||||
|
||||
def test_show_snapshot_not_exist(self):
|
||||
def fake_get_snapshot(self, context, id):
|
||||
raise exception.SnapshotNotFound(snapshot_id=id)
|
||||
self.stubs.Set(cinder.API, 'get_snapshot', fake_get_snapshot)
|
||||
self.assertRaises(exc.HTTPNotFound,
|
||||
self.controller.show, self.req, FAKE_UUID_A)
|
||||
|
||||
|
||||
class CreateSnapshotTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(CreateSnapshotTestCase, self).setUp()
|
||||
@@ -863,6 +878,20 @@ class DeleteSnapshotTestCase(test.TestCase):
|
||||
result = self.controller.delete(self.req, result['snapshot']['id'])
|
||||
self.assertEqual(result.status_int, 202)
|
||||
|
||||
def test_delete_snapshot_not_exists(self):
|
||||
def fake_delete_snapshot_not_exist(self, context, snapshot_id):
|
||||
raise exception.SnapshotNotFound(snapshot_id=snapshot_id)
|
||||
|
||||
self.stubs.Set(cinder.API, 'delete_snapshot',
|
||||
fake_delete_snapshot_not_exist)
|
||||
self.req.method = 'POST'
|
||||
self.body = {'snapshot': {'volume_id': 1}}
|
||||
result = self.controller.create(self.req, body=self.body)
|
||||
|
||||
self.req.method = 'DELETE'
|
||||
self.assertRaises(exc.HTTPNotFound, self.controller.delete,
|
||||
self.req, result['snapshot']['id'])
|
||||
|
||||
|
||||
class AssistedSnapshotCreateTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user