From 650ee38a6b9c6d1efd50606416a0b2b78d20bf37 Mon Sep 17 00:00:00 2001 From: Sahdev Zala Date: Wed, 27 Aug 2014 07:54:59 -0500 Subject: [PATCH] Check tosca node requirements Befor iterating over tosca node requirement makes sure that it is provided. Change-Id: Iecba38b8344ce57f43a7fb34e50b3ca1fd606eb5 Closes-Bug: #1358812 --- translator/hot/translate_node_templates.py | 29 +++++++++++----------- translator/toscalib/nodetemplate.py | 4 +-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/translator/hot/translate_node_templates.py b/translator/hot/translate_node_templates.py index bb021526..1911319c 100644 --- a/translator/hot/translate_node_templates.py +++ b/translator/hot/translate_node_templates.py @@ -67,7 +67,7 @@ class TranslateNodeTemplates(): hot_resources = [] hot_lookup = {} - attachment_suffix = 0 + suffix = 0 # Copy the TOSCA graph: nodetemplate for node in self.nodetemplates: hot_node = TOSCA_TO_HOT_TYPE[node.type](node) @@ -78,20 +78,21 @@ class TranslateNodeTemplates(): # which doesn't match to Heat Resources 1 to 1. if node.type == "tosca.nodes.Compute": volume_name = None - reuirements = node.requirements + requirements = node.requirements + if requirements: # Find the name of associated BlockStorage node - for requires in reuirements: - for value in requires.values(): - for n in self.nodetemplates: - if n.name == value: - volume_name = value - break - attachment_suffix = attachment_suffix + 1 - attachment_node = self._get_attachment_node(node, - attachment_suffix, - volume_name) - if attachment_node: - hot_resources.append(attachment_node) + for requires in requirements: + for value in requires.values(): + for n in self.nodetemplates: + if n.name == value: + volume_name = value + break + suffix = suffix + 1 + attachment_node = self._get_attachment_node(node, + suffix, + volume_name) + if attachment_node: + hot_resources.append(attachment_node) # Handle life cycle operations: this may expand each node # into multiple HOT resources and may change their name diff --git a/translator/toscalib/nodetemplate.py b/translator/toscalib/nodetemplate.py index 6ffe5c6a..11e3daad 100644 --- a/translator/toscalib/nodetemplate.py +++ b/translator/toscalib/nodetemplate.py @@ -54,7 +54,7 @@ class NodeTemplate(EntityTemplate): def related_nodes(self): if not self.related: for relation, node in self.type_definition.relationship.items(): - for tpl in self.node_templates: + for tpl in self.templates: if tpl == node.type: self.related[NodeTemplate(tpl)] = relation return self.related.keys() @@ -69,7 +69,7 @@ class NodeTemplate(EntityTemplate): name = node break if name: - tpl = NodeTemplate(name, self.node_templates) + tpl = NodeTemplate(name, self.templates) caps = tpl.capabilities for c in caps: if c.name == cap_name: