cbuildbot_launch: Add DepotToolsEnsureBootstrap.

This preperation step ensures that the CIPD binaries needed by
depot_tools are installed before the build starts. They are normally
auto-updated, but this doesn't work inside the chroot. By installing
them now, we ensure they are never fetched inside the chroot.

BUG=chromium:769369
TEST=run_tests
     cros tryjob --local lumpy-compile-only-pre-cq

Change-Id: Ibfb5286cf66e38c4a7d383a0a216bfcc2896fbb7
Reviewed-on: https://chromium-review.googlesource.com/691258
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Reviewed-by: Daniel Jacques <dnj@chromium.org>
Reviewed-by: Aviv Keshet <akeshet@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
Trybot-Ready: Don Garrett <dgarrett@chromium.org>
diff --git a/scripts/cbuildbot_launch_unittest.py b/scripts/cbuildbot_launch_unittest.py
index 612a707..aff339b 100644
--- a/scripts/cbuildbot_launch_unittest.py
+++ b/scripts/cbuildbot_launch_unittest.py
@@ -88,6 +88,25 @@
     self.assertNotIn('LC_MONETARY', os.environ)
 
 
+class RunDepotToolsEnsureBootstrap(cros_build_lib_unittest.RunCommandTestCase,
+                                   cros_test_lib.TempDirTestCase):
+  """Test the helper function DepotToolsEnsureBootstrap."""
+
+  def testEnsureBootstrap(self):
+    """Verify that the script is run if present."""
+    script = os.path.join(self.tempdir, 'ensure_bootstrap')
+    osutils.Touch(script, makedirs=True)
+
+    cbuildbot_launch.DepotToolsEnsureBootstrap(self.tempdir)
+    self.assertCommandCalled(
+        [script], extra_env={'PATH': mock.ANY}, cwd=self.tempdir)
+
+  def testEnsureBootstrapMissing(self):
+    """Verify that the script is NOT run if not present."""
+    cbuildbot_launch.DepotToolsEnsureBootstrap(self.tempdir)
+    self.assertEqual(self.rc.call_count, 0)
+
+
 class RunTests(cros_build_lib_unittest.RunCommandTestCase):
   """Tests for cbuildbot_launch script."""