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

Side by Side Diff: appengine/swarming/handlers_bot.py

Issue 2958853002: Propagate name of system service account to the bot. (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | appengine/swarming/handlers_bot_test.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 2015 The LUCI Authors. All rights reserved. 1 # Copyright 2015 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 """Internal bot API handlers.""" 5 """Internal bot API handlers."""
6 6
7 import base64 7 import base64
8 import json 8 import json
9 import logging 9 import logging
10 10
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 try: 671 try:
672 # This part is tricky since it intentionally runs a transaction after 672 # This part is tricky since it intentionally runs a transaction after
673 # another one. 673 # another one.
674 if request.properties.is_terminate: 674 if request.properties.is_terminate:
675 bot_event('bot_terminate', task_id=run_result.task_id) 675 bot_event('bot_terminate', task_id=run_result.task_id)
676 self._cmd_terminate(run_result.task_id) 676 self._cmd_terminate(run_result.task_id)
677 else: 677 else:
678 bot_event( 678 bot_event(
679 'request_task', task_id=run_result.task_id, 679 'request_task', task_id=run_result.task_id,
680 task_name=request.name) 680 task_name=request.name)
681 self._cmd_run(request, secret_bytes, run_result.key, res.bot_id) 681 self._cmd_run(
682 request, secret_bytes, run_result.key,
683 res.bot_id, res.bot_group_cfg)
682 except: 684 except:
683 logging.exception('Dang, exception after reaping') 685 logging.exception('Dang, exception after reaping')
684 raise 686 raise
685 except runtime.DeadlineExceededError: 687 except runtime.DeadlineExceededError:
686 # If the timeout happened before a task was assigned there is no problems. 688 # If the timeout happened before a task was assigned there is no problems.
687 # If the timeout occurred after a task was assigned, that task will 689 # If the timeout occurred after a task was assigned, that task will
688 # timeout (BOT_DIED) since the bot didn't get the details required to 690 # timeout (BOT_DIED) since the bot didn't get the details required to
689 # run it) and it will automatically get retried (TODO) when the task times 691 # run it) and it will automatically get retried (TODO) when the task times
690 # out. 692 # out.
691 # TODO(maruel): Note the task if possible and hand it out on next poll. 693 # TODO(maruel): Note the task if possible and hand it out on next poll.
692 # https://code.google.com/p/swarming/issues/detail?id=130 694 # https://code.google.com/p/swarming/issues/detail?id=130
693 self.abort(500, 'Deadline') 695 self.abort(500, 'Deadline')
694 696
695 def _cmd_run(self, request, secret_bytes, run_result_key, bot_id): 697 def _cmd_run(
698 self, request, secret_bytes, run_result_key, bot_id, bot_group_cfg):
696 logging.info('Run: %s', request.task_id) 699 logging.info('Run: %s', request.task_id)
697 out = { 700 out = {
698 'cmd': 'run', 701 'cmd': 'run',
699 'manifest': { 702 'manifest': {
700 'bot_id': bot_id, 703 'bot_id': bot_id,
701 'caches': [ 704 'caches': [
702 c.to_dict() for c in request.properties.caches 705 c.to_dict() for c in request.properties.caches
703 ], 706 ],
704 'cipd_input': { 707 'cipd_input': {
705 'client_package': ( 708 'client_package': (
(...skipping 12 matching lines...) Expand all
718 'host': utils.get_versioned_hosturl(), 721 'host': utils.get_versioned_hosturl(),
719 'io_timeout': request.properties.io_timeout_secs, 722 'io_timeout': request.properties.io_timeout_secs,
720 'secret_bytes': (secret_bytes.secret_bytes.encode('base64') 723 'secret_bytes': (secret_bytes.secret_bytes.encode('base64')
721 if secret_bytes else None), 724 if secret_bytes else None),
722 'isolated': { 725 'isolated': {
723 'input': request.properties.inputs_ref.isolated, 726 'input': request.properties.inputs_ref.isolated,
724 'namespace': request.properties.inputs_ref.namespace, 727 'namespace': request.properties.inputs_ref.namespace,
725 'server': request.properties.inputs_ref.isolatedserver, 728 'server': request.properties.inputs_ref.isolatedserver,
726 } if request.properties.inputs_ref else None, 729 } if request.properties.inputs_ref else None,
727 'outputs': request.properties.outputs, 730 'outputs': request.properties.outputs,
728 'service_account': request.service_account, 731 'service_accounts': {
732 'system': {
733 # 'none', 'bot' or email. Bot interprets 'none' and 'bot' locally.
734 # When it sees something else, it uses /oauth_token API endpoint to
735 # grab tokens through server.
736 'service_account': bot_group_cfg.system_service_account or 'none',
737 },
738 'task': {
739 # Same here.
740 'service_account': request.service_account,
741 },
742 },
729 'task_id': task_pack.pack_run_result_key(run_result_key), 743 'task_id': task_pack.pack_run_result_key(run_result_key),
730 }, 744 },
731 } 745 }
732 self.send_response(utils.to_json_encodable(out)) 746 self.send_response(utils.to_json_encodable(out))
733 747
734 def _cmd_sleep(self, sleep_streak, quarantined): 748 def _cmd_sleep(self, sleep_streak, quarantined):
735 duration = task_scheduler.exponential_backoff(sleep_streak) 749 duration = task_scheduler.exponential_backoff(sleep_streak)
736 logging.debug( 750 logging.debug(
737 'Sleep: streak: %d; duration: %ds; quarantined: %s', 751 'Sleep: streak: %d; duration: %ds; quarantined: %s',
738 sleep_streak, duration, quarantined) 752 sleep_streak, duration, quarantined)
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 ('/swarming/api/v1/bot/poll', BotPollHandler), 1069 ('/swarming/api/v1/bot/poll', BotPollHandler),
1056 ('/swarming/api/v1/bot/server_ping', ServerPingHandler), 1070 ('/swarming/api/v1/bot/server_ping', ServerPingHandler),
1057 ('/swarming/api/v1/bot/task_update', BotTaskUpdateHandler), 1071 ('/swarming/api/v1/bot/task_update', BotTaskUpdateHandler),
1058 ('/swarming/api/v1/bot/task_update/<task_id:[a-f0-9]+>', 1072 ('/swarming/api/v1/bot/task_update/<task_id:[a-f0-9]+>',
1059 BotTaskUpdateHandler), 1073 BotTaskUpdateHandler),
1060 ('/swarming/api/v1/bot/task_error', BotTaskErrorHandler), 1074 ('/swarming/api/v1/bot/task_error', BotTaskErrorHandler),
1061 ('/swarming/api/v1/bot/task_error/<task_id:[a-f0-9]+>', 1075 ('/swarming/api/v1/bot/task_error/<task_id:[a-f0-9]+>',
1062 BotTaskErrorHandler), 1076 BotTaskErrorHandler),
1063 ] 1077 ]
1064 return [webapp2.Route(*i) for i in routes] 1078 return [webapp2.Route(*i) for i in routes]
OLDNEW
« no previous file with comments | « no previous file | appengine/swarming/handlers_bot_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698