audit: Verify usb by run fdisk before run check on the DUT
Found the case where we had some strange device reported as USB but it was just strange file/record. This will save us from false check run.
BUG=b:168926205
TEST=run local audit task
./site_utils/admin_audit/main.py --hostname chromeos1-row4-rack4-host2 --results-dir /tr --host-info-file /tr/host_info_store/chromeos1-row4-rack4-host2.store verify-servo-usb-drive
Change-Id: I1814d68fcef170dda681347e2f99e128a673b1a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2573376
Tested-by: Otabek Kasimov <otabek@google.com>
Reviewed-by: Garry Wang <xianuowang@chromium.org>
Commit-Queue: Otabek Kasimov <otabek@google.com>
diff --git a/site_utils/admin_audit/verifiers.py b/site_utils/admin_audit/verifiers.py
index 24688c0..eed5876 100644
--- a/site_utils/admin_audit/verifiers.py
+++ b/site_utils/admin_audit/verifiers.py
@@ -161,11 +161,29 @@
cmd = ('. /usr/share/misc/chromeos-common.sh; get_device_type %s' %
path)
check_run = self._dut_host.run(cmd, timeout=30, ignore_status=True)
- if check_run.stdout.strip() == 'USB':
+ if check_run.stdout.strip() != 'USB':
+ continue
+ if self._quick_check_if_device_responsive(self._dut_host, path):
logging.info('USB drive detected on DUT side as %s', path)
return path
return None
+ def _quick_check_if_device_responsive(self, host, usb_path):
+ """Verify that device """
+ validate_cmd = 'fdisk -l %s' % usb_path
+ try:
+ resp = host.run(validate_cmd, ignore_status=True, timeout=30)
+ if resp.exit_status == 0:
+ return True
+ logging.error('USB %s is not detected by fdisk!', usb_path)
+ except error.AutoservRunError as e:
+ if 'Timeout encountered' in str(e):
+ logging.warning('Timeout encountered during fdisk run.')
+ else:
+ logging.error('(Not critical) fdisk check fail for %s; %s',
+ usb_path, str(e))
+ return False
+
def _run_check_on_host(self, host, usb):
"""Run badblocks on the provided host.