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
This commit is contained in:
Hiroyuki JO 2019-07-10 11:46:20 +09:00
parent b36f9515e9
commit d21c0ffffa
2 changed files with 11 additions and 3 deletions

View File

@ -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,

View File

@ -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}})