cros-sdk: Improve check for missing lvm tools
Instead of checking up front, perform the check once we know that LVM
will be needed for the current requested operations. This allows people
who have an existing chroot to continue using it without passing
--nouse-image every time while still giving a clear error message when
somebody tries to create a new chroot that uses LVM.
Also adds thin_check to the list of needed tools. thin_check isn't
called directly by cros_sdk, but can be called internally by the various
lvm commands. By checking up front, we make sure they won't fail with a
mysterious error message later.
BUG=chromium:730144
TEST=Ran cros_sdk with misspelled tools to make sure the message
triggers only when needed.
Change-Id: I11b65470e9fc7d2b07beb05b65f8e1afcdf9e8cb
Reviewed-on: https://chromium-review.googlesource.com/600540
Commit-Ready: Benjamin Gordon <bmgordon@chromium.org>
Tested-by: Benjamin Gordon <bmgordon@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
diff --git a/scripts/cros_sdk.py b/scripts/cros_sdk.py
index 603b1e5..9a7ddcf 100644
--- a/scripts/cros_sdk.py
+++ b/scripts/cros_sdk.py
@@ -67,7 +67,7 @@
# Tools needed when use_image is true (the default).
IMAGE_NEEDED_TOOLS = ('losetup', 'lvchange', 'lvcreate', 'lvs', 'mke2fs',
- 'pvscan', 'vgchange', 'vgcreate', 'vgs')
+ 'pvscan', 'thin_check', 'vgchange', 'vgcreate', 'vgs')
def GetArchStageTarballs(version):
@@ -644,8 +644,6 @@
_ReportMissing(osutils.FindMissingBinaries(NEEDED_TOOLS))
if options.proxy_sim:
_ReportMissing(osutils.FindMissingBinaries(PROXY_NEEDED_TOOLS))
- if options.use_image:
- _ReportMissing(osutils.FindMissingBinaries(IMAGE_NEEDED_TOOLS))
if (sdk_latest_version == '<unknown>' or
bootstrap_latest_version == '<unknown>'):
@@ -692,6 +690,23 @@
if options.enter:
options.create |= not chroot_exists
+ # If we're going to be using a loopback image for the chroot, we need
+ # LVM tools installed. We can skip the check if something that looks
+ # like a chroot is already visible in the expected place, since we won't
+ # actually call any LVM commands in that case.
+ if options.use_image and options.create:
+ missing = osutils.FindMissingBinaries(IMAGE_NEEDED_TOOLS)
+ if missing:
+ raise SystemExit(
+ 'The tool(s) %s were not found.\n'
+ 'Please make sure the lvm2 and thin-provisioning-tools packages '
+ 'are installed on your host.\n'
+ 'Example(ubuntu):\n'
+ ' sudo apt-get install lvm2 thin-provisioning-tools\n\n'
+ 'If you want to run without lvm2, pass --nouse-image (chroot '
+ 'snapshots will be unavailable).'
+ % ', '.join(missing))
+
# This dance is to support mounting the chroot inside a separate mount
# namespace. While we're here in the original namespace, we set up a
# temporary shared subtree