From 5eb4e206c08b7471857a16f2da587a6b10ab7b0a Mon Sep 17 00:00:00 2001 From: Tee Ngo Date: Wed, 5 Dec 2018 16:21:55 -0500 Subject: [PATCH] Fix various issues with helm-override-show This commit addresses the following issues with helm-override-show command: - incorrect response if user overrides is not available, system overrides should be displayed as opposed to exception. - incorrect response for invalid/unsupported chart name and/or namespace. Tests conducted: The following commands were used to verify the changes: - system helm-override-show ingress abc - system helm-override-show abc ingress - system helm-override-show abc def - system helm-override-show ingress openstack - system helm-override-update ingress openstack \ --set pod.replicas.ingress=2 - system helm-override-show ingress openstack Story: 2003909 Task: 28180 Task: 28265 Change-Id: I96e4c682c13b129a04e8827a00c63e39882c133a Signed-off-by: Tee Ngo --- .../sysinv/api/controllers/v1/helm_charts.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/helm_charts.py b/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/helm_charts.py index fe9613ecc3..deed1a55f0 100644 --- a/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/helm_charts.py +++ b/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/helm_charts.py @@ -42,6 +42,7 @@ class HelmChartsController(rest.RestController): :param name: name of helm chart :param namespace: namespace of chart overrides """ + self.validate_name_and_namespace(name, namespace) # Get any user-specified overrides. try: @@ -52,20 +53,24 @@ class HelmChartsController(rest.RestController): if name in constants.SUPPORTED_HELM_CHARTS: user_overrides = '' else: - raise + # Unsupported/invalid chart name (and namespace) + raise wsme.exc.ClientSideError(_("Override not found.")) # Get any system overrides. try: system_overrides = pecan.request.rpcapi.get_helm_chart_overrides( pecan.request.context, name, namespace) system_overrides = yaml.safe_dump(system_overrides) - except (exception.InvalidHelmChart, exception.InvalidHelmNamespace): - raise + except Exception: + # Unsupported/invalid namespace + raise wsme.exc.ClientSideError(_("Override not found.")) # Merge the system overrides with the saved user-specified overrides, # with user-specified overrides taking priority over the system # overrides. - file_overrides = [system_overrides, user_overrides] + file_overrides = [system_overrides, user_overrides] \ + if user_overrides else [system_overrides] + combined_overrides = pecan.request.rpcapi.merge_overrides( pecan.request.context, file_overrides=file_overrides) @@ -79,11 +84,9 @@ class HelmChartsController(rest.RestController): def validate_name_and_namespace(self, name, namespace): if not name: - raise wsme.exc.ClientSideError(_( - "Helm-override-update rejected: name must be specified")) + raise wsme.exc.ClientSideError(_("Name must be specified.")) if not namespace: - raise wsme.exc.ClientSideError(_( - "Helm-override-update rejected: namespace must be specified")) + raise wsme.exc.ClientSideError(_("Namespace must be specified.")) @wsme_pecan.wsexpose(wtypes.text, wtypes.text, wtypes.text, wtypes.text, wtypes.text) def patch(self, name, namespace, flag, values):