Fix error getting relationshps in case of custom_def capability
Change-Id: I5bbc21113451d17e887ee79426e4205d40f57f6a Related-Bug: #1687598
This commit is contained in:
@@ -83,7 +83,6 @@ class NodeType(StatefulEntityType):
|
|||||||
captype = value['capability']
|
captype = value['capability']
|
||||||
value = (self.
|
value = (self.
|
||||||
_get_node_type_by_cap(captype))
|
_get_node_type_by_cap(captype))
|
||||||
relation = self._get_relation(key, value)
|
|
||||||
keyword = key
|
keyword = key
|
||||||
node_type = value
|
node_type = value
|
||||||
rtype = RelationshipType(relation, keyword, self.custom_def)
|
rtype = RelationshipType(relation, keyword, self.custom_def)
|
||||||
@@ -102,9 +101,15 @@ class NodeType(StatefulEntityType):
|
|||||||
node_types = [node_type for node_type in self.TOSCA_DEF.keys()
|
node_types = [node_type for node_type in self.TOSCA_DEF.keys()
|
||||||
if node_type.startswith(self.NODE_PREFIX) and
|
if node_type.startswith(self.NODE_PREFIX) and
|
||||||
node_type != 'tosca.nodes.Root']
|
node_type != 'tosca.nodes.Root']
|
||||||
|
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:
|
for node_type in node_types + custom_node_types:
|
||||||
node_def = self.TOSCA_DEF[node_type]
|
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:
|
if isinstance(node_def, dict) and 'capabilities' in node_def:
|
||||||
node_caps = node_def['capabilities']
|
node_caps = node_def['capabilities']
|
||||||
for value in node_caps.values():
|
for value in node_caps.values():
|
||||||
@@ -114,7 +119,7 @@ class NodeType(StatefulEntityType):
|
|||||||
|
|
||||||
def _get_relation(self, key, ndtype):
|
def _get_relation(self, key, ndtype):
|
||||||
relation = None
|
relation = None
|
||||||
ntype = NodeType(ndtype)
|
ntype = NodeType(ndtype, self.custom_def)
|
||||||
caps = ntype.get_capabilities()
|
caps = ntype.get_capabilities()
|
||||||
if caps and key in caps.keys():
|
if caps and key in caps.keys():
|
||||||
c = caps[key]
|
c = caps[key]
|
||||||
|
|||||||
22
toscaparser/tests/data/custom_types/custom_cap.yaml
Normal file
22
toscaparser/tests/data/custom_types/custom_cap.yaml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
tosca_definitions_version: tosca_simple_yaml_1_0
|
||||||
|
|
||||||
|
capability_types:
|
||||||
|
|
||||||
|
tosca.capabilities.SomeCap:
|
||||||
|
derived_from: tosca.capabilities.Container
|
||||||
|
|
||||||
|
node_types:
|
||||||
|
|
||||||
|
tosca.nodes.NodeWithReq:
|
||||||
|
derived_from: tosca.nodes.SoftwareComponent
|
||||||
|
requirements:
|
||||||
|
- host:
|
||||||
|
capability: tosca.capabilities.SomeCap
|
||||||
|
relationship: tosca.relationships.HostedOn
|
||||||
|
occurrences: [1, 1]
|
||||||
|
|
||||||
|
tosca.nodes.NodeWithCap:
|
||||||
|
derived_from: tosca.nodes.SoftwareComponent
|
||||||
|
capabilities:
|
||||||
|
host:
|
||||||
|
type: tosca.capabilities.SomeCap
|
||||||
23
toscaparser/tests/data/test_custom_capabilty.yaml
Normal file
23
toscaparser/tests/data/test_custom_capabilty.yaml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
tosca_definitions_version: tosca_simple_yaml_1_0
|
||||||
|
|
||||||
|
description: TOSCA simple profile to test a custom defined capability
|
||||||
|
|
||||||
|
imports:
|
||||||
|
- custom_types/custom_cap.yaml
|
||||||
|
|
||||||
|
topology_template:
|
||||||
|
|
||||||
|
node_templates:
|
||||||
|
|
||||||
|
node_req:
|
||||||
|
type: tosca.nodes.NodeWithReq
|
||||||
|
requirements:
|
||||||
|
- host: node_cap
|
||||||
|
|
||||||
|
node_cap:
|
||||||
|
type: tosca.nodes.NodeWithCap
|
||||||
|
requirements:
|
||||||
|
- host: server
|
||||||
|
|
||||||
|
server:
|
||||||
|
type: tosca.nodes.Compute
|
||||||
@@ -851,3 +851,9 @@ class ToscaTemplateTest(TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
['ALRM1', 'SP1', 'SP2'],
|
['ALRM1', 'SP1', 'SP2'],
|
||||||
sorted([policy.name for policy in tosca.policies]))
|
sorted([policy.name for policy in tosca.policies]))
|
||||||
|
|
||||||
|
def test_custom_capability(self):
|
||||||
|
tosca_tpl = os.path.join(
|
||||||
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
|
"data/test_custom_capabilty.yaml")
|
||||||
|
ToscaTemplate(tosca_tpl)
|
||||||
|
|||||||
Reference in New Issue
Block a user