cbuildbot_launch: Add post-build chroot cleanup stage
The new stage unmounts the chroot and detaches the loopback device. For
most builders that reboot after running, this doesn't make any
difference. For builders that don't reboot between runs, this helps
reduce loopback device leaks.
BUG=chromium:752562,chromium:730144
TEST=unit tests; cros tryjob master-paladin-tryjob
Change-Id: I7f321ae0be1d5ffabcdc3a71b61246a3a65cd963
Reviewed-on: https://chromium-review.googlesource.com/907748
Commit-Ready: Benjamin Gordon <bmgordon@chromium.org>
Tested-by: Benjamin Gordon <bmgordon@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
diff --git a/scripts/cbuildbot_launch_unittest.py b/scripts/cbuildbot_launch_unittest.py
index 99db582..3fdbc4d 100644
--- a/scripts/cbuildbot_launch_unittest.py
+++ b/scripts/cbuildbot_launch_unittest.py
@@ -167,6 +167,8 @@
autospec=True)
mock_checkout = self.PatchObject(cbuildbot_launch, 'InitialCheckout',
autospec=True)
+ mock_cleanup_chroot = self.PatchObject(cbuildbot_launch, 'CleanupChroot',
+ autospec=True)
cbuildbot_launch._main(['-r', '/root', 'config'])
@@ -200,6 +202,10 @@
cwd='/root/repository',
error_code_ok=True)
+ # Ensure we clean the chroot, as expected.
+ self.assertEqual(mock_cleanup_chroot.mock_calls, [
+ mock.call('/root/repository')])
+
def testMainMax(self):
"""Test a larger set of command line options."""
self.PatchObject(osutils, 'SafeMakedirs', autospec=True)
@@ -216,6 +222,8 @@
autospec=True)
mock_checkout = self.PatchObject(cbuildbot_launch, 'InitialCheckout',
autospec=True)
+ mock_cleanup_chroot = self.PatchObject(cbuildbot_launch, 'CleanupChroot',
+ autospec=True)
cbuildbot_launch._main(['--buildroot', '/root',
'--branch', 'branch',
@@ -257,6 +265,10 @@
cwd='/root/repository',
error_code_ok=True)
+ # Ensure we clean the chroot, as expected.
+ self.assertEqual(mock_cleanup_chroot.mock_calls, [
+ mock.call('/root/repository')])
+
class CleanBuildRootTest(cros_test_lib.MockTempDirTestCase):
"""Tests for CleanBuildRoot method."""