From ca3a2a88045bfed6098975f004c22a5ee31119ec Mon Sep 17 00:00:00 2001 From: Valeriya Shvetcova Date: Wed, 26 May 2021 00:34:50 +0300 Subject: [PATCH] Fix parent types if relationships 1. Fix passing arguments when parent type is taken 2. Take parent interfaces when interfaces are taken 3. Choose custom definitions first when capability type is taken Change-Id: Ifb74a2a68bf627323ff6bfe5a8d5e0a9a222f86b Closes-Bug: #1929616 --- toscaparser/elements/capabilitytype.py | 6 +++--- toscaparser/elements/relationshiptype.py | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/toscaparser/elements/capabilitytype.py b/toscaparser/elements/capabilitytype.py index dc36dd86..a3afa0e5 100644 --- a/toscaparser/elements/capabilitytype.py +++ b/toscaparser/elements/capabilitytype.py @@ -66,10 +66,10 @@ class CapabilityTypeDef(StatefulEntityType): if parent_cap: parent_cap = parent_cap.type while parent_cap != self.TOSCA_TYPEURI_CAPABILITY_ROOT: - if parent_cap in self.TOSCA_DEF.keys(): - capabilities[parent_cap] = self.TOSCA_DEF[parent_cap] - elif custom_def and parent_cap in custom_def.keys(): + if custom_def and parent_cap in custom_def.keys(): capabilities[parent_cap] = custom_def[parent_cap] + elif parent_cap in self.TOSCA_DEF.keys(): + capabilities[parent_cap] = self.TOSCA_DEF[parent_cap] parent_cap = capabilities[parent_cap]['derived_from'] return capabilities diff --git a/toscaparser/elements/relationshiptype.py b/toscaparser/elements/relationshiptype.py index 50ecd4a1..3419804f 100644 --- a/toscaparser/elements/relationshiptype.py +++ b/toscaparser/elements/relationshiptype.py @@ -35,11 +35,22 @@ class RelationshipType(StatefulEntityType): '''Return a relationship this reletionship is derived from.''' prel = self.derived_from(self.defs) if prel: - return RelationshipType(prel, self.custom_def) + return RelationshipType(prel, custom_def=self.custom_def) @property def interfaces(self): - return self.get_value(self.INTERFACES) + interfaces = self.get_value(self.INTERFACES) + + if self.parent_type is not None: + if self.parent_type.interfaces is not None: + import copy + parent_interfaces = copy.deepcopy(self.parent_type.interfaces) + + if parent_interfaces: + if interfaces: + parent_interfaces.update(interfaces) + interfaces = parent_interfaces + return interfaces @property def valid_target_types(self):