Make service_create return 400 with invalid json manifest

Currently when service_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.

Change-Id: I8a4b7ab9217947b56db625c66164c19865f113fc
Closes-bug: #1429757
This commit is contained in:
Madhuri Kumari 2015-03-09 09:10:43 +00:00
parent cd3190758f
commit 0425ee11d5
2 changed files with 12 additions and 1 deletions

View File

@ -116,7 +116,10 @@ class Service(v1_base.K8sResourceBase):
def parse_manifest(self):
if not self.manifest and not self.manifest_url:
raise exception.InvalidParameterValue("'manifest' can't be empty")
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 "port" in manifest:
self.port = manifest["port"]

View File

@ -285,6 +285,14 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual(400, response.status_int)
self.assertTrue(response.json['error_message'])
def test_create_service_invalid_manifest(self):
sdict = apiutils.service_post_data()
sdict['manifest'] = 'wrong_manifest'
response = self.post_json('/services', sdict, 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):