faft: Create a lockfile on test init and remove it on cleanup

In order to remove possible interference from outside utilities
add a lockfile that is present during FAFT testing and cleaned up
when FAFT is done.

This is going to be used by chromeos-setgoodkernel which operates
on GPT 30 seconds after boot, and also runs chromeos-firmwareupdate
with --mode=bootok.  Depending on the test being run either of
these actions can interfere with FAFT testing and lead to inconstent
results and makes it very difficult to debug test failures.

BUG=chrome-os-partner:30832
TEST=run suite:faft_bios on samus, check that lockfile is created
during test init and removed in test cleanup step.

Change-Id: I3f483110d3dcdd14eaa55c1a59aa1387cd38c617
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222010
Reviewed-by: Yusuf Mohsinally <mohsinally@chromium.org>
Reviewed-by: danny chan <dchan@chromium.org>
diff --git a/server/cros/faft/firmware_test.py b/server/cros/faft/firmware_test.py
index 0ac666a..7419826 100644
--- a/server/cros/faft/firmware_test.py
+++ b/server/cros/faft/firmware_test.py
@@ -42,6 +42,7 @@
         self._autotest_client = autotest.Autotest(self._client)
         self._autotest_client.install()
         self.faft_client = RPCProxy(host)
+        self.lockfile = '/var/tmp/faft/lock'
 
     def wait_for_client(self, install_deps=False, timeout=100):
         """Wait for the client to come back online.
@@ -172,6 +173,7 @@
         self._record_system_info()
         self._setup_gbb_flags()
         self._stop_service('update-engine')
+        self._create_faft_lockfile()
         self._setup_ec_write_protect(ec_wp)
         self.fw_vboot2 = self.faft_client.system.get_fw_vboot2()
         logging.info('vboot version: %d', 2 if self.fw_vboot2 else 1)
@@ -193,6 +195,7 @@
         self._restore_ec_write_protect()
         self._restore_gbb_flags()
         self._start_service('update-engine')
+        self._remove_faft_lockfile()
         self._record_servo_log()
         self._record_faft_client_log()
         self._cleanup_uart_capture()
@@ -444,6 +447,18 @@
         else:
             return None
 
+    def _create_faft_lockfile(self):
+        """Creates the FAFT lockfile."""
+        logging.info('Creating FAFT lockfile...')
+        command = 'touch %s' % (self.lockfile)
+        self.faft_client.system.run_shell_command(command)
+
+    def _remove_faft_lockfile(self):
+        """Removes the FAFT lockfile."""
+        logging.info('Removing FAFT lockfile...')
+        command = 'rm -f %s' % (self.lockfile)
+        self.faft_client.system.run_shell_command(command)
+
     def _stop_service(self, service):
         """Stops a upstart service on the client.