Example #1
0
    def test_constraint_for_scalar_unit(self):
        tpl_snippet = '''
        server:
          type: tosca.my.nodes.Compute
          properties:
            disk_size: 500 MB
            mem_size: 1 MB
        '''
        nodetemplates = yamlparser.simple_parse(tpl_snippet)
        nodetemplate = NodeTemplate('server', nodetemplates, self.custom_def)
        props = nodetemplate.get_properties()
        if 'disk_size' in props.keys():
            error = self.assertRaises(exception.ValidationError,
                                      props['disk_size'].validate)
            self.assertEqual(
                'disk_size: 500 MB must be greater or '
                'equal to "1 GB".', error.__str__())

        if 'mem_size' in props.keys():
            error = self.assertRaises(exception.ValidationError,
                                      props['mem_size'].validate)
            self.assertEqual(
                'mem_size: 1 MB is out of range '
                '(min:1 MiB, '
                'max:1 GiB).', error.__str__())
    def test_constraint_for_scalar_unit(self):
        tpl_snippet = '''
        server:
          type: tosca.my.nodes.Compute
          properties:
            cpu_frequency: 0.05 GHz
            disk_size: 500 MB
            mem_size: 1 MB
        '''
        nodetemplates = yamlparser.simple_parse(tpl_snippet)
        nodetemplate = NodeTemplate('server', nodetemplates, self.custom_def)
        props = nodetemplate.get_properties()
        if 'cpu_frequency' in props.keys():
            error = self.assertRaises(exception.ValidationError,
                                      props['cpu_frequency'].validate)
            self.assertEqual('cpu_frequency: 0.05 GHz must be greater or '
                             'equal to "0.1 GHz".', error.__str__())
        if 'disk_size' in props.keys():
            error = self.assertRaises(exception.ValidationError,
                                      props['disk_size'].validate)
            self.assertEqual('disk_size: 500 MB must be greater or '
                             'equal to "1 GB".', error.__str__())

        if 'mem_size' in props.keys():
            error = self.assertRaises(exception.ValidationError,
                                      props['mem_size'].validate)
            self.assertEqual('mem_size: 1 MB is out of range '
                             '(min:1 MiB, '
                             'max:1 GiB).', error.__str__())
Example #3
0
 def _nodetemplates(self):
     '''node templates objects. '''
     nodetemplates = []
     tpls = self._tpl_nodetemplates()
     for name, value in tpls.iteritems():
         tpl = NodeTemplate(name, tpls)
         tpl.validate()
         nodetemplates.append(tpl)
     return nodetemplates
Example #4
0
 def _nodetemplates(self):
     '''node templates objects. '''
     nodetemplates = []
     tpls = self._tpl_nodetemplates()
     for name, value in tpls.iteritems():
         tpl = NodeTemplate(name, tpls)
         tpl.validate()
         nodetemplates.append(tpl)
     return nodetemplates
Example #5
0
 def test_scenario_scalar_unit_positive(self):
     tpl = self.tpl_snippet
     nodetemplates = yamlparser.simple_parse(tpl)
     nodetemplate = NodeTemplate('server', nodetemplates)
     props = nodetemplate.get_properties()
     if props and 'mem_size' in props.keys():
         prop = props['mem_size']
         self.assertIsNone(prop.validate())
         resolved = prop.value
     self.assertEqual(resolved, self.expected)
Example #6
0
 def test_scenario_scalar_unit_positive(self):
     tpl = self.tpl_snippet
     nodetemplates = yamlparser.simple_parse(tpl)
     nodetemplate = NodeTemplate('server', nodetemplates)
     props = nodetemplate.get_capability('host').get_properties()
     if props and 'mem_size' in props.keys():
         prop = props['mem_size']
         self.assertIsNone(prop.validate())
         resolved = prop.value
     self.assertEqual(resolved, self.expected)
 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
