Catch an exception on resource routing update
1. What is the problem When resource routing needs to update its attribute named pod_id, it will fail if the pod where the new pod_id lays on doesn't exist. This update error was caught through internal server error originally and it was not detailed enough. 2. What is the solution for the problem Dismiss this update request by giving a regular invalid parameter error and tell the operator that the new pod for resource routing should exist. The pod to which the pod_id belongs can only be selected from the existing pods. Because it is a foreign key and highly depends on pod table. At the same time, we should add one test case for this circumstance. 3. What the features need to be implemented to the Tricircle to realize the solution None. Change-Id: Iae6e3368c7f0ff0cd751aca932cba818328bb723
This commit is contained in:
parent
a36a9d046b
commit
2af0625d62
@ -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)
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user