From 9f575be0ea322e8a68cb4afffb6b4308824ffde2 Mon Sep 17 00:00:00 2001 From: Valeriya Shvetcova Date: Mon, 15 Jun 2020 18:37:48 +0300 Subject: [PATCH] Add parent interfaces to the list of NodeType interfaces Change-Id: Ia957ad11985a3b6665f0015d17dacfd79a1a3d95 Closes-Bug: #1883563 --- toscaparser/elements/nodetype.py | 18 +++++++++++++++++- toscaparser/nodetemplate.py | 22 +++++++++++++--------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/toscaparser/elements/nodetype.py b/toscaparser/elements/nodetype.py index aa92698b..07551e7a 100644 --- a/toscaparser/elements/nodetype.py +++ b/toscaparser/elements/nodetype.py @@ -169,7 +169,23 @@ class NodeType(StatefulEntityType): @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) + parent_interfaces.pop(ifaces.LIFECYCLE, None) + parent_interfaces.pop(ifaces.CONFIGURE, None) + parent_interfaces.pop(ifaces.LIFECYCLE_SHORTNAME, None) + parent_interfaces.pop(ifaces.CONFIGURE_SHORTNAME, None) + + if parent_interfaces: + if interfaces: + parent_interfaces.update(interfaces) + interfaces = parent_interfaces + + return interfaces @property def lifecycle_inputs(self): diff --git a/toscaparser/nodetemplate.py b/toscaparser/nodetemplate.py index 82b72d18..dd5d8ff5 100644 --- a/toscaparser/nodetemplate.py +++ b/toscaparser/nodetemplate.py @@ -264,16 +264,20 @@ class NodeTemplate(EntityTemplate): value, InterfacesDef. interfaces_relationship_configure_operations, 'interfaces') - elif name in self.type_definition.interfaces.keys(): - self._common_validate_field( - value, - self._collect_custom_iface_operations(name), - 'interfaces') else: - ExceptionCollector.appendException( - UnknownFieldError( - what='"interfaces" of template "%s"' % - self.name, field=name)) + interfaces = self.type_definition.interfaces + if interfaces is None: + interfaces = dict() + if name in interfaces.keys(): + self._common_validate_field( + value, + self._collect_custom_iface_operations(name), + 'interfaces') + else: + ExceptionCollector.appendException( + UnknownFieldError( + what='"interfaces" of template "%s"' % + self.name, field=name)) def _collect_custom_iface_operations(self, name): allowed_operations = []