• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 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
5import logging
6
7from autotest_lib.client.common_lib.cros import autoupdater
8from autotest_lib.client.common_lib.cros import dev_server
9from autotest_lib.server import afe_utils
10from autotest_lib.server import site_utils
11from autotest_lib.server import test
12from autotest_lib.server.cros.dynamic_suite import frontend_wrappers
13
14
15class servohost_Reboot(test.test):
16    """Enable a safe reboot for a servo host."""
17    version = 1
18
19    def run_once(self, host, force_reboot=False):
20        """
21        Perfom a safe reboot for a servo host.
22
23        A servo host could be used by multiple duts so we need to lock them down
24        to ensure they're not running a test that requires the servo.
25
26        @param host: Dut that was designated to kick off the reboot for the
27                servo host.
28        """
29        s_host = host._servo_host
30        reboot_needed = force_reboot
31
32        # If we don't have to force reboot, check if we need to reboot at all.
33        if not force_reboot:
34          servo_host_build = afe_utils.get_stable_cros_image_name(
35                  s_host.get_board())
36          ds = dev_server.ImageServer.resolve(s_host.hostname)
37          url = ds.get_update_url(servo_host_build)
38          updater = autoupdater.ChromiumOSUpdater(update_url=url, host=s_host)
39          reboot_needed = (updater.check_update_status() ==
40                           autoupdater.UPDATER_NEED_REBOOT)
41        if reboot_needed:
42            # Get the list of duts to lock but take out the current host so we
43            # don't wait forever.
44            afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10)
45            dut_list = s_host.get_attached_duts(afe)
46            dut_list.remove(host.hostname)
47
48            # Lock the duts and reboot the servo host.
49            lock_msg = 'reboot for servo host %s' % s_host.hostname
50            with site_utils.lock_duts_and_wait(
51                    dut_list, afe, lock_msg=lock_msg) as lock_success:
52                logging.info(
53                        'status waiting for duts to go idle for '
54                        'servo host[%s]: %s', s_host.hostname, lock_success)
55                if lock_success:
56                    s_host.reboot()
57