From ed210b40ffcc57fc6e8287d209af30d06ff25008 Mon Sep 17 00:00:00 2001 From: Chris Sosa Date: Fri, 19 Nov 2010 14:01:11 -0800 Subject: [PATCH] Add new chrome revving module to crosutils. Have subsequent review for cbuildbot that calls this for the pfq. This module has 3 modes ... TOT, latest_release, sticky_release that describe the three different types of revs for chrome we will be supporting. For tot, we grab the latest svn revision # from the chrome src tree, and rev to the corresponding ebuild i.e. 9.0.553.0_alpha-r1 with CROS_SVN_COMMIT=svn revision number. For latest_release, we grab the latest release from the releases page, and create an ebuild (or rev a previously existing on with same version) and use the release candidate suffix _rc. For sticky_release, we use much of the same logic as latest_release, however, we specifically look to rev _rc's in the sticky branch. This change depends on http://codereview.chromium.org/5172003 for the cros_mark_as_stable changes. Change-Id: Idc1f4cd905cc1dcb4c44422f6104760077a24b8d BUG=chromium-os:8693 TEST=Ran cros_mark_as_stable with --packages="chromeos-base/chromeos-chrome" --chrome_version=0.8.65.0 --chrome_revision=67890 commit. Re-ran unit-tests as well (though thinking about adding another unit test for chrome revving) Review URL: http://codereview.chromium.org/4798001 --- bin/cros_mark_chrome_as_stable | 1 + bin/cros_mark_chrome_as_stable.py | 330 +++++++++++++++++++++ bin/cros_mark_chrome_as_stable_unittest.py | 269 +++++++++++++++++ 3 files changed, 600 insertions(+) create mode 120000 bin/cros_mark_chrome_as_stable create mode 100755 bin/cros_mark_chrome_as_stable.py create mode 100755 bin/cros_mark_chrome_as_stable_unittest.py diff --git a/bin/cros_mark_chrome_as_stable b/bin/cros_mark_chrome_as_stable new file mode 120000 index 0000000000..e429dbe05e --- /dev/null +++ b/bin/cros_mark_chrome_as_stable @@ -0,0 +1 @@ +cros_mark_chrome_as_stable.py \ No newline at end of file diff --git a/bin/cros_mark_chrome_as_stable.py b/bin/cros_mark_chrome_as_stable.py new file mode 100755 index 0000000000..3f8802ad3a --- /dev/null +++ b/bin/cros_mark_chrome_as_stable.py @@ -0,0 +1,330 @@ +#!/usr/bin/python2.4 + +# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""This module uprevs Chrome for cbuildbot.""" + +import optparse +import os +import re +import sys +import urllib + +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +import cros_mark_as_stable + +sys.path.append(os.path.join(os.path.dirname(__file__), '../lib')) +from cros_build_lib import RunCommand, Info, Warning + +BASE_CHROME_SVN_URL = 'http://src.chromium.org/svn' + +# Command for which chrome ebuild to uprev. +TIP_OF_TRUNK, LATEST_RELEASE, STICKY = 'tot', 'latest_release', 'sticky_release' +CHROME_REV = [TIP_OF_TRUNK, LATEST_RELEASE, STICKY] + +# Helper regex's for finding ebuilds. +_CHROME_VERSION_REGEX = '\d+\.\d+\.\d+\.\d+' +_NON_STICKY_REGEX = '%s[(_rc.*)|(_alpha.*)]+' % _CHROME_VERSION_REGEX + +# Dir where all the action happens. +_CHROME_OVERLAY_DIR = ('%(srcroot)s/third_party/chromiumos-overlay' + '/chromeos-base/chromeos-chrome') + +# Different than cros_mark so devs don't have local collisions. +_STABLE_BRANCH_NAME = 'chrome_stabilizing_branch' + +_GIT_COMMIT_MESSAGE = ('Marking %(chrome_rev)s for chrome ebuild with version ' + '%(chrome_version)s as stable.') + + +def _GetSvnUrl(): + """Returns the path to the svn url for the given chrome branch.""" + return os.path.join(BASE_CHROME_SVN_URL, 'trunk') + + +def _GetTipOfTrunkSvnRevision(): + """Returns the current svn revision for the chrome tree.""" + svn_url = _GetSvnUrl() + svn_info = RunCommand(['svn', 'info', svn_url], redirect_stdout=True) + + revision_re = re.compile('^Revision:\s+(\d+).*') + for line in svn_info.splitlines(): + match = revision_re.search(line) + if match: + return match.group(1) + + raise Exception('Could not find revision information from %s' % svn_url) + + +def _GetTipOfTrunkVersion(): + """Returns the current Chrome version.""" + svn_url = _GetSvnUrl() + chrome_version_file = urllib.urlopen(os.path.join(svn_url, 'src', 'chrome', + 'VERSION')) + chrome_version_info = chrome_version_file.read() + chrome_version_file.close() + + # Sanity check. + if '404 Not Found' in chrome_version_info: + raise Exception('Url %s does not have version file.' % svn_url) + + chrome_version_array = [] + + for line in chrome_version_info.splitlines(): + chrome_version_array.append(line.rpartition('=')[2]) + + return '.'.join(chrome_version_array) + + +def _GetLatestRelease(branch=None): + """Gets the latest release version from the buildspec_url for the branch. + + Args: + branch: If set, gets the latest release for branch, otherwise latest + release. + Returns: + Latest version string. + """ + buildspec_url = 'http://src.chromium.org/svn/releases' + svn_ls = RunCommand(['svn', 'ls', buildspec_url], redirect_stdout=True) + sorted_ls = RunCommand(['sort', '--version-sort'], input=svn_ls, + redirect_stdout=True) + if branch: + chrome_version_re = re.compile('^%s\.\d+.*' % branch) + else: + chrome_version_re = re.compile('^[0-9]\..*') + for chrome_version in sorted_ls.splitlines(): + if chrome_version_re.match(chrome_version): + current_version = chrome_version + + return current_version.rstrip('/') + + +def _GetStickyVersion(stable_ebuilds): + """Discovers the sticky version from the current stable_ebuilds.""" + sticky_ebuilds = [] + non_sticky_re = re.compile(_NON_STICKY_REGEX) + for ebuild in stable_ebuilds: + if not non_sticky_re.match(ebuild.version): + sticky_ebuilds.append(ebuild) + + if not sticky_ebuilds: + raise Exception('No sticky ebuilds found') + elif len(sticky_ebuilds) > 1: + Warning('More than one sticky ebuild found') + + return cros_mark_as_stable.BestEBuild(sticky_ebuilds).chrome_version + + +class ChromeEBuild(cros_mark_as_stable.EBuild): + """Thin sub-class of EBuild that adds a chrome_version field.""" + chrome_version_re = re.compile('.*chromeos-chrome-(%s|9999).*' % ( + _CHROME_VERSION_REGEX)) + chrome_version = '' + + def __init__(self, path): + cros_mark_as_stable.EBuild.__init__(self, path) + re_match = self.chrome_version_re.match(self.ebuild_path_no_revision) + if re_match: + self.chrome_version = re_match.group(1) + + def __cmp__(self, other): + """Use ebuild paths for comparison.""" + if self.ebuild_path == other.ebuild_path: + return 0 + elif self.ebuild_path > other.ebuild_path: + return 1 + else: + return (-1) + + +def FindChromeCandidates(overlay_dir): + """Return a tuple of chrome's unstable ebuild and stable ebuilds. + + Args: + overlay_dir: The path to chrome's portage overlay dir. + Returns: + Tuple [unstable_ebuild, stable_ebuilds]. + Raises: + Exception: if no unstable ebuild exists for Chrome. + """ + stable_ebuilds = [] + unstable_ebuilds = [] + for path in [ + os.path.join(overlay_dir, entry) for entry in os.listdir(overlay_dir)]: + if path.endswith('.ebuild'): + ebuild = ChromeEBuild(path) + if not ebuild.chrome_version: + Warning('Poorly formatted ebuild found at %s' % path) + else: + if not ebuild.is_stable: + unstable_ebuilds.append(ebuild) + else: + stable_ebuilds.append(ebuild) + + # Apply some sanity checks. + if not unstable_ebuilds: + raise Exception('Missing 9999 ebuild for %s' % overlay_dir) + if not stable_ebuilds: + Warning('Missing stable ebuild for %s' % overlay_dir) + + return cros_mark_as_stable.BestEBuild(unstable_ebuilds), stable_ebuilds + + +def FindChromeUprevCandidate(stable_ebuilds, chrome_rev, sticky_branch): + """Finds the Chrome uprev candidate for the given chrome_rev. + + Using the pre-flight logic, this means the stable ebuild you are uprevving + from. The difference here is that the version could be different and in + that case we want to find it to delete it. + + Args: + stable_ebuilds: A list of stable ebuilds. + chrome_rev: The chrome_rev designating which candidate to find. + sticky_branch: The the branch that is currently sticky with Major/Minor + components. For example: 9.0.553 + Returns: + Returns the EBuild, otherwise None if none found. + """ + candidates = [] + if chrome_rev == TIP_OF_TRUNK: + chrome_branch_re = re.compile('%s.*_alpha.*' % _CHROME_VERSION_REGEX) + for ebuild in stable_ebuilds: + if chrome_branch_re.search(ebuild.version): + candidates.append(ebuild) + + elif chrome_rev == STICKY: + chrome_branch_re = re.compile('%s\.\d+.*_rc.*' % sticky_branch) + for ebuild in stable_ebuilds: + if chrome_branch_re.search(ebuild.version): + candidates.append(ebuild) + + else: + chrome_branch_re = re.compile('%s.*_rc.*' % _CHROME_VERSION_REGEX) + for ebuild in stable_ebuilds: + if chrome_branch_re.search(ebuild.version) and ( + not ebuild.chrome_version.startswith(sticky_branch)): + candidates.append(ebuild) + + if candidates: + return cros_mark_as_stable.BestEBuild(candidates) + else: + return None + + +def MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_rev, + chrome_version, commit, overlay_dir): + """Uprevs the chrome ebuild specified by chrome_rev. + + This is the main function that uprevs the chrome_rev from a stable candidate + to its new version. + + Args: + stable_candidate: ebuild that corresponds to the stable ebuild we are + revving from. If None, builds the a new ebuild given the version + and logic for chrome_rev type with revision set to 1. + unstable_ebuild: ebuild corresponding to the unstable ebuild for chrome. + chrome_rev: one of CHROME_REV + TIP_OF_TRUNK - Requires commit value. Revs the ebuild for the TOT + version and uses the portage suffix of _alpha. + LATEST_RELEASE - This uses the portage suffix of _rc as they are release + candidates for the next sticky version. + STICKY - Revs the sticky version. + chrome_version: The \d.\d.\d.\d version of Chrome. + commit: Used with TIP_OF_TRUNK. The svn revision of chrome. + overlay_dir: Path to the chromeos-chrome package dir. + """ + base_path = os.path.join(overlay_dir, 'chromeos-chrome-%s' % chrome_version) + # Case where we have the last stable candidate with same version just rev. + if stable_candidate and stable_candidate.chrome_version == chrome_version: + new_ebuild_path = '%s-r%d.ebuild' % ( + stable_candidate.ebuild_path_no_revision, + stable_candidate.current_revision + 1) + else: + if chrome_rev == TIP_OF_TRUNK: + portage_suffix = '_alpha' + else: + portage_suffix = '_rc' + + new_ebuild_path = base_path + ('%s-r1.ebuild' % portage_suffix) + + cros_mark_as_stable.EBuildStableMarker.MarkAsStable( + unstable_ebuild.ebuild_path, new_ebuild_path, 'CROS_SVN_COMMIT', commit) + RunCommand(['git', 'add', new_ebuild_path]) + if stable_candidate: + RunCommand(['git', 'rm', stable_candidate.ebuild_path]) + + cros_mark_as_stable.EBuildStableMarker.CommitChange( + _GIT_COMMIT_MESSAGE % {'chrome_rev': chrome_rev, + 'chrome_version': chrome_version}) + + +def main(argv): + usage = '%s OPTIONS commit|clean|push' + parser = optparse.OptionParser(usage) + parser.add_option('-c', '--chrome_rev', default=None, + help='One of %s' % CHROME_REV) + parser.add_option('-s', '--srcroot', default='.', + help='Path to the src directory') + parser.add_option('-t', '--tracking_branch', default='cros/master', + help='Branch we are tracking changes against') + (options, argv) = parser.parse_args(argv) + + if len(argv) != 2 or argv[1] not in ( + cros_mark_as_stable.COMMAND_DICTIONARY.keys()): + parser.error('Arguments are invalid, see usage.') + + command = argv[1] + overlay_dir = os.path.abspath(_CHROME_OVERLAY_DIR % + {'srcroot': options.srcroot}) + + os.chdir(overlay_dir) + if command == 'clean': + cros_mark_as_stable.Clean(options.tracking_branch) + return + elif command == 'push': + cros_mark_as_stable.PushChange(_STABLE_BRANCH_NAME, options.tracking_branch) + return + + if not options.chrome_rev or options.chrome_rev not in CHROME_REV: + parser.error('Commit requires type set to one of %s.' % CHROME_REV) + + chrome_rev = options.chrome_rev + version_to_uprev = None + commit_to_use = None + + (unstable_ebuild, stable_ebuilds) = FindChromeCandidates(overlay_dir) + sticky_version = _GetStickyVersion(stable_ebuilds) + sticky_branch = sticky_version.rpartition('.')[0] + + if chrome_rev == TIP_OF_TRUNK: + version_to_uprev = _GetTipOfTrunkVersion() + commit_to_use = _GetTipOfTrunkSvnRevision() + elif chrome_rev == LATEST_RELEASE: + version_to_uprev = _GetLatestRelease() + else: + version_to_uprev = _GetLatestRelease(sticky_branch) + + stable_candidate = FindChromeUprevCandidate(stable_ebuilds, chrome_rev, + sticky_branch) + # There are some cases we don't need to do anything. Check for them. + if stable_candidate and (version_to_uprev == stable_candidate.chrome_version + and not commit_to_use): + Info('Found nothing to do for chrome_rev %s with version %s.' % ( + chrome_rev, version_to_uprev)) + else: + work_branch = cros_mark_as_stable.GitBranch( + _STABLE_BRANCH_NAME, options.tracking_branch) + work_branch.CreateBranch() + try: + MarkChromeEBuildAsStable(stable_candidate, unstable_ebuild, chrome_rev, + version_to_uprev, commit_to_use, overlay_dir) + except: + work_branch.Delete() + raise + + +if __name__ == '__main__': + main(sys.argv) diff --git a/bin/cros_mark_chrome_as_stable_unittest.py b/bin/cros_mark_chrome_as_stable_unittest.py new file mode 100755 index 0000000000..ab16cd68ea --- /dev/null +++ b/bin/cros_mark_chrome_as_stable_unittest.py @@ -0,0 +1,269 @@ +#!/usr/bin/python + +# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Unit tests for cros_mark_chrome_as_stable.py.""" + +import cros_mark_chrome_as_stable +import mox +import os +import shutil +import sys +import tempfile +import unittest +import urllib + +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +import cros_mark_as_stable + +unstable_data = 'KEYWORDS=~x86 ~arm' +stable_data = 'KEYWORDS=x86 arm' + +def _TouchAndWrite(path, data=None): + """Writes data (if it exists) to the file specified by the path.""" + fh = open(path, 'w') + if data: + fh.write(data) + + fh.close() + + +class CrosMarkChromeAsStable(mox.MoxTestBase): + + def setUp(self): + """Setup vars and create mock dir.""" + mox.MoxTestBase.setUp(self) + self.tmp_overlay = tempfile.mkdtemp(prefix='chromiumos-overlay') + self.mock_chrome_dir = os.path.join(self.tmp_overlay, 'chromeos-base', + 'chromeos-chrome') + os.makedirs(self.mock_chrome_dir) + + self.unstable = os.path.join(self.mock_chrome_dir, + 'chromeos-chrome-9999.ebuild') + self.sticky_branch = '8.0.224' + self.sticky_version = '%s.503' % self.sticky_branch + self.sticky = os.path.join(self.mock_chrome_dir, + 'chromeos-chrome-%s.ebuild' % + self.sticky_version) + self.sticky_rc_version = '%s.504' % self.sticky_branch + self.sticky_rc = os.path.join(self.mock_chrome_dir, + 'chromeos-chrome-%s_rc-r1.ebuild' % + self.sticky_rc_version) + self.latest_stable_version = '8.0.300.1' + self.latest_stable = os.path.join(self.mock_chrome_dir, + 'chromeos-chrome-%s_rc-r2.ebuild' % + self.latest_stable_version) + self.tot_stable_version = '9.0.305.0' + self.tot_stable = os.path.join(self.mock_chrome_dir, + 'chromeos-chrome-%s_alpha-r1.ebuild' % + self.tot_stable_version) + + self.sticky_new_rc_version = '%s.520' % self.sticky_branch + self.sticky_new_rc = os.path.join(self.mock_chrome_dir, + 'chromeos-chrome-%s_rc-r1.ebuild' % + self.sticky_new_rc_version) + self.latest_new_version = '9.0.305.1' + self.latest_new = os.path.join(self.mock_chrome_dir, + 'chromeos-chrome-%s_rc-r1.ebuild' % + self.latest_new_version) + self.tot_new_version = '9.0.306.0' + self.tot_new = os.path.join(self.mock_chrome_dir, + 'chromeos-chrome-%s_alpha-r1.ebuild' % + self.tot_new_version) + + _TouchAndWrite(self.unstable, unstable_data) + _TouchAndWrite(self.sticky, stable_data) + _TouchAndWrite(self.sticky_rc, stable_data) + _TouchAndWrite(self.latest_stable, stable_data) + _TouchAndWrite(self.tot_stable, stable_data) + + def tearDown(self): + """Cleans up mock dir.""" + shutil.rmtree(self.tmp_overlay) + + def testFindChromeCandidates(self): + """Test creation of stable ebuilds from mock dir.""" + unstable, stable_ebuilds = cros_mark_chrome_as_stable.FindChromeCandidates( + self.mock_chrome_dir) + + self.assertEqual(unstable.ebuild_path, self.unstable) + self.assertEqual(len(stable_ebuilds), 4) + self.assertTrue(cros_mark_chrome_as_stable.ChromeEBuild(self.sticky) in + stable_ebuilds) + self.assertTrue(cros_mark_chrome_as_stable.ChromeEBuild(self.sticky_rc) in + stable_ebuilds) + self.assertTrue(cros_mark_chrome_as_stable.ChromeEBuild(self.latest_stable) + in stable_ebuilds) + self.assertTrue(cros_mark_chrome_as_stable.ChromeEBuild(self.tot_stable) in + stable_ebuilds) + + def _GetStableEBuilds(self): + """Common helper to create a list of stable ebuilds.""" + return [ + cros_mark_chrome_as_stable.ChromeEBuild(self.sticky), + cros_mark_chrome_as_stable.ChromeEBuild(self.sticky_rc), + cros_mark_chrome_as_stable.ChromeEBuild(self.latest_stable), + cros_mark_chrome_as_stable.ChromeEBuild(self.tot_stable), + ] + + def testTOTFindChromeUprevCandidate(self): + """Tests if we can find tot uprev candidate from our mock dir data.""" + stable_ebuilds = self._GetStableEBuilds() + + candidate = cros_mark_chrome_as_stable.FindChromeUprevCandidate( + stable_ebuilds, cros_mark_chrome_as_stable.TIP_OF_TRUNK, + self.sticky_branch) + + self.assertEqual(candidate.ebuild_path, self.tot_stable) + + def testLatestFindChromeUprevCandidate(self): + """Tests if we can find latest uprev candidate from our mock dir data.""" + stable_ebuilds = self._GetStableEBuilds() + + candidate = cros_mark_chrome_as_stable.FindChromeUprevCandidate( + stable_ebuilds, cros_mark_chrome_as_stable.LATEST_RELEASE, + self.sticky_branch) + + self.assertEqual(candidate.ebuild_path, self.latest_stable) + + def testStickyFindChromeUprevCandidate(self): + """Tests if we can find sticky uprev candidate from our mock dir data.""" + stable_ebuilds = self._GetStableEBuilds() + + candidate = cros_mark_chrome_as_stable.FindChromeUprevCandidate( + stable_ebuilds, cros_mark_chrome_as_stable.STICKY, + self.sticky_branch) + + self.assertEqual(candidate.ebuild_path, self.sticky_rc) + + def testGetTipOfTrunkSvnRevision(self): + """Tests if we can get the latest svn revision from TOT.""" + self.mox.StubOutWithMock(cros_mark_chrome_as_stable, 'RunCommand') + cros_mark_chrome_as_stable.RunCommand( + ['svn', 'info', cros_mark_chrome_as_stable._GetSvnUrl()], + redirect_stdout=True).AndReturn( + 'Some Junk 2134\nRevision: 12345\nOtherInfo: test_data') + self.mox.ReplayAll() + revision = cros_mark_chrome_as_stable._GetTipOfTrunkSvnRevision() + self.mox.VerifyAll() + self.assertEquals(revision, '12345') + + def testGetTipOfTrunkVersion(self): + """Tests if we get the latest version from TOT.""" + self.mox.StubOutWithMock(urllib, 'urlopen') + mock_file = self.mox.CreateMock(file) + urllib.urlopen(os.path.join(cros_mark_chrome_as_stable._GetSvnUrl(), 'src', + 'chrome', 'VERSION')).AndReturn(mock_file) + mock_file.read().AndReturn('A=8\nB=0\nC=256\nD=0') + mock_file.close() + + self.mox.ReplayAll() + version = cros_mark_chrome_as_stable._GetTipOfTrunkVersion() + self.mox.VerifyAll() + self.assertEquals(version, '8.0.256.0') + + def testGetLatestRelease(self): + """Tests if we can find the latest release from our mock url data.""" + test_data = '\n'.join(['7.0.224.1/', + '7.0.224.2/', + '8.0.365.5/', + 'LATEST.txt']) + self.mox.StubOutWithMock(cros_mark_chrome_as_stable, 'RunCommand') + cros_mark_chrome_as_stable.RunCommand( + ['svn', 'ls', 'http://src.chromium.org/svn/releases'], + redirect_stdout=True).AndReturn('some_data') + cros_mark_chrome_as_stable.RunCommand( + ['sort', '--version-sort'], input='some_data', + redirect_stdout=True).AndReturn(test_data) + self.mox.ReplayAll() + release = cros_mark_chrome_as_stable._GetLatestRelease() + self.mox.VerifyAll() + self.assertEqual('8.0.365.5', release) + + def testGetLatestStickyRelease(self): + """Tests if we can find the latest sticky release from our mock url data.""" + test_data = '\n'.join(['7.0.222.1/', + '8.0.224.2/', + '8.0.365.5/', + 'LATEST.txt']) + self.mox.StubOutWithMock(cros_mark_chrome_as_stable, 'RunCommand') + cros_mark_chrome_as_stable.RunCommand( + ['svn', 'ls', 'http://src.chromium.org/svn/releases'], + redirect_stdout=True).AndReturn('some_data') + cros_mark_chrome_as_stable.RunCommand( + ['sort', '--version-sort'], input='some_data', + redirect_stdout=True).AndReturn(test_data) + self.mox.ReplayAll() + release = cros_mark_chrome_as_stable._GetLatestRelease(self.sticky_branch) + self.mox.VerifyAll() + self.assertEqual('8.0.224.2', release) + + def testStickyVersion(self): + """Tests if we can find the sticky version from our mock directories.""" + stable_ebuilds = self._GetStableEBuilds() + sticky_version = cros_mark_chrome_as_stable._GetStickyVersion( + stable_ebuilds) + self.assertEqual(sticky_version, self.sticky_version) + + def testChromeEBuildInit(self): + """Tests if the chrome_version is set correctly in a ChromeEBuild.""" + ebuild = cros_mark_chrome_as_stable.ChromeEBuild(self.sticky) + self.assertEqual(ebuild.chrome_version, self.sticky_version) + + def _CommonMarkAsStableTest(self, chrome_rev, new_version, old_ebuild_path, + new_ebuild_path, commit_string_indicator): + """Common function used for test functions for MarkChromeEBuildAsStable. + + This function stubs out others calls, and runs MarkChromeEBuildAsStable + with the specified args. + + Args: + chrome_rev: standard chrome_rev argument + new_version: version we are revving up to + old_ebuild_path: path to the stable ebuild + new_ebuild_path: path to the to be created path + commit_string_indicator: a string that the commit message must contain + """ + self.mox.StubOutWithMock(cros_mark_chrome_as_stable, 'RunCommand') + self.mox.StubOutWithMock(cros_mark_as_stable.EBuildStableMarker, + 'CommitChange') + stable_candidate = cros_mark_chrome_as_stable.ChromeEBuild(old_ebuild_path) + unstable_ebuild = cros_mark_chrome_as_stable.ChromeEBuild(self.unstable) + chrome_version = new_version + commit = None + overlay_dir = self.mock_chrome_dir + + cros_mark_chrome_as_stable.RunCommand(['git', 'add', new_ebuild_path]) + cros_mark_chrome_as_stable.RunCommand(['git', 'rm', old_ebuild_path]) + cros_mark_as_stable.EBuildStableMarker.CommitChange( + mox.StrContains(commit_string_indicator)) + + self.mox.ReplayAll() + cros_mark_chrome_as_stable.MarkChromeEBuildAsStable( + stable_candidate, unstable_ebuild, chrome_rev, chrome_version, commit, + overlay_dir) + self.mox.VerifyAll() + + def testStickyMarkAsStable(self): + """Tests to see if we can mark chrome as stable for a new sticky release.""" + self._CommonMarkAsStableTest(cros_mark_chrome_as_stable.STICKY, + self.sticky_new_rc_version, self.sticky_rc, + self.sticky_new_rc, 'sticky_release') + + def testLatestMarkAsStable(self): + """Tests to see if we can mark chrome for a latest release.""" + self._CommonMarkAsStableTest(cros_mark_chrome_as_stable.LATEST_RELEASE, + self.latest_new_version, self.latest_stable, + self.latest_new, 'latest_release') + + def testTotMarkAsStable(self): + """Tests to see if we can mark chrome for tot.""" + self._CommonMarkAsStableTest(cros_mark_chrome_as_stable.TIP_OF_TRUNK, + self.tot_new_version, self.tot_stable, + self.tot_new, 'tot') + + +if __name__ == '__main__': + unittest.main()