Merge "Return 404 if volume type encryption is not found"
This commit is contained in:
commit
96cda5a6bb
|
@ -188,7 +188,10 @@ class VolumeTypeEncryptionController(wsgi.Controller):
|
|||
expl = _('Cannot delete encryption specs. Volume type in use.')
|
||||
raise webob.exc.HTTPBadRequest(explanation=expl)
|
||||
else:
|
||||
db.volume_type_encryption_delete(context, type_id)
|
||||
try:
|
||||
db.volume_type_encryption_delete(context, type_id)
|
||||
except exception.VolumeTypeEncryptionNotFound as ex:
|
||||
raise webob.exc.HTTPNotFound(explanation=ex.msg)
|
||||
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
|
|
|
@ -2946,6 +2946,9 @@ def volume_type_encryption_delete(context, volume_type_id):
|
|||
with session.begin():
|
||||
encryption = volume_type_encryption_get(context, volume_type_id,
|
||||
session)
|
||||
if not encryption:
|
||||
raise exception.VolumeTypeEncryptionNotFound(
|
||||
type_id=volume_type_id)
|
||||
encryption.update({'deleted': True,
|
||||
'deleted_at': timeutils.utcnow(),
|
||||
'updated_at': literal_column('updated_at')})
|
||||
|
|
|
@ -475,6 +475,27 @@ class VolumeTypeEncryptionTest(test.TestCase):
|
|||
|
||||
db.volume_type_destroy(context.get_admin_context(), volume_type['id'])
|
||||
|
||||
def test_delete_with_no_encryption(self):
|
||||
volume_type = self._default_volume_type
|
||||
# create an volume type
|
||||
db.volume_type_create(context.get_admin_context(), volume_type)
|
||||
|
||||
# without creating encryption type, try to delete
|
||||
# and check if 404 is raised.
|
||||
res = self._get_response(volume_type, req_method='DELETE',
|
||||
req_headers='application/json',
|
||||
url='/v2/fake/types/%s/encryption/provider')
|
||||
self.assertEqual(404, res.status_code)
|
||||
expected = {
|
||||
"itemNotFound": {
|
||||
"message": "Volume type encryption for type "
|
||||
"fake_type_id does not exist.",
|
||||
"code": 404
|
||||
}
|
||||
}
|
||||
self.assertEqual(expected, json.loads(res.body))
|
||||
db.volume_type_destroy(context.get_admin_context(), volume_type['id'])
|
||||
|
||||
def test_update_item(self):
|
||||
volume_type = self._default_volume_type
|
||||
|
||||
|
|
|
@ -1211,7 +1211,7 @@ class DBAPIEncryptionTestCase(BaseTest):
|
|||
self._assertEqualObjects(encryption, encryption_get,
|
||||
self._ignored_keys)
|
||||
|
||||
def test_volume_type_update_with_no_create(self):
|
||||
def test_volume_type_encryption_update_with_no_create(self):
|
||||
self.assertRaises(exception.VolumeTypeEncryptionNotFound,
|
||||
db.volume_type_encryption_update,
|
||||
self.ctxt,
|
||||
|
@ -1238,6 +1238,12 @@ class DBAPIEncryptionTestCase(BaseTest):
|
|||
encryption['volume_type_id'])
|
||||
self.assertIsNone(encryption_get)
|
||||
|
||||
def test_volume_type_encryption_delete_no_create(self):
|
||||
self.assertRaises(exception.VolumeTypeEncryptionNotFound,
|
||||
db.volume_type_encryption_delete,
|
||||
self.ctxt,
|
||||
'fake_no_create_type')
|
||||
|
||||
def test_volume_encryption_get(self):
|
||||
# normal volume -- metadata should be None
|
||||
volume = db.volume_create(self.ctxt, {})
|
||||
|
|
Loading…
Reference in New Issue