Example #8
0
 def test_invalid_scalar_unit(self):
     tpl_snippet = '''
     server:
       type: tosca.my.nodes.Compute
       properties:
         disk_size: MB
         mem_size: 1 QB
     '''
     nodetemplates = yamlparser.simple_parse(tpl_snippet)
     nodetemplate = NodeTemplate('server', nodetemplates, self.custom_def)
     for p in nodetemplate.get_properties_objects():
         self.assertRaises(ValueError, p.validate)
Example #9
0
 def test_invalid_scalar_unit(self):
     tpl_snippet = '''
     server:
       type: tosca.my.nodes.Compute
       properties:
         disk_size: MB
         mem_size: 1 QB
     '''
     nodetemplates = yamlparser.simple_parse(tpl_snippet)
     nodetemplate = NodeTemplate('server', nodetemplates, self.custom_def)
     for p in nodetemplate.get_properties_objects():
         self.assertRaises(ValueError, p.validate)
Example #10
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 = (translator.toscalib.utils.yamlparser.
                         simple_parse(tpl_snippet))['node_templates']
        custom_def = (translator.toscalib.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 = (translator.toscalib.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))
Example #11
0
 def _nodetemplates(self):
     custom_defs = {}
     node_types = self._get_custom_types(NODE_TYPES)
     if node_types:
         custom_defs.update(node_types)
     data_types = self._get_custom_types(DATATYPE_DEFINITIONS)
     if data_types:
         custom_defs.update(data_types)
     capability_types = self._get_custom_types(CAPABILITY_TYPES)
     if capability_types:
         custom_defs.update(capability_types)
     nodetemplates = []
     tpls = self._tpl_nodetemplates()
     for name in tpls:
         tpl = NodeTemplate(name, tpls, custom_defs,
                            self.relationship_templates)
         tpl.validate(self)
         nodetemplates.append(tpl)
     return nodetemplates
 def _nodetemplates(self):
     custom_defs = {}
     node_types = self._get_custom_types(NODE_TYPES)
     if node_types:
         custom_defs.update(node_types)
     data_types = self._get_custom_types(DATATYPE_DEFINITIONS)
     if data_types:
         custom_defs.update(data_types)
     capability_types = self._get_custom_types(CAPABILITY_TYPES)
     if capability_types:
         custom_defs.update(capability_types)
     nodetemplates = []
     tpls = self._tpl_nodetemplates()
     for name in tpls:
         tpl = NodeTemplate(name, tpls, custom_defs,
                            self.relationship_templates)
         tpl.validate(self)
         nodetemplates.append(tpl)
     return nodetemplates
Example #13
0
    def _single_node_template_content_test(self, tpl_snippet, expectederror,
                                           expectedmessage):
        nodetemplates = (translator.toscalib.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__())
Example #14
0
 def _tosca_compute_test(self, tpl_snippet, expectedprops):
     nodetemplates = (translator.toscalib.utils.yamlparser.simple_parse(
         tpl_snippet)['node_templates'])
     name = list(nodetemplates.keys())[0]
     try:
         nodetemplate = NodeTemplate(name, nodetemplates)
         toscacompute = ToscaCompute(nodetemplate)
         toscacompute.handle_properties()
         if not self._compare_properties(toscacompute.properties,
                                         expectedprops):
             raise Exception(
                 _("Hot Properties are not"
                   " same as expected properties"))
     except Exception:
         # for time being rethrowing. Will be handled future based
         # on new development in Glance and Graffiti
         raise
Example #15
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 = (translator.toscalib.utils.yamlparser.simple_parse(
            tpl_snippet))['node_templates']
        custom_def = (
            translator.toscalib.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 = (
            translator.toscalib.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 = (translator.toscalib.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__())
Example #17
0
 def _requirements_not_implemented(self, tpl_snippet, tpl_name):
     nodetemplates = (translator.toscalib.utils.yamlparser.simple_parse(
         tpl_snippet))['node_templates']
     self.assertRaises(
         NotImplementedError,
         lambda: NodeTemplate(tpl_name, nodetemplates).relationships)