• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 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 import error
8from autotest_lib.client.common_lib import utils
9from autotest_lib.server import test
10from autotest_lib.server.hosts.drone_api_client.client import TLSClient
11
12
13class infra_TLSExecDUTCommand(test.test):
14    """
15    Run a command on the host via the TLS API (ExecDutCommand) and ensure the
16    output is as expected.
17
18    """
19
20    version = 1
21
22    def run_once(self, host):
23        """
24        Run the test.
25
26        @param host: A host object representing the DUT.
27
28        """
29        tlsclient = TLSClient(hostname=host.hostname)
30        res = tlsclient.run_cmd("echo success")
31        if not isinstance(res, utils.CmdResult):
32            raise error.TestError(
33                "Client returned type: '{}'. Expected type: 'utils.CmdResult'"
34                .format(type(res)))
35        if res.exit_status != 0:
36            logging.info("STD_ERR of res {}".format(res.stderr))
37            raise error.TestError("TLS CMD exit status was: '{}'. Expected: '0'"
38                                  .format(res.exit_status))
39        if res.stdout != "success\n":
40            raise error.TestError("TLS returned: '{}'. Expected: '{}'"
41                                  .format(res.stdout, "success\n"))
42