def testCopy(self): gs_path = 'gs://bucket/some/path' local_path = '/some/local/path' http_path = 'http://host.domain/some/path' result = 'TheResult' self.mox.StubOutWithMock(gslib, 'Copy') self.mox.StubOutWithMock(filelib, 'Copy') self.mox.StubOutWithMock(urilib, 'URLRetrieve') # Set up the test replay script. # Run 1, two local files. filelib.Copy(local_path, local_path + '.1').AndReturn(result) # Run 2, local and GS. gslib.Copy(local_path, gs_path).AndReturn(result) # Run 4, GS and GS gslib.Copy(gs_path, gs_path + '.1').AndReturn(result) # Run 7, HTTP and local urilib.URLRetrieve(http_path, local_path).AndReturn(result) # Run 8, local and HTTP self.mox.ReplayAll() # Run the test verification. self.assertEquals(result, urilib.Copy(local_path, local_path + '.1')) self.assertEquals(result, urilib.Copy(local_path, gs_path)) self.assertEquals(result, urilib.Copy(gs_path, gs_path + '.1')) self.assertEquals(result, urilib.Copy(http_path, local_path)) self.assertRaises(urilib.NotSupportedBetweenTypes, urilib.Copy, local_path, http_path) self.mox.VerifyAll()
def testCopy(self): src_path = '/path/to/some/file' dest_path = 'gs://bucket/some/gs/path' self.mox.StubOutWithMock(utils, 'RunCommand') # Set up the test replay script. # Run 1, success. cmd = [self.gsutil, 'cp', src_path, dest_path] utils.RunCommand(cmd, redirect_stdout=True, redirect_stderr=True, return_result=True) # Run 2, failure. for _ix in xrange(gslib.RETRY_ATTEMPTS + 1): cmd = [self.gsutil, 'cp', src_path, dest_path] utils.RunCommand( cmd, redirect_stdout=True, redirect_stderr=True, return_result=True).AndRaise( utils.CommandFailedException(GS_RETRY_FAILURE)) self.mox.ReplayAll() # Run the test verification. gslib.Copy(src_path, dest_path) self.assertRaises(gslib.CopyFail, gslib.Copy, src_path, dest_path) self.mox.VerifyAll()
def Copy(src_uri, dest_uri): """Copy one uri to another. Args: src_uri: URI to copy from. dest_uri: Path to copy to. Raises: NotSupportedBetweenTypes if Cmp cannot be done between the two URIs provided. """ uri_type1 = GetUriType(src_uri) uri_type2 = GetUriType(dest_uri) uri_types = set([uri_type1, uri_type2]) if TYPE_GS in uri_types: # GS only supported between other GS files or local files. if len(uri_types) == 1 or TYPE_LOCAL in uri_types: return gslib.Copy(src_uri, dest_uri) if TYPE_LOCAL in uri_types and len(uri_types) == 1: return filelib.Copy(src_uri, dest_uri) if uri_type1 in (TYPE_HTTP, TYPE_HTTPS) and uri_type2 == TYPE_LOCAL: # Download file from URL. return URLRetrieve(src_uri, dest_uri) raise NotSupportedBetweenTypes(uri_type1, uri_type2)
def testCreateWithContents(self): gs_path = 'gs://chromeos-releases-test/create-with-contents-test' contents = 'Stuff with Rocks In' self.mox.StubOutWithMock(gslib, 'Copy') gslib.Copy(mox.IsA(str), gs_path) self.mox.ReplayAll() gslib.CreateWithContents(gs_path, contents) self.mox.VerifyAll()
def testCopy(self): src_path = '/path/to/some/file' dest_path = 'gs://bucket/some/gs/path' # Set up the test replay script. # Run 1, success. cmd = [self.gsutil, 'cp', src_path, dest_path] cros_build_lib.RunCommand(cmd, redirect_stdout=True, redirect_stderr=True) # Run 2, failure. error = cros_build_lib.RunCommandError(GS_RETRY_FAILURE, self.cmd_result) for _ix in xrange(gslib.RETRY_ATTEMPTS + 1): cmd = [self.gsutil, 'cp', src_path, dest_path] cros_build_lib.RunCommand( cmd, redirect_stdout=True, redirect_stderr=True).AndRaise(error) self.mox.ReplayAll() # Run the test verification. gslib.Copy(src_path, dest_path) self.assertRaises(gslib.CopyFail, gslib.Copy, src_path, dest_path) self.mox.VerifyAll()
def populateUri(self, uri): local_path = os.path.join(self.tempdir, 'remote_content') osutils.WriteFile(local_path, 'some sample content') gslib.Copy(local_path, uri) return local_path
def _AutotestPayloads(self, payload_tests): """Create necessary test artifacts and initiate Autotest runs. Args: payload_tests: An iterable of PayloadTest objects defining payload tests. """ # Create inner hierarchy for dumping Autotest control files. control_dir = os.path.join(self._work_dir, 'autotests') control_dump_dir = os.path.join(control_dir, self.CONTROL_FILE_SUBDIR) os.makedirs(control_dump_dir) # Customize the test suite's name based on this build's channel. test_channel = self._build.channel.rpartition('-')[0] suite_name = (self.PAYGEN_AU_SUITE_TEMPLATE % test_channel) # Emit a control file for each payload. logging.info('Emitting control files into %s', control_dump_dir) for payload_test in payload_tests: self._EmitControlFile(payload_test, suite_name, control_dump_dir) tarball_name = self.CONTROL_TARBALL_TEMPLATE % test_channel # Must use an absolute tarball path since tar is run in a different cwd. tarball_path = os.path.join(control_dir, tarball_name) # Create the tarball. logging.info('Packing %s in %s into %s', self.CONTROL_FILE_SUBDIR, control_dir, tarball_path) cmd_result = cros_build_lib.CreateTarball( tarball_path, control_dir, compression=cros_build_lib.COMP_BZIP2, inputs=[self.CONTROL_FILE_SUBDIR]) if cmd_result.returncode != 0: logging.error('Error (%d) when tarring control files', cmd_result.returncode) raise PayloadTestError( 'failed to create autotest tarball (return code %d)' % cmd_result.returncode) # Upload the tarball, be sure to make it world-readable. upload_target = os.path.join(self._archive_build_uri, tarball_name) logging.info('Uploading autotest control tarball to %s', upload_target) gslib.Copy(tarball_path, upload_target, acl='public-read') # Do not run the suite for older builds whose suite staging logic is # broken. We use the build's milestone number as a rough estimate to # whether or not it's recent enough. We derive the milestone number from # the archive build name, which takes the form # boardname-release/R12-3456.78.9 (in this case it is 12). try: build_mstone = int( self._archive_build.partition('/')[2].partition('-')[0][1:]) if build_mstone < RUN_SUITE_MIN_MSTONE: logging.warning( 'Build milestone < %s, test suite scheduling skipped', RUN_SUITE_MIN_MSTONE) return except ValueError: raise PayloadTestError( 'Failed to infer archive build milestone number (%s)' % self._archive_build) # Send the information needed to actually schedule and run the tests. return suite_name