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

Side by Side Diff: appengine/swarming/swarming_bot/bot_code/bot_main.py

Issue 2969513002: Add a default Isolate gRPC proxy in config (Closed)
Patch Set: Fix problem in tests Created 3 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
OLDNEW
1 # Copyright 2013 The LUCI Authors. All rights reserved. 1 # Copyright 2013 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 """Swarming bot main process. 5 """Swarming bot main process.
6 6
7 This is the program that communicates with the Swarming server, ensures the code 7 This is the program that communicates with the Swarming server, ensures the code
8 is always up to date and executes a child process to run tasks and upload 8 is always up to date and executes a child process to run tasks and upload
9 results back. 9 results back.
10 10
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 'dimensions': {u'id': ['none']}, 509 'dimensions': {u'id': ['none']},
510 'state': {}, 510 'state': {},
511 'version': generate_version(), 511 'version': generate_version(),
512 } 512 }
513 base_dir = os.path.dirname(THIS_FILE) 513 base_dir = os.path.dirname(THIS_FILE)
514 # Use temporary Bot object to call get_attributes. Attributes are needed to 514 # Use temporary Bot object to call get_attributes. Attributes are needed to
515 # construct the "real" bot.Bot. 515 # construct the "real" bot.Bot.
516 attributes = get_attributes( 516 attributes = get_attributes(
517 bot.Bot( 517 bot.Bot(
518 remote_client.createRemoteClient(config['server'], 518 remote_client.createRemoteClient(config['server'],
519 None, config['is_grpc']), 519 None, config.get('swarming_grpc_proxy')),
520 attributes, 520 attributes,
521 config['server'], 521 config['server'],
522 config['server_version'], 522 config['server_version'],
523 base_dir, 523 base_dir,
524 _on_shutdown_hook)) 524 _on_shutdown_hook))
525 525
526 # Make remote client callback use the returned bot object. We assume here 526 # Make remote client callback use the returned bot object. We assume here
527 # RemoteClient doesn't call its callback in the constructor (since 'botobj' is 527 # RemoteClient doesn't call its callback in the constructor (since 'botobj' is
528 # undefined during the construction). 528 # undefined during the construction).
529 botobj = bot.Bot( 529 botobj = bot.Bot(
530 remote_client.createRemoteClient( 530 remote_client.createRemoteClient(
531 config['server'], 531 config['server'],
532 lambda: _get_authentication_headers(botobj), 532 lambda: _get_authentication_headers(botobj),
533 config['is_grpc']), 533 config.get('swarming_grpc_proxy')),
534 attributes, 534 attributes,
535 config['server'], 535 config['server'],
536 config['server_version'], 536 config['server_version'],
537 base_dir, 537 base_dir,
538 _on_shutdown_hook) 538 _on_shutdown_hook)
539 return botobj 539 return botobj
540 540
541 541
542 def _cleanup_bot_directory(botobj): 542 def _cleanup_bot_directory(botobj):
543 """Delete anything not expected in the swarming bot directory. 543 """Delete anything not expected in the swarming bot directory.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 697
698 def _run_bot_inner(arg_error, quit_bit): 698 def _run_bot_inner(arg_error, quit_bit):
699 """Runs the bot until an event occurs. 699 """Runs the bot until an event occurs.
700 700
701 One of the three following even can occur: 701 One of the three following even can occur:
702 - host reboots 702 - host reboots
703 - bot process restarts (this includes self-update) 703 - bot process restarts (this includes self-update)
704 - bot process shuts down (this includes a signal is received) 704 - bot process shuts down (this includes a signal is received)
705 """ 705 """
706 config = get_config() 706 config = get_config()
707 if config['enable_ts_monitoring']: 707 if config.get('enable_ts_monitoring'):
708 _init_ts_mon() 708 _init_ts_mon()
709 try: 709 try:
710 # First thing is to get an arbitrary url. This also ensures the network is 710 # First thing is to get an arbitrary url. This also ensures the network is
711 # up and running, which is necessary before trying to get the FQDN below. 711 # up and running, which is necessary before trying to get the FQDN below.
712 # There's no need to do error handling here - the "ping" is just to "wake 712 # There's no need to do error handling here - the "ping" is just to "wake
713 # up" the network; if there's something seriously wrong, the handshake will 713 # up" the network; if there's something seriously wrong, the handshake will
714 # fail and we'll handle it there. 714 # fail and we'll handle it there.
715 remote = remote_client.createRemoteClient(config['server'], None, 715 remote = remote_client.createRemoteClient(config['server'], None,
716 config['is_grpc']) 716 config.get('swarming_grpc_proxy'))
717 remote.ping() 717 remote.ping()
718 except Exception: 718 except Exception:
719 # url_read() already traps pretty much every exceptions. This except 719 # url_read() already traps pretty much every exceptions. This except
720 # clause is kept there "just in case". 720 # clause is kept there "just in case".
721 logging.exception('server_ping threw') 721 logging.exception('server_ping threw')
722 722
723 # If we are on GCE, we want to make sure GCE metadata server responds, since 723 # If we are on GCE, we want to make sure GCE metadata server responds, since
724 # we use the metadata to derive bot ID, dimensions and state. 724 # we use the metadata to derive bot ID, dimensions and state.
725 if platforms.is_gce(): 725 if platforms.is_gce():
726 logging.info('Running on GCE, waiting for the metadata server') 726 logging.info('Running on GCE, waiting for the metadata server')
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 """Returns the data from config.json.""" 1180 """Returns the data from config.json."""
1181 global _ERROR_HANDLER_WAS_REGISTERED 1181 global _ERROR_HANDLER_WAS_REGISTERED
1182 try: 1182 try:
1183 with contextlib.closing(zipfile.ZipFile(THIS_FILE, 'r')) as f: 1183 with contextlib.closing(zipfile.ZipFile(THIS_FILE, 'r')) as f:
1184 config = json.load(f.open('config/config.json', 'r')) 1184 config = json.load(f.open('config/config.json', 'r'))
1185 if config['server'].endswith('/'): 1185 if config['server'].endswith('/'):
1186 raise ValueError('Invalid server entry %r' % config['server']) 1186 raise ValueError('Invalid server entry %r' % config['server'])
1187 except (IOError, OSError, TypeError, ValueError): 1187 except (IOError, OSError, TypeError, ValueError):
1188 logging.exception('Invalid config.json!') 1188 logging.exception('Invalid config.json!')
1189 config = { 1189 config = {
1190 'enable_ts_monitoring': False,
1191 'is_grpc': False,
1192 'server': '', 1190 'server': '',
1193 'server_version': 'version1', 1191 'server_version': 'version1',
1194 } 1192 }
1195 if not _ERROR_HANDLER_WAS_REGISTERED and config['server']: 1193 if not _ERROR_HANDLER_WAS_REGISTERED and config['server']:
1196 on_error.report_on_exception_exit(config['server']) 1194 on_error.report_on_exception_exit(config['server'])
1197 _ERROR_HANDLER_WAS_REGISTERED = True 1195 _ERROR_HANDLER_WAS_REGISTERED = True
1198 return config 1196 return config
1199 1197
1200 1198
1201 def main(argv): 1199 def main(argv):
(...skipping 30 matching lines...) Expand all
1232 error = None 1230 error = None
1233 if len(args.unsupported) != 0: 1231 if len(args.unsupported) != 0:
1234 error = 'Unexpected arguments: %s' % args 1232 error = 'Unexpected arguments: %s' % args
1235 try: 1233 try:
1236 return _run_bot(error) 1234 return _run_bot(error)
1237 finally: 1235 finally:
1238 _call_hook_safe( 1236 _call_hook_safe(
1239 True, bot.Bot(None, None, None, None, base_dir, None), 1237 True, bot.Bot(None, None, None, None, base_dir, None),
1240 'on_bot_shutdown') 1238 'on_bot_shutdown')
1241 logging.info('main() returning') 1239 logging.info('main() returning')
OLDNEW
« no previous file with comments | « appengine/swarming/server/bot_code.py ('k') | appengine/swarming/swarming_bot/bot_code/bot_main_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698