Exemplo n.º 1
0
    def UploadToCloudStorage(self, bucket, target_path):
        """Uploads video file to cloud storage.

    Args:
      target_path: Path indicating where to store the file in cloud storage.
    """
        cloud_storage.Insert(bucket, target_path, self._video_file_obj.name)
  def Format(self, page_test_results):
    super(HtmlOutputFormatter, self).Format(page_test_results)

    html = self._GetHtmlTemplate()
    html = html.replace('%json_results%', json.dumps(self.GetCombinedResults()))
    html = html.replace('%json_units%', self._GetUnitJson())
    html = html.replace('%plugins%', self._GetPlugins())
    self._SaveResults(html)

    if self._upload_results:
      file_path = os.path.abspath(self._html_output_stream.name)
      file_name = 'html-results/results-%s' % datetime.datetime.now().strftime(
          '%Y-%m-%d_%H-%M-%S')
      try:
        cloud_storage.Insert(cloud_storage.PUBLIC_BUCKET, file_name, file_path)
        print
        print ('View online at '
               'http://storage.googleapis.com/chromium-telemetry/%s'
               % file_name)
      except cloud_storage.PermissionError as e:
        logging.error('Cannot upload profiling files to cloud storage due to '
                      ' permission error: %s' % e.message)
    print
    print 'View result at file://%s' % os.path.abspath(
        self._html_output_stream.name)
Exemplo n.º 3
0
  def AddRecordedUserStories(self, user_stories, upload_to_cloud_storage=False):
    if not user_stories:
      os.remove(self.temp_target_wpr_file_path)
      return

    (target_wpr_file, target_wpr_file_path) = self._NextWprFileName()
    for user_story in user_stories:
      self._SetWprFileForUserStory(user_story.display_name, target_wpr_file)
    shutil.move(self.temp_target_wpr_file_path, target_wpr_file_path)

    # Update the hash file.
    target_wpr_file_hash = cloud_storage.CalculateHash(target_wpr_file_path)
    with open(target_wpr_file_path + '.sha1', 'wb') as f:
      f.write(target_wpr_file_hash)
      f.flush()

    self._WriteToFile()
    self._DeleteAbandonedWprFiles()

    # Upload to cloud storage
    if upload_to_cloud_storage:
      if not self._bucket:
        logging.warning('UserStorySet must have bucket specified to upload '
                        'user stories to cloud storage.')
        return
      try:
        cloud_storage.Insert(self._bucket, target_wpr_file_hash,
                             target_wpr_file_path)
      except cloud_storage.CloudStorageError, e:
        logging.warning('Failed to upload wpr file %s to cloud storage. '
                        'Error:%s' % target_wpr_file_path, e)
Exemplo n.º 4
0
 def UploadToCloud(self, bucket):
   temp_fh = None
   try:
     if self._serialized_file_handle:
       fh = self._serialized_file_handle
     else:
       temp_fh = self._GetTempFileHandle()
       fh = temp_fh
     remote_path = ('trace-file-id_%s-%s-%d%s' % (
         fh.id,
         datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'),
         random.randint(1, 100000),
         fh.extension))
     self._cloud_url = cloud_storage.Insert(
         bucket, remote_path, fh.GetAbsPath())
     sys.stderr.write(
         'View generated trace files online at %s for page %s\n' %
         (self._cloud_url, self.page.url if self.page else 'unknown'))
     return self._cloud_url
   except cloud_storage.PermissionError as e:
     logging.error('Cannot upload trace files to cloud storage due to '
                   ' permission error: %s' % e.message)
   finally:
     if temp_fh:
       os.remove(temp_fh.GetAbsPath())
 def _UploadBitmapToCloudStorage(self, bucket, name, bitmap, public=False):
   # This sequence of steps works on all platforms to write a temporary
   # PNG to disk, following the pattern in bitmap_unittest.py. The key to
   # avoiding PermissionErrors seems to be to not actually try to write to
   # the temporary file object, but to re-open its name for all operations.
   temp_file = tempfile.NamedTemporaryFile().name
   bitmap.WritePngFile(temp_file)
   cloud_storage.Insert(bucket, name, temp_file, publicly_readable=public)
