cros_sdk_unittest: Add test for command prerequisites

Since the unit tests directly call functions from cros_build_lib, they
bypass the normal cros_sdk checks that warn the user about missing
packages.  Any resulting errors are then very unintuitive.  Add a couple
of tests that will fail with a more obvious error message if a necessary
package is missing from the system.

BUG=None
TEST=Removed thin-provisioning-tools and ran tests.

Change-Id: Ibff6b70dec0d8d3e9583aab0f87e9040caca6ceb
Reviewed-on: https://chromium-review.googlesource.com/660998
Commit-Ready: Benjamin Gordon <bmgordon@chromium.org>
Tested-by: Benjamin Gordon <bmgordon@chromium.org>
Reviewed-by: Ningning Xia <nxia@chromium.org>
diff --git a/scripts/cros_sdk_unittest.py b/scripts/cros_sdk_unittest.py
index 52d318c..254ca61 100644
--- a/scripts/cros_sdk_unittest.py
+++ b/scripts/cros_sdk_unittest.py
@@ -15,6 +15,36 @@
 from chromite.lib import sudo
 
 
+class CrosSdkPrerequisitesTest(cros_test_lib.TempDirTestCase):
+  """Tests for required packages on the host machine.
+
+  These are not real unit tests.  If these tests fail, it means your machine is
+  missing necessary commands to support image-backed chroots.  Run cros_sdk in
+  a terminal to get info about what you need to install.
+  """
+
+  def testLvmCommandsPresent(self):
+    """Check for commands from the lvm2 package."""
+    with sudo.SudoKeepAlive():
+      cmd = ['lvs', '--version']
+      result = cros_build_lib.RunCommand(cmd, error_code_ok=True)
+      self.assertEqual(result.returncode, 0)
+
+  def testThinProvisioningToolsPresent(self):
+    """Check for commands from the thin-provisioning-tools package."""
+    with sudo.SudoKeepAlive():
+      cmd = ['thin_check', '-V']
+      result = cros_build_lib.RunCommand(cmd, error_code_ok=True)
+      self.assertEqual(result.returncode, 0)
+
+  def testLosetupCommandPresent(self):
+    """Check for commands from the mount package."""
+    with sudo.SudoKeepAlive():
+      cmd = ['losetup', '--help']
+      result = cros_build_lib.RunCommand(cmd, error_code_ok=True)
+      self.assertEqual(result.returncode, 0)
+
+
 # TODO(bmgordon): Figure out how to mock out --create and --enter and then
 # add tests that combine those with snapshots.
 class CrosSdkSnapshotTest(cros_test_lib.TempDirTestCase):