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