init: Preserve .labmachine across powerwash for debug images.

In test images, certain important behaviors are enabled if a file
named .labmachine is present in the root of the stateful file
system.  The behaviors are needed to recover from various critical
events, such as loss of network, and loss of AC power.

The file doesn't automatically exist; it must be created by the
Autotest install code.  Additionally, power wash can delete the
file.  This changes clobber-state to preserve the file across
powerwash in test and dev images.  Without this change, devices may
become unrepairable after certain tests.

BUG=chromium:463177
TEST=manually powerwash with the .labmachine file present

Change-Id: I3f74bf923e74bc1993ea058db0fc50cc1970ebff
Reviewed-on: https://chromium-review.googlesource.com/260581
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Bertrand Simonnet <bsimonnet@chromium.org>
diff --git a/init/clobber-state b/init/clobber-state
index cd0a952..af1ac31 100755
--- a/init/clobber-state
+++ b/init/clobber-state
@@ -32,8 +32,9 @@
 FACTORY_WIPE_FIRMWARE_PID=""
 
 PRESERVED_TAR="/tmp/preserve.tar"
+LABMACHINE=".labmachine"
 STATE_PATH="/mnt/stateful_partition"
-POWERWASH_COUNT="/mnt/stateful_partition/unencrypted/preserve/powerwash_count"
+POWERWASH_COUNT="${STATE_PATH}/unencrypted/preserve/powerwash_count"
 
 # List of files to preserve relative to /mnt/stateful_partition/
 PRESERVED_FILES=""
@@ -69,6 +70,16 @@
   fi
 fi
 
+# Test images in the lab enable certain extra behaviors if the
+# .labmachine flag file is present.  Those behaviors include some
+# important recovery behaviors (cf. the recover_duts upstart job).
+# We need those behaviors to survive across power wash, otherwise,
+# the current boot could wind up as a black hole.
+if [ -f "${STATE_PATH}/${LABMACHINE}" ] &&
+    crossystem 'debug_build?1'; then
+  PRESERVED_FILES="${PRESERVED_FILES} ${LABMACHINE}"
+fi
+
 PRESERVED_LIST=""
 if [ -n "$PRESERVED_FILES" ]; then
   # We want to preserve permissions and recreate the directory structure