Skip to content

Commit

Permalink
Merge pull request #1227 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer authored Oct 21, 2021
2 parents 0e9140e + cadb0ac commit 865ebb2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
25 changes: 14 additions & 11 deletions IM/tosca/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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:
Expand Down Expand Up @@ -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
"""
Expand All @@ -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
Expand Down
11 changes: 1 addition & 10 deletions test/files/tosca_long.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/unit/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +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)
radl = parse_radl(str(radl))
net = radl.get_network_by_id('public_net')
net1 = radl.get_network_by_id('public_net_1')
Expand Down Expand Up @@ -94,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"""
Expand Down

0 comments on commit 865ebb2

Please sign in to comment.