Commit ed35b760 authored by aiolos's avatar aiolos Committed by Commit bot

Add Copy to cloud storage to allow copying from one remote path to another.

This is needed so that we can pull the needed binaries for
chrome reference builds from their current location in cloud
storage to a bucket that is accessible from the perf bots and
anyone with Google internal access running the tests manually.

BUG=467260

Review URL: https://codereview.chromium.org/1008013003

Cr-Commit-Position: refs/heads/master@{#321209}
parent 43d6a17f
......@@ -179,6 +179,24 @@ def Move(bucket1, bucket2, remote_path):
_RunCommand(['mv', url1, url2])
def Copy(bucket_from, bucket_to, remote_path_from, remote_path_to):
"""Copy a file from one location in CloudStorage to another.
Args:
bucket_from: The cloud storage bucket where the file is currently located.
bucket_to: The cloud storage bucket it is being copied to.
remote_path_from: The file path where the file is located in bucket_from.
remote_path_to: The file path it is being copied to in bucket_to.
It should: cause no changes locally or to the starting file, and will
overwrite any existing files in the destination location.
"""
url1 = 'gs://%s/%s' % (bucket_from, remote_path_from)
url2 = 'gs://%s/%s' % (bucket_to, remote_path_to)
logging.info('Copying %s to %s' % (url1, url2))
_RunCommand(['cp', url1, url2])
def Delete(bucket, remote_path):
url = 'gs://%s/%s' % (bucket, remote_path)
logging.info('Deleting %s' % url)
......
......@@ -153,3 +153,15 @@ class CloudStorageUnitTest(unittest.TestCase):
finally:
cloud_storage.GetIfChanged = orig_get_if_changed
stubs.Restore()
def testCopy(self):
orig_run_command = cloud_storage._RunCommand
def AssertCorrectRunCommandArgs(args):
self.assertEqual(expected_args, args)
cloud_storage._RunCommand = AssertCorrectRunCommandArgs
expected_args = ['cp', 'gs://bucket1/remote_path1',
'gs://bucket2/remote_path2']
try:
cloud_storage.Copy('bucket1', 'bucket2', 'remote_path1', 'remote_path2')
finally:
cloud_storage._RunCommand = orig_run_command
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment