Revert "cbuildbot_launch: Move cbuildbot checkout to subdirectory."

This reverts commit 783b257a6ee52e9db95fe32e359271afec6d09bb.

Reason for revert: seems to break many builders, causing chromite/cbuildbot/repository.py to complain /b/cbuild/repository is not the root of a repository.

Original change's description:
> cbuildbot_launch: Move cbuildbot checkout to subdirectory.
> 
> Move the repo checkout to a subdirectory of cbuildbot_launches working
> directory. This allows us to break apart various directories (such as
> the cache) apart from the source control managed directories. In
> particular, this allows the buildroot state value to be preserved even
> when we wipe out the repo checkout.
> 
> BUG=chromium:682071
> TEST=Unittests + local build/test script.
> 
> Change-Id: I84d868703888deae5ae4c8f698c8ffb580d529a1
> Reviewed-on: https://chromium-review.googlesource.com/510019
> Commit-Ready: Don Garrett <dgarrett@chromium.org>
> Tested-by: Don Garrett <dgarrett@chromium.org>
> Reviewed-by: Don Garrett <dgarrett@chromium.org>
> 

BUG=chromium:682071

Change-Id: I04fb798242418e0a417fe7cf82962cdd11524f41
Reviewed-on: https://chromium-review.googlesource.com/519364
Reviewed-by: Ben Zhang <benzh@chromium.org>
Commit-Queue: Ben Zhang <benzh@chromium.org>
Tested-by: Ben Zhang <benzh@chromium.org>
diff --git a/scripts/cbuildbot_launch_unittest.py b/scripts/cbuildbot_launch_unittest.py
index 6888a07..ece44ae 100644
--- a/scripts/cbuildbot_launch_unittest.py
+++ b/scripts/cbuildbot_launch_unittest.py
@@ -92,10 +92,9 @@
   """Tests for cbuildbot_launch script."""
 
   ARGS_BASE = ['--buildroot', '/buildroot']
-  EXPECTED_ARGS_BASE = ['--buildroot', '/cbuildbot_buildroot']
   ARGS_GIT_CACHE = ['--git-cache-dir', '/git-cache']
   ARGS_CONFIG = ['config']
-  CMD = ['/cbuildbot_buildroot/chromite/bin/cbuildbot']
+  CMD = ['/buildroot/chromite/bin/cbuildbot']
 
   def verifyRunCbuildbot(self, args, expected_cmd, version):
     """Ensure we invoke cbuildbot correctly."""
@@ -105,31 +104,30 @@
         cros_build_lib, 'GetTargetChromiteApiVersion', autospec=True,
         return_value=version)
 
-    cbuildbot_launch.RunCbuildbot('/cbuildbot_buildroot', options)
+    cbuildbot_launch.RunCbuildbot(options)
 
     self.assertCommandCalled(
-        expected_cmd, cwd='/cbuildbot_buildroot', error_code_ok=True)
+        expected_cmd, cwd=options.buildroot, error_code_ok=True)
 
   def testRunCbuildbotSimple(self):
     """Ensure we invoke cbuildbot correctly."""
     self.verifyRunCbuildbot(
         self.ARGS_BASE + self.ARGS_CONFIG,
-        self.CMD + self.ARGS_CONFIG + self.EXPECTED_ARGS_BASE,
+        self.CMD + self.ARGS_CONFIG + self.ARGS_BASE,
         (0, 4))
 
   def testRunCbuildbotNotFiltered(self):
     """Ensure we invoke cbuildbot correctly."""
     self.verifyRunCbuildbot(
         self.ARGS_BASE + self.ARGS_CONFIG + self.ARGS_GIT_CACHE,
-        (self.CMD + self.ARGS_CONFIG + self.EXPECTED_ARGS_BASE +
-         self.ARGS_GIT_CACHE),
+        self.CMD + self.ARGS_CONFIG + self.ARGS_BASE + self.ARGS_GIT_CACHE,
         (0, 4))
 
   def testRunCbuildbotFiltered(self):
     """Ensure we invoke cbuildbot correctly."""
     self.verifyRunCbuildbot(
         self.ARGS_BASE + self.ARGS_CONFIG + self.ARGS_GIT_CACHE,
-        self.CMD + self.ARGS_CONFIG + self.EXPECTED_ARGS_BASE,
+        self.CMD + self.ARGS_CONFIG + self.ARGS_BASE,
         (0, 2))
 
   def testMainMin(self):
@@ -140,8 +138,6 @@
                                                   constants.REEXEC_API_MINOR))
     mock_repo = mock.MagicMock()
     mock_repo.branch = 'master'
