Пример #1
0
def _parse_command(command, result, reset):
    """
    method to parse reset command.
    for example: http://server/reset_job?testcase={result.testcase.name}&result_id={result.id}
    will be parsed according under current result context.
    """
    try:
        assert isinstance(result, TestResult)
        run_variables = result.test_run.run_variables.data_json if result.test_run.run_variables else {}
        cmd = command.format(result=result, reset=reset, **run_variables)
        return cmd, None
    except Exception as e:
        logger.exception('Failed to parse command: {}'.format(command))

        message = 'while parsing command "{}" due to {}: {}'.format(
            command, type(e).__name__, e.args)
        return command, message
Пример #2
0
    def handler(self, request, pk=None):
        """handle task with required info."""

        if request.method == 'GET':
            return self.retrieve(self, request, pk=pk)

        instance = self.get_object()

        try:

            if request.method == 'POST':
                status = request.POST.get('status', 'Error')
                message = request.POST.get('message', '')

                instance.status = 0 if status == 'Sent' else 1
                instance.data = append_json(instance.data, 'message', message)
                instance.save()

                return Response(data={'status': status, 'message': message})

        except Exception as e:
            logger.exception('Failed to handle task: {}'.format(pk))
            return Response(data=str(e.args), status=400)
Пример #3
0
    def handler(self, request, pk=None):
        """
        Handle single reset result.
        1. update current reset result with provided info.
        2. create error object if required.
        3. update original result with latest outcome.
        4. update original run to passed if all result passed
        """

        if request.method == 'GET':
            return self.retrieve(self, request, pk=pk)

        current_reset = self.get_object()
        assert isinstance(current_reset, ResetResult)
        required_fields = ['outcome', 'duration', 'run_on', 'test_client', 'stdout']
        optional_field = ['exception_type', 'message', 'stacktrace', 'stdout', 'stderr']

        try:
            for f in required_fields:
                value = self.request.POST.get(f)

                if f == 'stdout' and not value:
                    value = None

                if value is None:
                    raise ValueError('Field "{}" is required!'.format(f))

                if f == 'duration':
                    current_reset.duration = timedelta(seconds=float(value))

                elif f == 'test_client':
                    current_reset.test_client = TestClient.objects.get(id=int(value))

                else:
                    setattr(current_reset, f, value)

            has_error = self.request.POST.get(optional_field[0], None)

            if has_error:
                error = ResultError() if not current_reset.error else current_reset.error

                for f in optional_field:
                    value = self.request.POST.get(f, None)
                    setattr(error, f, value)

                error.save()
                current_reset.error = error

            # update original result outcome to current reset outcome
            current_reset.reset_status = 2  # done
            current_reset.save()
            current_reset.origin_result.outcome = current_reset.outcome
            current_reset.origin_result.save()

            # update original run status to passed if all passed
            run = current_reset.origin_result.test_run
            if run.result_total() == run.result_passed():
                run.status = 0  # passed
                run.save()

            return Response(data={'message': 'Result has been saved.'})

        except Exception as e:
            logger.exception('Failed to handle reset result: {}'.format(pk))
            current_reset.reset_status = 3  # failed
            current_reset.save()
            return Response(data={'message': str(e.args)}, status=400)