def test_send(self,
                  mock_HTTPConnection, mock_time, mock_generate_nonce):
        """Can send data to the server."""
        mock_time.return_value = 1342229050
        mock_generate_nonce.return_value = "46810593"

        host = "datazilla.mozilla.org"
        project = "project"
        key = "oauth-key"
        secret = "oauth-secret"
        req = DatazillaRequest(host, project, key, secret)

        mock_conn = mock_HTTPConnection.return_value
        mock_request = mock_conn.request
        mock_response = mock_conn.getresponse.return_value

        response = req.send({"some": "data"})

        self.assertEqual(mock_HTTPConnection.call_count, 1)
        self.assertEqual(mock_HTTPConnection.call_args[0][0], host)

        self.assertEqual(mock_response, response)

        self.assertEqual(mock_request.call_count, 1)

        method, path, data, header = mock_request.call_args[0]
        self.assertEqual(method, "POST")
        self.assertEqual(path, "/project/api/load_test")
        self.assertEqual(data, 'oauth_body_hash=2jmj7l5rSw0yVb%2FvlWAYkK%2FYBwk%3D&oauth_nonce=46810593&oauth_timestamp=1342229050&oauth_consumer_key=oauth-key&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_token=&user=project&oauth_signature=mKpovMfgWJqlcVKSdcTCbw4gfaM%3D&data=%257B%2522some%2522%253A%2520%2522data%2522%257D')

        self.assertEqual(
            header['Content-type'],
            'application/x-www-form-urlencoded',
            )
Beispiel #2
0
    def test_add_second_datazilla_result(self):
        """Adding a second DatazillaResult joins their results."""
        req = DatazillaRequest('http',
                               'host',
                               'project',
                               'key',
                               'secret',
                               branch='mozilla-try')
        res1 = DatazillaResult({'suite1': {'test': [1]}})
        res2 = DatazillaResult({'suite2': {'test': [2]}})

        req.add_datazilla_result(res1)
        req.add_datazilla_result(res2)

        self.assertEqual(
            req.results.results,
            {
                'suite1': {
                    'test': [1]
                },
                'suite2': {
                    'test': [2]
                }
            },
        )
    def test_send_without_oauth(self, mock_HTTPConnection):
        """Can send data to the server without oauth"""

        protocol = 'http'
        host = "datazilla.mozilla.org"
        project = "project"
        key = None
        secret = None
        req = DatazillaRequest(protocol, host, project, key, secret, branch='mozilla-try')

        mock_conn = mock_HTTPConnection.return_value
        mock_request = mock_conn.request
        mock_response = mock_conn.getresponse.return_value

        response = req.send({"some": "data"})

        self.assertEqual(mock_HTTPConnection.call_count, 1)
        self.assertEqual(mock_HTTPConnection.call_args[0][0], host)

        self.assertEqual(mock_response, response)

        self.assertEqual(mock_request.call_count, 1)

        method, path, data, header = mock_request.call_args[0]
        self.assertEqual(method, "POST")
        self.assertEqual(path, "/project/api/load_test")
        self.assertEqual(data, 'data=%257B%2522some%2522%253A%2520%2522data%2522%257D')

        self.assertEqual(
            header['Content-type'],
            'application/x-www-form-urlencoded',
            )
    def test_add_datazilla_result(self):
        """Can add a DatazillaResult to a DatazillaRequest."""
        req = DatazillaRequest('host', 'project', 'key', 'secret')
        res = DatazillaResult({'suite': {'test': [1, 2, 3]}})

        req.add_datazilla_result(res)

        self.assertEqual(req.results.results, res.results)
    def test_add_second_datazilla_result(self):
        """Adding a second DatazillaResult joins their results."""
        req = DatazillaRequest('host', 'project', 'key', 'secret')
        res1 = DatazillaResult({'suite1': {'test': [1]}})
        res2 = DatazillaResult({'suite2': {'test': [2]}})

        req.add_datazilla_result(res1)
        req.add_datazilla_result(res2)

        self.assertEqual(
            req.results.results,
            {'suite1': {'test': [1]}, 'suite2': {'test': [2]}},
            )
Beispiel #6
0
    def test_add_datazilla_result(self):
        """Can add a DatazillaResult to a DatazillaRequest."""
        req = DatazillaRequest('http',
                               'host',
                               'project',
                               'key',
                               'secret',
                               branch='mozilla-try')
        res = DatazillaResult({'suite': {'test': [1, 2, 3]}})

        req.add_datazilla_result(res)

        self.assertEqual(req.results.results, res.results)
