From a2d3e896b9c7655c87ad617bee3be5b36b5f4836 Mon Sep 17 00:00:00 2001 From: Dan Voiculeasa Date: Mon, 9 Aug 2021 19:11:09 +0300 Subject: [PATCH] Fix helm charts tests for DebianOS 1) Cannot JSON serialize MagicMock objects. Instead of letting the test environment create MagicMock objects, create custom objects. 2) A transition from PyYAML 3.13 to PyYAML 5.3.1 is made for DebianOS. The default value of 'default_flow_style' was changed to 'False' in PyYAML 5.1.1. For backwards compatibility we now need to explicitly assign the 'None' value where default_flow_style is not populated. Story 2009101 Task: 42976 Signed-off-by: Dan Voiculeasa Change-Id: Ide1b8b593dafa4680b204f50168ed898625b3b40 (cherry picked from commit bbe77385d6069defc9f9f0d0d4a8b80e90d793f7) --- .../sysinv/sysinv/sysinv/api/controllers/v1/helm_charts.py | 3 ++- sysinv/sysinv/sysinv/sysinv/tests/api/test_helm_charts.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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 86524f8528..67b63ece7b 100644 --- a/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/helm_charts.py +++ b/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/helm_charts.py @@ -83,7 +83,8 @@ class HelmChartsController(rest.RestController): try: system_overrides = pecan.request.rpcapi.get_helm_chart_overrides( pecan.request.context, app_name, name, namespace) - system_overrides = yaml.safe_dump(system_overrides) \ + system_overrides = yaml.safe_dump(system_overrides, + default_flow_style=None) \ if system_overrides else None except Exception as e: raise wsme.exc.ClientSideError(_("Unable to get the helm chart overrides " diff --git a/sysinv/sysinv/sysinv/sysinv/tests/api/test_helm_charts.py b/sysinv/sysinv/sysinv/sysinv/tests/api/test_helm_charts.py index 03be16b71d..c62f4dfabd 100644 --- a/sysinv/sysinv/sysinv/sysinv/tests/api/test_helm_charts.py +++ b/sysinv/sysinv/sysinv/sysinv/tests/api/test_helm_charts.py @@ -172,6 +172,8 @@ class ApiHelmChartShowTestSuiteMixin(ApiHelmChartTestCaseMixin): def test_no_system_override(self): self.fake_system_app.return_value = False + self.fake_merge_overrides.return_value = {} + url = self.get_single_url_helm_override('platform-integ-apps', 'ceph-pools-audit', 'kube-system') response = self.get_json(url) @@ -264,6 +266,7 @@ class ApiHelmChartShowTestSuiteMixin(ApiHelmChartTestCaseMixin): self.fake_helm_apps.return_value = ['platform-integ-apps'] # Return helm chart overrides self.fake_override.return_value = {"enabled": True} + self.fake_merge_overrides.return_value = {} url = self.get_single_url_helm_override('platform-integ-apps', 'ceph-pools-audit', 'kube-system') @@ -294,6 +297,7 @@ class ApiHelmChartDeleteTestSuiteMixin(ApiHelmChartTestCaseMixin): # Test that a valid DELETE operation is successful def test_delete_helm_override_success(self): self.fake_system_app.return_value = False + self.fake_merge_overrides.return_value = {} # Verify that user override exists initially url = self.get_single_url_helm_override('platform-integ-apps', @@ -502,6 +506,8 @@ class ApiHelmChartPatchTestSuiteMixin(ApiHelmChartTestCaseMixin): headers=self.API_HEADERS, expect_errors=True) self.fake_system_app.return_value = False + self.fake_merge_overrides.return_value = {} + response = self.get_json(url, expect_errors=True) self.assertEqual(response.status_code, http_client.OK) # Verify the values of the response with the values in database