Change 404 to 400 when resource not found exception raises
According to the new document and Hong Bin's opinion,I changed code 404 to 400 of the classes as follows: ImageNotFound OSDistroFieldNotFound FlavorNotFound NetworkNotFound, because they are nonexistent resources. So these four exceptions will report code 400 in the future and we should pay attention to it. Change-Id: I4040340f9605e3ed03af2ec3b965bf2fc54a0d98 Closes-Bug: #1494122
This commit is contained in:
parent
a941344dae
commit
93d9f0fe9f
|
@ -486,7 +486,9 @@ class OperationInProgress(Invalid):
|
|||
|
||||
|
||||
class ImageNotFound(ResourceNotFound):
|
||||
"""The code here changed to 400 according to the latest document."""
|
||||
message = _("Image %(image_id)s could not be found.")
|
||||
code = 400
|
||||
|
||||
|
||||
class ImageNotAuthorized(MagnumException):
|
||||
|
@ -494,7 +496,9 @@ class ImageNotAuthorized(MagnumException):
|
|||
|
||||
|
||||
class OSDistroFieldNotFound(ResourceNotFound):
|
||||
"""The code here changed to 400 according to the latest document."""
|
||||
message = _("Image %(image_id)s doesn't contain os_distro field.")
|
||||
code = 400
|
||||
|
||||
|
||||
class KubernetesAPIFailed(MagnumException):
|
||||
|
@ -543,11 +547,15 @@ class UnsupportedK8sMemoryFormat(MagnumException):
|
|||
|
||||
|
||||
class FlavorNotFound(ResourceNotFound):
|
||||
"""The code here changed to 400 according to the latest document."""
|
||||
message = _("Unable to find flavor %(flavor)s.")
|
||||
code = 400
|
||||
|
||||
|
||||
class NetworkNotFound(ResourceNotFound):
|
||||
"""The code here changed to 400 according to the latest document."""
|
||||
message = _("Unable to find network %(network)s.")
|
||||
code = 400
|
||||
|
||||
|
||||
class TrustCreateFailed(MagnumException):
|
||||
|
|
|
@ -150,7 +150,7 @@ class BayModelTest(base.BaseMagnumTest):
|
|||
self.keypairs_client.create_keypair(name='default')
|
||||
gen_model = datagen.baymodel_data_with_valid_keypair()
|
||||
self.assertRaises(
|
||||
exceptions.NotFound,
|
||||
exceptions.BadRequest,
|
||||
self.baymodel_client.post_baymodel, gen_model)
|
||||
|
||||
@testtools.testcase.attr('negative')
|
||||
|
|
|
@ -593,7 +593,7 @@ class TestPost(api_base.FunctionalTest):
|
|||
response = self.post_json('/bays', bdict, expect_errors=True)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertTrue(mock_valid_os_res.called)
|
||||
self.assertEqual(404, response.status_int)
|
||||
self.assertEqual(400, response.status_int)
|
||||
|
||||
@mock.patch('magnum.api.attr_validator.validate_os_resources')
|
||||
def test_create_bay_with_invalid_ext_network(self, mock_valid_os_res):
|
||||
|
@ -602,7 +602,7 @@ class TestPost(api_base.FunctionalTest):
|
|||
response = self.post_json('/bays', bdict, expect_errors=True)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertTrue(mock_valid_os_res.called)
|
||||
self.assertEqual(404, response.status_int)
|
||||
self.assertEqual(400, response.status_int)
|
||||
|
||||
@mock.patch('magnum.api.attr_validator.validate_os_resources')
|
||||
def test_create_bay_with_invalid_keypair(self, mock_valid_os_res):
|
||||
|
@ -620,7 +620,7 @@ class TestPost(api_base.FunctionalTest):
|
|||
response = self.post_json('/bays', bdict, expect_errors=True)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertTrue(mock_valid_os_res.called)
|
||||
self.assertEqual(404, response.status_int)
|
||||
self.assertEqual(400, response.status_int)
|
||||
|
||||
@mock.patch('magnum.api.attr_validator.validate_os_resources')
|
||||
def test_create_bay_with_multi_images_same_name(self, mock_valid_os_res):
|
||||
|
@ -638,7 +638,7 @@ class TestPost(api_base.FunctionalTest):
|
|||
response = self.post_json('/bays', bdict, expect_errors=True)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertTrue(mock_valid_os_res.called)
|
||||
self.assertEqual(404, response.status_int)
|
||||
self.assertEqual(400, response.status_int)
|
||||
|
||||
|
||||
class TestDelete(api_base.FunctionalTest):
|
||||
|
|
|
@ -682,7 +682,7 @@ class TestPost(api_base.FunctionalTest):
|
|||
bdict = apiutils.baymodel_post_data()
|
||||
del bdict['uuid']
|
||||
response = self.post_json('/baymodels', bdict, expect_errors=True)
|
||||
self.assertEqual(404, response.status_int)
|
||||
self.assertEqual(400, response.status_int)
|
||||
|
||||
@mock.patch('magnum.api.attr_validator.validate_image')
|
||||
@mock.patch('magnum.api.attr_validator.validate_keypair')
|
||||
|
|
Loading…
Reference in New Issue