Beispiel #1
0
    def test_datasets(self):
        """Tests dataset creation for submission to datazilla"""

        req = DatazillaRequest(
            protocol='http',
            host='host',
            project='project',
            oauth_key='key',
            oauth_secret='secret',
            machine_name='qm-pxp01',
            os='linux',
            os_version='Ubuntu 11.10',
            platform='x86_64',
            build_name='Firefox',
            version='14.0a2',
            revision='785345035a3b',
            branch='Mozilla-Aurora',
            id='20120228122102',
        )

        results = {'suite1': {'test1': [1]}, 'suite2': {'test2': [2]}}
        req.add_datazilla_result(DatazillaResult(results))

        datasets = req.datasets()

        self.assertEqual(len(datasets), 2)

        for dataset in datasets:
            self.assertEqual(
                set(dataset.keys()),
                set(['results', 'test_build', 'test_machine', 'testrun']))
            self.assertEqual(
                dataset['test_build'], {
                    'branch': 'Mozilla-Aurora',
                    'id': '20120228122102',
                    'name': 'Firefox',
                    'revision': '785345035a3b',
                    'version': '14.0a2'
                })
            self.assertEqual(
                dataset['test_machine'], {
                    'name': 'qm-pxp01',
                    'os': 'linux',
                    'osversion': 'Ubuntu 11.10',
                    'platform': 'x86_64'
                })
            self.assertEqual(set(dataset['testrun'].keys()),
                             set(['suite', 'date']))
            suite = dataset['testrun']['suite']
            self.assertTrue(suite in results)
            self.assertEqual(dataset['results'], results[suite])
    def test_datasets(self):
        """Tests dataset creation for submission to datazilla"""

        req = DatazillaRequest(
            protocol='http',
            host='host',
            project='project',
            oauth_key='key',
            oauth_secret='secret',
            machine_name='qm-pxp01',
            os='linux',
            os_version='Ubuntu 11.10',
            platform='x86_64',
            build_name='Firefox',
            version='14.0a2',
            revision='785345035a3b',
            branch='Mozilla-Aurora',
            id='20120228122102',
            )

        results = {'suite1': {'test1': [1]}, 'suite2': {'test2': [2]}}
        req.add_datazilla_result(DatazillaResult(results))

        datasets = req.datasets()

        self.assertEqual(len(datasets), 2)

        for dataset in datasets:
            self.assertEqual(set(dataset.keys()), set(['results', 'test_build', 'test_machine', 'testrun']))
            self.assertEqual(dataset['test_build'],
                             {'branch': 'Mozilla-Aurora',
                              'id': '20120228122102',
                              'name': 'Firefox',
                              'revision': '785345035a3b',
                              'version': '14.0a2'})
            self.assertEqual(dataset['test_machine'],
                             {'name': 'qm-pxp01',
                              'os': 'linux',
                              'osversion': 'Ubuntu 11.10',
                              'platform': 'x86_64'})
            self.assertEqual(set(dataset['testrun'].keys()), set(['suite', 'date']))
            suite = dataset['testrun']['suite']
            self.assertTrue(suite in results)
            self.assertEqual(dataset['results'], results[suite])
