Exemplo n.º 1
0
 def _inputs(self):
     inputs = []
     for name, attrs in self._tpl_inputs().items():
         input = Input(name, attrs)
         if self.parsed_params and name in self.parsed_params:
             input.validate(self.parsed_params[name])
         inputs.append(input)
     return inputs
Exemplo n.º 2
0
 def _inputs(self):
     inputs = []
     for name, attrs in self._tpl_inputs().items():
         input = Input(name, attrs)
         if self.parsed_params and name in self.parsed_params:
             input.validate(self.parsed_params[name])
         inputs.append(input)
     return inputs
Exemplo n.º 3
0
 def test_built_in_nested_datatype_portdef(self):
     tpl_snippet = '''
     inputs:
       db_port:
         type: PortDef
         description: Port for the MySQL database
     '''
     inputs = yamlparser.simple_parse(tpl_snippet)['inputs']
     name, attrs = list(inputs.items())[0]
     input = Input(name, attrs)
     self.assertIsNone(input.validate(3360))
     err = self.assertRaises(exception.ValidationError, input.validate,
                             336000)
     self.assertEqual(
         _('db_port(input): The value "336000" of property "None" is out of '
           'range "(min:1, max:65535)".'), err.__str__())
Exemplo n.º 4
0
 def test_built_in_nested_datatype_portdef(self):
     tpl_snippet = '''
     inputs:
       db_port:
         type: PortDef
         description: Port for the MySQL database
     '''
     inputs = yamlparser.simple_parse(tpl_snippet)['inputs']
     name, attrs = list(inputs.items())[0]
     input = Input(name, attrs)
     self.assertIsNone(input.validate(3360))
     err = self.assertRaises(exception.ValidationError, input.validate,
                             336000)
     self.assertEqual(_('The value "336000" of property "None" is out of '
                        'range "(min:1, max:65535)".'),
                      err.__str__())
Exemplo n.º 5
0
 def test_built_in_nested_datatype_portdef(self):
     tpl_snippet = '''
     inputs:
       db_port:
         type: PortDef
         description: Port for the MySQL database
     '''
     inputs = yamlparser.simple_parse(tpl_snippet)['inputs']
     name, attrs = list(inputs.items())[0]
     input = Input(name, attrs)
     self.assertIsNone(input.validate(3360))
     try:
         input.validate(336000)
     except Exception as err:
         self.assertTrue(isinstance(err, exception.ValidationError))
         self.assertEqual('None: 336000 is out of range (min:1, '
                          'max:65535).', err.__str__())
 def test_inputs(self):
     tpl_snippet = '''
     inputs:
       cpus:
         type: integer
         description: Number of CPUs for the server.
         constraint:
           - valid_values: [ 1, 2, 4, 8 ]
     '''
     inputs = (toscaparser.utils.yamlparser.
               simple_parse(tpl_snippet)['inputs'])
     name, attrs = list(inputs.items())[0]
     input = Input(name, attrs)
     try:
         input.validate()
     except Exception as err:
         self.assertTrue(isinstance(err, exception.UnknownFieldError))
         self.assertEqual('Input cpus contain(s) unknown field: '
                          '"constraint", refer to the definition to '
                          'verify valid values.', err.__str__())
Exemplo n.º 7
0
    def _inputs(self):
        inputs = []
        for name, attrs in self._tpl_inputs().items():
            input = Input(name, attrs)
            if self.parsed_params and name in self.parsed_params:
                input.validate(self.parsed_params[name])
            else:
                default = input.default
                if default:
                    input.validate(default)
            if (self.parsed_params and input.name not in self.parsed_params
                or self.parsed_params is None) and input.required \
                    and input.default is None:
                exception.ExceptionCollector.appendException(
                    exception.MissingRequiredParameterError(
                        what='Template',
                        input_name=input.name))

            inputs.append(input)
        return inputs
    def _inputs(self):
        inputs = []
        for name, attrs in self._tpl_inputs().items():
            log.debug("Input {}: {}".format(name, attrs))
            exception.TOSCAException.set_context("input", name)
            try:
                input = Input(name, attrs, self.custom_defs)
                if self.parsed_params and name in self.parsed_params:
                    input.validate(self.parsed_params[name])
                else:
                    log.debug("Not found in parsed params: {}".format(
                        self.parsed_params))
                    default = input.default
                    if default:
                        input.validate(default)
                if (self.parsed_params and input.name not in self.parsed_params
                    or self.parsed_params is None) and input.required \
                        and input.default is None:
                    log.error(
                        _('The required parameter %s '
                          'is not provided') % input.name)
                    exception.ExceptionCollector.appendException(
                        exception.MissingRequiredParameterError(
                            what='Template', input_name=input.name))

                inputs.append(input)
            except Exception as e:
                log.error(_("Error in parsing input {}: {}").format(name, e))
                if exception.ExceptionCollector.collecting is False:
                    raise e

        exception.TOSCAException.reset_context()
        return inputs
