From d21c0ffffad8bce0365fe2a7f17f94d7377dd6fa Mon Sep 17 00:00:00 2001 From: Hiroyuki JO Date: Wed, 10 Jul 2019 11:46:20 +0900 Subject: [PATCH] Fix ToscaPolicies overwrites scheduler_hints ToscaPlicies.handle_properties overwrites if scheduler_hints exists. This patch changes it to use 'update' method to add new key and value. Change-Id: I6062980eaa3c392a48c878518d2d61425eceb86f Story: #2004963 Task: #29403 --- translator/hot/tosca/tests/test_tosca_policies.py | 8 +++++++- translator/hot/tosca/tosca_policies.py | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/translator/hot/tosca/tests/test_tosca_policies.py b/translator/hot/tosca/tests/test_tosca_policies.py index 24368ab6..6cd73e14 100644 --- a/translator/hot/tosca/tests/test_tosca_policies.py +++ b/translator/hot/tosca/tests/test_tosca_policies.py @@ -35,6 +35,11 @@ class ToscaPoicyTest(TestCase): toscacompute = ToscaCompute(nodetemplate) toscacompute.handle_properties() + # adding a property to test that + # ToscaPolicies.handle_properties does not overwrite this. + toscacompute.properties['scheduler_hints'] = { + 'target_cell': 'cell0'} + policy = Policy(policy_name, tpl, targets, "node_templates") toscapolicy = ToscaPolicies(policy) @@ -73,7 +78,8 @@ class ToscaPoicyTest(TestCase): 'scheduler_hints': { 'group': { 'get_resource': - 'my_compute_placement_policy'}}, + 'my_compute_placement_policy'}, + 'target_cell': 'cell0'}, 'user_data_format': 'SOFTWARE_CONFIG'} self._tosca_policy_test( tpl_snippet, diff --git a/translator/hot/tosca/tosca_policies.py b/translator/hot/tosca/tosca_policies.py index 19f121a1..402a0ad8 100755 --- a/translator/hot/tosca/tosca_policies.py +++ b/translator/hot/tosca/tosca_policies.py @@ -38,5 +38,7 @@ class ToscaPolicies(HotResource): self.properties["policies"] = [group_policy] for resource in resources: if resource.name in self.policy.targets: - resource.properties["scheduler_hints"] = { - "group": {"get_resource": self.name}} + if not resource.properties.get("scheduler_hints"): + resource.properties["scheduler_hints"] = {} + resource.properties["scheduler_hints"].update( + {"group": {"get_resource": self.name}})