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 logging 6 7_ERROR_PREFIX = 'CTS Test Precondition Failed' 8 9def bluetooth(hosts): 10 """Check for missing bluetooth hardware. 11 """ 12 # TODO(ianrlee): Reenable, once a nice check is found in b/148621587. 13 # for host in hosts: 14 # output = host.run('hcitool dev').stdout 15 # lines = output.splitlines() 16 # if len(lines) < 2 or not lines[0].startswith('Devices:'): 17 # return False, '%s: Bluetooth device is missing.'\ 18 # 'Stdout of the command "hcitool dev"'\ 19 # 'on host %s was %s' % (_ERROR_PREFIX, host, output) 20 return True, '' 21 22 23def region_us(hosts): 24 """Check that region is set to "us". 25 """ 26 for host in hosts: 27 output = host.run('vpd -g region', ignore_status=True).stdout 28 if output not in ['us', '']: 29 return False, '%s: Region is not "us" or empty. '\ 30 'STDOUT of the command "vpd -l '\ 31 'region" on host %s was %s'\ 32 % (_ERROR_PREFIX, host, output) 33 return True, '' 34 35prerequisite_map = { 36 'bluetooth': bluetooth, 37 'region_us': region_us, 38} 39 40def check(prereq, hosts): 41 """Execute the prerequisite check. 42 43 @return boolean indicating if check passes. 44 @return string error message if check fails. 45 """ 46 if prereq not in prerequisite_map: 47 logging.info('%s is not a valid prerequisite.', prereq) 48 return True, '' 49 return prerequisite_map[prereq](hosts) 50