Exemplo n.º 6
0
def _SyncFilesToCloud(input_api, output_api):
    """Searches for .sha1 files and uploads them to Cloud Storage.

  It validates all the hashes and skips upload if not necessary.
  """

    cloud_storage = LoadSupport(input_api)

    results = []
    for hash_path, file_hash in _GetFilesNotInCloud(input_api):
        file_path, _ = os.path.splitext(hash_path)

        if not re.match('^([A-Za-z0-9]{40})$', file_hash):
            results.append(
                output_api.PresubmitError(
                    'Hash file does not contain a valid SHA-1 hash: %s' %
                    hash_path))
            continue
        if not os.path.exists(file_path):
            results.append(
                output_api.PresubmitError(
                    'Hash file exists, but file not found: %s' % hash_path))
            continue
        if cloud_storage.CalculateHash(file_path) != file_hash:
            results.append(
                output_api.PresubmitError(
                    'Hash file does not match file\'s actual hash: %s' %
                    hash_path))
            continue

        try:
            bucket_aliases_string = ', '.join(cloud_storage.BUCKET_ALIASES)
            bucket_input = raw_input(
                'Uploading to Cloud Storage: %s\n'
                'Which bucket should this go in? (%s) ' %
                (file_path, bucket_aliases_string)).lower()
            bucket = cloud_storage.BUCKET_ALIASES.get(bucket_input, None)
            if not bucket:
                results.append(
                    output_api.PresubmitError(
                        '"%s" was not one of %s' %
                        (bucket_input, bucket_aliases_string)))
                return results

            cloud_storage.Insert(bucket, file_hash, file_path)
            results.append(
                output_api.PresubmitNotifyResult(
                    'Uploaded file to Cloud Storage: %s' % file_path))
        except cloud_storage.CloudStorageError, e:
            results.append(
                output_api.PresubmitError(
                    'Unable to upload to Cloud Storage: %s\n\n%s' %
                    (file_path, e)))
 def testInsertCreatesValidCloudUrl(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_url = cloud_storage.Insert(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_url)
     finally:
         cloud_storage._RunCommand = orig_run_command
 def UploadProfilingFilesToCloud(self, bucket):
     for page, file_handle_list in self._pages_to_profiling_files.iteritems(
     ):
         for file_handle in file_handle_list:
             remote_path = (
                 'profiler-file-id_%s-%s%-d%s' %
                 (file_handle.id,
                  datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'),
                  random.randint(1, 100000), file_handle.extension))
             try:
                 cloud_url = cloud_storage.Insert(bucket, remote_path,
                                                  file_handle.GetAbsPath())
                 sys.stderr.write(
                     'View generated profiler files online at %s for page %s\n'
                     % (cloud_url, page.display_name))
                 self._pages_to_profiling_files_cloud_url[page].append(
                     cloud_url)
             except cloud_storage.PermissionError as e:
                 logging.error(
                     'Cannot upload profiling files to cloud storage due to '
                     ' permission error: %s' % e.message)
Exemplo n.º 9
0
 def UploadToCloud(self, bucket):
     if self._temp_file is None:
         raise ValueError(
             'Tried to upload nonexistent trace to Cloud Storage.')
     try:
         if self._serialized_file_handle:
             fh = self._serialized_file_handle
         else:
             fh = self._temp_file
         remote_path = (
             'trace-file-id_%s-%s-%d%s' %
             (fh.id, datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'),
              random.randint(1, 100000), fh.extension))
         self._cloud_url = cloud_storage.Insert(bucket, remote_path,
                                                fh.GetAbsPath())
         sys.stderr.write(
             'View generated trace files online at %s for page %s\n' %
             (self._cloud_url, self.page.url if self.page else 'unknown'))
         return self._cloud_url
     except cloud_storage.PermissionError as e:
         logging.error('Cannot upload trace files to cloud storage due to '
                       ' permission error: %s' % e.message)
Exemplo n.º 10
0
    def Format(self, page_test_results):
        chart_json_dict = chart_json_output_formatter.ResultsAsChartDict(
            self._metadata, page_test_results.all_page_specific_values,
            page_test_results.all_summary_values)

        self._TranslateChartJson(chart_json_dict)
        self._PrintPerfResult('telemetry_page_measurement_results',
                              'num_failed', [len(page_test_results.failures)],
                              'count', 'unimportant')

        html = self._GetHtmlTemplate()
        html = html.replace('%json_results%',
                            json.dumps(self.GetCombinedResults()))
        html = html.replace('%json_units%', self._GetUnitJson())
        html = html.replace('%plugins%', self._GetPlugins())
        self._SaveResults(html)

        if self._upload_results:
            file_path = os.path.abspath(self._output_stream.name)
            file_name = 'html-results/results-%s' % datetime.datetime.now(
            ).strftime('%Y-%m-%d_%H-%M-%S')
            try:
                cloud_storage.Insert(cloud_storage.PUBLIC_BUCKET, file_name,
                                     file_path)
                print
                print(
                    'View online at '
                    'http://storage.googleapis.com/chromium-telemetry/%s' %
                    file_name)
            except cloud_storage.PermissionError as e:
                logging.error(
                    'Cannot upload profiling files to cloud storage due to '
                    ' permission error: %s' % e.message)
        print
        print 'View result at file://%s' % os.path.abspath(
            self._output_stream.name)