From 94b2532978a8eb49c6909cc3e2382f4dc7c86b4c Mon Sep 17 00:00:00 2001 From: YiFeng Date: Fri, 16 Jun 2023 16:14:19 +0900 Subject: [PATCH] Fix delete PM threshold API not returning 404 When specifying a non-existing threshold id, the delete PM threshold API returns httpcode 500. This patch changes 500 to 404. Closes-Bug: #2023357 Change-Id: Ibdd4471bdf354d69b5c064b83caf0b052a2d3d0a --- tacker/sol_refactored/controller/vnfpm_v2.py | 2 +- .../controller/test_vnfpm_v2.py | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tacker/sol_refactored/controller/vnfpm_v2.py b/tacker/sol_refactored/controller/vnfpm_v2.py index b4acba866..c6faaeb6d 100644 --- a/tacker/sol_refactored/controller/vnfpm_v2.py +++ b/tacker/sol_refactored/controller/vnfpm_v2.py @@ -431,7 +431,7 @@ class VnfPmControllerV2(sol_wsgi.SolAPIController): pm_threshold = pm_threshold_utils.get_pm_threshold( context, thresholdId) if not pm_threshold: - raise sol_ex.PMThresholdNotExist(thresholdId=thresholdId) + raise sol_ex.PMThresholdNotExist(threshold_id=thresholdId) self.threshold_plugin.delete_threshold( context=context, pm_threshold=pm_threshold) diff --git a/tacker/tests/unit/sol_refactored/controller/test_vnfpm_v2.py b/tacker/tests/unit/sol_refactored/controller/test_vnfpm_v2.py index ed36a372b..f65719d29 100644 --- a/tacker/tests/unit/sol_refactored/controller/test_vnfpm_v2.py +++ b/tacker/tests/unit/sol_refactored/controller/test_vnfpm_v2.py @@ -575,6 +575,13 @@ class TestVnfpmV2(base.BaseTestCase): result = self.controller.show_threshold(self.request, 'pm_threshold_1') self.assertEqual(200, result.status) + @mock.patch.object(objects.base.TackerPersistentObject, 'get_by_id') + def test_pm_threshold_show_not_exist(self, mock_pm): + mock_pm.return_value = None + self.assertRaises( + sol_ex.PMThresholdNotExist, self.controller.show_threshold, + request=self.request, thresholdId='pm_threshold_1') + @mock.patch.object(objects.base.TackerPersistentObject, 'update') @mock.patch.object(objects.base.TackerPersistentObject, 'get_by_id') @mock.patch.object(common_script_utils, 'test_notification') @@ -611,6 +618,24 @@ class TestVnfpmV2(base.BaseTestCase): body=body) self.assertEqual(200, result.status) + @mock.patch.object(objects.base.TackerPersistentObject, 'get_by_id') + def test_pm_threshold_update_not_exist(self, mock_pm): + mock_pm.return_value = None + _SubscriptionAuthentication = { + 'authType': ['BASIC'], + 'paramsBasic': { + 'userName': 'test_name', + 'password': 'test_pwd' + } + } + body = { + 'callbackUri': 'callbackuri_update', + 'authentication': _SubscriptionAuthentication + } + self.assertRaises( + sol_ex.PMThresholdNotExist, self.controller.update_threshold, + request=self.request, thresholdId='id', body=body) + @mock.patch.object(PrometheusPluginThreshold, 'create_threshold') @mock.patch.object(objects.base.TackerPersistentObject, 'get_by_id') def test_pm_threshold_delete( @@ -621,3 +646,10 @@ class TestVnfpmV2(base.BaseTestCase): result = self.controller.delete_threshold( self.request, 'pm_threshold_1') self.assertEqual(204, result.status) + + @mock.patch.object(objects.base.TackerPersistentObject, 'get_by_id') + def test_pm_threshold_delete_not_exist(self, mock_pm): + mock_pm.return_value = None + self.assertRaises( + sol_ex.PMThresholdNotExist, self.controller.delete_threshold, + request=self.request, thresholdId='pm_threshold_1')