Beispiel #7
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 #9
0
    def test_send(self, mock_HTTPConnection, mock_time, mock_generate_nonce):
        """Can send data to the server."""
        mock_time.return_value = 1342229050
        mock_generate_nonce.return_value = "46810593"

        protocol = 'http'
        host = "datazilla.mozilla.org"
        project = "project"
        key = "oauth-key"
        secret = "oauth-secret"
        req = DatazillaRequest(protocol,
                               host,
                               project,
                               key,
                               secret,
                               branch='mozilla-try')

        mock_conn = mock_HTTPConnection.return_value
        mock_request = mock_conn.request
        mock_response = mock_conn.getresponse.return_value

        response = req.send({"some": "data"})

        self.assertEqual(mock_HTTPConnection.call_count, 1)
        self.assertEqual(mock_HTTPConnection.call_args[0][0], host)

        self.assertEqual(mock_response, response)

        self.assertEqual(mock_request.call_count, 1)

        method, path, data, header = mock_request.call_args[0]
        self.assertEqual(method, "POST")
        self.assertEqual(path, "/project/api/load_test")
        self.assertEqual(
            data,
            'oauth_body_hash=2jmj7l5rSw0yVb%2FvlWAYkK%2FYBwk%3D&oauth_nonce=46810593&oauth_timestamp=1342229050&oauth_consumer_key=oauth-key&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_token=&user=project&oauth_signature=mKpovMfgWJqlcVKSdcTCbw4gfaM%3D&data=%257B%2522some%2522%253A%2520%2522data%2522%257D'
        )

        self.assertEqual(
            header['Content-type'],
            'application/x-www-form-urlencoded',
        )
Beispiel #10
0
    def test_init_with_date(self):
        """Can provide test date on instantiation."""
        req = DatazillaRequest('http',
                               'host',
                               'project',
                               'key',
                               'secret',
                               test_date=12345,
                               branch='mozilla-try')

        self.assertEqual(req.test_date, 12345)
 def test_create_from_results_collection(self):
     collection = DatazillaResultsCollection(machine_name='localhost',
                                             os='linux')
     test_date = collection.test_date
     req = DatazillaRequest.create('host', 'project', 'key', 'secret', collection)
     self.assertEqual(req.machine_name, 'localhost')
     self.assertEqual(req.os, 'linux')
     self.assertEqual(req.test_date, test_date)
     self.assertEqual(req.host, 'host')
     self.assertEqual(req.project, 'project')
     self.assertEqual(req.oauth_key, 'key')
     self.assertEqual(req.oauth_secret, 'secret')
Beispiel #12
0
    def test_send_without_oauth(self, mock_HTTPConnection):
        """Can send data to the server without oauth"""

        protocol = 'http'
        host = "datazilla.mozilla.org"
        project = "project"
        key = None
        secret = None
        req = DatazillaRequest(protocol,
                               host,
                               project,
                               key,
                               secret,
                               branch='mozilla-try')

        mock_conn = mock_HTTPConnection.return_value
        mock_request = mock_conn.request
        mock_response = mock_conn.getresponse.return_value

        response = req.send({"some": "data"})

        self.assertEqual(mock_HTTPConnection.call_count, 1)
        self.assertEqual(mock_HTTPConnection.call_args[0][0], host)

        self.assertEqual(mock_response, response)

        self.assertEqual(mock_request.call_count, 1)

        method, path, data, header = mock_request.call_args[0]
        self.assertEqual(method, "POST")
        self.assertEqual(path, "/project/api/load_test")
        self.assertEqual(
            data, 'data=%257B%2522some%2522%253A%2520%2522data%2522%257D')

        self.assertEqual(
            header['Content-type'],
            'application/x-www-form-urlencoded',
        )
Beispiel #13
0
 def test_create_from_results_collection(self):
     collection = DatazillaResultsCollection(machine_name='localhost',
                                             os='linux',
                                             branch='mozilla-try')
     test_date = collection.test_date
     req = DatazillaRequest.create('http', 'host', 'project', 'key',
                                   'secret', collection)
     self.assertEqual(req.machine_name, 'localhost')
     self.assertEqual(req.os, 'linux')
     self.assertEqual(req.test_date, test_date)
     self.assertEqual(req.host, 'host')
     self.assertEqual(req.project, 'project')
     self.assertEqual(req.oauth_key, 'key')
     self.assertEqual(req.oauth_secret, 'secret')
