bootstrap: Rework bootstrap to do full ChromeOS checkouts.
In order to safely move between new and old branches, the bootstrap
script needs to do checkouts on the branch before invoking the
branched version of cbuildbot.
This will have the advantage of allowing old branches to use
git-cache, after bootstrap supports git-cache.
This is a nearly full rewrite of the bootstrap script.
BUG=chromium:684907
TEST=Unittests.
Change-Id: I887116ef8b921c19c5f83d728d8d9fc96aa3d4ec
Reviewed-on: https://chromium-review.googlesource.com/443138
Commit-Ready: Don Garrett <dgarrett@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
diff --git a/scripts/bootstrap_unittest.py b/scripts/bootstrap_unittest.py
index 21bc7a9..fe59862 100644
--- a/scripts/bootstrap_unittest.py
+++ b/scripts/bootstrap_unittest.py
@@ -6,51 +6,101 @@
from __future__ import print_function
-from chromite.scripts import bootstrap
+import mock
+
+from chromite.cbuildbot import repository
from chromite.lib import cros_build_lib_unittest
-from chromite.lib import cros_test_lib
+from chromite.lib import osutils
+from chromite.scripts import bootstrap
+
+# pylint
+EXPECTED_MANIFEST_URL = 'https://chrome-internal-review.googlesource.com/chromeos/manifest-internal' # pylint: disable=line-too-long
class BootstrapTest(cros_build_lib_unittest.RunCommandTestCase):
"""Tests for bootstrap script."""
- def testExtractBranchName(self):
+ def testPreParseArguments(self):
"""Test that we can correctly extract branch values from cbuildbot args."""
cases = (
- ([], 'master'),
- (['--arg1', 'value', '-a', '--arg2'], 'master'),
- (['--branch', 'branch'], 'branch'),
- (['-b', 'branch'], 'branch'),
- (['--arg1', 'value', '-a', '--branch', 'branch', '--arg2'], 'branch'),
- (['--arg1', '-a', '--branch', 'branch', 'config'], 'branch'),
+ (['--buildroot', '/build'],
+ None, '/build', None),
+ (['--branch', 'branch', '-r', '/build'],
+ 'branch', '/build', None),
+ (['-r', '/build', '-b', 'branch', 'config'],
+ 'branch', '/build', None),
)
- for args, expected in cases:
- result = bootstrap.ExtractBranchName(args)
- self.assertEqual(result, expected)
+ for args, expected_branch, expected_root, expected_git_cache in cases:
+ result = bootstrap.PreParseArguments(args)
+ self.assertEqual(result.branch, expected_branch)
+ self.assertEqual(result.buildroot, expected_root)
+ self.assertEqual(result.git_cache_dir, expected_git_cache)
+
+ def testInitialCheckoutMin(self):
+ """Test InitialCheckout with minimum settings."""
+ mock_repo = self.PatchObject(repository, 'RepoRepository', autospec=True)
+ self.PatchObject(osutils, 'SafeMakedirs', autospec=True)
+
+ bootstrap.InitialCheckout(None, '/buildroot', None)
+
+ self.assertEqual(mock_repo.mock_calls, [
+ mock.call(EXPECTED_MANIFEST_URL, '/buildroot',
+ branch=None, git_cache_dir=None),
+ mock.call().Sync()
+ ])
+
+ def testInitialCheckoutMax(self):
+ """Test InitialCheckout with all settings."""
+ mock_repo = self.PatchObject(repository, 'RepoRepository', autospec=True)
+ self.PatchObject(osutils, 'SafeMakedirs', autospec=True)
+
+ bootstrap.InitialCheckout('release-R56-9000.B', '/buildroot', '/git-cache')
+
+ self.assertEqual(mock_repo.mock_calls, [
+ mock.call(EXPECTED_MANIFEST_URL, '/buildroot',
+ branch='release-R56-9000.B', git_cache_dir='/git-cache'),
+ mock.call().Sync()
+ ])
def testRunCbuildbot(self):
- bootstrap.RunCbuildbot('/mock/chromite', ['foo', 'bar', 'arg'])
+ """Ensure we invoke cbuildbot correctly."""
+ bootstrap.RunCbuildbot('/buildroot', ['foo', 'bar', 'arg'])
self.assertCommandContains(
- ['/mock/chromite/bin/cbuildbot', 'foo', 'bar', 'arg'])
+ ['/buildroot/chromite/bin/cbuildbot', 'foo', 'bar', 'arg'])
- def testMainMaster(self):
- bootstrap.main(['foo'])
+ def testMainMin(self):
+ """Test a minimal set of command line options."""
+ mock_checkout = self.PatchObject(bootstrap, 'InitialCheckout',
+ autospec=True)
- # cbuildbot script is in tempdir, so can't be listed here.
- self.assertCommandContains(['foo'])
+ bootstrap.main(['--buildroot', '/buildroot', 'foo'])
- def testMainBranch(self):
- bootstrap.main(['--branch', 'branch', 'foo'])
+ # Ensure we checkout, as expected.
+ self.assertEqual(mock_checkout.mock_calls,
+ [mock.call(None, '/buildroot', None)])
- # cbuildbot script is in tempdir, so can't be listed here.
- self.assertCommandContains(['--branch', 'branch', 'foo'])
+ # Ensure we invoke cbuildbot, as expected.
+ self.assertCommandCalled(
+ ['/buildroot/chromite/bin/cbuildbot',
+ '--buildroot', '/buildroot', 'foo'],
+ cwd='/buildroot', error_code_ok=True)
+ def testMainMax(self):
+ """Test a maximal set of command line options."""
+ mock_checkout = self.PatchObject(bootstrap, 'InitialCheckout',
+ autospec=True)
-class LiveWorktreeTest(cros_test_lib.TempDirTestCase):
- """Integration tests for git worktree usage."""
+ bootstrap.main(['--buildroot', '/buildroot', '--branch', 'branch',
+ '--git-cache-dir', '/git-cache', 'foo'])
- @cros_test_lib.NetworkTest()
- def testCreateChromiteBranch(self):
- """Test that we can a git worktree, from the current chromite, branched."""
- bootstrap.CloneChromiteOnBranch('release-R56-9000.B', self.tempdir)
+ # Ensure we checkout, as expected.
+ self.assertEqual(mock_checkout.mock_calls,
+ [mock.call('branch', '/buildroot', '/git-cache')])
+
+ # Ensure we invoke cbuildbot, as expected.
+ self.assertCommandCalled(
+ ['/buildroot/chromite/bin/cbuildbot',
+ '--buildroot', '/buildroot', '--branch', 'branch',
+ '--git-cache-dir', '/git-cache', 'foo'],
+ cwd='/buildroot', error_code_ok=True)