Esempio n. 1
0
    def testCloudStorageUploaderInequality(self):
        new_local_path = os.path.abspath(os.path.join('new', 'local', 'path'))
        self.fs.CreateFile(new_local_path)
        new_bucket = 'new_bucket'
        new_remote_path = 'new_remote/path'

        upload_data = uploader.CloudStorageUploader(self.bucket,
                                                    self.remote_path,
                                                    self.local_path)
        upload_data_all_different = uploader.CloudStorageUploader(
            new_bucket, new_remote_path, new_local_path)
        upload_data_different_bucket = uploader.CloudStorageUploader(
            new_bucket, self.remote_path, self.local_path)
        upload_data_different_remote_path = uploader.CloudStorageUploader(
            self.bucket, new_remote_path, self.local_path)
        upload_data_different_local_path = uploader.CloudStorageUploader(
            self.bucket, self.remote_path, new_local_path)

        self.assertNotEqual(upload_data, 'a string!')
        self.assertNotEqual(upload_data, 0)
        self.assertNotEqual(upload_data, 2354)
        self.assertNotEqual(upload_data, None)
        self.assertNotEqual(upload_data, upload_data_all_different)
        self.assertNotEqual(upload_data_all_different, upload_data)
        self.assertNotEqual(upload_data, upload_data_different_bucket)
        self.assertNotEqual(upload_data_different_bucket, upload_data)
        self.assertNotEqual(upload_data, upload_data_different_remote_path)
        self.assertNotEqual(upload_data_different_remote_path, upload_data)
        self.assertNotEqual(upload_data, upload_data_different_local_path)
        self.assertNotEqual(upload_data_different_local_path, upload_data)
Esempio n. 2
0
 def testCloudStorageUploaderEquality(self):
     upload_data = uploader.CloudStorageUploader(self.bucket,
                                                 self.remote_path,
                                                 self.local_path)
     upload_data_exact = uploader.CloudStorageUploader(
         self.bucket, self.remote_path, self.local_path)
     upload_data_equal = uploader.CloudStorageUploader(
         'cloud_storage_bucket', 'config_folder/remote_path',
         os.path.abspath(os.path.join('path', 'to', 'dependency')))
     self.assertEqual(upload_data, upload_data)
     self.assertEqual(upload_data, upload_data_exact)
     self.assertEqual(upload_data_exact, upload_data)
     self.assertEqual(upload_data, upload_data_equal)
     self.assertEqual(upload_data_equal, upload_data)
Esempio n. 3
0
  def AddCloudStorageDependencyUpdateJob(
      self, dependency, platform, dependency_path, version=None,
      execute_job=True):
    """Update the file downloaded from cloud storage for a dependency/platform.

    Upload a new file to cloud storage for the given dependency and platform
    pair and update the cloud storage hash and the version for the given pair.

    Example usage:
      The following should update the default platform for 'dep_name':
          UpdateCloudStorageDependency('dep_name', 'default', 'path/to/file')

      The following should update both the mac and win platforms for 'dep_name',
      or neither if either update fails:
          UpdateCloudStorageDependency(
              'dep_name', 'mac_x86_64', 'path/to/mac/file', execute_job=False)
          UpdateCloudStorageDependency(
              'dep_name', 'win_AMD64', 'path/to/win/file', execute_job=False)
          ExecuteUpdateJobs()

    Args:
      dependency: The dependency to update.
      platform: The platform to update the dependency info for.
      dependency_path: Path to the new dependency to be used.
      version: Version of the updated dependency, for checking future updates
          against.
      execute_job: True if the config should be written to disk and the file
          should be uploaded to cloud storage after the update. False if
          multiple updates should be performed atomically. Must call
          ExecuteUpdateJobs after all non-executed jobs are added to complete
          the update.

    Raises:
      ReadWriteError: If the config was not initialized as writable, or if
          |execute_job| is True but the config has update jobs still pending
          execution.
      ValueError: If no information exists in the config for |dependency| on
          |platform|.
    """
    self._ValidateIsConfigUpdatable(
        execute_job=execute_job, dependency=dependency, platform=platform)
    cs_hash = cloud_storage.CalculateHash(dependency_path)
    if version:
      self._SetPlatformData(dependency, platform, 'version_in_cs', version)
    self._SetPlatformData(dependency, platform, 'cloud_storage_hash', cs_hash)

    cs_base_folder = self._GetPlatformData(
        dependency, platform, 'cloud_storage_base_folder')
    cs_bucket = self._GetPlatformData(
        dependency, platform, 'cloud_storage_bucket')
    cs_remote_path = self._CloudStorageRemotePath(
        dependency, cs_hash, cs_base_folder)
    self._pending_uploads.append(uploader.CloudStorageUploader(
        cs_bucket, cs_remote_path, dependency_path))
    if execute_job:
      self.ExecuteUpdateJobs()
Esempio n. 4
0
 def testCloudStorageUploaderCreation(self):
   upload_data = uploader.CloudStorageUploader(
       self.bucket, self.remote_path, self.local_path)
   expected_bucket = self.bucket
   expected_remote_path = self.remote_path
   expected_cs_backup_path = '%s.old' % expected_remote_path
   expected_local_path = self.local_path
   self.assertEqual(expected_bucket, upload_data._cs_bucket)
   self.assertEqual(expected_remote_path, upload_data._cs_remote_path)
   self.assertEqual(expected_local_path, upload_data._local_path)
   self.assertEqual(expected_cs_backup_path, upload_data._cs_backup_path)