[autotest] Update Servo label exists method
Previously ServoLabel checked if the _servo_host object was not None.
That wasn't always true since during the reset job, the _servo_host
object does not get created since 'try_lab_servo' isn't true when
creating the host. This uses the method that servo_host module uses
to check for prior to creating the _servo_host object.
BUG=chromium:609143
TEST=locally with chromeos1-row5-rack6-host1
Change-Id: Ic4b65a28351f01d129e37b84ac4a9f097171fa0b
Reviewed-on: https://chromium-review.googlesource.com/342153
Commit-Ready: Kevin Cheng <kevcheng@chromium.org>
Tested-by: Kevin Cheng <kevcheng@chromium.org>
Reviewed-by: Kalin Stoyanov <kalin@chromium.org>
Reviewed-by: Dan Shi <dshi@google.com>
diff --git a/server/hosts/cros_label.py b/server/hosts/cros_label.py
index cf379e3..368298d 100644
--- a/server/hosts/cros_label.py
+++ b/server/hosts/cros_label.py
@@ -17,6 +17,7 @@
from autotest_lib.server.cros.dynamic_suite import constants as ds_constants
from autotest_lib.server.hosts import base_label
from autotest_lib.server.hosts import common_label
+from autotest_lib.server.hosts import servo_host
from autotest_lib.site_utils import hwid_lib
# pylint: disable=missing-docstring
@@ -297,7 +298,8 @@
_NAME = 'servo'
def exists(self, host):
- return host._servo_host is not None
+ return servo_host.servo_host_is_up(
+ servo_host.make_servo_hostname(host.hostname))
class VideoLabel(base_label.StringLabel):
diff --git a/server/hosts/servo_host.py b/server/hosts/servo_host.py
index 42b9559..a04a90b 100644
--- a/server/hosts/servo_host.py
+++ b/server/hosts/servo_host.py
@@ -80,6 +80,26 @@
return '.'.join(host_parts)
+def servo_host_is_up(servo_hostname):
+ """
+ Given a servo host name, return if it's up or not.
+
+ @param servo_hostname: hostname of the servo host.
+
+ @return True if it's up, False otherwise
+ """
+ # Technically, this duplicates the SSH ping done early in the servo
+ # proxy initialization code. However, this ping ends in a couple
+ # seconds when if fails, rather than the 60 seconds it takes to decide
+ # that an SSH ping has timed out. Specifically, that timeout happens
+ # when our servo DNS name resolves, but there is no host at that IP.
+ logging.info('Pinging servo host at %s', servo_hostname)
+ ping_config = ping_runner.PingConfig(
+ servo_hostname, count=3,
+ ignore_result=True, ignore_status=True)
+ return ping_runner.PingRunner().ping(ping_config).received > 0
+
+
class ServoHost(ssh_host.SSHHost):
"""Host class for a host that controls a servo, e.g. beaglebone."""
@@ -763,22 +783,9 @@
if not required_by_test:
return None
return ServoHost(required_by_test=True, is_in_lab=False, **servo_args)
- elif servo_args is not None or try_lab_servo:
- # Technically, this duplicates the SSH ping done early in the servo
- # proxy initialization code. However, this ping ends in a couple
- # seconds when if fails, rather than the 60 seconds it takes to decide
- # that an SSH ping has timed out. Specifically, that timeout happens
- # when our servo DNS name resolves, but there is no host at that IP.
- # TODO(dshi): crbug.com/380773 Remove this ping check once the bug is
- # fixed. Autotest should not try to verify servo if servo is
- # not required for the test.
- ping_config = ping_runner.PingConfig(
- lab_servo_hostname, count=3,
- ignore_result=True, ignore_status=True)
- logging.info('Pinging servo at %s', lab_servo_hostname)
- host_is_up = ping_runner.PingRunner().ping(ping_config).received > 0
- if host_is_up:
- return ServoHost(servo_host=lab_servo_hostname, is_in_lab=is_in_lab,
- required_by_test=required_by_test)
+ elif ((servo_args is not None or try_lab_servo)
+ and servo_host_is_up(lab_servo_hostname)):
+ return ServoHost(servo_host=lab_servo_hostname, is_in_lab=is_in_lab,
+ required_by_test=required_by_test)
else:
return None