def main(): parser = argparse.ArgumentParser() parser.add_argument('--adb-path', help='Absolute path to the adb binary to use.') parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('--known-devices-file', action='append', default=[], dest='known_devices_files', help='Path to known device lists.') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_custom_deps = None if args.adb_path: devil_custom_deps = { 'adb': { devil_env.GetPlatform(): [args.adb_path], }, } devil_env.config.Initialize(configs=devil_custom_deps) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = device_status.GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] RecoverDevices(devices, blacklist)
def main(): parser = argparse.ArgumentParser() logging_common.AddLoggingArguments(parser) script_common.AddEnvironmentArguments(parser) parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('--known-devices-file', action='append', default=[], dest='known_devices_files', help='Path to known device lists.') parser.add_argument('--enable-usb-reset', action='store_true', help='Reset USB if necessary.') args = parser.parse_args() logging_common.InitializeLogging(args) script_common.InitializeEnvironment(args) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = device_status.GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] RecoverDevices(devices, blacklist, enable_usb_reset=args.enable_usb_reset)
def main(): parser = argparse.ArgumentParser() parser.add_argument("--adb-path", help="Absolute path to the adb binary to use.") parser.add_argument("--blacklist-file", help="Device blacklist JSON file.") parser.add_argument( "--known-devices-file", action="append", default=[], dest="known_devices_files", help="Path to known device lists.", ) parser.add_argument("-v", "--verbose", action="count", default=1, help="Log more information.") args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_dynamic_config = {"config_type": "BaseConfig", "dependencies": {}} if args.adb_path: devil_dynamic_config["dependencies"].update( {"adb": {"file_info": {devil_env.GetPlatform(): {"local_paths": [args.adb_path]}}}} ) devil_env.config.Initialize(configs=[devil_dynamic_config]) blacklist = device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None expected_devices = device_status.GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] RecoverDevices(devices, blacklist)
def testGetSerial(self): with self.assertCalls( (mock.call.devil.utils.cmd_helper.GetCmdStatusAndOutputWithTimeout( ['lsusb'], timeout=10), (None, DEVICE_LIST)), (mock.call.devil.utils.cmd_helper.GetCmdStatusAndOutputWithTimeout( ['lsusb', '-v', '-s', '003:007'], timeout=10), (None, RAW_OUTPUT))): self.assertEqual(lsusb.get_android_devices(), ['01d2450ea194a93b'])
def main(): parser = argparse.ArgumentParser() parser.add_argument("--adb-path", help="Absolute path to the adb binary to use.") parser.add_argument("--blacklist-file", help="Device blacklist JSON file.") parser.add_argument( "--known-devices-file", action="append", default=[], dest="known_devices_files", help="Path to known device lists.", ) parser.add_argument("--enable-usb-reset", action="store_true", help="Reset USB if necessary.") parser.add_argument("-v", "--verbose", action="count", default=1, help="Log more information.") args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_dynamic_config = devil_env.EmptyConfig() if args.adb_path: devil_dynamic_config["dependencies"].update( devil_env.LocalConfigItem("adb", devil_env.GetPlatform(), args.adb_path) ) devil_env.config.Initialize(configs=[devil_dynamic_config]) blacklist = device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None expected_devices = device_status.GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] RecoverDevices(devices, blacklist, enable_usb_reset=args.enable_usb_reset)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--adb-path', help='Absolute path to the adb binary to use.') parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('--known-devices-file', action='append', default=[], dest='known_devices_files', help='Path to known device lists.') parser.add_argument('--enable-usb-reset', action='store_true', help='Reset USB if necessary.') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_dynamic_config = devil_env.EmptyConfig() if args.adb_path: devil_dynamic_config['dependencies'].update( devil_env.LocalConfigItem( 'adb', devil_env.GetPlatform(), args.adb_path)) devil_env.config.Initialize(configs=[devil_dynamic_config]) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = device_status.GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] RecoverDevices(devices, blacklist, enable_usb_reset=args.enable_usb_reset)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--adb-path', help='Absolute path to the adb binary to use.') parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('--known-devices-file', action='append', default=[], dest='known_devices_files', help='Path to known device lists.') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_dynamic_config = devil_env.EmptyConfig() if args.adb_path: devil_dynamic_config['dependencies'].update( devil_env.LocalConfigItem( 'adb', devil_env.GetPlatform(), args.adb_path)) devil_env.config.Initialize(configs=[devil_dynamic_config]) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = device_status.GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] RecoverDevices(devices, blacklist)
def main(): parser = argparse.ArgumentParser() AddArguments(parser) args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_dynamic_config = { 'config_type': 'BaseConfig', 'dependencies': {}, } if args.adb_path: devil_dynamic_config['dependencies'].update({ 'adb': { 'file_info': { devil_env.GetPlatform(): { 'local_paths': [args.adb_path] } } } }) devil_env.config.Initialize(configs=[devil_dynamic_config]) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] statuses = DeviceStatus(devices, blacklist) # Log the state of all devices. _LogStatuses(statuses) # Update the last devices file(s). if args.overwrite_known_devices_files: for path in args.known_devices_files: device_list.WritePersistentDeviceList( path, [status['serial'] for status in statuses]) # Write device info to file for buildbot info display. _WriteBuildbotFile(args.buildbot_path, statuses) # Dump the device statuses to JSON. if args.json_output: with open(args.json_output, 'wb') as f: f.write(json.dumps(statuses, indent=4)) live_devices = [status['serial'] for status in statuses if (status['adb_status'] == 'device' and not IsBlacklisted(status['serial'], blacklist))] # If all devices failed, or if there are no devices, it's an infra error. return 0 if live_devices else exit_codes.INFRA
def main(): parser = argparse.ArgumentParser() AddArguments(parser) args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_dynamic_config = devil_env.EmptyConfig() if args.adb_path: devil_dynamic_config['dependencies'].update( devil_env.LocalConfigItem('adb', devil_env.GetPlatform(), args.adb_path)) devil_env.config.Initialize(configs=[devil_dynamic_config]) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [ device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices) ] statuses = DeviceStatus(devices, blacklist) # Log the state of all devices. _LogStatuses(statuses) # Update the last devices file(s). if args.overwrite_known_devices_files: for path in args.known_devices_files: device_list.WritePersistentDeviceList( path, [status['serial'] for status in statuses]) # Write device info to file for buildbot info display. _WriteBuildbotFile(args.buildbot_path, statuses) # Dump the device statuses to JSON. if args.json_output: with open(args.json_output, 'wb') as f: f.write( json.dumps(statuses, indent=4, sort_keys=True, separators=(',', ': '))) live_devices = [ status['serial'] for status in statuses if (status['adb_status'] == 'device' and not IsBlacklisted(status['serial'], blacklist)) ] # If all devices failed, or if there are no devices, it's an infra error. if not live_devices: logger.error('No available devices.') return 0 if live_devices else exit_codes.INFRA
def main(): parser = argparse.ArgumentParser() logging_common.AddLoggingArguments(parser) script_common.AddEnvironmentArguments(parser) AddArguments(parser) args = parser.parse_args() logging_common.InitializeLogging(args) script_common.InitializeEnvironment(args) denylist = (device_denylist.Denylist(args.denylist_file) if args.denylist_file else None) expected_devices = GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [ device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices) ] statuses = DeviceStatus(devices, denylist) # Log the state of all devices. _LogStatuses(statuses) # Update the last devices file(s). if args.overwrite_known_devices_files: for path in args.known_devices_files: device_list.WritePersistentDeviceList( path, [status['serial'] for status in statuses]) # Write device info to file for buildbot info display. _WriteBuildbotFile(args.buildbot_path, statuses) # Dump the device statuses to JSON. if args.json_output: with open(args.json_output, 'wb') as f: f.write( json.dumps(statuses, indent=4, sort_keys=True, separators=(',', ': '))) live_devices = [ status['serial'] for status in statuses if (status['adb_status'] == 'device' and not IsDenylisted(status['serial'], denylist)) ] # If all devices failed, or if there are no devices, it's an infra error. if not live_devices: logger.error('No available devices.') return 0 if live_devices else exit_codes.INFRA
def main(): parser = argparse.ArgumentParser() AddArguments(parser) args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_custom_deps = None if args.adb_path: devil_custom_deps = { 'adb': { devil_env.GetPlatform(): [args.adb_path], }, } devil_env.config.Initialize(configs=devil_custom_deps) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [ device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices) ] statuses = DeviceStatus(devices, blacklist) # Log the state of all devices. _LogStatuses(statuses) # Update the last devices file(s). if args.overwrite_known_devices_files: for path in args.known_devices_files: device_list.WritePersistentDeviceList( path, [status['serial'] for status in statuses]) # Write device info to file for buildbot info display. _WriteBuildbotFile(args.buildbot_path, statuses) # Dump the device statuses to JSON. if args.json_output: with open(args.json_output, 'wb') as f: f.write(json.dumps(statuses, indent=4)) live_devices = [ status['serial'] for status in statuses if (status['adb_status'] == 'device' and not IsBlacklisted(status['serial'], blacklist)) ] # If all devices failed, or if there are no devices, it's an infra error. return 0 if live_devices else exit_codes.INFRA
def DeviceStatus(devices, blacklist): """Generates status information for the given devices. Args: devices: The devices to generate status for. blacklist: The current device blacklist. Returns: A dict of the following form: { '<serial>': { 'serial': '<serial>', 'adb_status': str, 'usb_status': bool, 'blacklisted': bool, # only if the device is connected and not blacklisted 'type': ro.build.product, 'build': ro.build.id, 'build_detail': ro.build.fingerprint, 'battery': { ... }, 'imei_slice': str, 'wifi_ip': str, }, ... } """ adb_devices = { a[0].GetDeviceSerial(): a for a in adb_wrapper.AdbWrapper.Devices(desired_state=None, long_list=True) } usb_devices = set(lsusb.get_android_devices()) def blacklisting_device_status(device): serial = device.adb.GetDeviceSerial() adb_status = (adb_devices[serial][1] if serial in adb_devices else 'missing') usb_status = bool(serial in usb_devices) device_status = { 'serial': serial, 'adb_status': adb_status, 'usb_status': usb_status, } if not IsBlacklisted(serial, blacklist): if adb_status == 'device': try: build_product = device.build_product build_id = device.build_id build_fingerprint = device.GetProp('ro.build.fingerprint', cache=True) wifi_ip = device.GetProp('dhcp.wlan0.ipaddress') battery_info = _BatteryStatus(device, blacklist) imei_slice = _IMEISlice(device) if (device.product_name == 'mantaray' and battery_info.get('AC powered', None) != 'true'): logging.error( 'Mantaray device not connected to AC power.') device_status.update({ 'ro.build.product': build_product, 'ro.build.id': build_id, 'ro.build.fingerprint': build_fingerprint, 'battery': battery_info, 'imei_slice': imei_slice, 'wifi_ip': wifi_ip, }) except device_errors.CommandFailedError: logging.exception( 'Failure while getting device status for %s.', str(device)) if blacklist: blacklist.Extend([serial], reason='status_check_failure') except device_errors.CommandTimeoutError: logging.exception( 'Timeout while getting device status for %s.', str(device)) if blacklist: blacklist.Extend([serial], reason='status_check_timeout') elif blacklist: blacklist.Extend( [serial], reason=adb_status if usb_status else 'offline') device_status['blacklisted'] = IsBlacklisted(serial, blacklist) return device_status parallel_devices = device_utils.DeviceUtils.parallel(devices) statuses = parallel_devices.pMap(blacklisting_device_status).pGet(None) return statuses
def DeviceStatus(devices, blacklist): """Generates status information for the given devices. Args: devices: The devices to generate status for. blacklist: The current device blacklist. Returns: A dict of the following form: { '<serial>': { 'serial': '<serial>', 'adb_status': str, 'usb_status': bool, 'blacklisted': bool, # only if the device is connected and not blacklisted 'type': ro.build.product, 'build': ro.build.id, 'build_detail': ro.build.fingerprint, 'battery': { ... }, 'imei_slice': str, 'wifi_ip': str, }, ... } """ adb_devices = { a[0].GetDeviceSerial(): a for a in adb_wrapper.AdbWrapper.Devices(desired_state=None, long_list=True) } usb_devices = set(lsusb.get_android_devices()) def blacklisting_device_status(device): serial = device.adb.GetDeviceSerial() adb_status = adb_devices[serial][1] if serial in adb_devices else "unknown" usb_status = bool(serial in usb_devices) device_status = {"serial": serial, "adb_status": adb_status, "usb_status": usb_status} if adb_status == "device": if not _IsBlacklisted(serial, blacklist): try: build_product = device.build_product build_id = device.build_id build_fingerprint = device.GetProp("ro.build.fingerprint", cache=True) wifi_ip = device.GetProp("dhcp.wlan0.ipaddress") battery_info = _BatteryStatus(device, blacklist) imei_slice = _IMEISlice(device) if device.product_name == "mantaray" and battery_info.get("AC powered", None) != "true": logging.error("Mantaray device not connected to AC power.") device_status.update( { "ro.build.product": build_product, "ro.build.id": build_id, "ro.build.fingerprint": build_fingerprint, "battery": battery_info, "imei_slice": imei_slice, "wifi_ip": wifi_ip, # TODO(jbudorick): Remove these once no clients depend on them. "type": build_product, "build": build_id, "build_detail": build_fingerprint, } ) except device_errors.CommandFailedError: logging.exception("Failure while getting device status for %s.", str(device)) if blacklist: blacklist.Extend([serial]) except device_errors.CommandTimeoutError: logging.exception("Timeout while getting device status for %s.", str(device)) if blacklist: blacklist.Extend([serial]) elif blacklist: blacklist.Extend([serial]) device_status["blacklisted"] = _IsBlacklisted(serial, blacklist) return device_status parallel_devices = device_utils.DeviceUtils.parallel(devices) statuses = parallel_devices.pMap(blacklisting_device_status).pGet(None) return statuses
def DeviceStatus(devices, blacklist): """Generates status information for the given devices. Args: devices: The devices to generate status for. blacklist: The current device blacklist. Returns: A dict of the following form: { '<serial>': { 'serial': '<serial>', 'adb_status': str, 'usb_status': bool, 'blacklisted': bool, # only if the device is connected and not blacklisted 'type': ro.build.product, 'build': ro.build.id, 'build_detail': ro.build.fingerprint, 'battery': { ... }, 'imei_slice': str, 'wifi_ip': str, }, ... } """ adb_devices = { a[0].GetDeviceSerial(): a for a in adb_wrapper.AdbWrapper.Devices(desired_state=None, long_list=True) } usb_devices = set(lsusb.get_android_devices()) def blacklisting_device_status(device): serial = device.adb.GetDeviceSerial() adb_status = ( adb_devices[serial][1] if serial in adb_devices else 'missing') usb_status = bool(serial in usb_devices) device_status = { 'serial': serial, 'adb_status': adb_status, 'usb_status': usb_status, } if not IsBlacklisted(serial, blacklist): if adb_status == 'device': try: build_product = device.build_product build_id = device.build_id build_fingerprint = device.GetProp('ro.build.fingerprint', cache=True) wifi_ip = device.GetProp('dhcp.wlan0.ipaddress') battery_info = _BatteryStatus(device, blacklist) imei_slice = _IMEISlice(device) if (device.product_name == 'mantaray' and battery_info.get('AC powered', None) != 'true'): logging.error('Mantaray device not connected to AC power.') device_status.update({ 'ro.build.product': build_product, 'ro.build.id': build_id, 'ro.build.fingerprint': build_fingerprint, 'battery': battery_info, 'imei_slice': imei_slice, 'wifi_ip': wifi_ip, }) except device_errors.CommandFailedError: logging.exception('Failure while getting device status for %s.', str(device)) if blacklist: blacklist.Extend([serial], reason='status_check_failure') except device_errors.CommandTimeoutError: logging.exception('Timeout while getting device status for %s.', str(device)) if blacklist: blacklist.Extend([serial], reason='status_check_timeout') elif blacklist: blacklist.Extend([serial], reason=adb_status if usb_status else 'offline') device_status['blacklisted'] = IsBlacklisted(serial, blacklist) return device_status parallel_devices = device_utils.DeviceUtils.parallel(devices) statuses = parallel_devices.pMap(blacklisting_device_status).pGet(None) return statuses
def main(): parser = argparse.ArgumentParser() parser.add_argument('--out-dir', help='Directory where the device path is stored', default=os.path.join(host_paths.DIR_SOURCE_ROOT, 'out')) parser.add_argument('--restart-usb', action='store_true', help='DEPRECATED. ' 'This script now always tries to reset USB.') parser.add_argument('--json-output', help='Output JSON information into a specified file.') parser.add_argument('--adb-path', type=os.path.abspath, help='Absolute path to the adb binary to use.') parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('--known-devices-file', action='append', default=[], dest='known_devices_files', help='Path to known device lists.') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_chromium.Initialize(adb_path=args.adb_path) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = set() try: for path in args.known_devices_files: if os.path.exists(path): expected_devices.update( device_list.GetPersistentDeviceList(path)) except IOError: logging.warning('Problem reading %s, skipping.', path) logging.info('Expected devices:') for device in expected_devices: logging.info(' %s', device) usb_devices = set(lsusb.get_android_devices()) devices = [ device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices) ] RecoverDevices(devices, blacklist) statuses = DeviceStatus(devices, blacklist) # Log the state of all devices. for status in statuses: logging.info(status['serial']) adb_status = status.get('adb_status') blacklisted = status.get('blacklisted') logging.info(' USB status: %s', 'online' if status.get('usb_status') else 'offline') logging.info(' ADB status: %s', adb_status) logging.info(' Blacklisted: %s', str(blacklisted)) if adb_status == 'device' and not blacklisted: logging.info(' Device type: %s', status.get('ro.build.product')) logging.info(' OS build: %s', status.get('ro.build.id')) logging.info(' OS build fingerprint: %s', status.get('ro.build.fingerprint')) logging.info(' Battery state:') for k, v in status.get('battery', {}).iteritems(): logging.info(' %s: %s', k, v) logging.info(' IMEI slice: %s', status.get('imei_slice')) logging.info(' WiFi IP: %s', status.get('wifi_ip')) # Update the last devices file(s). for path in args.known_devices_files: device_list.WritePersistentDeviceList( path, [status['serial'] for status in statuses]) # Write device info to file for buildbot info display. if os.path.exists('/home/chrome-bot'): with open('/home/chrome-bot/.adb_device_info', 'w') as f: for status in statuses: try: if status['adb_status'] == 'device': f.write( '{serial} {adb_status} {build_product} {build_id} ' '{temperature:.1f}C {level}%\n'.format( serial=status['serial'], adb_status=status['adb_status'], build_product=status['type'], build_id=status['build'], temperature=float( status['battery']['temperature']) / 10, level=status['battery']['level'])) elif status.get('usb_status', False): f.write('{serial} {adb_status}\n'.format( serial=status['serial'], adb_status=status['adb_status'])) else: f.write('{serial} offline\n'.format( serial=status['serial'])) except Exception: # pylint: disable=broad-except pass # Dump the device statuses to JSON. if args.json_output: with open(args.json_output, 'wb') as f: f.write(json.dumps(statuses, indent=4)) live_devices = [ status['serial'] for status in statuses if (status['adb_status'] == 'device' and not _IsBlacklisted(status['serial'], blacklist)) ] # If all devices failed, or if there are no devices, it's an infra error. if not live_devices: logging.error('No available devices.') return 0 if live_devices else exit_codes.INFRA
help='Path to known presentation.device lists.') parser.add_argument('--enable-usb-reset', action='store_true', help='Reset USB if necessary.') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_dynamic_config = devil_env.EmptyConfig() if args.adb_path: devil_dynamic_config['dependencies'].update( devil_env.LocalConfigItem( 'adb', devil_env.GetPlatform(), args.adb_path)) devil_env.config.Initialize(configs=[devil_dynamic_config]) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = device_status.GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] RecoverDevices(devices, blacklist, enable_usb_reset=args.enable_usb_reset) if __name__ == '__main__': sys.exit(presentation.main())
def main(): parser = argparse.ArgumentParser() parser.add_argument('--out-dir', help='Directory where the device path is stored', default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) parser.add_argument('--restart-usb', action='store_true', help='DEPRECATED. ' 'This script now always tries to reset USB.') parser.add_argument('--json-output', help='Output JSON information into a specified file.') parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) last_devices_path = os.path.join( args.out_dir, device_list.LAST_DEVICES_FILENAME) try: expected_devices = set( device_list.GetPersistentDeviceList(last_devices_path)) except IOError: expected_devices = set() usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] RecoverDevices(devices, blacklist) statuses = DeviceStatus(devices, blacklist) # Log the state of all devices. for status in statuses: logging.info(status['serial']) adb_status = status.get('adb_status') blacklisted = status.get('blacklisted') logging.info(' USB status: %s', 'online' if status.get('usb_status') else 'offline') logging.info(' ADB status: %s', adb_status) logging.info(' Blacklisted: %s', str(blacklisted)) if adb_status == 'device' and not blacklisted: logging.info(' Device type: %s', status.get('ro.build.product')) logging.info(' OS build: %s', status.get('ro.build.id')) logging.info(' OS build fingerprint: %s', status.get('ro.build.fingerprint')) logging.info(' Battery state:') for k, v in status.get('battery', {}).iteritems(): logging.info(' %s: %s', k, v) logging.info(' IMEI slice: %s', status.get('imei_slice')) logging.info(' WiFi IP: %s', status.get('wifi_ip')) # Update the last devices file. device_list.WritePersistentDeviceList( last_devices_path, [status['serial'] for status in statuses]) # Write device info to file for buildbot info display. if os.path.exists('/home/chrome-bot'): with open('/home/chrome-bot/.adb_device_info', 'w') as f: for status in statuses: try: if status['adb_status'] == 'device': f.write('{serial} {adb_status} {build_product} {build_id} ' '{temperature:.1f}C {level}%\n'.format( serial=status['serial'], adb_status=status['adb_status'], build_product=status['type'], build_id=status['build'], temperature=float(status['battery']['temperature']) / 10, level=status['battery']['level'] )) else: f.write('{serial} {adb_status}'.format( serial=status['serial'], adb_status=status['adb_status'] )) except Exception: # pylint: disable=broad-except pass # Dump the device statuses to JSON. if args.json_output: with open(args.json_output, 'wb') as f: f.write(json.dumps(statuses, indent=4)) live_devices = [status['serial'] for status in statuses if (status['adb_status'] == 'device' and not _IsBlacklisted(status['serial'], blacklist))] # If all devices failed, or if there are no devices, it's an infra error. return 0 if live_devices else constants.INFRA_EXIT_CODE
def main(): parser = argparse.ArgumentParser() parser.add_argument('--json-output', help='Output JSON information into a specified file.') parser.add_argument('--adb-path', help='Absolute path to the adb binary to use.') parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('--known-devices-file', action='append', default=[], dest='known_devices_files', help='Path to known device lists.') parser.add_argument('--buildbot-path', '-b', default='/home/chrome-bot/.adb_device_info', help='Absolute path to buildbot file location') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') parser.add_argument('-w', '--overwrite-known-devices-files', action='store_true', help='If set, overwrites known devices files wiht new ' 'values.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_custom_deps = None if args.adb_path: devil_custom_deps = { 'adb': { devil_env.GetPlatform(): [args.adb_path], }, } devil_env.config.Initialize(configs=devil_custom_deps) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [ device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices) ] statuses = DeviceStatus(devices, blacklist) # Log the state of all devices. _LogStatuses(statuses) # Update the last devices file(s). if args.overwrite_known_devices_files: for path in args.known_devices_files: device_list.WritePersistentDeviceList( path, [status['serial'] for status in statuses]) # Write device info to file for buildbot info display. _WriteBuildbotFile(args.buildbot_path, statuses) # Dump the device statuses to JSON. if args.json_output: with open(args.json_output, 'wb') as f: f.write(json.dumps(statuses, indent=4)) live_devices = [ status['serial'] for status in statuses if (status['adb_status'] == 'device' and not IsBlacklisted(status['serial'], blacklist)) ] # If all devices failed, or if there are no devices, it's an infra error. return 0 if live_devices else exit_codes.INFRA
def main(): parser = argparse.ArgumentParser() parser.add_argument( "--out-dir", help="Directory where the device path is stored", default=os.path.join(constants.DIR_SOURCE_ROOT, "out"), ) parser.add_argument( "--restart-usb", action="store_true", help="DEPRECATED. " "This script now always tries to reset USB." ) parser.add_argument("--json-output", help="Output JSON information into a specified file.") parser.add_argument("--blacklist-file", help="Device blacklist JSON file.") parser.add_argument("-v", "--verbose", action="count", default=1, help="Log more information.") args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) blacklist = device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None last_devices_path = os.path.join(args.out_dir, device_list.LAST_DEVICES_FILENAME) try: expected_devices = set(device_list.GetPersistentDeviceList(last_devices_path)) except IOError: expected_devices = set() usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] RecoverDevices(devices, blacklist) statuses = DeviceStatus(devices, blacklist) # Log the state of all devices. for status in statuses: logging.info(status["serial"]) adb_status = status.get("adb_status") blacklisted = status.get("blacklisted") logging.info(" USB status: %s", "online" if status.get("usb_status") else "offline") logging.info(" ADB status: %s", adb_status) logging.info(" Blacklisted: %s", str(blacklisted)) if adb_status == "device" and not blacklisted: logging.info(" Device type: %s", status.get("ro.build.product")) logging.info(" OS build: %s", status.get("ro.build.id")) logging.info(" OS build fingerprint: %s", status.get("ro.build.fingerprint")) logging.info(" Battery state:") for k, v in status.get("battery", {}).iteritems(): logging.info(" %s: %s", k, v) logging.info(" IMEI slice: %s", status.get("imei_slice")) logging.info(" WiFi IP: %s", status.get("wifi_ip")) # Update the last devices file. device_list.WritePersistentDeviceList(last_devices_path, [status["serial"] for status in statuses]) # Write device info to file for buildbot info display. if os.path.exists("/home/chrome-bot"): with open("/home/chrome-bot/.adb_device_info", "w") as f: for status in statuses: try: if status["adb_status"] == "device": f.write( "{serial} {adb_status} {build_product} {build_id} " "{temperature:.1f}C {level}%\n".format( serial=status["serial"], adb_status=status["adb_status"], build_product=status["type"], build_id=status["build"], temperature=float(status["battery"]["temperature"]) / 10, level=status["battery"]["level"], ) ) else: f.write( "{serial} {adb_status}".format(serial=status["serial"], adb_status=status["adb_status"]) ) except Exception: # pylint: disable=broad-except pass # Dump the device statuses to JSON. if args.json_output: with open(args.json_output, "wb") as f: f.write(json.dumps(statuses, indent=4)) live_devices = [ status["serial"] for status in statuses if (status["adb_status"] == "device" and not _IsBlacklisted(status["serial"], blacklist)) ] # If all devices failed, or if there are no devices, it's an infra error. return 0 if live_devices else constants.INFRA_EXIT_CODE
def main(): parser = argparse.ArgumentParser() parser.add_argument('--json-output', help='Output JSON information into a specified file.') parser.add_argument('--adb-path', help='Absolute path to the adb binary to use.') parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('--known-devices-file', action='append', default=[], dest='known_devices_files', help='Path to known device lists.') parser.add_argument('--buildbot-path', '-b', default='/home/chrome-bot/.adb_device_info', help='Absolute path to buildbot file location') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') parser.add_argument('-w', '--overwrite-known-devices-files', action='store_true', help='If set, overwrites known devices files wiht new ' 'values.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_custom_deps = None if args.adb_path: devil_custom_deps = { 'adb': { devil_env.GetPlatform(): [args.adb_path], }, } devil_env.config.Initialize(configs=devil_custom_deps) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] statuses = DeviceStatus(devices, blacklist) # Log the state of all devices. _LogStatuses(statuses) # Update the last devices file(s). if args.overwrite_known_devices_files: for path in args.known_devices_files: device_list.WritePersistentDeviceList( path, [status['serial'] for status in statuses]) # Write device info to file for buildbot info display. _WriteBuildbotFile(args.buildbot_path, statuses) # Dump the device statuses to JSON. if args.json_output: with open(args.json_output, 'wb') as f: f.write(json.dumps(statuses, indent=4)) live_devices = [status['serial'] for status in statuses if (status['adb_status'] == 'device' and not IsBlacklisted(status['serial'], blacklist))] # If all devices failed, or if there are no devices, it's an infra error. return 0 if live_devices else exit_codes.INFRA