Merge "Catch an exception on resource routing update"
This commit is contained in:
commit
d809ff98c8
@ -197,6 +197,22 @@ class RoutingController(rest.RestController):
|
|||||||
return utils.format_api_error(
|
return utils.format_api_error(
|
||||||
400, _('There is no such resource type'))
|
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:
|
try:
|
||||||
routing_updated = db_api.update_resource_routing(
|
routing_updated = db_api.update_resource_routing(
|
||||||
context, _id, update_dict)
|
context, _id, update_dict)
|
||||||
|
@ -391,5 +391,14 @@ class RoutingControllerTest(unittest.TestCase):
|
|||||||
res = self.controller.put(-123, **body_update1)
|
res = self.controller.put(-123, **body_update1)
|
||||||
self._validate_error_code(res, 404)
|
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):
|
def tearDown(self):
|
||||||
core.ModelBase.metadata.drop_all(core.get_engine())
|
core.ModelBase.metadata.drop_all(core.get_engine())
|
||||||
|
Loading…
Reference in New Issue
Block a user