From 958b53b3a8a8005b3476e6301a4b97447c14904b Mon Sep 17 00:00:00 2001 From: Hugo Brito Date: Fri, 7 Jul 2023 16:21:14 -0300 Subject: [PATCH] Improve strategy error messages in dcmanager-api This commit adds the strategy type in the exception message for the following commands: dcmanager -strategy create/abort/apply/delete Test Plan: 1. Test the `dcmanager -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 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 --- .../api/controllers/v1/sw_update_strategy.py | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/distributedcloud/dcmanager/api/controllers/v1/sw_update_strategy.py b/distributedcloud/dcmanager/api/controllers/v1/sw_update_strategy.py index c71eaf4ec..10cd82aea 100755 --- a/distributedcloud/dcmanager/api/controllers/v1/sw_update_strategy.py +++ b/distributedcloud/dcmanager/api/controllers/v1/sw_update_strategy.py @@ -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'))