enterprise_RemoraRequisitionServer.

Clearing the tpm and rebooting is handled by the server-side test.
Saving the tpm password is handled by the client test.
Also added utility methods to remotely access TPM status,
fetch the TPM password, clear the TPM, remove state from the DUT,
reboot the machine.

BUG=chromium:342884
TEST=manual

Change-Id: Ib56dd3352b429b1a131d260eecf6d970c90a8ef8
Reviewed-on: https://chromium-review.googlesource.com/202637
Reviewed-by: Achuith Bhandarkar <achuith@chromium.org>
Tested-by: Achuith Bhandarkar <achuith@chromium.org>
Commit-Queue: Achuith Bhandarkar <achuith@chromium.org>
diff --git a/client/common_lib/cros/enrollment.py b/client/common_lib/cros/enrollment.py
index f4c8a35..2f10b97 100644
--- a/client/common_lib/cros/enrollment.py
+++ b/client/common_lib/cros/enrollment.py
@@ -2,73 +2,14 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-import logging, os
+import logging
 
 from autotest_lib.client.bin import utils
-from autotest_lib.client.cros import cros_ui, cryptohome, ownership
+from autotest_lib.client.common_lib.cros import tpm_utils
 from telemetry.core import exceptions
 from telemetry.core.backends.chrome import cros_interface
 
 
-_PASSWD_FILE = '/var/tmp/tpm_passwd'
-
-
-def ClearTPM():
-    """Clears the TPM (if it is owned) using the password stored in
-    /var/tmp/tpm_passwd. Returns True if tpm was owned.
-
-    @return True if the TPM was owned - enrollment should not be attempted.
-    """
-    status = cryptohome.get_tpm_status()
-    if not status['Owned']:
-        logging.debug('TPM is not owned')
-        return False
-    password = status['Password']
-    if not password:
-        if not os.path.isfile(_PASSWD_FILE):
-            logging.warn('Password file %s doesn\'t exist, cannot clear TPM. '
-                         'You need to have the firmware clear the TPM, for '
-                         'instance using crossystem or by toggling the dev '
-                         'switch.', _PASSWD_FILE)
-            return True
-        with open(_PASSWD_FILE) as f:
-            password = f.read().rstrip()
-
-    if not password:
-        logging.warn('Password file %s empty, cannot clear TPM. '
-                     'You need to have the firmware clear the TPM, for '
-                     'instance using crossystem or by toggling the dev switch.',
-                     _PASSWD_FILE)
-        return True
-
-    cros_ui.stop()
-    res = utils.system_output('tpm_clear --pass ' + password)
-    logging.warn(repr(res))
-
-    cryptohome.remove_all_vaults()
-    ownership.clear_ownership_files_no_restart()
-    logging.warn('Please reboot the system')
-    return True
-
-
-def _SaveTPMPassword():
-    """Save TPM Password to /var/tpm/tpm_passwd.
-
-    During enrollment, the TPM password becomes visible - we capture it and
-    save it in to a local file, so we can clear the TPM at the end of the test.
-    """
-    password = utils.poll_for_condition(
-            lambda: cryptohome.get_tpm_status()['Password'],
-            sleep_interval=0.5, timeout=60)
-    if password:
-        with open(_PASSWD_FILE, 'w') as f:
-            f.write(password)
-    else:
-        logging.warn('Could not save TPM password')
-    logging.info('TPM Password: ' + password)
-    return password
-
-
 def _ExecuteOobeCmd(browser, cmd):
     logging.info('Invoking ' + cmd)
     oobe = browser.oobe
@@ -93,7 +34,7 @@
     utils.poll_for_condition(lambda: browser.oobe_exists, timeout=30)
 
     _ExecuteOobeCmd(browser, 'Oobe.skipToLoginForTesting();')
-    _SaveTPMPassword()
+    tpm_utils.SaveTPMPassword()
 
 
 def FinishEnrollment(oobe):