Browse Source

Merge "Make rc_create return 400 with invalid json manifest"

Jenkins 4 years ago
parent
commit
255428cc8e

+ 4
- 1
magnum/api/controllers/v1/replicationcontroller.py View File

@@ -109,7 +109,10 @@ class ReplicationController(v1_base.K8sResourceBase):
109 109
         return cls._convert_with_links(sample, 'http://localhost:9511', expand)
110 110
 
111 111
     def parse_manifest(self):
112
-        manifest = k8s_manifest.parse(self._get_manifest())
112
+        try:
113
+            manifest = k8s_manifest.parse(self._get_manifest())
114
+        except ValueError as e:
115
+            raise exception.InvalidParameterValue(message=str(e))
113 116
         self.name = manifest["id"]
114 117
         if "labels" in manifest:
115 118
             self.labels = manifest["labels"]

+ 8
- 0
magnum/tests/api/controllers/v1/test_replicationcontroller.py View File

@@ -323,6 +323,14 @@ class TestPost(api_base.FunctionalTest):
323 323
         self.assertEqual(400, response.status_int)
324 324
         self.assertTrue(response.json['error_message'])
325 325
 
326
+    def test_create_rc_with_invalid_manifest(self):
327
+        rc_dict = apiutils.rc_post_data()
328
+        rc_dict['manifest'] = 'wrong_manifest'
329
+        response = self.post_json('/rcs', rc_dict, expect_errors=True)
330
+        self.assertEqual('application/json', response.content_type)
331
+        self.assertEqual(400, response.status_int)
332
+        self.assertTrue(response.json['error_message'])
333
+
326 334
 
327 335
 class TestDelete(api_base.FunctionalTest):
328 336
 

Loading…
Cancel
Save