Beispiel #14
0
def post_to_datazilla(appinfo, configinfo):
    """ take test_results (json) and upload them to datazilla """

    with open(os.path.join(configinfo['energia_dir'], 'report.csv'), 'r') as fHandle:
        data = fHandle.readlines()

    header = True
    browsers = []
    for line in data:
        if header:
            header = False
            continue
        parts = line.split(',')
        if len(parts) != 18:
            continue

        if parts[15] not in browsers:
            browsers.append(parts[15])

    tests = {'GT Watts': 4, 'IA Watts': 8, 'Processor Watts': 13}
    for browser in browsers:
      for test in tests:
        result = DatazillaResult()
        suite_name = "PowerGadget"
        machine_name = "tor-win8"
        os_name = "Win"
        browsername = browser
        if browsername == "Internet Explorer":
            browsername = "IE"
        os_version = "8-%s (%s)" % (browsername, test)
        platform = "x64"
    
        result.add_testsuite(suite_name)
        request = DatazillaRequest("https",
                               "datazilla.mozilla.org",
                               "power",
                               configinfo['oauth_key'],
                               configinfo['oauth_secret'],
                               machine_name=machine_name,
                               os=os_name,
                               os_version=os_version,
                               platform=platform,
                               build_name=appinfo['build_name'],
                               version=appinfo['build_version'],
                               revision=appinfo['build_revision'],
                               branch=appinfo['build_branch'],
                               id=appinfo['build_id'])

        header = True
        for line in data:
            if header:
                header = False
                continue
            if len(parts) != 18:
                conitinue
            parts = line.split(',')

            #Skip data from other browsers
            if parts[15] != browser:
                continue

            result.add_test_results(suite_name, parts[16], [str(parts[tests[test]])])

        request.add_datazilla_result(result)
        responses = request.submit()
        for resp in responses:
            print('server response: %d %s %s' % (resp.status, resp.reason, resp.read()))
Beispiel #15
0
    def post(self, results, server, path, scheme, tbpl_output):
        """post the data to datazilla"""

        # datazilla project
        project = path.strip('/')
        url = '%s://%s/%s' % (scheme, server, project)

        # oauth credentials
        oauth_key = None
        oauth_secret = None
        if self.oauth:
            project_oauth = self.oauth.get(project)
            if project_oauth:
                required = ['oauthKey', 'oauthSecret']
                if set(required).issubset(project_oauth.keys()):
                    oauth_key = project_oauth['oauthKey']
                    oauth_secret = project_oauth['oauthSecret']
                else:
                    utils.info(
                        "%s not found for project '%s' in '%s' (found: %s)",
                        required, project, self.authfile, project_oauth.keys())
            else:
                utils.info(
                    "No oauth credentials found for project '%s' in '%s'",
                    project, self.authfile)
        utils.info("datazilla: %s//%s/%s; oauth=%s", scheme, server, project,
                   bool(oauth_key and oauth_secret))

        # submit the request
        req = DatazillaRequest.create(scheme, server, project, oauth_key,
                                      oauth_secret, results)
        responses = req.submit()

        # print error responses
        for response in 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()
                print "Error posting to %s: %s %s" % (url, response.status,
                                                      reason)
            else:
                res = response.read()
                print "Datazilla response is: %s" % res.lower()

        # TBPL output
        # URLs are in the form of
        # https://datazilla.mozilla.org/<path>/summary/<branch>/<revision>?product=Firefox&branch_version=16.0a1
        # see https://bugzilla.mozilla.org/show_bug.cgi?id=816634#c8
        if results.branch and results.revision:

            # compute url
            path = '/%s/summary/%s/%s' % (project, results.branch,
                                          results.revision)
            query = '&'.join([
                '%s=%s' % (j, urllib.quote(getattr(results, i)))
                for i, j in (('build_name', 'product'), ('version',
                                                         'branch_version'))
                if getattr(results, i)
            ])
            if query:
                query = '?' + query
            url = '%(scheme)s://%(server)s%(path)s%(query)s' % dict(
                scheme=scheme, server=server, path=path, query=query)

            # build TBPL output
            # XXX this will not work for multiple URLs :(
            tbpl_output.setdefault('datazilla', {})
            for dataset in results.datasets():
                tbpl_output['datazilla'][dataset['testrun']['suite']] = {
                    'url': url
                }
            utils.info("Datazilla results at %s", url)
