• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 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 common
6from autotest_lib.client.common_lib import hosts
7from autotest_lib.server.hosts import repair_utils
8
9
10class _LabstationUpdateVerifier(hosts.Verifier):
11    """
12    Verifier to trigger a labstation update, if necessary.
13
14    The operation doesn't wait for the update to complete and is
15    considered a success whether or not the servo is currently
16    up-to-date.
17    """
18
19    def verify(self, host):
20        """First, only run this verifier if the host is in the physical lab.
21        Secondly, skip if the test is being run by test_that, because subnet
22        restrictions can cause the update to fail.
23        """
24        if host.is_in_lab() and host.job and host.job.in_lab:
25            host.update_image(wait_for_update=False)
26
27    @property
28    def description(self):
29        return 'Labstation image is updated to current stable-version'
30
31
32class _LabstationRebootVerifier(hosts.Verifier):
33    """Check if reboot is need for the labstation and perform a reboot if it's
34    not currently using by any tests.
35    """
36    def verify(self, host):
37        if host.is_reboot_requested():
38            host.try_reboot()
39
40    @property
41    def description(self):
42        return 'Reboot labstation if requested and the labstation is not in use'
43
44
45def create_labstation_repair_strategy():
46    """
47    Return a `RepairStrategy` for a `LabstationHost`.
48    """
49    verify_dag = [
50        (repair_utils.SshVerifier,   'ssh',     []),
51        (_LabstationUpdateVerifier,  'update',  ['ssh']),
52        (_LabstationRebootVerifier,  'reboot',  ['ssh']),
53    ]
54
55    repair_actions = [
56        (repair_utils.RPMCycleRepair, 'rpm', [], ['ssh']),
57    ]
58    return hosts.RepairStrategy(verify_dag, repair_actions, 'labstation')