Re-work the devinstall wipe to specificlally wipe only the devinstall state.

Devinstall installs packages into /usr/local/bin which is bind mounted from
/mnt/stateful_partition/dev_image. Instead of attempting to wipe all of
/mnt/stateful_partition/* we instead just wipe

TEST=Ran it multiple times.

Change-Id: Ide4fba063f067aefef2ae2c41cbbbed84578f330
Tested-by: Chris Sosa <>
Reviewed-by: Don Garrett <>
Commit-Queue: Chris Sosa <>
diff --git a/devmode-test/ b/devmode-test/
index 0e498fb..ca19e5f 100755
--- a/devmode-test/
+++ b/devmode-test/
@@ -12,6 +12,7 @@
 stateful partition and then runs gmerge.
+import getpass
 import logging
 import optparse
 import os
@@ -90,17 +91,20 @@
         _LOCALHOST, self.tmpdir, self.port,
         debug_level=logging.DEBUG, interactive=False)
-  def _WipeStatefulPartition(self):
-    """Deletes everything from the working image path's stateful partition."""
+  def _WipeDevInstall(self):
+    """Wipes the devinstall state."""
     r_mount_point = os.path.join(self.tmpdir, 'm')
     s_mount_point = os.path.join(self.tmpdir, 's')
+    dev_image_path = os.path.join(s_mount_point, 'dev_image')
                             r_mount_point, s_mount_point, read_only=False,
-    # Run in shell mode to interpret '*' as a glob.
-    cros_build_lib.SudoRunCommand('rm -rf %s/*' % s_mount_point, shell=True,
-                                  debug_level=logging.DEBUG)
-    mount_helper.UnmountImage(r_mount_point, s_mount_point)
+    try:
+      cros_build_lib.SudoRunCommand(['chown', '--recursive', getpass.getuser(),
+                                     s_mount_point], debug_level=logging.DEBUG)
+      shutil.rmtree(dev_image_path)
+    finally:
+      mount_helper.UnmountImage(r_mount_point, s_mount_point)
   def _FindUnusedPort(self):
     """Returns a currently unused port."""
@@ -156,8 +160,8 @@
     shutil.copyfile(vm_path, self.working_image_path)
     logging.debug('Copy of vm image stored at %s.', self.working_image_path)
-'Wiping the stateful partition to prepare test.')
-    self._WipeStatefulPartition()
+'Wiping /usr/local/bin from the image.')
+    self._WipeDevInstall()'Starting the vm on port %d.', self.port)