def test_normative_type_by_short_name(self): # test template with a short name Compute template = os.path.join( os.path.dirname(os.path.abspath(__file__)), "data/test_tosca_normative_type_by_shortname.yaml") tosca_tpl = ToscaTemplate(template) expected_type = "tosca.nodes.Compute" for tpl in tosca_tpl.nodetemplates: self.assertEqual(tpl.type, expected_type) for tpl in tosca_tpl.nodetemplates: compute_type = NodeType(tpl.type) self.assertEqual( sorted(['tosca.capabilities.Container', 'tosca.capabilities.OperatingSystem', 'tosca.capabilities.network.Bindable', 'tosca.capabilities.Scalable']), sorted([c.type for c in compute_type.get_capabilities_objects()]))
def test_normative_type_by_short_name(self): # test template with a short name Compute template = os.path.join( os.path.dirname(os.path.abspath(__file__)), "data/test_tosca_normative_type_by_shortname.yaml") tosca_tpl = ToscaTemplate(template) expected_type = "tosca.nodes.Compute" for tpl in tosca_tpl.nodetemplates: self.assertEqual(tpl.type, expected_type) for tpl in tosca_tpl.nodetemplates: compute_type = NodeType(tpl.type) self.assertEqual( sorted(['tosca.capabilities.Container', 'tosca.capabilities.Node', 'tosca.capabilities.OperatingSystem', 'tosca.capabilities.network.Bindable', 'tosca.capabilities.Scalable']), sorted([c.type for c in compute_type.get_capabilities_objects()]))
def build_node_type_fact(node_type: NodeType) -> str: prop_defs = "[" \ + ", ".join([build_property_def(prop_def) for prop_def in node_type.get_properties_def_objects()]) \ + "]" def build_capability_def(cap_def: CapabilityTypeDef): return f"capability({cap_def.name}, '{cap_def.type}')" cap_defs = "[" \ + ", ".join([build_capability_def(cap_def) for cap_def in node_type.get_capabilities_objects()]) \ + "]" def build_type_requirement(req_name, req_def): req_cap = req_def.get("capability", "tosca.capabilities.Root") req_node = req_def.get("node", "tosca.nodes.Root") req_rel = req_def.get("relationship", "tosca.relationships.Root") occ = req_def.get("occurrences") if occ is None: req_occ = "occurrences(1, unbounded)" else: req_occ = f"occurrences({occ[0]}, {'unbounded' if occ[1] == 'UNBOUNDED' else occ[1]})" return f"requirement({req_name}, '{req_cap}', '{req_node}', '{req_rel}', {req_occ})" req_l = [] for req in node_type.requirements: # type: ignore req_name = list(req)[0] # Gets the first key of req req_def = req[req_name] req_l.append(build_type_requirement(req_name, req_def)) requirements = "[" + ", ".join(req_l) + "]" return textwrap.dedent(f""" node_type( '{node_type.type}', '{node_type.parent_type.type if node_type.parent_type is not None else 'none'}', {prop_defs}, {cap_defs}, {requirements} )""")