Beispiel #16
0
    def test_submit(self, mock_send):
        """Submits blob of JSON data for each test suite."""
        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',
        )

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

        req.submit()

        self.assertEqual(mock_send.call_count, 2)
        data1 = mock_send.call_args_list[0][0][0]
        data2 = mock_send.call_args_list[1][0][0]

        results = sorted([data1.pop('results'), data2.pop('results')])

        self.assertEqual(results, sorted([{'test1': [1]}, {'test2': [2]}]))

        suites = sorted(
            [data1['testrun'].pop('suite'), data2['testrun'].pop('suite')])

        self.assertEqual(suites, sorted(['suite1', 'suite2']))

        # aside from results and suite, datasets are the same
        self.assertEqual(data1, data2)

        self.assertEqual(
            data1['test_build'],
            {
                'branch': 'Mozilla-Aurora',
                'id': '20120228122102',
                'name': 'Firefox',
                'revision': '785345035a3b',
                'version': '14.0a2',
            },
        )

        self.assertEqual(
            data1['test_machine'],
            {
                'name': 'qm-pxp01',
                'os': 'linux',
                'osversion': 'Ubuntu 11.10',
                'platform': 'x86_64',
            },
        )

        self.assertEqual(data1['testrun']['date'], req.test_date)
Beispiel #17
0
    def post(self, results, server, path, scheme, tbpl_output):
        """post the data to datazilla"""

        # datazilla project
        project = path.strip('/')
        url = '%s://%s/%s' % (scheme, server, project)

        # oauth credentials
        oauth_key = None
        oauth_secret = None
        if self.oauth:
            project_oauth = self.oauth.get(project)
            if project_oauth:
                required = ['oauthKey', 'oauthSecret']
                if set(required).issubset(project_oauth.keys()):
                    oauth_key = project_oauth['oauthKey']
                    oauth_secret = project_oauth['oauthSecret']
                else:
                    utils.info("%s not found for project '%s' in '%s' (found: %s)", required, project, self.authfile, project_oauth.keys())
            else:
                utils.info("No oauth credentials found for project '%s' in '%s'", project, self.authfile)
        utils.info("datazilla: %s//%s/%s; oauth=%s", scheme, server, project, bool(oauth_key and oauth_secret))

        # submit the request
        req = DatazillaRequest.create(scheme, server, project, oauth_key, oauth_secret, results)
        responses = req.submit()

        # print error responses
        for response in 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()
                print "Error posting to %s: %s %s" % (url, response.status, reason)
            else:
                res = response.read()
                print "Datazilla response is: %s" % res.lower()

        # TBPL output
        # URLs are in the form of
        # https://datazilla.mozilla.org/<path>/summary/<branch>/<revision>?product=Firefox&branch_version=16.0a1
        # see https://bugzilla.mozilla.org/show_bug.cgi?id=816634#c8
        if results.branch and results.revision:

            # compute url
            path = '/%s/summary/%s/%s' % (project, results.branch, results.revision)
            query = '&'.join(['%s=%s' % (j, urllib.quote(getattr(results, i)))
                              for i, j in
                              (('build_name', 'product'),
                               ('version', 'branch_version'))
                              if getattr(results, i)])
            if query:
                query = '?' + query
            url = '%(scheme)s://%(server)s%(path)s%(query)s' % dict(scheme=scheme,
                                                                    server=server,
                                                                    path=path,
                                                                    query=query)

            # build TBPL output
            # XXX this will not work for multiple URLs :(
            tbpl_output.setdefault('datazilla', {})
            for dataset in results.datasets():
                tbpl_output['datazilla'][dataset['testrun']['suite']] = {'url': url}
            utils.info("Datazilla results at %s", url)
    def test_submit(self, mock_send):
        """Submits blob of JSON data for each test suite."""
        req = DatazillaRequest(
            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',
            )

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

        req.submit()

        self.assertEqual(mock_send.call_count, 2)
        data1 = mock_send.call_args_list[0][0][0]
        data2 = mock_send.call_args_list[1][0][0]

        results = sorted([data1.pop('results'), data2.pop('results')])

        self.assertEqual(results, sorted([{'test1': [1]}, {'test2': [2]}]))

        suites = sorted(
            [data1['testrun'].pop('suite'), data2['testrun'].pop('suite')])

        self.assertEqual(suites, sorted(['suite1', 'suite2']))

        # aside from results and suite, datasets are the same
        self.assertEqual(data1, data2)

        self.assertEqual(
            data1['test_build'],
            {
                'branch': 'Mozilla-Aurora',
                'id': '20120228122102',
                'name': 'Firefox',
                'revision': '785345035a3b',
                'version': '14.0a2',
                },
            )

        self.assertEqual(
            data1['test_machine'],
            {
                'name': 'qm-pxp01',
                'os': 'linux',
                'osversion': 'Ubuntu 11.10',
                'platform': 'x86_64',
                },
            )

        self.assertEqual(data1['testrun']['date'], req.test_date)
