Changeset 249652 in webkit


Ignore:
Timestamp:
Sep 9, 2019 11:29:12 AM (5 years ago)
Author:
Jonathan Bedard
Message:

run-webkit-tests: Report results archive to results.webkit.org
https://bugs.webkit.org/show_bug.cgi?id=201321

Reviewed by Aakash Jain.

  • Scripts/webkitpy/layout_tests/controllers/manager.py:

(Manager.run): After all tests are finish, upload the results archive for each
configuration.

  • Scripts/webkitpy/results/upload.py:

(Upload):
(Upload.init): Automatically define timestamp.
(Upload.upload_archive): Upload an archive associated with the test run.

  • Scripts/webkitpy/results/upload_unittest.py:

(UploadTest.test_buildbot):
(UploadTest):
(UploadTest.test_archive_upload):

Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r249648 r249652  
     12019-09-09  Jonathan Bedard  <jbedard@apple.com>
     2
     3        run-webkit-tests: Report results archive to results.webkit.org
     4        https://bugs.webkit.org/show_bug.cgi?id=201321
     5
     6        Reviewed by Aakash Jain.
     7
     8        * Scripts/webkitpy/layout_tests/controllers/manager.py:
     9        (Manager.run): After all tests are finish, upload the results archive for each
     10        configuration.
     11        * Scripts/webkitpy/results/upload.py:
     12        (Upload):
     13        (Upload.__init__): Automatically define timestamp.
     14        (Upload.upload_archive): Upload an archive associated with the test run.
     15        * Scripts/webkitpy/results/upload_unittest.py:
     16        (UploadTest.test_buildbot):
     17        (UploadTest):
     18        (UploadTest.test_archive_upload):
     19
    1202019-09-09  Chris Dumez  <cdumez@apple.com>
    221
  • trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py

    r248270 r249652  
    3838import logging
    3939import random
     40import shutil
    4041import sys
    4142import time
     
    245246        max_child_processes_for_run = 1
    246247        child_processes_option_value = self._options.child_processes
     248        uploads = []
    247249
    248250        for device_type in device_type_list:
     
    282284                    details=Upload.create_details(options=self._options),
    283285                    commits=self._port.commits_for_upload(),
     286                    timestamp=start_time,
    284287                    run_stats=Upload.create_run_stats(
    285288                        start_time=start_time_for_device,
     
    289292                    results=self._results_to_upload_json_trie(self._expectations[device_type], temp_initial_results),
    290293                )
    291                 for url in self._options.report_urls:
    292                     self._printer.write_update('Uploading to {} ...'.format(url))
    293                     if not upload.upload(url, log_line_func=self._printer.writeln):
     294                for hostname in self._options.report_urls:
     295                    self._printer.write_update('Uploading to {} ...'.format(hostname))
     296                    if not upload.upload(hostname, log_line_func=self._printer.writeln):
    294297                        num_failed_uploads += 1
     298                    else:
     299                        uploads.append(upload)
    295300                self._printer.writeln('Uploads completed!')
    296301
     
    310315        end_time = time.time()
    311316        result = self._end_test_run(start_time, end_time, initial_results, retry_results, enabled_pixel_tests_in_retry)
     317
     318        if self._options.report_urls and uploads:
     319            self._printer.writeln('\n')
     320            self._printer.write_update('Preparing to upload test archive ...')
     321
     322            with self._filesystem.mkdtemp() as temp:
     323                archive = self._filesystem.join(temp, 'test-archive')
     324                shutil.make_archive(archive, 'zip', self._results_directory)
     325
     326                for upload in uploads:
     327                    for hostname in self._options.report_urls:
     328                        self._printer.write_update('Uploading archive to {} ...'.format(hostname))
     329                        if not upload.upload_archive(hostname, self._filesystem.open_binary_file_for_reading(archive + '.zip'), log_line_func=self._printer.writeln):
     330                            num_failed_uploads += 1
     331
    312332        if num_failed_uploads:
    313333            result.exit_code = -1
  • trunk/Tools/Scripts/webkitpy/results/upload.py

    r243030 r249652  
    2626import requests
    2727import sys
     28import time
    2829
    2930import platform as host_platform
     
    3233class Upload(object):
    3334    UPLOAD_ENDPOINT = '/api/upload'
     35    ARCHIVE_UPLOAD_ENDPOINT = '/api/upload/archive'
    3436    BUILDBOT_DETAILS = ['buildbot-master', 'builder-name', 'build-number', 'buildbot-worker']
    3537    VERSION = 0
     
    100102        self.configuration = configuration
    101103        self.commits = commits
    102         self.timestamp = timestamp
     104        self.timestamp = int(timestamp or time.time())
    103105        self.details = details
    104106        self.run_stats = run_stats
     
    166168        return result
    167169
    168     def upload(self, url, log_line_func=lambda val: sys.stdout.write(val + '\n')):
     170    def upload(self, hostname, log_line_func=lambda val: sys.stdout.write(val + '\n')):
    169171        try:
    170             response = requests.post(url + self.UPLOAD_ENDPOINT, data=json.dumps(self, cls=Upload.Encoder))
     172            response = requests.post('{}{}'.format(hostname, self.UPLOAD_ENDPOINT), data=json.dumps(self, cls=Upload.Encoder))
    171173        except requests.exceptions.ConnectionError:
    172             log_line_func(' ' * 4 + 'Failed to upload to {}, results server not online'.format(url))
     174            log_line_func(' ' * 4 + 'Failed to upload to {}, results server not online'.format(hostname))
    173175            return False
    174176        except ValueError as e:
     
    177179
    178180        if response.status_code != 200:
    179             log_line_func(' ' * 4 + 'Error uploading to {}:'.format(url))
    180             log_line_func(' ' * 8 + response.json()['description'])
    181             return False
    182 
    183         log_line_func(' ' * 4 + 'Uploaded results to {}'.format(url))
     181            log_line_func(' ' * 4 + 'Error uploading to {}'.format(hostname))
     182            log_line_func(' ' * 8 + response.json().get('description'))
     183            return False
     184
     185        log_line_func(' ' * 4 + 'Uploaded results to {}'.format(hostname))
    184186        return True
     187
     188    def upload_archive(self, hostname, archive, log_line_func=lambda val: sys.stdout.write(val + '\n')):
     189        try:
     190            meta_data = dict(
     191                version=self.VERSION,
     192                suite=self.suite,
     193                configuration=json.dumps(self.configuration or self.create_configuration()),
     194                commits=json.dumps(self.commits),
     195            )
     196            if self.timestamp:
     197                meta_data['timestamp'] = self.timestamp
     198            response = requests.post(
     199                '{}{}'.format(hostname, self.ARCHIVE_UPLOAD_ENDPOINT),
     200                data=meta_data,
     201                files=dict(file=archive),
     202            )
     203
     204        except requests.exceptions.ConnectionError:
     205            log_line_func(' ' * 4 + 'Failed to upload test archive to {}, results server not online'.format(hostname))
     206            return False
     207        except ValueError as e:
     208            log_line_func(' ' * 4 + 'Failed to encode archive reference data: {}'.format(e))
     209            return False
     210
     211        if response.status_code != 200:
     212            log_line_func(' ' * 4 + 'Error uploading archive to {}'.format(hostname))
     213            log_line_func(' ' * 8 + response.json().get('description'))
     214            return False
     215
     216        log_line_func(' ' * 4 + 'Uploaded test archive to {}'.format(hostname))
     217        return True
  • trunk/Tools/Scripts/webkitpy/results/upload_unittest.py

    r243030 r249652  
    128128
    129129        with mock.patch('requests.post', new=lambda url, data: self.MockResponse()):
    130             self.assertTrue(upload.upload('https://webkit.org/results', log_line_func=lambda _: None))
     130            self.assertTrue(upload.upload('https://results.webkit.org', log_line_func=lambda _: None))
    131131
    132132        with mock.patch('requests.post', new=lambda url, data: self.raise_requests_ConnectionError()):
    133             self.assertFalse(upload.upload('https://webkit.org/results', log_line_func=lambda _: None))
     133            lines = []
     134            self.assertFalse(upload.upload('https://results.webkit.org', log_line_func=lambda line: lines.append(line)))
     135            self.assertEqual([' ' * 4 + 'Failed to upload to https://results.webkit.org, results server not online'], lines)
    134136
    135137        mock_404 = mock.patch('requests.post', new=lambda url, data: self.MockResponse(
     
    138140        ))
    139141        with mock_404:
    140             self.assertFalse(upload.upload('https://webkit.org/results', log_line_func=lambda _: None))
     142            self.assertFalse(upload.upload('https://results.webkit.org', log_line_func=lambda _: None))
    141143
    142144    def test_packed_test(self):
     
    215217            'buildbot-worker': 'bot123',
    216218        }))
     219
     220    def test_archive_upload(self):
     221        upload = Upload(
     222            suite='webkitpy-tests',
     223            commits=[Upload.create_commit(
     224                repository_id='webkit',
     225                id='5',
     226                branch='trunk',
     227            )],
     228        )
     229
     230        with mock.patch('requests.post', new=lambda url, data, files: self.MockResponse()):
     231            self.assertTrue(upload.upload_archive('https://results.webkit.org', archive='content', log_line_func=lambda _: None))
     232
     233        with mock.patch('requests.post', new=lambda url, data, files: self.raise_requests_ConnectionError()):
     234            lines = []
     235            self.assertFalse(upload.upload_archive('https://results.webkit.org', archive='content', log_line_func=lambda line: lines.append(line)))
     236            self.assertEqual([' ' * 4 + 'Failed to upload test archive to https://results.webkit.org, results server not online'], lines)
     237
     238        mock_404 = mock.patch('requests.post', new=lambda url, data, files: self.MockResponse(
     239            status_code=404,
     240            text=json.dumps(dict(description='No such address')),
     241        ))
     242        with mock_404:
     243            lines = []
     244            self.assertFalse(upload.upload_archive('https://results.webkit.org', archive='content', log_line_func=lambda line: lines.append(line)))
     245            self.assertEqual([
     246                ' ' * 4 + 'Error uploading archive to https://results.webkit.org',
     247                ' ' * 8 + 'No such address',
     248            ], lines)
Note: See TracChangeset for help on using the changeset viewer.