Beispiel #1
0
    def main(self):
        schema = self._client.get_schema(path=self._path)
        if schema['data']['kind'] != 'action':
            raise ModuleFailException('{0} is not an action'.format(self._path))

        input_schema = [c for c in schema['data']['children']
                        if c.get('is_action_input', False)]

        for key, value in self._input.items():
            child = next((c for c in input_schema if c['name'] == key), None)
            if child is None:
                raise ModuleFailException('no parameter {0}'.format(key))

            # implement type validation in the future

        if self._check_mode:
            return {}
        else:
            return self._run_and_verify()
Beispiel #2
0
    def main(self):
        violations = []

        # build list of values from configured data
        value_builder = ValueBuilder(self._client, 'verify')
        for key, value in self._data.items():
            value_builder.build('', key, value)

        for expected_value in value_builder.values:
            if expected_value.state == State.PRESENT:
                violations.append({
                    'path': expected_value.path,
                    'expected-value': 'present',
                    'value': 'absent'
                })
            elif expected_value.state == State.ABSENT:
                violations.append({
                    'path': expected_value.path,
                    'expected-value': 'absent',
                    'value': 'present'
                })
            elif expected_value.state == State.SET:
                try:
                    value = self._client.get_value(
                        expected_value.path)['value']
                except NsoException as ex:
                    if ex.error.get('type', '') == 'data.not_found':
                        value = None
                    else:
                        raise

                # handle different types properly
                n_value = normalize_value(expected_value.value, value,
                                          expected_value.path)
                if n_value != expected_value.value:
                    # if the value comparision fails, try mapping identityref
                    value_type = value_builder.get_type(expected_value.path)
                    if value_type is not None and 'identityref' in value_type:
                        n_value, t_value = self.get_prefix_name(value)

                    if expected_value.value != n_value:
                        violations.append({
                            'path': expected_value.path,
                            'expected-value': expected_value.value,
                            'value': n_value
                        })
            else:
                raise ModuleFailException(
                    'value state {0} not supported at {1}'.format(
                        expected_value.state, expected_value.path))

        return violations
Beispiel #3
0
    def _run_and_verify(self):
        output = self._client.run_action(None, self._path, self._input)
        for key, value in self._output_required.items():
            if key not in output:
                raise ModuleFailException('{0} not in result'.format(key))

            n_value = normalize_value(value, output[key], key)
            if value != n_value:
                msg = '{0} value mismatch. expected {1} got {2}'.format(
                    key, value, n_value)
                raise ModuleFailException(msg)

        for key in self._output_invalid.keys():
            if key in output:
                raise ModuleFailException('{0} not allowed in result'.format(key))

        if self._validate_strict:
            for name in output.keys():
                if name not in self._output_required:
                    raise ModuleFailException('{0} not allowed in result'.format(name))

        return output