blob: 7adac4cfdbba9a09cc674431d413de0a8abe655f [file] [log] [blame]
Wai-Hong Tam0ed9fe12019-05-23 11:00:58 -07001# Copyright 2015 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#
5# Expects to be run in an environment with sudo and no interactive password
6# prompt, such as within the Chromium OS development chroot.
7
8
9"""This file provides core logic for pdtester verify/repair process."""
10
11from autotest_lib.server.hosts import servo_host
12
13
14# Names of the host attributes in the database that represent the values for
15# the pdtester_host and pdtester_port for a PD tester connected to the DUT.
16PDTESTER_HOST_ATTR = 'pdtester_host'
17PDTESTER_PORT_ATTR = 'pdtester_port'
18
19
20def make_pdtester_hostname(dut_hostname):
21 """Given a DUT's hostname, return the hostname of its PD tester.
22
23 @param dut_hostname: hostname of a DUT.
24
25 @return hostname of the DUT's PD tester.
26
27 """
28 host_parts = dut_hostname.split('.')
29 host_parts[0] = host_parts[0] + '-pdtester'
30 return '.'.join(host_parts)
31
32
33class PDTesterHost(servo_host.ServoHost):
34 """Host class for a host that controls a PDTester object."""
35
36
37 def _initialize(self, pdtester_host='localhost', pdtester_port=9998,
38 required_by_test=True, is_in_lab=None, *args, **dargs):
39 """Initialize a PDTesterHost instance.
40
41 A PDTesterHost instance represents a host that controls a PD tester.
42
43 @param pdtester_host: Name of the host where the servod process
44 is running.
45 @param pdtester_port: Port the servod process is listening on.
46
47 """
48 super(PDTesterHost, self)._initialize(pdtester_host, pdtester_port,
49 False, None, *args, **dargs)
50 self.connect_servo()
51
52
53def create_pdtester_host(pdtester_args):
54 """Create a PDTesterHost object used to access pdtester servo
55
56 The `pdtester_args` parameter is a dictionary specifying optional
57 PDTester client parameter overrides (i.e. a specific host or port).
58 When specified, the caller requires that an exception be raised
59 unless both the PDTesterHost and the PDTester are successfully
60 created.
61
62 @param pdtester_args: A dictionary that contains args for creating
63 a PDTesterHost object,
64 e.g. {'planton_host': '172.11.11.111',
65 'pdtester_port': 9999}.
66 See comments above.
67
68 @returns: A PDTesterHost object or None. See comments above.
69
70 """
71 # TODO Make this work in the lab chromium:564836
72 if pdtester_args is None:
73 return None
74 return PDTesterHost(Required_by_test=True, is_in_lab=False, **pdtester_args)