• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 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 servo 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 servo_host and servo_port for a servo connected to the DUT.
16PLANKTON_HOST_ATTR = 'plankton_host'
17PLANKTON_PORT_ATTR = 'plnakton_port'
18
19
20def make_plankton_hostname(dut_hostname):
21    """Given a DUT's hostname, return the hostname of its servo.
22
23    @param dut_hostname: hostname of a DUT.
24
25    @return hostname of the DUT's servo.
26
27    """
28    host_parts = dut_hostname.split('.')
29    host_parts[0] = host_parts[0] + '-plankton'
30    return '.'.join(host_parts)
31
32
33class PlanktonHost(servo_host.ServoHost):
34    """Host class for a host that controls a servo, e.g. beaglebone."""
35
36
37    def _initialize(self, plankton_host='localhost', plankton_port=9998,
38                    required_by_test=True, is_in_lab=None, *args, **dargs):
39        """Initialize a ServoHost instance.
40
41        A ServoHost instance represents a host that controls a servo.
42
43        @param plankton_host: Name of the host where the servod process
44                           is running.
45        @param plankton_port: Port the servod process is listening on.
46
47        """
48        super(PlanktonHost, self)._initialize(plankton_host, plankton_port,
49                                              False, None, *args, **dargs)
50
51
52def create_plankton_host(plankton_args):
53    """Create a PlanktonHost object used to access plankton servo
54
55    The `plankton_args` parameter is a dictionary specifying optional
56    Servo client parameter overrides (i.e. a specific host or port).
57    When specified, the caller requires that an exception be raised
58    unless both the PlanktonHost and the Servo are successfully
59    created.
60
61    @param plankton_args: A dictionary that contains args for creating
62                       a PlanktonHost object,
63                       e.g. {'planton_host': '172.11.11.111',
64                             'plankton_port': 9999}.
65                       See comments above.
66
67    @returns: A PlanktonHost object or None. See comments above.
68
69    """
70    # TODO Make this work in the lab chromium:564836
71    if plankton_args is None:
72        return None
73    return PlanktonHost(Required_by_test=True, is_in_lab=False, **plankton_args)
74