Пример #1
0
 def _nodetemplates(self):
     nodetemplates = []
     tpls = self._tpl_nodetemplates()
     for name in tpls:
         tpl = NodeTemplate(name, tpls, self.custom_defs,
                            self.relationship_templates,
                            self.rel_types)
         tpl.validate(self)
         nodetemplates.append(tpl)
     return nodetemplates
Пример #2
0
    def test_custom_capability_type_definition(self):
        tpl_snippet = '''
        node_templates:
          test_app:
            type: tosca.nodes.WebApplication.TestApp
            capabilities:
              test_cap:
                properties:
                  test: 1
        '''
        # custom definition with capability type definition
        custom_def = '''
        tosca.nodes.WebApplication.TestApp:
          derived_from: tosca.nodes.WebApplication
          capabilities:
            test_cap:
               type: tosca.capabilities.TestCapability
        tosca.capabilities.TestCapability:
          derived_from: tosca.capabilities.Root
          properties:
            test:
              type: integer
              required: no
        '''
        expected_capabilities = ['test_cap']
        nodetemplates = (parser.utils.yamlparser.
                         simple_parse(tpl_snippet))['node_templates']
        custom_def = (parser.utils.yamlparser.
                      simple_parse(custom_def))
        name = list(nodetemplates.keys())[0]
        tpl = NodeTemplate(name, nodetemplates, custom_def)
        self.assertEqual(
            expected_capabilities,
            sorted(tpl.get_capabilities().keys()))

        # custom definition without capability type definition
        custom_def = '''
        tosca.nodes.WebApplication.TestApp:
          derived_from: tosca.nodes.WebApplication
          capabilities:
            test_cap:
               type: tosca.capabilities.TestCapability
        '''
        custom_def = (parser.utils.yamlparser.
                      simple_parse(custom_def))
        tpl = NodeTemplate(name, nodetemplates, custom_def)
        err = self.assertRaises(
            exception.InvalidTypeError,
            lambda: NodeTemplate(name, nodetemplates,
                                 custom_def).get_capabilities_objects())
        self.assertEqual('Type "tosca.capabilities.TestCapability" is not '
                         'a valid type.', six.text_type(err))
    def _single_node_template_content_test(self, tpl_snippet, expectederror,
                                           expectedmessage):
        nodetemplates = (parser.utils.yamlparser.
                         simple_parse(tpl_snippet))['node_templates']
        name = list(nodetemplates.keys())[0]
        try:
            nodetemplate = NodeTemplate(name, nodetemplates,
                                        self._custom_types())
            nodetemplate.validate()
            nodetemplate.requirements
            nodetemplate.get_capabilities_objects()
            nodetemplate.get_properties_objects()
            nodetemplate.interfaces

        except Exception as err:
            self.assertTrue(isinstance(err, expectederror))
            self.assertEqual(expectedmessage, err.__str__())