Beispiel #19
0
    def post(self, results, server, path, scheme, tbpl_output):
        """post the data to datazilla"""

        # datazilla project
        project = path.strip('/')
        url = '%s://%s/%s' % (scheme, server, project)

        # oauth credentials
        oauth_key = None
        oauth_secret = None
        if self.oauth:
            project_oauth = self.oauth.get(project)
            if project_oauth:
                required = ['oauthKey', 'oauthSecret']
                if set(required).issubset(project_oauth.keys()):
                    oauth_key = project_oauth['oauthKey']
                    oauth_secret = project_oauth['oauthSecret']
                else:
                    utils.info("%s not found for project '%s' in '%s' (found: %s)", required, project, self.authfile, project_oauth.keys())
            else:
                utils.info("No oauth credentials found for project '%s' in '%s'", project, self.authfile)
        utils.info("datazilla: %s//%s/%s; oauth=%s", scheme, server, project, bool(oauth_key and oauth_secret))

        # submit the request
        req = DatazillaRequest.create(scheme, server, project, oauth_key, oauth_secret, results)
        responses = req.submit()

        # print error responses
        for response in 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()
                print "Error posting to %s: %s %s" % (url, response.status, reason)
            else:
                res = response.read()
                print "Datazilla response is: %s" % res.lower()

        # TBPL output
        # URLs are in the form of
        # https://datazilla.mozilla.org/?start=1379423909&stop=1380028709&product=Firefox&repository=Mozilla-Inbound&os=linux&os_version=Ubuntu%2012.04&test=a11yr&x86=false&project=talos
        if results.branch and results.revision:
            # compute url
            now = str(datetime.datetime.now())
            diff = str(datetime.datetime.now() - datetime.timedelta(days=7))
            jsend = int(time.mktime(time.strptime(now.split('.')[0], "%Y-%m-%d %H:%M:%S")))
            jsstart = int(time.mktime(time.strptime(diff.split('.')[0], "%Y-%m-%d %H:%M:%S")))

            params = {}
            if results.platform == 'x86':
                params['x86_64'] = 'false'
            else:
                params['x86'] = 'false'

            revision = ""
            if results.revision and results.revision != 'NULL':
                params['graph_search'] = results.revision

            params['start'] = jsstart
            params['stop'] = jsend
            params['product'] = results.build_name
            params['repository'] = results.branch
            params['os'] = results.os.lower()
            # As per bug 957166, we need to Capitalize Android
            if params['os'] == 'android':
                params['os'] = 'Android'

            params['os_version'] = results.os_version
            params['project'] = project
            query = '?%s' % '&'.join(['%s=%s' % (key, urllib.quote(str(value))) for key, value in params.items()])

            url = '%(scheme)s://%(server)s%(query)s' % dict(scheme=scheme,
                                                                    server=server,
                                                                    query=query)

            # build TBPL output
            # XXX this will not work for multiple URLs :(
            tbpl_output.setdefault('datazilla', {})
            for dataset in results.datasets():
                url = "%s&test=%s" % (url, dataset['testrun']['suite'])
                tbpl_output['datazilla'][dataset['testrun']['suite']] = {'url': url}
                utils.info("Datazilla results at %s", url)
Beispiel #20
0
    def post_to_datazilla(self):
        """ 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.
        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

        with open('/home/mozauto/power_logger/report.csv', 'r') as fHandle:
            data = fHandle.readlines()

        header = True
        browsers = []
        for line in data:
            if header:
                header = False
                continue
            parts = line.split(',')
            if parts[1] not in browsers:
                browsers.append(parts[1])

        for browser in browsers:
            result = DatazillaResult()
            suite_name = "PowerGadget"
            machine_name = "perf-windows-003"
            os_name = "Win"
            browsername = browser
            if browsername == "Internet Explorer":
                browsrename = "IE"
            os_version = "7 - %s" % browsername
            platform = "x86"
        
            result.add_testsuite(suite_name)
            #TODO: JMAHER: hardcoded microperf here, this project should be in a config file and a real name
            request = DatazillaRequest("https",
                                   "datazilla.mozilla.org",
                                   "power",
                                   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)

            header = True
            for line in data:
                if header:
                    header = False
                    continue
                parts = line.split(',')

                #Skip data from other browsers
                if parts[1] != browser:
                    continue

                result.add_test_results(suite_name, parts[13], [str(parts[14])])
                print "JMAHER: added data: %s: %s = %s, %s" % (os_version, suite_name, parts[13], [str(parts[14])])            

            request.add_datazilla_result(result)
            responses = request.submit()
            for resp in responses:
                print 'server response: %d %s %s' % (resp.status, resp.reason, resp.read())
Beispiel #21
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