• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import logging
6
7from autotest_lib.client.common_lib.cros import tpm_utils
8from autotest_lib.server import autotest
9from autotest_lib.server import test
10
11
12class policy_DeviceServer(test.test):
13    """
14    policy_DeviceServer test used to kick off any arbitrary client test.
15
16    """
17    version = 1
18
19    def clear_tpm_if_owned(self):
20        """Clear the TPM only if device is already owned."""
21        tpm_status = tpm_utils.TPMStatus(self.host)
22        logging.info('TPM status: %s', tpm_status)
23        if tpm_status['Owned']:
24            logging.info('Clearing TPM because this device is owned.')
25            tpm_utils.ClearTPMOwnerRequest(self.host)
26
27
28    def cleanup(self):
29        """Cleanup for this test."""
30        self.clear_tpm_if_owned()
31        self.host.reboot()
32
33
34    def run_once(self, client_test, host, case=None):
35        """
36        Starting point of this test.
37
38        Note: base class sets host as self._host.
39
40        @param client_test: the name of the Client test to run.
41        @param case: the case to run for the given Client test.
42
43        """
44
45        # Clear TPM to ensure that client test can enroll device.
46        self.host = host
47        self.clear_tpm_if_owned()
48
49        self.autotest_client = autotest.Autotest(self.host)
50        self.autotest_client.run_test(
51            client_test, case=case, check_client_result=True)