Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: scripts/slave/recipe_modules/chromium_android/api.py

Issue 2146433003: [Android] Reland splitting of device recovery and device status. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | scripts/slave/recipe_modules/chromium_android/example.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import contextlib 5 import contextlib
6 import datetime 6 import datetime
7 import json 7 import json
8 import os 8 import os
9 import re 9 import re
10 import sys 10 import sys
(...skipping 14 matching lines...) Expand all
25 25
26 def get_config_defaults(self): 26 def get_config_defaults(self):
27 return { 27 return {
28 'REVISION': self.m.properties.get('revision', ''), 28 'REVISION': self.m.properties.get('revision', ''),
29 'CHECKOUT_PATH': self.m.path['checkout'], 29 'CHECKOUT_PATH': self.m.path['checkout'],
30 } 30 }
31 31
32 @property 32 @property
33 def devices(self): 33 def devices(self):
34 assert self._devices is not None,\ 34 assert self._devices is not None,\
35 'devices is only available after device_status_check()' 35 'devices is only available after device_status()'
36 return self._devices 36 return self._devices
37 37
38 @property 38 @property
39 def out_path(self): 39 def out_path(self):
40 return self.m.path['checkout'].join('out') 40 return self.m.path['checkout'].join('out')
41 41
42 @property 42 @property
43 def coverage_dir(self): 43 def coverage_dir(self):
44 return self.out_path.join(self.c.BUILD_CONFIG, 'coverage') 44 return self.out_path.join(self.c.BUILD_CONFIG, 'coverage')
45 45
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 args = ['--verbose', '--adb-path', self.m.adb.adb_path()] 322 args = ['--verbose', '--adb-path', self.m.adb.adb_path()]
323 return self.m.python('authorize_adb_devices', script, args, infra_step=True, 323 return self.m.python('authorize_adb_devices', script, args, infra_step=True,
324 env=self.m.chromium.get_env()) 324 env=self.m.chromium.get_env())
325 325
326 def detect_and_setup_devices(self, restart_usb=False, skip_wipe=False, 326 def detect_and_setup_devices(self, restart_usb=False, skip_wipe=False,
327 disable_location=False, min_battery_level=None, 327 disable_location=False, min_battery_level=None,
328 disable_network=False, disable_java_debug=False, 328 disable_network=False, disable_java_debug=False,
329 reboot_timeout=None, max_battery_temp=None, 329 reboot_timeout=None, max_battery_temp=None,
330 remove_system_webview=False): 330 remove_system_webview=False):
331 self.authorize_adb_devices() 331 self.authorize_adb_devices()
332 self.device_status_check(restart_usb=restart_usb) 332 self.device_recovery()
333 self.provision_devices( 333 self.provision_devices(
334 skip_wipe=skip_wipe, disable_location=disable_location, 334 skip_wipe=skip_wipe, disable_location=disable_location,
335 min_battery_level=min_battery_level, disable_network=disable_network, 335 min_battery_level=min_battery_level, disable_network=disable_network,
336 disable_java_debug=disable_java_debug, reboot_timeout=reboot_timeout, 336 disable_java_debug=disable_java_debug, reboot_timeout=reboot_timeout,
337 max_battery_temp=max_battery_temp, 337 max_battery_temp=max_battery_temp,
338 remove_system_webview=remove_system_webview) 338 remove_system_webview=remove_system_webview)
339 self.device_status()
339 340
340 @property 341 @property
341 def blacklist_file(self): 342 def blacklist_file(self):
342 return self.out_path.join('bad_devices.json') 343 return self.out_path.join('bad_devices.json')
343 344
344 345
345 def revert_device_file_format(self): 346 def revert_device_file_format(self):
346 # If current device file is jsonified, revert it back to original format. 347 # If current device file is jsonified, revert it back to original format.
347 if self.m.path.exists(self.known_devices_file): 348 if self.m.path.exists(self.known_devices_file):
348 with self.m.step.nest('fix_device_file_format'): 349 with self.m.step.nest('fix_device_file_format'):
(...skipping 10 matching lines...) Expand all
359 except ValueError: 360 except ValueError:
360 # File wasn't json, so no need to revert. 361 # File wasn't json, so no need to revert.
361 self.m.step.active_result.presentation.step_text += ( 362 self.m.step.active_result.presentation.step_text += (
362 'file format is compatible') 363 'file format is compatible')
363 364
364 def device_status_check(self, restart_usb=False, **kwargs): 365 def device_status_check(self, restart_usb=False, **kwargs):
365 # TODO(bpastene): Remove once chromium revisions prior to 366 # TODO(bpastene): Remove once chromium revisions prior to
366 # crrev.com/1faecde0c03013b6cd725da413339c60223f8948 are no longer tested. 367 # crrev.com/1faecde0c03013b6cd725da413339c60223f8948 are no longer tested.
367 # See crbug.com/619707 for context. 368 # See crbug.com/619707 for context.
368 self.revert_device_file_format() 369 self.revert_device_file_format()
370 self.device_recovery()
371 self.device_status()
369 372
370 # TODO(phajdan.jr): Remove path['build'] usage, http://crbug.com/437264 . 373 def device_recovery(self, restart_usb=False, **kwargs):
371 args = [ 374 args = [
375 '--blacklist-file', self.blacklist_file,
376 '--known-devices-file', self.known_devices_file,
372 '--adb-path', self.m.adb.adb_path(), 377 '--adb-path', self.m.adb.adb_path(),
378 '-v'
379 ]
380 self.m.step(
381 'device_recovery',
382 [self.m.path['checkout'].join('third_party', 'catapult', 'devil',
383 'devil', 'android', 'tools',
384 'device_recovery.py')] + args,
385 env=self.m.chromium.get_env(),
386 infra_step=True,
387 **kwargs)
388
389 def device_status(self, **kwargs):
390 buildbot_file = '/home/chrome-bot/.adb_device_info'
391 args = [
392 '--json-output', self.m.json.output(),
373 '--blacklist-file', self.blacklist_file, 393 '--blacklist-file', self.blacklist_file,
374 '--json-output', self.m.json.output(), 394 '--known-devices-file', self.known_devices_file,
375 '--known-devices-file', self.known_devices_file 395 '--buildbot-path', buildbot_file,
396 '--adb-path', self.m.adb.adb_path(),
397 '-v', '--overwrite-known-devices-files',
376 ] 398 ]
377 if restart_usb:
378 args += ['--restart-usb']
379
380 try: 399 try:
381 result = self.m.step( 400 result = self.m.step(
382 'device_status_check', 401 'device_status',
383 [self.m.path['checkout'].join('build', 'android', 'buildbot', 402 [self.m.path['checkout'].join('third_party', 'catapult', 'devil',
384 'bb_device_status_check.py')] + args, 403 'devil', 'android', 'tools',
404 'device_status.py')] + args,
385 step_test_data=lambda: self.m.json.test_api.output([ 405 step_test_data=lambda: self.m.json.test_api.output([
386 { 406 {
387 "battery": { 407 "battery": {
388 "status": "5", 408 "status": "5",
389 "scale": "100", 409 "scale": "100",
390 "temperature": "249", 410 "temperature": "249",
391 "level": "100", 411 "level": "100",
392 "AC powered": "false", 412 "AC powered": "false",
393 "health": "2", 413 "health": "2",
394 "voltage": "4286", 414 "voltage": "4286",
395 "Wireless powered": "false", 415 "Wireless powered": "false",
396 "USB powered": "true", 416 "USB powered": "true",
397 "technology": "Li-ion", 417 "technology": "Li-ion",
398 "present": "true" 418 "present": "true"
399 }, 419 },
400 "wifi_ip": "", 420 "wifi_ip": "",
401 "imei_slice": "Unknown", 421 "imei_slice": "Unknown",
402 "build": "LRX21O", 422 "ro.build.id": "LRX21O",
423 "ro.build.product": "product_name",
403 "build_detail": 424 "build_detail":
404 "google/razor/flo:5.0/LRX21O/1570415:userdebug/dev-keys", 425 "google/razor/flo:5.0/LRX21O/1570415:userdebug/dev-keys",
405 "serial": "07a00ca4", 426 "serial": "07a00ca4",
406 "type": "flo",
407 "adb_status": "device", 427 "adb_status": "device",
408 "blacklisted": False, 428 "blacklisted": False,
409 "usb_status": True, 429 "usb_status": True,
410 }, 430 },
411 { 431 {
412 "adb_status": "offline", 432 "adb_status": "offline",
413 "blacklisted": True, 433 "blacklisted": True,
414 "serial": "03e0363a003c6ad4", 434 "serial": "03e0363a003c6ad4",
415 "usb_status": False, 435 "usb_status": False,
416 }, 436 },
(...skipping 16 matching lines...) Expand all
433 self._devices = [] 453 self._devices = []
434 offline_device_index = 1 454 offline_device_index = 1
435 for d in result.json.output: 455 for d in result.json.output:
436 try: 456 try:
437 if not d['usb_status']: 457 if not d['usb_status']:
438 key = '%s: missing' % d['serial'] 458 key = '%s: missing' % d['serial']
439 elif d['adb_status'] != 'device': 459 elif d['adb_status'] != 'device':
440 key = '%s: adb status %s' % (d['serial'], d['adb_status']) 460 key = '%s: adb status %s' % (d['serial'], d['adb_status'])
441 elif d['blacklisted']: 461 elif d['blacklisted']:
442 key = '%s: blacklisted' % d['serial'] 462 key = '%s: blacklisted' % d['serial']
443 else: 463 else:
rnephew (Reviews Here) 2016/07/12 16:16:47 Changes from last attempt found here.
jbudorick 2016/07/12 16:18:08 Acknowledged.
444 key = '%s %s %s' % (d['type'], d['build'], d['serial']) 464 key = '%s %s %s' % (d['ro.build.product'], d['ro.build.id'],
465 d['serial'])
445 self._devices.append(d['serial']) 466 self._devices.append(d['serial'])
446 except KeyError: 467 except KeyError:
447 key = 'unknown device %d' % offline_device_index 468 key = 'unknown device %d' % offline_device_index
448 offline_device_index += 1 469 offline_device_index += 1
449 result.presentation.logs[key] = self.m.json.dumps( 470 result.presentation.logs[key] = self.m.json.dumps(
450 d, indent=2).splitlines() 471 d, indent=2).splitlines()
451 result.presentation.step_text = 'Online devices: %s' % len(self._devices) 472 result.presentation.step_text = 'Online devices: %s' % len(self._devices)
452 return result 473 return result
453 except self.m.step.InfraFailure as f: 474 except self.m.step.InfraFailure as f:
454 params = { 475 params = {
455 'summary': ('Device Offline on %s %s' % 476 'summary': ('Device Offline on %s %s' %
456 (self.m.properties['mastername'], self.m.properties['slavename'])), 477 (self.m.properties['mastername'], self.m.properties['slavename'])),
457 'comment': ('Buildbot: %s\n(Please do not change any labels)' % 478 'comment': ('Buildbot: %s\n(Please do not change any labels)' %
458 self.m.properties['buildername']), 479 self.m.properties['buildername']),
459 'labels': 'Restrict-View-Google,OS-Android,Infra,Infra-Labs', 480 'labels': 'Restrict-View-Google,OS-Android,Infra,Infra-Labs',
460 } 481 }
461 link = ('https://code.google.com/p/chromium/issues/entry?%s' % 482 link = ('https://code.google.com/p/chromium/issues/entry?%s' %
462 urllib.urlencode(params)) 483 urllib.urlencode(params))
463 f.result.presentation.links.update({ 484 f.result.presentation.links.update({
464 'report a bug': link 485 'report a bug': link
465 }) 486 })
466 raise 487 raise
467 488
489
468 def provision_devices(self, skip_wipe=False, disable_location=False, 490 def provision_devices(self, skip_wipe=False, disable_location=False,
469 min_battery_level=None, disable_network=False, 491 min_battery_level=None, disable_network=False,
470 disable_java_debug=False, max_battery_temp=None, 492 disable_java_debug=False, max_battery_temp=None,
471 disable_system_chrome=False, reboot_timeout=None, 493 disable_system_chrome=False, reboot_timeout=None,
472 remove_system_webview=False, emulators=False, 494 remove_system_webview=False, emulators=False,
473 **kwargs): 495 **kwargs):
474 args = [ 496 args = [
475 '--adb-path', self.m.adb.adb_path(), 497 '--adb-path', self.m.adb.adb_path(),
476 '--blacklist-file', self.blacklist_file, 498 '--blacklist-file', self.blacklist_file,
477 '--output-device-blacklist', self.m.json.output(add_json_log=False), 499 '--output-device-blacklist', self.m.json.output(add_json_log=False),
(...skipping 30 matching lines...) Expand all
508 if emulators: 530 if emulators:
509 args.append('--emulators') 531 args.append('--emulators')
510 result = self.m.python( 532 result = self.m.python(
511 'provision_devices', 533 'provision_devices',
512 self.m.path['checkout'].join( 534 self.m.path['checkout'].join(
513 'build', 'android', 'provision_devices.py'), 535 'build', 'android', 'provision_devices.py'),
514 args=args, 536 args=args,
515 env=self.m.chromium.get_env(), 537 env=self.m.chromium.get_env(),
516 infra_step=True, 538 infra_step=True,
517 **kwargs) 539 **kwargs)
518 blacklisted_devices = result.json.output
519 if blacklisted_devices:
520 result.presentation.status = self.m.step.WARNING
521 for d in blacklisted_devices:
522 key = 'blacklisted %s' % d
523 result.presentation.logs[key] = [d]
524 540
525 def apk_path(self, apk): 541 def apk_path(self, apk):
526 return self.m.chromium.output_dir.join('apks', apk) if apk else None 542 return self.m.chromium.output_dir.join('apks', apk) if apk else None
527 543
528 def adb_install_apk(self, apk, allow_downgrade=False, devices=None): 544 def adb_install_apk(self, apk, allow_downgrade=False, devices=None):
529 install_cmd = [ 545 install_cmd = [
530 self.m.path['checkout'].join('build', 546 self.m.path['checkout'].join('build',
531 'android', 547 'android',
532 'adb_install_apk.py'), 548 'adb_install_apk.py'),
533 apk, '-v', '--blacklist-file', self.blacklist_file, 549 apk, '-v', '--blacklist-file', self.blacklist_file,
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 self.create_adb_symlink() 943 self.create_adb_symlink()
928 if self.c.gce_setup: 944 if self.c.gce_setup:
929 self.launch_gce_instances(snapshot=self.c.gce_snapshot, 945 self.launch_gce_instances(snapshot=self.c.gce_snapshot,
930 count=self.c.gce_count) 946 count=self.c.gce_count)
931 self.spawn_logcat_monitor() 947 self.spawn_logcat_monitor()
932 self.provision_devices(emulators=True, 948 self.provision_devices(emulators=True,
933 remove_system_webview=remove_system_webview) 949 remove_system_webview=remove_system_webview)
934 else: 950 else:
935 self.spawn_logcat_monitor() 951 self.spawn_logcat_monitor()
936 self.authorize_adb_devices() 952 self.authorize_adb_devices()
937 self.device_status_check() 953 self.device_recovery()
938 if perf_setup: 954 if perf_setup:
939 kwargs = { 955 kwargs = {
940 'min_battery_level': 95, 956 'min_battery_level': 95,
941 'disable_network': True, 957 'disable_network': True,
942 'disable_java_debug': True, 958 'disable_java_debug': True,
943 'max_battery_temp': 350} 959 'max_battery_temp': 350}
944 else: 960 else:
945 kwargs = {} 961 kwargs = {}
946 self.provision_devices(remove_system_webview=remove_system_webview, 962 self.provision_devices(remove_system_webview=remove_system_webview,
947 **kwargs) 963 **kwargs)
964 self.device_status()
948 if self.m.chromium.c.gyp_env.GYP_DEFINES.get('asan', 0) == 1: 965 if self.m.chromium.c.gyp_env.GYP_DEFINES.get('asan', 0) == 1:
949 self.asan_device_setup() 966 self.asan_device_setup()
950 967
951 self.spawn_device_monitor() 968 self.spawn_device_monitor()
952 969
953 def common_tests_final_steps(self, logcat_gs_bucket='chromium-android'): 970 def common_tests_final_steps(self, logcat_gs_bucket='chromium-android'):
954 if not self.c.gce_setup: 971 if not self.c.gce_setup:
955 self.shutdown_device_monitor() 972 self.shutdown_device_monitor()
956 self.logcat_dump(gs_bucket=logcat_gs_bucket) 973 self.logcat_dump(gs_bucket=logcat_gs_bucket)
957 self.stack_tool_steps() 974 self.stack_tool_steps()
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 script = self.c.test_runner 1377 script = self.c.test_runner
1361 if wrapper_script_suite_name: 1378 if wrapper_script_suite_name:
1362 script = self.m.chromium.output_dir.join('bin', 'run_%s' % 1379 script = self.m.chromium.output_dir.join('bin', 'run_%s' %
1363 wrapper_script_suite_name) 1380 wrapper_script_suite_name)
1364 else: 1381 else:
1365 env = kwargs.get('env', {}) 1382 env = kwargs.get('env', {})
1366 env['CHROMIUM_OUTPUT_DIR'] = env.get('CHROMIUM_OUTPUT_DIR', 1383 env['CHROMIUM_OUTPUT_DIR'] = env.get('CHROMIUM_OUTPUT_DIR',
1367 self.m.chromium.output_dir) 1384 self.m.chromium.output_dir)
1368 kwargs['env'] = env 1385 kwargs['env'] = env
1369 return self.m.python(step_name, script, args, **kwargs) 1386 return self.m.python(step_name, script, args, **kwargs)
OLDNEW
« no previous file with comments | « no previous file | scripts/slave/recipe_modules/chromium_android/example.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698