Ian Lee | 318c7f2 | 2020-01-13 12:36:44 -0800 | [diff] [blame] | 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 | |
| 5 | import logging |
| 6 | |
| 7 | def bluetooth(hosts): |
| 8 | """Check for missing bluetooth hardware. |
| 9 | """ |
Kazuhiro Inaba | 4fa47ab | 2020-02-03 12:33:33 +0900 | [diff] [blame^] | 10 | # TODO(ianrlee): Reenable, once a nice check is found in b/148621587. |
| 11 | #for host in hosts: |
| 12 | # output = host.run('hcitool dev').stdout |
| 13 | # lines = output.splitlines() |
| 14 | # if len(lines) < 2 or not lines[0].startswith('Devices:'): |
| 15 | # return False, 'Failed: Bluetooth device is missing.'\ |
| 16 | # 'Stdout of the command "hcitool dev1"'\ |
| 17 | # 'on host %s was %s' % (host, output) |
Ian Lee | 318c7f2 | 2020-01-13 12:36:44 -0800 | [diff] [blame] | 18 | return True, '' |
| 19 | |
| 20 | |
| 21 | def region_us(hosts): |
| 22 | """Check that region is set to "us". |
| 23 | """ |
| 24 | for host in hosts: |
| 25 | output = host.run('vpd -g region').stdout |
Kazuhiro Inaba | b90e248 | 2020-01-24 14:07:32 +0900 | [diff] [blame] | 26 | if output != 'us': |
Ian Lee | 318c7f2 | 2020-01-13 12:36:44 -0800 | [diff] [blame] | 27 | return False, 'Failed: Region is not "us".'\ |
| 28 | 'Stdout of the command "vpd -l'\ |
| 29 | '| grep region" on host %s was %s'\ |
| 30 | % (host, output) |
| 31 | return True, '' |
| 32 | |
| 33 | prerequisite_map = { |
| 34 | 'bluetooth': bluetooth, |
| 35 | 'region_us': region_us, |
| 36 | } |
| 37 | |
| 38 | def check(prereq, hosts): |
| 39 | """Execute the prerequisite check. |
| 40 | |
| 41 | @return boolean indicating if check passes. |
| 42 | @return string error message if check fails. |
| 43 | """ |
| 44 | if prereq not in prerequisite_map: |
| 45 | logging.info('%s is not a valid prerequisite.', prereq) |
| 46 | return True, '' |
| 47 | return prerequisite_map[prereq](hosts) |