-    mock_repo.directory = '/root/repository'
-
     mock_repo_create = self.PatchObject(repository, 'RepoRepository',
                                         autospec=True, return_value=mock_repo)
     mock_clean = self.PatchObject(cbuildbot_launch, 'CleanBuildroot',
@@ -149,16 +145,17 @@
     mock_checkout = self.PatchObject(cbuildbot_launch, 'InitialCheckout',
                                      autospec=True)
 
-    cbuildbot_launch._main(['-r', '/root', 'config'])
+    cbuildbot_launch._main(['--buildroot', '/buildroot', 'config'])
 
     # Did we create the repo instance correctly?
     self.assertEqual(mock_repo_create.mock_calls,
-                     [mock.call(EXPECTED_MANIFEST_URL, '/root/repository',
+                     [mock.call(EXPECTED_MANIFEST_URL, '/buildroot',
                                 git_cache_dir=None, branch='master')])
 
     # Ensure we clean, as expected.
-    self.assertEqual(mock_clean.mock_calls, [
-        mock.call('/root', mock_repo, {'branch_name': 'master'})])
+    self.assertEqual(mock_clean.mock_calls,
+                     [mock.call('/buildroot', mock_repo,
+                                {'branch_name': 'master'})])
 
     # Ensure we checkout, as expected.
     self.assertEqual(mock_checkout.mock_calls,
@@ -166,9 +163,9 @@
 
     # Ensure we invoke cbuildbot, as expected.
     self.assertCommandCalled(
-        ['/root/repository/chromite/bin/cbuildbot',
-         'config', '-r', '/root/repository'],
-        cwd='/root/repository',
+        ['/buildroot/chromite/bin/cbuildbot',
+         'config', '--buildroot', '/buildroot'],
+        cwd='/buildroot',
         error_code_ok=True)
 
   def testMainMax(self):
@@ -179,8 +176,6 @@
                                                   constants.REEXEC_API_MINOR))
     mock_repo = mock.MagicMock()
     mock_repo.branch = 'branch'
-    mock_repo.directory = '/root/repository'
-
     mock_repo_create = self.PatchObject(repository, 'RepoRepository',
                                         autospec=True, return_value=mock_repo)
     mock_clean = self.PatchObject(cbuildbot_launch, 'CleanBuildroot',
@@ -188,19 +183,20 @@
     mock_checkout = self.PatchObject(cbuildbot_launch, 'InitialCheckout',
                                      autospec=True)
 
-    cbuildbot_launch._main(['--buildroot', '/root',
+    cbuildbot_launch._main(['--buildroot', '/buildroot',
                             '--branch', 'branch',
                             '--git-cache-dir', '/git-cache',
                             'config'])
 
     # Did we create the repo instance correctly?
     self.assertEqual(mock_repo_create.mock_calls,
-                     [mock.call(EXPECTED_MANIFEST_URL, '/root/repository',
+                     [mock.call(EXPECTED_MANIFEST_URL, '/buildroot',
                                 git_cache_dir='/git-cache', branch='branch')])
 
     # Ensure we clean, as expected.
-    self.assertEqual(mock_clean.mock_calls, [
-        mock.call('/root', mock_repo, {'branch_name': 'branch'})])
+    self.assertEqual(mock_clean.mock_calls,
+                     [mock.call('/buildroot', mock_repo,
+                                {'branch_name': 'branch'})])
 
     # Ensure we checkout, as expected.
     self.assertEqual(mock_checkout.mock_calls,
@@ -208,12 +204,12 @@
 
     # Ensure we invoke cbuildbot, as expected.
     self.assertCommandCalled(
-        ['/root/repository/chromite/bin/cbuildbot',
+        ['/buildroot/chromite/bin/cbuildbot',
          'config',
-         '--buildroot', '/root/repository',
+         '--buildroot', '/buildroot',
          '--branch', 'branch',
          '--git-cache-dir', '/git-cache'],
-        cwd='/root/repository',
+        cwd='/buildroot',
         error_code_ok=True)
 
 
@@ -222,23 +218,22 @@
 
   def setUp(self):
     """Create standard buildroot contents for cleanup."""
-    self.root = os.path.join(self.tempdir)
+    self.root = os.path.join(self.tempdir, 'buildroot')
     self.state = os.path.join(self.root, '.cbuildbot_launch_state')
-    self.buildroot = os.path.join(self.root, 'buildroot')
-    self.repo = os.path.join(self.buildroot, '.repo/repo')
-    self.chroot = os.path.join(self.buildroot, 'chroot/chroot')
-    self.general = os.path.join(self.buildroot, 'general/general')
+    self.repo = os.path.join(self.root, '.repo/repo')
+    self.chroot = os.path.join(self.root, 'chroot/chroot')
+    self.general = os.path.join(self.root, 'general/general')
     # TODO: Add .cache, and distfiles.
 
     self.mock_repo = mock.MagicMock()
-    self.mock_repo.directory = self.buildroot
 
     self.metrics = {}
 
   def populateBuildroot(self, state=None):
     """Create standard buildroot contents for cleanup."""
+    osutils.SafeMakedirs(self.root)
+
     if state:
-      osutils.SafeMakedirs(self.root)
       osutils.WriteFile(self.state, state)
 
     # Create files.
@@ -249,20 +244,18 @@
     """Test CleanBuildroot with no history."""
     self.mock_repo.branch = 'master'
 
-    cbuildbot_launch.CleanBuildroot(
-        self.root, self.mock_repo, self.metrics)
+    cbuildbot_launch.CleanBuildroot(self.root, self.mock_repo, self.metrics)
 
-    self.assertEqual(osutils.ReadFile(self.state), '2 master')
+    self.assertEqual(osutils.ReadFile(self.state), '1 master')
 
   def testBuildrootNoState(self):
     """Test CleanBuildroot with no state information."""
     self.populateBuildroot()
     self.mock_repo.branch = 'master'
 
-    cbuildbot_launch.CleanBuildroot(
-        self.root, self.mock_repo, self.metrics)
+    cbuildbot_launch.CleanBuildroot(self.root, self.mock_repo, self.metrics)
 
-    self.assertEqual(osutils.ReadFile(self.state), '2 master')
+    self.assertEqual(osutils.ReadFile(self.state), '1 master')
     self.assertNotExists(self.repo)
     self.assertNotExists(self.chroot)
     self.assertNotExists(self.general)
@@ -272,36 +265,33 @@
     self.populateBuildroot('0 master')
     self.mock_repo.branch = 'master'
 
-    cbuildbot_launch.CleanBuildroot(
-        self.root, self.mock_repo, self.metrics)
+    cbuildbot_launch.CleanBuildroot(self.root, self.mock_repo, self.metrics)
 
-    self.assertEqual(osutils.ReadFile(self.state), '2 master')
+    self.assertEqual(osutils.ReadFile(self.state), '1 master')
     self.assertNotExists(self.repo)
     self.assertNotExists(self.chroot)
     self.assertNotExists(self.general)
 
   def testBuildrootBranchChange(self):
     """Test CleanBuildroot with a change in branches."""
-    self.populateBuildroot('2 branchA')
+    self.populateBuildroot('1 branchA')
     self.mock_repo.branch = 'branchB'
 
-    cbuildbot_launch.CleanBuildroot(
-        self.root, self.mock_repo, self.metrics)
+    cbuildbot_launch.CleanBuildroot(self.root, self.mock_repo, self.metrics)
 
-    self.assertEqual(osutils.ReadFile(self.state), '2 branchB')
+    self.assertEqual(osutils.ReadFile(self.state), '1 branchB')
     self.assertExists(self.repo)
     self.assertNotExists(self.chroot)
     self.assertExists(self.general)
 
   def testBuildrootBranchMatch(self):
     """Test CleanBuildroot with no change in branch."""
-    self.populateBuildroot('2 branchA')
+    self.populateBuildroot('1 branchA')
     self.mock_repo.branch = 'branchA'
 
-    cbuildbot_launch.CleanBuildroot(
-        self.root, self.mock_repo, self.metrics)
+    cbuildbot_launch.CleanBuildroot(self.root, self.mock_repo, self.metrics)
 
-    self.assertEqual(osutils.ReadFile(self.state), '2 branchA')
+    self.assertEqual(osutils.ReadFile(self.state), '1 branchA')
     self.assertExists(self.repo)
     self.assertExists(self.chroot)
     self.assertExists(self.general)
@@ -312,10 +302,9 @@
     self.mock_repo.branch = 'branchA'
     self.mock_repo.BuildRootGitCleanup.side_effect = Exception
 
-    cbuildbot_launch.CleanBuildroot(
-        self.root, self.mock_repo, self.metrics)
+    cbuildbot_launch.CleanBuildroot(self.root, self.mock_repo, self.metrics)
 
-    self.assertEqual(osutils.ReadFile(self.state), '2 branchA')
+    self.assertEqual(osutils.ReadFile(self.state), '1 branchA')
     self.assertNotExists(self.repo)
     self.assertNotExists(self.chroot)
     self.assertNotExists(self.general)
@@ -354,14 +343,14 @@
     # Read Write
     cbuildbot_launch.SetBuildrootState('happy-branch', self.root)
     results = cbuildbot_launch.GetBuildrootState(self.root)
-    self.assertEqual(results, (2, 'happy-branch'))
+    self.assertEqual(results, (1, 'happy-branch'))
 
   def testSetBuildrootState(self):
     """Test SetBuildrootState."""
     # Write out a state file.
     osutils.SafeMakedirs(self.root)
     cbuildbot_launch.SetBuildrootState('happy-branch', self.root)
-    self.assertEqual(osutils.ReadFile(self.state), '2 happy-branch')
+    self.assertEqual(osutils.ReadFile(self.state), '1 happy-branch')
 
     # Change to a future version.
     self.PatchObject(cbuildbot_launch, 'BUILDROOT_BUILDROOT_LAYOUT', 22)