def process_results(self, target):
        if not self.command:
            raise ValidationError('DockerTool: No command given.')
        if not self.test_results:
            raise ValidationError('DockerTool: No {} "{}" found.'.format(
                self.command, target.entity))

        method_name = '_process_{}'.format(self.command)
        m = getattr(self, method_name, None)
        if not m:
            raise ValidationError(
                'There is no method {} in DockerTool.'.format(method_name))
        res = m(entity=target.entity)

        actual = res[0] if isinstance(res, list) else res

        set_breakpoint()

        if not get_truth(actual, all_matchers[target.matcher], target.value):
            raise ValidationError(
                'Expected: {} {} {} "{}", \nActual: {}'.format(
                    '"{}":'.format(target.entity) if target.entity else '',
                    target.property if target.property else target.entity,
                    target.matcher, target.value if target.value else '',
                    actual))
 def run(self, target):
     self.target = target
     if not self.command:
         raise ValidationError('DockerTool: run(): No command given.')
     command = getattr(self, self.command, None)
     if callable(command):
         command()
     else:
         raise ValidationError(
             'DockerTool: run(): Cannot find command "{}" in DockerTool.'.
             format(self.command))
    def validate(self):
        self.property = self.entity if not self.property else self.property

        try:
            self._find_robot_instance()
            self._check_test_data()
            call_validator(self.instance.sut.target_type, validators.Context, self.allowed_contexts)

            call_validator(self.matcher, validators.InList, Address.properties.get('entity', {}).get('matchers', []))
            call_validator(self.value, validators.InList, Address.properties.get('entity', {}).get('values', []))

            # split address in case a port is given
            split_entity = self.entity.split(':')
            if len(split_entity) > 2:
                raise ValidationError('Value "{}" is invalid.'.format(self.entity))
            self.address = split_entity[0]
            self.port = split_entity[1] if len(split_entity) == 2 else '80'

            # valid in addition to domain names are: all container names, service names with and without stack name
            override = [c.attrs['Config']['Hostname'] for c in self.instance.containers]
            override.extend([s.name for s in self.instance.services])
            override.extend([s.name.split('{}_'.format(self.instance.deployment_name))[1:][0]
                             for s in self.instance.services])
            call_validator(entity=self.address, validator=validators.Domain, override=override)
            call_validator(self.port, validators.Port)
        except (SetupError, ValidationError) as exc:
            raise exc
Exemple #4
0
    def _check_test_data(self):
        """
        Check that all required parameters were supplied for a test case

        Returns:

        """
        missing = [key for key, value in self.get_as_dict().iteritems() if not value]
        if missing:
            raise ValidationError('Checking test data: No value supplied for {}'.format(missing))
Exemple #5
0
def validate(f, value, types, enum=None):
    """Validation decorator types for hybrid_properties

    """
    if enum:
        if value not in enum and value is not None:
            raise ValidationError(
                ("Value '{}' not in allowed value list for {} for property {}."
                 ).format(value, enum, f.__name__))
    if not types:
        return
    _types = types + (type(None), )
    # If type is str, accept unicode as well, it will be sanitized
    if str in _types:
        _types = _types + (unicode, )
    if not isinstance(value, _types):
        raise ValidationError(
            ("Value '{}' is of type {} and is not one of the allowed types "
             "for property {}: {}.").format(value, type(value), f.__name__,
                                            _types))
def set_context(instance, context_type=None, context=None):
    if instance.fatal_error:
        raise ValidationError(
            'set_context: Fatal error has occured during suite setup.')

    context_types = ['application', 'service', 'node', 'network']

    if context_type not in context_types:
        raise SetupError(
            'Invalid context given. Must be {}'.format(context_types))

    instance.update_sut(target_type=context_type,
                        target=context,
                        service_id='{}_{}'.format(instance.deployment_name,
                                                  context))
Exemple #7
0
    def run_test(self):
        """
        Entry point for a test run. The step methods are called here.

        Returns:
            None

        """
        if self.instance.fatal_error:
            raise ValidationError('We do not start validation as a fatal error occured during test setup.')

        if not self.instance.sut.target_type:
            raise ValidationError('No context given. Context must be set with "Set <context_type> context to <target>.')

        # set a flag to indicate that we at least tried to execute a test
        self.instance.validation_attempted = True

        # override sidecar decision for network context
        if 'network' == self.instance.sut.target_type:
            self.options['sidecar_required'] = True
            self.options['test_volume_required'] = True

        test_volume_required = self.options.get('test_volume_required', False)
        sidecar_required = self.options.get('sidecar_required', False)

        try:
            self.validate()
            self._prepare_transform()
            self.transform()
        except (ValidationError, NotFoundError, DeploymentError) as exc:
            self._cleanup()
            raise exc

        try:
            self.instance.orchestrator.get_or_create_deployment()
        except (ValidationError, NotFoundError, DeploymentError) as exc:
            self._cleanup()
            raise exc

        try:
            if test_volume_required:
                self._create_test_volume()
            if sidecar_required:
                sidecar_command = self.options.get('sidecar_command', None)
                self._create_sidecar(command=sidecar_command)
            if not sidecar_required and test_volume_required:
                self._connect_volume_to_sut()
            tool_instance = self.options.get('test_tool', None)(
                controller=self.instance.orchestrator.controller,
                sut=self.instance.sut
            )
            self._prepare_run(tool_instance)
            tool_instance.command = self.options.get('command', None) or tool_instance.command
        except (ValidationError, NotFoundError, DeploymentError) as exc:
            self._cleanup()
            raise exc

        try:
            # set_breakpoint()
            tool_instance.run(self)
        except (ValidationError, NotFoundError, DeploymentError) as exc:
            raise exc
        finally:
            self._cleanup()

        try:
            self.evaluate_results(tool_instance)
        except ValidationError as exc:
            raise exc