diff --git a/tricircle/api/controllers/routing.py b/tricircle/api/controllers/routing.py index 4e72adca..bfe07b5e 100644 --- a/tricircle/api/controllers/routing.py +++ b/tricircle/api/controllers/routing.py @@ -197,6 +197,22 @@ class RoutingController(rest.RestController): return utils.format_api_error( 400, _('There is no such resource type')) + # the pod with new pod_id should exist in pod table + if 'pod_id' in update_dict: + new_pod_id = update_dict.get('pod_id') + try: + # find the pod through the pod_id and verify whether it exists + db_api.get_pod(context, new_pod_id) + except t_exc.ResourceNotFound: + return utils.format_api_error( + 400, _("The pod %(new_pod_id)s doesn't" + " exist") % {'new_pod_id': new_pod_id}) + except Exception as e: + LOG.exception(_LE('Failed to update resource routing: ' + '%(exception)s '), {'exception': e}) + return utils.format_api_error( + 500, _('Failed to update resource routing')) + try: routing_updated = db_api.update_resource_routing( context, _id, update_dict) diff --git a/tricircle/tests/unit/api/controllers/test_routing.py b/tricircle/tests/unit/api/controllers/test_routing.py index a559ca22..dfb4d998 100644 --- a/tricircle/tests/unit/api/controllers/test_routing.py +++ b/tricircle/tests/unit/api/controllers/test_routing.py @@ -391,5 +391,14 @@ class RoutingControllerTest(unittest.TestCase): res = self.controller.put(-123, **body_update1) self._validate_error_code(res, 404) + # failure case, the pod where the new pod_id lays on + # should exist in pod table + + # a variable used for later test + new_pod_id = uuidutils.generate_uuid() + body_update6 = {'routing': {'pod_id': new_pod_id}} + res = self.controller.put(id, **body_update6) + self._validate_error_code(res, 400) + def tearDown(self): core.ModelBase.metadata.drop_all(core.get_engine())