summaryrefslogtreecommitdiffstats
path: root/tosca2heat/tosca-parser/toscaparser
diff options
context:
space:
mode:
Diffstat (limited to 'tosca2heat/tosca-parser/toscaparser')
-rw-r--r--tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py13
-rw-r--r--tosca2heat/tosca-parser/toscaparser/elements/nodetype.py21
-rw-r--r--tosca2heat/tosca-parser/toscaparser/nodetemplate.py9
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py3
4 files changed, 36 insertions, 10 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py b/tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py
index 54cd9fe..5fa9661 100644
--- a/tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py
+++ b/tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py
@@ -81,3 +81,16 @@ class CapabilityTypeDef(StatefulEntityType):
if pnode:
return CapabilityTypeDef(self.name, pnode,
self.nodetype, self.custom_def)
+
+ def inherits_from(self, type_names):
+ '''Check this capability is in type_names
+
+ Check if this capability or some of its parent types
+ are in the list of types: type_names
+ '''
+ if self.type in type_names:
+ return True
+ elif self.parent_type:
+ return self.parent_type.inherits_from(type_names)
+ else:
+ return False
diff --git a/tosca2heat/tosca-parser/toscaparser/elements/nodetype.py b/tosca2heat/tosca-parser/toscaparser/elements/nodetype.py
index 7d68c0b..7f3da2d 100644
--- a/tosca2heat/tosca-parser/toscaparser/elements/nodetype.py
+++ b/tosca2heat/tosca-parser/toscaparser/elements/nodetype.py
@@ -82,8 +82,9 @@ class NodeType(StatefulEntityType):
if isinstance(value, dict):
captype = value['capability']
value = (self.
- _get_node_type_by_cap(key, captype))
- relation = self._get_relation(key, value)
+ _get_node_type_by_cap(captype))
+ # _get_node_type_by_cap(key, captype))
+ # relation = self._get_relation(key, value)
keyword = key
node_type = value
rtype = RelationshipType(relation, keyword, self.custom_def)
@@ -91,7 +92,7 @@ class NodeType(StatefulEntityType):
relationship[rtype] = relatednode
return relationship
- def _get_node_type_by_cap(self, key, cap):
+ def _get_node_type_by_cap(self, cap):
'''Find the node type that has the provided capability
This method will lookup all node types if they have the
@@ -102,9 +103,15 @@ class NodeType(StatefulEntityType):
node_types = [node_type for node_type in self.TOSCA_DEF.keys()
if node_type.startswith(self.NODE_PREFIX) and
node_type != 'tosca.nodes.Root']
-
- for node_type in node_types:
- node_def = self.TOSCA_DEF[node_type]
+ custom_node_types = [node_type for node_type in self.custom_def.keys()
+ if node_type.startswith(self.NODE_PREFIX) and
+ node_type != 'tosca.nodes.Root']
+
+ for node_type in node_types + custom_node_types:
+ if node_type in self.TOSCA_DEF:
+ node_def = self.TOSCA_DEF[node_type]
+ else:
+ node_def = self.custom_def[node_type]
if isinstance(node_def, dict) and 'capabilities' in node_def:
node_caps = node_def['capabilities']
for value in node_caps.values():
@@ -114,7 +121,7 @@ class NodeType(StatefulEntityType):
def _get_relation(self, key, ndtype):
relation = None
- ntype = NodeType(ndtype)
+ ntype = NodeType(ndtype, self.custom_def)
caps = ntype.get_capabilities()
if caps and key in caps.keys():
c = caps[key]
diff --git a/tosca2heat/tosca-parser/toscaparser/nodetemplate.py b/tosca2heat/tosca-parser/toscaparser/nodetemplate.py
index ca855ad..0d65ac5 100644
--- a/tosca2heat/tosca-parser/toscaparser/nodetemplate.py
+++ b/tosca2heat/tosca-parser/toscaparser/nodetemplate.py
@@ -79,7 +79,9 @@ class NodeTemplate(EntityTemplate):
# TODO(spzala) implement look up once Glance meta data is available
# to find a matching TOSCA node using the TOSCA types
msg = _('Lookup by TOSCA types is not supported. '
- 'Requirement for "%s" can not be full-filled.') % self.name
+ 'Requirement node "%(node)s" for "%(name)s"'
+ ' can not be full-filled.') \
+ % {'node': node, 'name': self.name}
if (node in list(self.type_definition.TOSCA_DEF.keys())
or node in self.custom_def):
ExceptionCollector.appendException(NotImplementedError(msg))
@@ -87,7 +89,9 @@ class NodeTemplate(EntityTemplate):
if node not in self.templates:
ExceptionCollector.appendException(
- KeyError(_('Node template "%s" was not found.') % node))
+ KeyError(_('Node template "%(node)s" was not found'
+ ' in "%(name)s".')
+ % {'node': node, 'name': self.name}))
return
related_tpl = NodeTemplate(node, self.templates, self.custom_def)
@@ -109,6 +113,7 @@ class NodeTemplate(EntityTemplate):
break
if relationship:
found_relationship_tpl = False
+
# apply available relationship templates if found
if self.available_rel_tpls:
for tpl in self.available_rel_tpls:
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py
index 77232df..fac8687 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py
@@ -571,7 +571,8 @@ class ToscaTemplateTest(TestCase):
exception.ExceptionCollector.assertExceptionMessage(
exception.UnknownFieldError, err7_msg)
- err8_msg = _('\'Node template "server1" was not found.\'')
+ err8_msg = _('\'Node template "server1" was not found in '
+ '"webserver".\'')
exception.ExceptionCollector.assertExceptionMessage(
KeyError, err8_msg)