Improve strategy error messages in dcmanager-api

This commit adds the strategy type in the exception message for
the following commands:
dcmanager <strategy-type>-strategy create/abort/apply/delete

Test Plan:
1. Test the `dcmanager <strategy_type>-strategy create/delete/abort/apply` commands for the following strategies:
- fw-update-strategy, kube-rootca-update-strategy, kube-upgrade-strategy, patch-strategy, prestage-strategy, and upgrade-strategy.
2. Validate that the exception message includes the <strategy_type> and the reason that the command failed. For example:
- "Unable to delete strategy of type 'firmware': Not found".

Closes-Bug: 2026604

Change-Id: I3ecf920e5688e3d51f2172aa20d8e2c12700b4b2
Signed-off-by: Hugo Brito <hugo.brito@windriver.com>
This commit is contained in:
Hugo Brito 2023-07-07 16:21:14 -03:00 committed by Hugo Nicodemos
parent 5ec99e186b
commit 958b53b3a8
1 changed files with 19 additions and 7 deletions

View File

@ -141,6 +141,9 @@ class SwUpdateStrategyController(object):
if not payload:
pecan.abort(400, _('Body required'))
# If 'type' is in the request params, filter the update_type
update_type_filter = request.params.get('type', None)
if actions is None:
policy.authorize(sw_update_strat_policy.POLICY_ROOT % "create", {},
restcomm.extract_credentials_for_policy())
@ -212,14 +215,14 @@ class SwUpdateStrategyController(object):
return self.orch_rpc_client.create_sw_update_strategy(context,
payload)
except RemoteError as e:
pecan.abort(422, e.value)
pecan.abort(
422, _("Unable to create strategy of type '%s': %s")
% (update_type_filter, e.value)
)
except Exception as e:
LOG.exception(e)
pecan.abort(500, _('Unable to create strategy'))
elif actions == 'actions':
# If 'type' is in the request params, filter the update_type
update_type_filter = request.params.get('type', None)
# Apply or abort a strategy
action = payload.get('action')
if not action:
@ -234,7 +237,10 @@ class SwUpdateStrategyController(object):
context,
update_type=update_type_filter)
except RemoteError as e:
pecan.abort(422, e.value)
pecan.abort(
422, _("Unable to apply strategy of type '%s': %s")
% (update_type_filter, e.value)
)
except Exception as e:
LOG.exception(e)
pecan.abort(500, _('Unable to apply strategy'))
@ -248,7 +254,10 @@ class SwUpdateStrategyController(object):
context,
update_type=update_type_filter)
except RemoteError as e:
pecan.abort(422, e.value)
pecan.abort(
422, _("Unable to abort strategy of type '%s': %s")
% (update_type_filter, e.value)
)
except Exception as e:
LOG.exception(e)
pecan.abort(500, _('Unable to abort strategy'))
@ -270,7 +279,10 @@ class SwUpdateStrategyController(object):
context,
update_type=update_type_filter)
except RemoteError as e:
pecan.abort(422, e.value)
pecan.abort(
422, _("Unable to delete strategy of type '%s': %s")
% (update_type_filter, e.value)
)
except Exception as e:
LOG.exception(e)
pecan.abort(500, _('Unable to delete strategy'))