示例#1
0
    def post(self):
        self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'

        headers = "\n".join([key + ': ' + value for key, value in self.request.headers.items()])

        # Do as best as we can to remove the password
        request_body_without_password = re.sub(r'"password"\s*:\s*".+?",', '', self.request.body)
        log = ReportLog(timestamp=datetime.now(), headers=headers, payload=request_body_without_password)
        log.put()

        try:
            self._body = json.loads(self.request.body)
        except ValueError:
            return self._output('Failed to parse the payload as a json. Report key: %d' % log.key().id())

        builder = self._modelByKeyNameInBodyOrError(Builder, 'builder-name')
        branch = self._modelByKeyNameInBodyOrError(Branch, 'branch')
        platform = self._modelByKeyNameInBodyOrError(Platform, 'platform')
        buildNumber = self._integerInBody('build-number')
        revision = self._integerInBody('revision')
        timestamp = self._timestampInBody()

        failed = False
        if builder and not (self.bypassAuthentication() or builder.authenticate(self._body.get('password', ''))):
            self._output('Authentication failed')
            failed = True

        if not self._resultsAreValid():
            self._output("The payload doesn't contain results or results are malformed")
            failed = True

        if not (builder and branch and platform and buildNumber and revision and timestamp) or failed:
            return

        build = self._createBuildIfPossible(builder, buildNumber, branch, platform, revision, timestamp)
        if not build:
            return

        for testName, result in self._body['results'].iteritems():
            test = self._addTestIfNeeded(testName, branch, platform)
            memcache.delete(Test.cacheKey(test.id, branch.id, platform.id))
            if isinstance(result, dict):
                TestResult(name=testName, build=build, value=float(result.get('avg', 0)), valueMedian=float(result.get('median', 0)),
                    valueStdev=float(result.get('stdev', 0)), valueMin=float(result.get('min', 0)), valueMax=float(result.get('max', 0))).put()
            else:
                TestResult(name=testName, build=build, value=float(result)).put()

        log = ReportLog.get(log.key())
        log.delete()

        # We need to update dashboard and manifest because they are affected by the existance of test results
        memcache.delete('dashboard')
        memcache.delete('manifest')

        return self._output('OK')
示例#2
0
    def post(self):
        self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'

        headers = "\n".join([key + ': ' + value for key, value in self.request.headers.items()])

        # Do as best as we can to remove the password
        request_body_without_password = re.sub(r'"password"\s*:\s*".+?",', '', self.request.body)
        log = ReportLog(timestamp=datetime.now(), headers=headers, payload=request_body_without_password)
        log.put()

        try:
            self._body = json.loads(self.request.body)
        except ValueError:
            return self._output('Failed to parse the payload as a json. Report key: %d' % log.key().id())

        builder = self._model_by_key_name_in_body_or_error(Builder, 'builder-name')
        branch = self._model_by_key_name_in_body_or_error(Branch, 'branch')
        platform = self._model_by_key_name_in_body_or_error(Platform, 'platform')
        build_number = self._integer_in_body('build-number')
        timestamp = self._timestamp_in_body()
        revision = self._integer_in_body('webkit-revision')
        chromium_revision = self._integer_in_body('webkit-revision') if 'chromium-revision' in self._body else None

        failed = False
        if builder and not (self.bypass_authentication() or builder.authenticate(self._body.get('password', ''))):
            self._output('Authentication failed')
            failed = True

        if not self._results_are_valid():
            self._output("The payload doesn't contain results or results are malformed")
            failed = True

        if not (builder and branch and platform and build_number and revision and timestamp) or failed:
            return

        build = self._create_build_if_possible(builder, build_number, branch, platform, timestamp, revision, chromium_revision)
        if not build:
            return

        def _float_or_none(dictionary, key):
            value = dictionary.get(key)
            if value:
                return float(value)
            return None

        for test_name, result in self._body['results'].iteritems():
            test = self._add_test_if_needed(test_name, branch, platform)
            memcache.delete(Test.cache_key(test.id, branch.id, platform.id))
            if isinstance(result, dict):
                TestResult(name=test_name, build=build, value=float(result['avg']), valueMedian=_float_or_none(result, 'median'),
                    valueStdev=_float_or_none(result, 'stdev'), valueMin=_float_or_none(result, 'min'), valueMax=_float_or_none(result, 'max')).put()
            else:
                TestResult(name=test_name, build=build, value=float(result)).put()

        log = ReportLog.get(log.key())
        log.delete()

        # We need to update dashboard and manifest because they are affected by the existance of test results
        memcache.delete('dashboard')
        memcache.delete('manifest')

        return self._output('OK')