Merge "Change 404 to 400 when resource not found exception raises"

This commit is contained in:
Jenkins 2016-01-18 08:26:34 +00:00 committed by Gerrit Code Review
commit 5f841f38c4
4 changed files with 14 additions and 6 deletions

View File

@ -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):

View File

@ -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')

View File

@ -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):

View File

@ -694,7 +694,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')