def _create_gerrit_instance(self, tmp_dir): default_host = 't3st-chr0m3' git_host = os.environ.get('CROS_TEST_GIT_HOST', constants.GOB_HOST % default_host) gerrit_host = os.environ.get( 'CROS_TEST_GERRIT_HOST', '%s-review.googlesource.com' % default_host) project_prefix = 'test-%s/' % (cros_build_lib.GetRandomString(), ) cookies_path = os.environ.get('CROS_TEST_COOKIES_PATH', constants.GITCOOKIES_PATH) # "o" is the cookie name that GoB uses in its instructions. cookie_names_str = os.environ.get('CROS_TEST_COOKIE_NAMES', 'o') cookie_names = {c for c in cookie_names_str.split(',') if c} tmpcookies_path = os.path.join(tmp_dir, '.gitcookies') if os.path.exists(cookies_path): shutil.copy(cookies_path, tmpcookies_path) else: osutils.Touch(tmpcookies_path) return self.GerritInstance( cookie_names=cookie_names, cookies_path=tmpcookies_path, gerrit_host=gerrit_host, gerrit_url='https://%s/' % gerrit_host, git_host=git_host, git_url='https://%s/' % git_host, project_prefix=project_prefix, )
def testGetHashSignatures(self): """Integration test that talks to the real signer with test hashes.""" ctx = gs.GSContext() clean_uri = ( 'gs://chromeos-releases/test-channel/%s/crostools-client/**' % (cros_build_lib.GetRandomString(), )) # Cleanup before we start ctx.Remove(clean_uri, ignore_missing=True) try: hashes = [ b'0' * 32, b'1' * 32, (b'29834370e415b3124a926c903906f18b' b'3d52e955147f9e6accd67e9512185a63') ] keysets = ['update_signer'] expected_sigs_hex = (( 'ba4c7a86b786c609bf6e4c5fb9c47525608678caa532bea8acc457aa6dd32b43' '5f094b331182f2e167682916990c40ff7b6b0128de3fa45ad0fd98041ec36d6f' '63b867bcf219804200616590a41a727c2685b48340efb4b480f1ef448fc7bc3f' 'b1c4b53209e950ecc721b07a52a41d9c025fd25602340c93d5295211308caa29' 'a03ed18516cf61411c508097d5b47620d643ed357b05213b2b9fa3a3f938d6c4' 'f52b85c3f9774edc376902458344d1c1cd72bc932f033c076c76fee2400716fe' '652306871ba923021ce245e0c778ad9e0e50e87a169b2aea338c4dc8b5c0c716' 'aabfb6133482e8438b084a09503db27ca546e910f8938f7805a8a76a3b0d0241', ), ( '2d909ca5b33a7fb6f2323ca0bf9de2e4f2266c73da4b6948a517dffa96783e08' 'ca36411d380f6e8a20011f599d8d73576b2a141a57c0873d089726e24f62c7e0' '346ba5fbde68414b0f874b627fb1557a6e9658c8fac96c54f458161ea770982b' 'fa9fe514120635e5ccb32e8219b9069cb0bf8063fba48d60d649c5af203cccef' 'ca5dbc2191f81f0215edbdee4ec8c1553e69b83036aca3e840227d317ff6cf8b' '968c973f698db1ce59f6871303dcdbe839400c5df4d2e6e505d68890010a4459' '6ca9fee77f4db6ea3448d98018437c319fc8c5f4603ef94b04e3a4eafa206b73' '91a2640d43128310285bc0f1c7e5060d37c433d663b1c6f01110b9a43f2a74f4', ), ('23791c99ab937f1ae5d4988afc9ceca39c290ac90e3da9f243f9a0b1c86c3c32' 'ab7241d43dfc233da412bab989cf02f15a01fe9ea4b2dc7dc9182117547836d6' '9310af3aa005ee3a6deb9602bc676dcc103bf3f7831d64ab844b4785c5c8b4b1' '4467e6b5ab6bf34c12f7534e0d5140151c8f28e8276e703dd6332c2bab9e7f4a' '495215998ff56e476b81bd6b8d765e1f87da50c22cd52c9afa8c43a6528ab898' '6d7a273d9136d5aff5c4d95985d16eeec7380539ef963e0784a0de42b42890df' 'c83702179f69f5c6eca4630807fbc4ab6241017e0942b15feada0b240e9729bf' '33bf456bd419da63302477e147963550a45c6cf60925ff48ad7b309fa158dcb2', )) expected_sigs = [[base64.b16decode(x[0], True)] for x in expected_sigs_hex] all_signatures = self.client.GetHashSignatures(hashes, keysets) self.assertEqual(all_signatures, expected_sigs) self.assertRaises(gs.GSNoSuchKey, ctx.List, clean_uri) finally: # Cleanup when we are over. ctx.Remove(clean_uri, ignore_missing=True)
def TemporaryURL(prefix): """Context manager to generate a random URL. At the end, the URL will be deleted. """ url = '%s/chromite-temp/%s/%s/%s' % (constants.TRASH_BUCKET, prefix, getpass.getuser(), cros_build_lib.GetRandomString()) ctx = GSContext() ctx.Remove(url, ignore_missing=True, recursive=True) try: yield url finally: ctx.Remove(url, ignore_missing=True, recursive=True)
def __init__(self, options): super(PinchromeCommand, self).__init__(options) # Make up a branch name which is unlikely to collide. self.branch_name = 'chrome_pin_' + cros_build_lib.GetRandomString()
def testGetRandomString(self): """Verify it looks sane.""" data = cros_build_lib.GetRandomString() self.assertRegex(data, r'^[a-z0-9]+$') self.assertEqual(32, len(data))
def UprevChrome(self, work_dir, pfq_build, build_number): """Uprev Chrome. Args: work_dir: directory to clone repository and update uprev. pfq_build: pfq build_id to uprev chrome. build_number: corresponding build number showed on waterfall. Raises: Exception when no commit ID is found in the public overlay CL. Exception when no commit ID is found in the private overlay CL. """ # Verify the format of reviewers reviewers = self.options.reviewers self.ValidateReviewers(reviewers) pub_overlay = os.path.join(work_dir, 'pub_overlay') priv_overlay = os.path.join(work_dir, 'priv_overlay') print('Setting up working directory...') # TODO(nxia): move cros_pinchrome.CloneWorkingRepo to a util class? cros_pinchrome.CloneWorkingRepo(pub_overlay, PUB_OVERLAY_URL, PUB_OVERLAY, MASTER_BRANCH) cros_pinchrome.CloneWorkingRepo(priv_overlay, PRIV_OVERLAY_URL, PRIV_OVERLAY, MASTER_BRANCH) print('Preparing CLs...') remote = 'origin' branch_name = constants.STAGING_PFQ_BRANCH_PREFIX + pfq_build remote_ref = ('refs/' + constants.PFQ_REF + '/' + branch_name) local_branch = '%s_%s' % (branch_name, cros_build_lib.GetRandomString()) logging.info('Checking remote refs.') self.CheckRemoteBranch(pub_overlay, remote, remote_ref) self.CheckRemoteBranch(priv_overlay, remote, remote_ref) # Fetch the remote refspec for the public overlay logging.info('git fetch %s %s:%s', remote, remote_ref, local_branch) git.RunGit(pub_overlay, ['fetch', remote, '%s:%s' % (remote_ref, local_branch)]) logging.info('git checkout %s', local_branch) git.RunGit(pub_overlay, ['checkout', local_branch]) pub_commit_body = self.ParseGitLog(pub_overlay) commit_message = self.CommitMessage(pub_commit_body, pfq_build, build_number) # Update the commit message and reset author. pub_cid = git.Commit(pub_overlay, commit_message, amend=True, reset_author=True) if not pub_cid: raise Exception( "Don't know the commit ID of the public overlay CL.") # Fetch the remote refspec for the private overlay. logging.info('git fetch %s %s:%s', remote, remote_ref, local_branch) git.RunGit(priv_overlay, ['fetch', remote, '%s:%s' % (remote_ref, local_branch)]) git.RunGit(priv_overlay, ['checkout', local_branch]) logging.info('git checkout %s', local_branch) priv_commit_body = self.ParseGitLog(priv_overlay) # Add CQ-DEPEND commit_message = self.CommitMessage(priv_commit_body, pfq_build, build_number, pub_cid) # Update the commit message and reset author priv_cid = git.Commit(priv_overlay, commit_message, amend=True, reset_author=True) if not priv_cid: raise Exception( "Don't know the commit ID of the private overlay CL.") # Add CQ-DEPEND commit_message = self.CommitMessage(pub_commit_body, pfq_build, build_number, '*' + priv_cid, pub_cid) git.Commit(pub_overlay, commit_message, amend=True) overlays = [(pub_overlay, PUB_OVERLAY_URL), (priv_overlay, PRIV_OVERLAY_URL)] for (_overlay, _overlay_url) in overlays: logging.info('git pull --rebase %s %s', remote, MASTER_BRANCH) git.RunGit(_overlay, ['pull', '--rebase', remote, MASTER_BRANCH]) logging.info('Upload CLs to Gerrit.') git.UploadCL(_overlay, _overlay_url, MASTER_BRANCH, skip=self.options.dry_run, draft=self.options.draft, debug_level=logging.NOTICE, reviewers=reviewers) print('Please review and submit the CLs together from Gerrit.') print('Successfully run cros uprevchrome!')
def PayloadName(channel, board, version, key=None, random_str=None, src_version=None, unsigned_image_type='test'): """Creates the gspath for a payload associated with a given build. Args: channel: What channel does the build belong to? Usually "xxx-channel". board: What board is the build for? "x86-alex", "lumpy", etc. version: What is the build version? "3015.0.0", "1945.76.3", etc key: What is the signing key? "premp", "mp", "mp-v2", etc; None (default) indicates that the image is not signed, e.g. a test image image_channel: Sometimes an image has a different channel than the build directory it's in. (ie: nplusone). image_version: Sometimes an image has a different version than the build directory it's in. (ie: nplusone). random_str: Force a given random string. None means generate one. src_version: If this payload is a delta, this is the version of the image it updates from. unsigned_image_type: the type descriptor (string) of an unsigned image; significant iff key is None (default: "test") Returns: The name for the specified build's payloads. Should be of the form: chromeos_0.12.433.257-2913.377.0_x86-alex_stable-channel_ delta_mp-v3.bin-b334762d0f6b80f471069153bbe8b97a.signed chromeos_2913.377.0_x86-alex_stable-channel_full_mp-v3. bin-610c97c30fae8561bde01a6116d65cb9.signed """ if random_str is None: random_str = cros_build_lib.GetRandomString() if key is None: signed_ext = '' key = unsigned_image_type else: signed_ext = '.signed' if src_version: template = ( 'chromeos_%(src_version)s-%(version)s_%(board)s_%(channel)s_' 'delta_%(key)s.bin-%(random_str)s%(signed_ext)s') return template % { 'channel': channel, 'board': board, 'version': version, 'key': key, 'random_str': random_str, 'src_version': src_version, 'signed_ext': signed_ext, } else: template = ('chromeos_%(version)s_%(board)s_%(channel)s_' 'full_%(key)s.bin-%(random_str)s%(signed_ext)s') return template % { 'channel': channel, 'board': board, 'version': version, 'key': key, 'random_str': random_str, 'signed_ext': signed_ext, }
def DLCPayloadName(channel, board, version, dlc_id, dlc_package, random_str=None, src_version=None, sign=True): """Creates the payload file name of a DLC image. Args: channel: What channel does the build belong to? Usually "xxx-channel". board: What board is the build for? "x86-alex", "lumpy", etc. version: What is the build version? "3015.0.0", "1945.76.3", etc dlc_id: This is the ID of the DLC module. dlc_package: Package name of the DLC module. random_str: Force a given random string. None means generate one. src_version: If this payload is a delta, this is the version of the image it updates from. sign: Whether to sign the payload. Returns: The name for the specified build's payloads. Should be in the form of: dlc_dummy-dlc_dummy-package_11869.0.0_kevin-arcnext_canary-channel_full .bin-250bc111ea4955aebc2af08db1f1773c.signed """ if random_str is None: random_str = cros_build_lib.GetRandomString() if sign is True: signed_ext = '.signed' else: signed_ext = '' if src_version: template = ( 'dlc_%(dlc_id)s_%(dlc_package)s_%(src_version)s-%(version)s_' '%(board)s_%(channel)s_delta.bin-%(random_str)s' '%(signed_ext)s') return template % { 'dlc_id': dlc_id, 'dlc_package': dlc_package, 'channel': channel, 'board': board, 'version': version, 'random_str': random_str, 'src_version': src_version, 'signed_ext': signed_ext, } else: template = ('dlc_%(dlc_id)s_%(dlc_package)s_%(version)s_%(board)s_' '%(channel)s_full.bin-%(random_str)s%(signed_ext)s') return template % { 'dlc_id': dlc_id, 'dlc_package': dlc_package, 'channel': channel, 'board': board, 'version': version, 'random_str': random_str, 'signed_ext': signed_ext, }