From 1a159c3cd71c2e3309fb0e8e93b58e03db144bf4 Mon Sep 17 00:00:00 2001 From: Wataru Juso Date: Fri, 5 Feb 2021 21:47:32 +0900 Subject: [PATCH] Modify notification request parameter name This patch fixed notification request parameters name that different from ETSI definition. Along with this fix, modified an issue where the initial word of under-score would be changed SnakeCase to CamelCase in common/utils function. Closes-Bug: #1914596 Change-Id: Iac04311aee1db7fb5836c32745d29bf63ac5ce20 --- tacker/common/utils.py | 28 +++++++++++++++++++++++++- tacker/conductor/conductor_server.py | 3 +++ tacker/tests/unit/common/test_utils.py | 8 +++++--- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/tacker/common/utils.py b/tacker/common/utils.py index bba4b0363..ae61963f9 100644 --- a/tacker/common/utils.py +++ b/tacker/common/utils.py @@ -378,8 +378,34 @@ def convert_snakecase_to_camelcase(request_data): This method takes care only keys in a `dict` or `dicts in a list`. For simple list with string items, the elements which are actual values are ignored during conversion. + Also, Snake case is a notation method that uses underscores to connect + words. For that reason, if the initial word of the key in dict starts + with '_', this function ignore to convert the key. :param request_data: dict with keys or list with items, in snake_case. + + Example: + Before:: + + [ + {"vnf_lcm_op_occ_id" : "uuid"}, + { + "_links" : { + "vnf_lcm_op_occ": {"href": "resource_link"} + } + } + ] + + After:: + + [ + {"vnfLcmOpOccId": "uuid"}, + { + "_links": { + "vnfLcmOpOcc": {"href": "resource_link"} + } + } + ] """ def convert(name): return re.sub('_([a-z])', @@ -389,7 +415,7 @@ def convert_snakecase_to_camelcase(request_data): new_dict = {} for key, property_value in request_data.items(): property_value = convert_snakecase_to_camelcase(property_value) - camelcase = convert(key) + camelcase = key if key.startswith('_') else convert(key) new_dict[camelcase] = property_value return new_dict diff --git a/tacker/conductor/conductor_server.py b/tacker/conductor/conductor_server.py index 78dfb54a8..fce43b9e5 100644 --- a/tacker/conductor/conductor_server.py +++ b/tacker/conductor/conductor_server.py @@ -1463,6 +1463,9 @@ class Conductor(manager.Manager): try: LOG.debug("send_notification start notification[%s]" % notification) + + notification = utils.convert_snakecase_to_camelcase(notification) + if (notification.get('notificationType') == 'VnfLcmOperationOccurrenceNotification'): vnf_lcm_subscriptions = \ diff --git a/tacker/tests/unit/common/test_utils.py b/tacker/tests/unit/common/test_utils.py index 139a086d7..b47d97033 100644 --- a/tacker/tests/unit/common/test_utils.py +++ b/tacker/tests/unit/common/test_utils.py @@ -68,9 +68,11 @@ class TestCamelToSnakeCase(testtools.TestCase): class TestSnakeToCamelCase(testtools.TestCase): def test_convert_snakecase_to_camelcase_dict(self): """Only the dict keys from list should be converted to camelcase""" - actual_val = utils.convert_snakecase_to_camelcase( - {"snake_case_key": "snake_case_value"}) - expected_val = {"snakeCaseKey": "snake_case_value"} + data = {"snake_case_key": "snake_case_value", + "_key": "ignore_key_value"} + actual_val = utils.convert_snakecase_to_camelcase(data) + expected_val = {"snakeCaseKey": "snake_case_value", + "_key": "ignore_key_value"} self.assertEqual(expected_val, actual_val) def test_convert_snakecase_to_camelcase_list_with_dict_items(self):