From dcac49c64a5259a9f71d1b3cd122d6de13aad1ad Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 21 Oct 2021 11:40:02 +0200 Subject: [PATCH 1/4] Fix TOSCA Configure interface --- IM/tosca/Tosca.py | 25 ++++++++++++++----------- test/unit/Tosca.py | 1 + 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/IM/tosca/Tosca.py b/IM/tosca/Tosca.py index 2c2565959..ec007b0ae 100644 --- a/IM/tosca/Tosca.py +++ b/IM/tosca/Tosca.py @@ -557,12 +557,13 @@ def _get_relationships_interfaces(relationships, node): rel_tpl = Tosca._get_relationship_template(rel, src, trgt) rel_tlp_def_interfaces = {} - if rel_tpl.type_definition.interfaces and 'Standard' in rel_tpl.type_definition.interfaces: - rel_tlp_def_interfaces = rel_tpl.type_definition.interfaces['Standard'] + for inteface_name in ['Standard', 'Configure']: + if rel_tpl.type_definition.interfaces and inteface_name in rel_tpl.type_definition.interfaces: + rel_tlp_def_interfaces = rel_tpl.type_definition.interfaces[inteface_name] if src.name == node.name: # Also add the configure of the target node of the relation - trgt_interfaces = Tosca._get_interfaces(trgt, ['pre_configure_source', 'post_configure_source']) + trgt_interfaces = Tosca._get_interfaces(trgt, steps=['pre_configure_source', 'post_configure_source']) for name in ['pre_configure_source', 'post_configure_source', 'add_source']: if trgt_interfaces and name in trgt_interfaces: res[name] = trgt_interfaces[name] @@ -576,7 +577,7 @@ def _get_relationships_interfaces(relationships, node): node_template=rel_tpl) elif trgt.name == node.name: - src_interfaces = Tosca._get_interfaces(src, ['pre_configure_target', 'post_configure_target']) + src_interfaces = Tosca._get_interfaces(src, steps=['pre_configure_target', 'post_configure_target']) for name in ['pre_configure_target', 'post_configure_target', 'add_target', 'target_changed', 'remove_target']: if src_interfaces and name in src_interfaces: @@ -1619,7 +1620,8 @@ def _get_root_parent_type(node): return node_type @staticmethod - def _get_interfaces(node, steps=['create', 'configure', 'start', 'stop', 'delete']): + def _get_interfaces(node, interface_names=['Standard','Configure'], + steps=['create', 'configure', 'start', 'stop', 'delete']): """ Get a dict of InterfacesDef of the specified node """ @@ -1630,12 +1632,13 @@ def _get_interfaces(node, steps=['create', 'configure', 'start', 'stop', 'delete node_type = node.type_definition while True: - if node_type.interfaces and 'Standard' in node_type.interfaces: - for name, elems in node_type.interfaces['Standard'].items(): - if name in steps: - if name not in interfaces: - interfaces[name] = InterfacesDef(node_type, 'Standard', name=name, - value=elems, node_template=node) + for interface_name in interface_names: + if node_type.interfaces and interface_name in node_type.interfaces: + for name, elems in node_type.interfaces[interface_name].items(): + if name in steps: + if name not in interfaces: + interfaces[name] = InterfacesDef(node_type, interface_name, name=name, + value=elems, node_template=node) if node_type.parent_type is not None: node_type = node_type.parent_type diff --git a/test/unit/Tosca.py b/test/unit/Tosca.py index 028c30d2a..950a78e06 100755 --- a/test/unit/Tosca.py +++ b/test/unit/Tosca.py @@ -50,6 +50,7 @@ def test_tosca_to_radl(self): tosca = Tosca(tosca_data) _, radl = tosca.to_radl() print(radl) + self.assertFalse(True) radl = parse_radl(str(radl)) net = radl.get_network_by_id('public_net') net1 = radl.get_network_by_id('public_net_1') From ae699efb3cce91beced94e7a3e2d77a9cc82e608 Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 21 Oct 2021 11:40:36 +0200 Subject: [PATCH 2/4] Fix TOSCA Configure interface --- test/unit/Tosca.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/unit/Tosca.py b/test/unit/Tosca.py index 950a78e06..0945bb64c 100755 --- a/test/unit/Tosca.py +++ b/test/unit/Tosca.py @@ -49,8 +49,6 @@ def test_tosca_to_radl(self): tosca_data = read_file_as_string('../files/tosca_long.yml') tosca = Tosca(tosca_data) _, radl = tosca.to_radl() - print(radl) - self.assertFalse(True) radl = parse_radl(str(radl)) net = radl.get_network_by_id('public_net') net1 = radl.get_network_by_id('public_net_1') From 2131e757e63c5b8b13cf5443b2c9de03e2993052 Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 21 Oct 2021 13:09:47 +0200 Subject: [PATCH 3/4] Fix TOSCA Configure interface --- test/files/tosca_long.yml | 11 +---------- test/unit/Tosca.py | 2 ++ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/test/files/tosca_long.yml b/test/files/tosca_long.yml index 1193ba375..77f9af03f 100644 --- a/test/files/tosca_long.yml +++ b/test/files/tosca_long.yml @@ -101,18 +101,9 @@ topology_template: - local_storage: node: my_onedata_storage relationship: - type: AttachesTo + type: tosca.relationships.indigo.OneDataStorage.AttachesTo properties: location: /mnt/disk - interfaces: - Configure: - pre_configure_source: - implementation: - file: https://raw.githubusercontent.com/indigo-dc/tosca-types/master/artifacts/onedata/oneclient_install.yml - type: tosca.artifacts.Implementation.YAML - inputs: - onedata_token: { get_property: [ TARGET, credential, token ] } - onedata_location: { get_property: [ SELF, location ] } my_onedata_storage: type: tosca.nodes.indigo.OneDataStorage diff --git a/test/unit/Tosca.py b/test/unit/Tosca.py index 0945bb64c..32e5b9a28 100755 --- a/test/unit/Tosca.py +++ b/test/unit/Tosca.py @@ -93,6 +93,8 @@ def test_tosca_to_radl(self): "{{ groups['lrms_wn']|map('extract', hostvars,'IM_NODE_PRIVATE_IP')|list" " if 'lrms_wn' in groups else []}}") self.assertEqual([d.id for d in radl.deploys][2], 'lrms_wn') + att_conf = radl.get_configure_by_name('lrms_server_tosca.relationships.indigo.onedatastorage.attachesto_conf') + conf = yaml.safe_load(att_conf.recipes)[0] def test_tosca_get_outputs(self): """Test TOSCA get_outputs function""" From cadb0ac6eac029586dac33e1cc161bddc15e27f4 Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 21 Oct 2021 13:26:42 +0200 Subject: [PATCH 4/4] Fix style --- IM/tosca/Tosca.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IM/tosca/Tosca.py b/IM/tosca/Tosca.py index ec007b0ae..28fe73195 100644 --- a/IM/tosca/Tosca.py +++ b/IM/tosca/Tosca.py @@ -1620,7 +1620,7 @@ def _get_root_parent_type(node): return node_type @staticmethod - def _get_interfaces(node, interface_names=['Standard','Configure'], + def _get_interfaces(node, interface_names=['Standard', 'Configure'], steps=['create', 'configure', 'start', 'stop', 'delete']): """ Get a dict of InterfacesDef of the specified node @@ -1638,7 +1638,7 @@ def _get_interfaces(node, interface_names=['Standard','Configure'], if name in steps: if name not in interfaces: interfaces[name] = InterfacesDef(node_type, interface_name, name=name, - value=elems, node_template=node) + value=elems, node_template=node) if node_type.parent_type is not None: node_type = node_type.parent_type