Exemplo n.º 9
0
 def test_inputs(self):
     tpl_snippet = '''
     inputs:
       cpus:
         type: integer
         description: Number of CPUs for the server.
         constraint:
           - valid_values: [ 1, 2, 4, 8 ]
     '''
     inputs = (
         toscaparser.utils.yamlparser.simple_parse(tpl_snippet)['inputs'])
     name, attrs = list(inputs.items())[0]
     input = Input(name, attrs)
     err = self.assertRaises(exception.UnknownFieldError, input.validate)
     self.assertEqual(
         _('Input "cpus" contains unknown field "constraint". '
           'Refer to the definition to verify valid values.'),
         err.__str__())
Exemplo n.º 10
0
    def _translate_input_test(self,
                              tpl_snippet,
                              input_params,
                              expectedmessage=None,
                              expected_hot_params=None):
        inputs_dict = (
            toscaparser.utils.yamlparser.simple_parse(tpl_snippet)['inputs'])
        inputs = []
        for name, attrs in inputs_dict.items():
            input = Input(name, attrs)
            inputs.append(input)

        translateinput = TranslateInputs(inputs, input_params)
        try:
            resulted_hot_params = translateinput.translate()
            if expected_hot_params:
                self._compare_hot_params(resulted_hot_params,
                                         expected_hot_params)
        except Exception as err:
            self.assertEqual(expectedmessage, err.__str__())
Exemplo n.º 11
0
    def _inputs(self):
        inputs = []
        for name, attrs in self._tpl_inputs().items():
            input = Input(name, attrs)
            if self.parsed_params and name in self.parsed_params:
                input.validate(self.parsed_params[name])
            else:
                default = input.default
                if default:
                    input.validate(default)
            if (self.parsed_params and input.name not in self.parsed_params
                or self.parsed_params is None) and input.required \
                    and input.default is None:
                log.warning('The required parameter %s '
                            'is not provided' % input.name)

            inputs.append(input)
        return inputs
Exemplo n.º 12
0
    def _inputs(self):
        inputs = []
        for name, attrs in self._tpl_inputs().items():
            input = Input(name, attrs, self.custom_defs)
            if self.parsed_params and name in self.parsed_params:
                input.validate(self.parsed_params[name])
            else:
                default = input.default
                if default:
                    input.validate(default)
            if (self.parsed_params and input.name not in self.parsed_params
                or self.parsed_params is None) and input.required \
                and input.default is None:
                exception.ExceptionCollector.appendException(
                    exception.MissingRequiredParameterError(
                        what='Template', input_name=input.name))

            inputs.append(input)
        return inputs
Exemplo n.º 13
0
    def _inputs(self):
        inputs = []
        parsed_params = self.parsed_params or {}
        for name, attrs in self._tpl_inputs().items():
            input = Input(name, attrs)
            if name in parsed_params:
                input.validate(parsed_params[name])
            else:
                default = input.default
                if default:
                    input.validate(default)
            if (input.name not in parsed_params and input.required
                                        and input.default is None):
                  exception.ExceptionCollector.appendException(
                    exception.MissingRequiredInputError(
                        what=_('Topology template'),
                        input_name=input.name))

            inputs.append(input)
        return inputs
Exemplo n.º 14
0
    def _translate_inputs(self):
        mano_inputs = []
        if 'key_name' in self.parsed_params and 'key_name' not in self.inputs:
            name = 'key_name'
            type = 'string'
            default = self.parsed_params[name]
            schema_dict = {'type': type, 'default': default}
            input = Input(name, schema_dict)
            self.inputs.append(input)

        self.log.info(_('Translating TOSCA input type to MANO input type.'))
        for input in self.inputs:
            mano_default = None
            mano_input_type = TOSCA_TO_MANO_INPUT_TYPES[input.type]

            if input.name in self.parsed_params:
                mano_default = DataEntity.validate_datatype(
                    input.type, self.parsed_params[input.name])
            elif input.default is not None:
                mano_default = DataEntity.validate_datatype(
                    input.type, input.default)
            else:
                if self.deploy:
                    msg = _("Need to specify a value "
                            "for input {0}.").format(input.name)
                    self.log.error(msg)
                    raise Exception(msg)
            if input.type == "scalar-unit.size":
                # Assumption here is to use this scalar-unit.size for size of
                # cinder volume in heat templates and will be in GB.
                # should add logic to support other types if needed.
                input_value = mano_default
                mano_default = (ScalarUnit_Size(
                    mano_default).get_num_from_scalar_unit('GiB'))
                if mano_default == 0:
                    msg = _('Unit value should be > 0.')
                    self.log.error(msg)
                    raise Exception(msg)
                elif int(mano_default) < mano_default:
                    mano_default = int(mano_default) + 1
                    self.log.warning(
                        _("Cinder unit value should be in"
                          " multiples of GBs. So corrected"
                          " %(input_value)s to %(mano_default)s"
                          " GB.") % {
                              'input_value': input_value,
                              'mano_default': mano_default
                          })
            if input.type == 'version':
                mano_default = TOSCAVersionProperty(mano_default).get_version()

            mano_constraints = []
            if input.constraints:
                for constraint in input.constraints:
                    if mano_default:
                        constraint.validate(mano_default)
                    hc, hvalue = self._translate_constraints(
                        constraint.constraint_key, constraint.constraint_value)
                    mano_constraints.append({hc: hvalue})

            mano_inputs.append(
                ManoParameter(self.log,
                              name=input.name,
                              type=mano_input_type,
                              description=input.description,
                              default=mano_default,
                              constraints=mano_constraints))
        return mano_inputs