Make rc_create return 400 with invalid json manifest
Currently when rc_create is passed an invalid json formatted manifest, 500 status is returned to user due to unhandled ValueError exception. This patch handles this exception and return 400 status to user when invalid manifest is passed. Partially closes-bug: #1429757 Change-Id: I7b4d4e050313f752c9f971a106899cfa1b98f627
This commit is contained in:
parent
cd3190758f
commit
e34ca072a0
|
@ -109,7 +109,10 @@ class ReplicationController(v1_base.K8sResourceBase):
|
|||
return cls._convert_with_links(sample, 'http://localhost:9511', expand)
|
||||
|
||||
def parse_manifest(self):
|
||||
manifest = k8s_manifest.parse(self._get_manifest())
|
||||
try:
|
||||
manifest = k8s_manifest.parse(self._get_manifest())
|
||||
except ValueError as e:
|
||||
raise exception.InvalidParameterValue(message=str(e))
|
||||
self.name = manifest["id"]
|
||||
if "labels" in manifest:
|
||||
self.labels = manifest["labels"]
|
||||
|
|
|
@ -323,6 +323,14 @@ class TestPost(api_base.FunctionalTest):
|
|||
self.assertEqual(400, response.status_int)
|
||||
self.assertTrue(response.json['error_message'])
|
||||
|
||||
def test_create_rc_with_invalid_manifest(self):
|
||||
rc_dict = apiutils.rc_post_data()
|
||||
rc_dict['manifest'] = 'wrong_manifest'
|
||||
response = self.post_json('/rcs', rc_dict, expect_errors=True)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertEqual(400, response.status_int)
|
||||
self.assertTrue(response.json['error_message'])
|
||||
|
||||
|
||||
class TestDelete(api_base.FunctionalTest):
|
||||
|
||||
|
|
Loading…
Reference in New Issue