Fix exception message for strategy create

For the strategy creation, we are unable to get the type from the
request params. Instead, this value must be obtained from the payload.

Test Plan:
1. Test the `dcmanager <strategy_type>-strategy create` command 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 create strategy of type 'kube-rootca-update': Bad strategy request: Strategy has no steps to apply".
3. Validate other commands delete/abort/apply remains the same.

Closes-Bug: 2026604

Change-Id: Id8c3145c5b8b8d222ade9e93a2172ad5388228c4
Signed-off-by: Hugo Brito <hugo.brito@windriver.com>
This commit is contained in:
Hugo Brito 2023-08-10 09:42:54 -03:00
parent 8f8b4463bb
commit b0abc75142

View File

@ -141,9 +141,6 @@ 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())
@ -217,12 +214,15 @@ class SwUpdateStrategyController(object):
except RemoteError as e:
pecan.abort(
422, _("Unable to create strategy of type '%s': %s")
% (update_type_filter, e.value)
% (strategy_type, 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: