This commit adds a check for volume type encryption existence before
marking it as deleted. If it isn't present call returns 404 error
code so that it can be handled properly in services that use the
REST API (like Heat).
APIImpact
HTTP 404 will be returned if volume type encryption is not found.
Change-Id: I3107b8df0121de1ebe9e812ef7a842d09500e030
Closes-Bug: #
1468751
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)
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')})
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
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,
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, {})