Tom Wai-Hong Tam | efe1c7f | 2014-01-02 14:00:11 +0800 | [diff] [blame] | 1 | # Copyright (c) 2014 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 | |
| 6 | """This file provides core logic for connecting a Chameleon Daemon.""" |
| 7 | |
| 8 | |
| 9 | import xmlrpclib |
| 10 | |
| 11 | from autotest_lib.client.bin import utils |
Tom Wai-Hong Tam | eaee340 | 2014-01-22 08:52:10 +0800 | [diff] [blame^] | 12 | from autotest_lib.server.cros.chameleon import chameleon |
Tom Wai-Hong Tam | efe1c7f | 2014-01-02 14:00:11 +0800 | [diff] [blame] | 13 | from autotest_lib.server.hosts import ssh_host |
| 14 | |
| 15 | |
| 16 | def make_chameleon_hostname(dut_hostname): |
| 17 | """Given a DUT's hostname, return the hostname of its Chameleon. |
| 18 | |
| 19 | @param dut_hostname: hostname of a DUT. |
| 20 | |
| 21 | @return hostname of the DUT's Chameleon. |
| 22 | |
| 23 | """ |
| 24 | host_parts = dut_hostname.split('.') |
| 25 | host_parts[0] = host_parts[0] + '-chameleon' |
| 26 | return '.'.join(host_parts) |
| 27 | |
| 28 | |
| 29 | class ChameleonHost(ssh_host.SSHHost): |
| 30 | """Host class for a host that controls a Chameleon.""" |
| 31 | |
| 32 | # Chameleond process name. |
| 33 | CHAMELEOND_PROCESS = 'chameleond' |
| 34 | |
| 35 | |
| 36 | # TODO(waihong): Add verify and repair logic which are required while |
| 37 | # deploying to Cros Lab. |
| 38 | |
| 39 | |
| 40 | def _initialize(self, chameleon_host='localhost', chameleon_port=9992, |
| 41 | *args, **dargs): |
| 42 | """Initialize a ChameleonHost instance. |
| 43 | |
| 44 | A ChameleonHost instance represents a host that controls a Chameleon. |
| 45 | |
| 46 | @param chameleon_host: Name of the host where the chameleond process |
| 47 | is running. |
| 48 | @param chameleon_port: Port the chameleond process is listening on. |
| 49 | |
| 50 | """ |
| 51 | super(ChameleonHost, self)._initialize(hostname=chameleon_host, |
| 52 | *args, **dargs) |
| 53 | self._is_in_lab = utils.host_is_in_lab_zone(self.hostname) |
| 54 | remote = 'http://%s:%s' % (self.hostname, chameleon_port) |
| 55 | self._chameleond_proxy = xmlrpclib.ServerProxy(remote) |
| 56 | |
| 57 | |
| 58 | def is_in_lab(self): |
| 59 | """Check whether the chameleon host is a lab device. |
| 60 | |
| 61 | @returns: True if the chameleon host is in Cros Lab, otherwise False. |
| 62 | |
| 63 | """ |
| 64 | return self._is_in_lab |
| 65 | |
| 66 | |
Tom Wai-Hong Tam | efe1c7f | 2014-01-02 14:00:11 +0800 | [diff] [blame] | 67 | def get_wait_up_processes(self): |
| 68 | """Get the list of local processes to wait for in wait_up. |
| 69 | |
| 70 | Override get_wait_up_processes in |
| 71 | autotest_lib.client.common_lib.hosts.base_classes.Host. |
| 72 | Wait for chameleond process to go up. Called by base class when |
| 73 | rebooting the device. |
| 74 | |
| 75 | """ |
| 76 | processes = [self.CHAMELEOND_PROCESS] |
| 77 | return processes |
| 78 | |
Tom Wai-Hong Tam | eaee340 | 2014-01-22 08:52:10 +0800 | [diff] [blame^] | 79 | |
| 80 | def create_chameleon_board(self): |
| 81 | """Create a ChameleonBoard object.""" |
| 82 | # TODO(waihong): Add verify and repair logic which are required while |
| 83 | # deploying to Cros Lab. |
| 84 | return chameleon.ChameleonBoard(self._chameleond_proxy) |