• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2011 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"""
6Factory install servo tests.
7
8This test supports the flags documented in FactoryInstallTest, plus:
9
10    servo_host: the host running the servod (defaults to localhost)
11    servo_port: the port on which to run servod (defaults to an unused
12        port)
13    debug_image_usb: whether to image the USB disk in servo mode (default to
14        true, may be set to false for debugging only if the USB disk is
15        already imaged)
16"""
17
18
19import glob, logging, os, re, time
20
21from autotest_lib.client.bin import utils as client_utils
22from autotest_lib.client.common_lib import error
23from autotest_lib.server import hosts
24from autotest_lib.server import utils
25from autotest_lib.server.cros.factory_install_test import FactoryInstallTest
26from autotest_lib.server.cros.servo import servo
27
28
29class factory_InstallServo(FactoryInstallTest):
30    """
31    Factory install VM tests.
32
33    See file-level docstring for more information.
34    """
35
36    def _create_servo(self, servo_host, servo_port):
37        self.servo = servo.Servo(
38                hosts.ServoHost(servo_host=servo_host, servo_port=servo_port))
39        def kill_servo():
40            del self.servo
41        self.cleanup_tasks.append(kill_servo)
42        self.servo.initialize_dut(cold_reset=True)
43
44        self.servo.enable_usb_hub()
45        self.servo_usb_disk = self.servo.probe_host_usb_dev()
46        if not self.servo_usb_disk:
47            raise error.TestError("Unable to find USB disk")
48        logging.info("Servo USB device detected at %s", self.servo_usb_disk)
49
50    def get_hwid_cfg(self):
51        """
52        Overridden from superclass.
53        """
54        return "servo"
55
56    def get_dut_client(self):
57        """
58        Overridden from superclass.
59        """
60        return hosts.SSHHost(self.dut_ip)
61
62    def run_factory_install(self, shim_image):
63        """
64        Overridden from superclass.
65        """
66        self.servo.install_recovery_image(image_path=shim_image)
67
68        # Wait for the IP address of the DUT to appear in the Miniohama
69        # server logs.
70        def get_dut_ip():
71            match = re.search(r"(\d+\.\d+\.\d+\.\d+) - -.*htpdate",
72                              open(self.miniomaha_output).read())
73            return match.group(1) if match else None
74
75        self.dut_ip = client_utils.poll_for_condition(
76            get_dut_ip, timeout=FactoryInstallTest.FACTORY_INSTALL_TIMEOUT_SEC,
77            desc="Get DUT IP")
78
79        logging.debug("DUT IP is %s", self.dut_ip)
80
81        if not self.get_dut_client().wait_up(
82            FactoryInstallTest.FACTORY_INSTALL_TIMEOUT_SEC):
83            raise error.TestFail("DUT never came up at %s" % self.dut_ip)
84
85    def reboot_for_wipe(self):
86        """
87        Overridden from superclass.
88        """
89        self.get_dut_client().reboot(
90            timeout=FactoryInstallTest.FIRST_BOOT_TIMEOUT_SEC)
91
92    def run_once(self, servo_host="localhost", servo_port=None,
93                 debug_image_usb=True,
94                 **args):
95        self.image_usb = self.parse_boolean(debug_image_usb)
96        self._create_servo(
97            servo_host,
98            int(servo_port) if servo_port else utils.get_unused_port())
99        super(factory_InstallServo, self).run_once(**args)
100