[labpack]: Update wifi_state label in host_info file.
Sometimes wifi is available on a host but it cannot be
detected. Consequently, the tests that depend on wifi will fail. It is
best to avoid such cascade of failures by first checking whether the
wifi chip can be detected. The current change is to do this check and
populate a host-info label.
This logic to detect wifi chip uses WifiVerifier.
BUG=b:186019529
TEST=unittests, run local repair task.
Change-Id: I58a846bd4cbdf4c1f368d24a9642c01c654200d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/labpack/+/2881333
Tested-by: Vineet Joshi <vkjoshi@google.com>
Reviewed-by: Otabek Kasimov <otabek@google.com>
Commit-Queue: Vineet Joshi <vkjoshi@google.com>
diff --git a/server/hosts/cros_repair.py b/server/hosts/cros_repair.py
index 3bb1c0e..1e0afd0 100644
--- a/server/hosts/cros_repair.py
+++ b/server/hosts/cros_repair.py
@@ -35,6 +35,7 @@
from autotest_lib.site_utils.admin_audit import verifiers as audit_verify
from autotest_lib.site_utils.admin_audit import constants as audit_const
from autotest_lib.site_utils.admin_audit import battery_validator
+from autotest_lib.site_utils.admin_audit import wifi_validator
from six.moves import range
try:
@@ -984,6 +985,44 @@
return 'Ensure DUT battery is in good state.'
+class AuditWifi(hosts.Verifier):
+ """Verify that wifi chip on the host is detected correctly.
+
+ Check if the wifi chip on the host has been recognized and its
+ device driver been loaded into the kernel.
+ """
+
+ @timeout_util.TimeoutDecorator(cros_constants.VERIFY_TIMEOUT_SEC)
+ def verify(self, host):
+ # pylint: disable=missing-docstring
+
+ # All exceptions get caught within the call to validate. The
+ # method always returns an appropriate state, including cases
+ # when timeout happens during detecting the state of wifi chip
+ # on the host.
+ state = self._get_validator(host).validate()
+
+ if state == audit_const.HW_STATE_UNKNOWN:
+ # Either timeout, or some other exception was witnessed
+ # while determining the wifi state.
+ raise hosts.AutoservNonCriticalVerifyError(
+ 'DUT wifi state cannot be extracted.')
+ if state == audit_const.HW_STATE_NEED_REPLACEMENT:
+ logging.info('Detected problems with wifi chip on the DUT.')
+
+ def _is_applicable(self, host):
+ return self._get_validator(host).is_wifi_expected()
+
+ def _get_validator(self, host):
+ if not getattr(self, '_validator', None):
+ self._validator = wifi_validator.WifiValidator(host)
+ return self._validator
+
+ @property
+ def description(self):
+ return 'Ensure that WiFi chip is detected on the device'
+
+
class ServoKeyboardMapVerifier(hosts.Verifier):
"""Not critical verify to flash servo keyboard for the host.
@@ -1653,6 +1692,7 @@
(StopStartUIVerifier, 'stop_start_ui', ('ssh', )),
(DUTStorageVerifier, 'storage', ('ssh', )),
(AuditBattery, 'audit_battery', ()),
+ (AuditWifi, 'audit_wifi', ('ssh', )),
(GscToolPresentVerifier, 'dut_gsctool', ('ssh', )),
(ServoKeyboardMapVerifier, 'dut_servo_keyboard', ('ssh', )),
(ServoMacAddressVerifier, 'dut_servo_macaddr', ('ssh', )),
diff --git a/server/hosts/cros_repair_unittest.py b/server/hosts/cros_repair_unittest.py
index 23ef54c..81c5eee 100755
--- a/server/hosts/cros_repair_unittest.py
+++ b/server/hosts/cros_repair_unittest.py
@@ -40,6 +40,7 @@
(cros_repair.StopStartUIVerifier, 'stop_start_ui', ('ssh', )),
(cros_repair.DUTStorageVerifier, 'storage', ('ssh', )),
(cros_repair.AuditBattery, 'audit_battery', ()),
+ (cros_repair.AuditWifi, 'audit_wifi', ('ssh', )),
(cros_repair.GscToolPresentVerifier, 'dut_gsctool', ('ssh', )),
(cros_repair.ServoKeyboardMapVerifier, 'dut_servo_keyboard',
('ssh', )),