From 395cbb77ef85dc545c0424cefafbef87eaaca7fb Mon Sep 17 00:00:00 2001 From: zhufl Date: Fri, 4 Dec 2020 09:47:54 +0800 Subject: [PATCH] Fix invalid "is not {}" judgement of empty dict "is not {}" should not be used to judge whether a dict is empty, because it will always return True. So does "is not []". >>> {} is not {} True >>> [] is not [] True Change-Id: I014517d999345e201c3ee96f0634c7975a0cc7bb --- tacker/tests/unit/vnfm/lcm_user_data/utils/test_utils.py | 3 +-- tacker/tosca/utils.py | 2 +- tacker/vnfm/lcm_user_data/utils.py | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tacker/tests/unit/vnfm/lcm_user_data/utils/test_utils.py b/tacker/tests/unit/vnfm/lcm_user_data/utils/test_utils.py index 1d611b2ac..60aea551a 100644 --- a/tacker/tests/unit/vnfm/lcm_user_data/utils/test_utils.py +++ b/tacker/tests/unit/vnfm/lcm_user_data/utils/test_utils.py @@ -129,8 +129,7 @@ class TestUtils(testtools.TestCase): def test_create_vdu_flavor_dict(self): vnfd_dict = self._read_file('vnfd_lcm_user_data.yaml') - test_vnfd_dict = {'VNF': {}, 'VDU1': - {'ram': 512, 'vcpus': 1, 'disk': 1}, 'CP1': {}} + test_vnfd_dict = {'VDU1': {'ram': 512, 'vcpus': 1, 'disk': 1}} vdu_flavor_dict = utils.create_vdu_flavor_dict(vnfd_dict) self.assertEqual(test_vnfd_dict, vdu_flavor_dict) diff --git a/tacker/tosca/utils.py b/tacker/tosca/utils.py index 9fbdc1c7e..9935be8c5 100644 --- a/tacker/tosca/utils.py +++ b/tacker/tosca/utils.py @@ -840,7 +840,7 @@ def _extract_policy_info(tosca_policies, inst_level_dict, aspect_delta_dict, aspect_id_dict, aspect_vdu_dict, vdu_delta_dict): default_inst_level_id = None - if tosca_policies is not []: + if tosca_policies: for p in tosca_policies: if p.type == ETSI_SCALING_ASPECT_DELTA: vdu_list = p.targets diff --git a/tacker/vnfm/lcm_user_data/utils.py b/tacker/vnfm/lcm_user_data/utils.py index 6097b1167..a1c6120d6 100644 --- a/tacker/vnfm/lcm_user_data/utils.py +++ b/tacker/vnfm/lcm_user_data/utils.py @@ -221,7 +221,7 @@ def create_vdu_flavor_dict(vnfd_dict): vdu_flavor_props = val.get( 'capabilities', {}).get( 'virtual_compute', {}).get('properties', {}) - if vdu_flavor_props is not {}: + if vdu_flavor_props: flavor_dict = {} for key, val in vdu_flavor_props.items(): if key == 'virtual_cpu': @@ -318,7 +318,7 @@ def create_vdu_flavor_capability_name_dict(vnfd_dict): vdu_flavor_props = val.get( 'capabilities', {}).get( 'virtual_compute', {}).get('properties', {}) - if vdu_flavor_props is not {}: + if vdu_flavor_props: for key, val in vdu_flavor_props.items(): if key == 'requested_additional_capabilities': capability_props = val.get('properties', {}) @@ -347,7 +347,7 @@ def create_sw_image_dict(vnfd_dict): for vdu_name, val in node_templates.items(): sw_image_data_props = val.get( 'properties', {}).get('sw_image_data', {}) - if sw_image_data_props is not {}: + if sw_image_data_props: if 'name' in sw_image_data_props.keys(): sw_image_data[vdu_name] = sw_image_data_props['name']