def testUploadCreatesValidCloudUrls(self): orig_run_command = cloud_storage._RunCommand try: cloud_storage._RunCommand = self._FakeRunCommand remote_path = 'test-remote-path.html' local_path = 'test-local-path.html' cloud_filepath = cloud_storage.Upload(cloud_storage.PUBLIC_BUCKET, remote_path, local_path) self.assertEqual( 'https://console.developers.google.com/m/cloudstorage' '/b/chromium-telemetry/o/test-remote-path.html', cloud_filepath.view_url) self.assertEqual('gs://chromium-telemetry/test-remote-path.html', cloud_filepath.fetch_url) finally: cloud_storage._RunCommand = orig_run_command
def UploadArtifacts(test_result, upload_bucket, run_identifier): """Upload all artifacts to cloud. For a test run, uploads all its artifacts to cloud and sets fetchUrl and viewUrl fields in intermediate_results. """ artifacts = test_result.get('outputArtifacts', {}) for name, artifact in artifacts.iteritems(): # TODO(crbug.com/981349): Think of a more general way to # specify which artifacts deserve uploading. if name in [DIAGNOSTICS_NAME, MEASUREMENTS_NAME]: continue remote_name = '/'.join([run_identifier, test_result['testPath'], name]) urlsafe_remote_name = re.sub(r'[^A-Za-z0-9/.-]+', '_', remote_name) cloud_filepath = cloud_storage.Upload( upload_bucket, urlsafe_remote_name, artifact['filePath']) # Per crbug.com/1033755 some services require fetchUrl. artifact['fetchUrl'] = cloud_filepath.fetch_url artifact['viewUrl'] = cloud_filepath.view_url logging.info('%s: Uploaded %s to %s', test_result['testPath'], name, artifact['viewUrl'])