Beispiel #1
0
    def _handle_nested_tosca_templates_with_topology(self):
        for filename, tosca_tpl in self.nested_tosca_tpls.items():
            topology_tpl = tosca_tpl.get(TOPOLOGY_TEMPLATE)
            if topology_tpl:
                custom_types = self._get_all_custom_defs().copy()
                custom_types.update(tosca_tpl.get(
                    'node_types', {}))  # XXX isn't this redundant?
                self.nested_topologies[filename] = TopologyTemplate(
                    topology_tpl, custom_types)

        # if a nodetemplate should be substituted, set its sub_mapping_tosca_template
        for nodetemplate in self.nodetemplates:
            if "substitute" not in nodetemplate.directives:
                continue
            for topology in self.nested_topologies.values():
                if not topology.substitution_mappings:
                    continue
                if topology.substitution_mappings.type == nodetemplate.type:
                    # the node template's properties treated as inputs
                    inputs = self._get_params_for_nested_template(nodetemplate)
                    # create a new substitution mapping object for the mapped node
                    # XXX SubstitutionMappings is just a simple wrapper around the def dict, only performs validation
                    # and sub_mapping_tosca_template is never unused!
                    nodetemplate.sub_mapping_tosca_template = SubstitutionMappings(
                        topology.substitution_mappings.sub_mapping_def,
                        topology, inputs, topology.outputs, nodetemplate,
                        topology.custom_defs)
                    break
Beispiel #2
0
 def _substitution_mappings(self):
     tpl_substitution_mapping = self._tpl_substitution_mappings()
     # if tpl_substitution_mapping and self.sub_mapped_node_template:
     if tpl_substitution_mapping:
         return SubstitutionMappings(tpl_substitution_mapping,
                                     self.nodetemplates, self.inputs,
                                     self.outputs,
                                     self.sub_mapped_node_template,
                                     self.custom_defs)
 def test_missing_required_keyname(self):
     tpl_snippet = '''
     substitution_mappings:
       capabilities:
         database_endpoint: [ db_app, database_endpoint ]
       requirements:
         receiver1: [ tran_app, receiver1 ]
     '''
     sub_mappings = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)
                     )['substitution_mappings']
     expected_message = _('SubstitutionMappings used in topology_template '
                          'is missing required field "node_type".')
     err = self.assertRaises(
         exception.MissingRequiredFieldError, lambda: SubstitutionMappings(
             sub_mappings, None, None, None, None, None))
     self.assertEqual(expected_message, err.__str__())
 def test_invalid_nodetype(self):
     tpl_snippet = '''
     substitution_mappings:
       node_type: example.DatabaseSubsystem1
       capabilities:
         database_endpoint: [ db_app, database_endpoint ]
       requirements:
         receiver1: [ tran_app, receiver1 ]
     '''
     sub_mappings = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)
                     )['substitution_mappings']
     custom_defs = self._get_custom_types()
     expected_message = _('Node type "example.DatabaseSubsystem1" '
                          'is not a valid type.')
     err = self.assertRaises(
         exception.InvalidNodeTypeError, lambda: SubstitutionMappings(
             sub_mappings, None, None, None, None, custom_defs))
     self.assertEqual(expected_message, err.__str__())
 def test_invalid_keyname(self):
     tpl_snippet = '''
     substitution_mappings:
       node_type: example.DatabaseSubsystem
       capabilities:
         database_endpoint: [ db_app, database_endpoint ]
       requirements:
         receiver1: [ tran_app, receiver1 ]
       invalid_key: 123
     '''
     sub_mappings = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)
                     )['substitution_mappings']
     expected_message = _('SubstitutionMappings contains unknown field '
                          '"invalid_key". Refer to the definition '
                          'to verify valid values.')
     err = self.assertRaises(
         exception.UnknownFieldError, lambda: SubstitutionMappings(
             sub_mappings, None, None, None, None, None))
     self.assertEqual(expected_message, err.__str__())
 def get_sub_mapping_node_type(cls, topology_tpl):
     if topology_tpl and isinstance(topology_tpl, dict):
         submap_tpl = topology_tpl.get(SUBSTITUION_MAPPINGS)
         return SubstitutionMappings.get_node_type(submap_tpl)
 def get_sub_mapping_node_type(cls, topology_tpl):
     if topology_tpl and isinstance(topology_tpl, dict):
         submap_tpl = topology_tpl.get(SUBSTITUION_MAPPINGS)
         return SubstitutionMappings.get_node_type(submap_tpl)