Beispiel #3
0
    def post_to_datazilla(self, test_result):
        """ take test_results (json) and upload them to datazilla """

        # We will attach wpt_data to the datazilla result as a top
        # level attribute to store out of band data about the test.
        wpt_data = {
            "url": "",
            "firstView": {},
            "repeatView": {}
        }
        wpt_data["label"] = test_result["data"]["label"]
        submit_results = False
        if self.job.datazilla == "on":
            # Do not short circuit the function but collect
            # additional data for use in emailing the user
            # before returning.
            submit_results = True

        self.logger.debug('Submit results to datazilla: %s' % self.job.datazilla)
        wpt_data["connectivity"] = test_result["data"]["connectivity"]
        wpt_data["location"] = test_result["data"]["location"]
        wpt_data["url"] = test_result["data"]["url"]
        runs = test_result["data"]["runs"]

        # runs[0] is a dummy entry
        # runs[1]["firstView"]["SpeedIndex"]
        # runs[1]["repeatView"]["SpeedIndex"]
        # runs[1]["firstView"]["requests"][0]["headers"]["request"][2]
        #    "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0 PTST/125"

        wpt_metric_keys = ['TTFB', 'render', 'docTime', 'fullyLoaded',
                           'SpeedIndex', 'SpeedIndexDT', 'bytesInDoc',
                           'requestsDoc', 'domContentLoadedEventStart',
                           'visualComplete']
        for wpt_key in wpt_metric_keys:
            for view in "firstView", "repeatView":
                wpt_data[view][wpt_key] = []

        if len(runs) == 1:
            raise Exception("post_to_datazilla: no runs")
        os_version = "unknown"
        os_name = "unknown"
        platform = "x86"
        reUserAgent = re.compile('User-Agent: Mozilla/5.0 \(Windows NT ([^;]*);.*')
        for run in runs:
            for wpt_key in wpt_metric_keys:
                for view in "firstView", "repeatView":
                    if not run[view]:
                        continue
                    if wpt_key in run[view]:
                        if run[view][wpt_key]:
                            wpt_data[view][wpt_key].append(run[view][wpt_key])
                    if os_name == "unknown":
                        try:
                            requests = run[view]["requests"]
                            if requests and len(requests) > 0:
                                request = requests[0]
                                if request:
                                    headers = request["headers"]
                                    if headers:
                                        request_headers = headers["request"]
                                        if request_headers:
                                            for request_header in request_headers:
                                                if "User-Agent" in request_header:
                                                    match = re.match(reUserAgent,
                                                                     request_header)
                                                    if match:
                                                        os_name = "WINNT"
                                                        os_version = match.group(1)
                                                        break
                        except KeyError:
                            pass

        machine_name = wpt_data["location"].split(":")[0]
        # limit suite name to 128 characters to match mysql column size
        suite_name = (wpt_data["location"] + "." + wpt_data["connectivity"])[:128]
        # limit {first,repeat}_name, to 255 characters to match mysql column size
        # leave protocol in the url in order to distinguish http vs https.
        first_name = wpt_data["url"][:252] + ":fv"
        repeat_name = wpt_data["url"][:252] + ":rv"

        result = DatazillaResult()
        result.add_testsuite(suite_name)
        result.add_test_results(suite_name, first_name, wpt_data["firstView"]["SpeedIndex"])
        result.add_test_results(suite_name, repeat_name, wpt_data["repeatView"]["SpeedIndex"])
        request = DatazillaRequest("https",
                                   "datazilla.mozilla.org",
                                   "webpagetest",
                                   self.oauth_key,
                                   self.oauth_secret,
                                   machine_name=machine_name,
                                   os=os_name,
                                   os_version=os_version,
                                   platform=platform,
                                   build_name=self.build_name,
                                   version=self.build_version,
                                   revision=self.build_revision,
                                   branch=self.build_branch,
                                   id=self.build_id)
        request.add_datazilla_result(result)
        datasets = request.datasets()
        for dataset in datasets:
            dataset["wpt_data"] = wpt_data
            if not submit_results:
                continue
            response = request.send(dataset)
            # print error responses
            if response.status != 200:
                # use lower-case string because buildbot is sensitive to upper case error
                # as in 'INTERNAL SERVER ERROR'
                # https://bugzilla.mozilla.org/show_bug.cgi?id=799576
                reason = response.reason.lower()
                self.logger.debug("Error posting to %s %s %s: %s %s" % (
                    wpt_data["url"], wpt_data["location"], wpt_data["connectivity"],
                    response.status, reason))
            else:
                res = response.read()
                self.logger.debug("Datazilla response for %s %s %s is: %s" % (
                    wpt_data["url"], wpt_data["location"], wpt_data["connectivity"],
                    res.lower()))
        return datasets