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

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

Issue 2689483004: swarming: Add server-side implementation for supplemental bot_config (Closed)
Patch Set: rebase Created 3 years, 10 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 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 import re 10 import re
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 # Bot identifier, extracted from 'id' dimension. 233 # Bot identifier, extracted from 'id' dimension.
234 bot_id = None 234 bot_id = None
235 # Version of the bot code, as reported by the bot itself. 235 # Version of the bot code, as reported by the bot itself.
236 version = None 236 version = None
237 # Dict with bot state (as reported by the bot). 237 # Dict with bot state (as reported by the bot).
238 state = None 238 state = None
239 # Dict with bot dimensions (union of bot-reported and server-side ones). 239 # Dict with bot dimensions (union of bot-reported and server-side ones).
240 dimensions = None 240 dimensions = None
241 # Instance of BotGroupConfig with server-side bot config (from bots.cfg). 241 # Instance of BotGroupConfig with server-side bot config (from bots.cfg).
242 bot_group_cfg = None 242 bot_group_cfg = None
243 # Supplemental bot_config to inject into the bot.
244 bot_config = None
243 # Bot quarantine message (or None if the bot is not in a quarantine). 245 # Bot quarantine message (or None if the bot is not in a quarantine).
244 quarantined_msg = None 246 quarantined_msg = None
245 247
246 def __init__(self, **kwargs): 248 def __init__(self, **kwargs):
247 for k, v in kwargs.iteritems(): 249 for k, v in kwargs.iteritems():
248 # Typo catching assert, ensure _ProcessResult class has the attribute. 250 # Typo catching assert, ensure _ProcessResult class has the attribute.
249 assert hasattr(self, k), k 251 assert hasattr(self, k), k
250 setattr(self, k, v) 252 setattr(self, k, v)
251 253
252 254
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 432
431 data = { 433 data = {
432 'bot_version': bot_code.get_bot_version(self.get_bot_contact_server())[0], 434 'bot_version': bot_code.get_bot_version(self.get_bot_contact_server())[0],
433 'server_version': utils.get_app_version(), 435 'server_version': utils.get_app_version(),
434 'bot_group_cfg_version': res.bot_group_cfg.version, 436 'bot_group_cfg_version': res.bot_group_cfg.version,
435 'bot_group_cfg': { 437 'bot_group_cfg': {
436 # Let the bot know its server-side dimensions (from bots.cfg file). 438 # Let the bot know its server-side dimensions (from bots.cfg file).
437 'dimensions': res.bot_group_cfg.dimensions, 439 'dimensions': res.bot_group_cfg.dimensions,
438 }, 440 },
439 } 441 }
442 if res.bot_group_cfg.bot_config_script:
443 _, script = config.config.get_self_config(
444 'scripts/' + res.bot_group_cfg.bot_config_script,
445 store_last_good=True)
446 logging.info(
447 'Injecting %s: %d bytes',
448 res.bot_group_cfg.bot_config_script,
449 len(script or ''))
450 if not script:
451 # Return an internal error, so that the bot retries slowly.
452 msg = 'Failed to find %s' % res.bot_group_cfg.bot_config_script
Vadim Sh. 2017/02/09 22:22:00 these will most probably happen when adding comple
M-A Ruel 2017/02/10 18:33:26 At least we'll get errors about these and the time
453 logging.error(msg)
454 self.abort(503, msg)
455 data['bot_config'] = script
440 self.send_response(data) 456 self.send_response(data)
441 457
442 458
443 class BotPollHandler(_BotBaseHandler): 459 class BotPollHandler(_BotBaseHandler):
444 """The bot polls for a task; returns either a task, update command or sleep. 460 """The bot polls for a task; returns either a task, update command or sleep.
445 461
446 In case of exception on the bot, this is enough to get it just far enough to 462 In case of exception on the bot, this is enough to get it just far enough to
447 eventually self-update to a working version. This is to ensure that coding 463 eventually self-update to a working version. This is to ensure that coding
448 errors in bot code doesn't kill all the fleet at once, they should still be up 464 errors in bot code doesn't kill all the fleet at once, they should still be up
449 just enough to be able to self-update again even if they don't get task 465 just enough to be able to self-update again even if they don't get task
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 ('/swarming/api/v1/bot/poll', BotPollHandler), 924 ('/swarming/api/v1/bot/poll', BotPollHandler),
909 ('/swarming/api/v1/bot/server_ping', ServerPingHandler), 925 ('/swarming/api/v1/bot/server_ping', ServerPingHandler),
910 ('/swarming/api/v1/bot/task_update', BotTaskUpdateHandler), 926 ('/swarming/api/v1/bot/task_update', BotTaskUpdateHandler),
911 ('/swarming/api/v1/bot/task_update/<task_id:[a-f0-9]+>', 927 ('/swarming/api/v1/bot/task_update/<task_id:[a-f0-9]+>',
912 BotTaskUpdateHandler), 928 BotTaskUpdateHandler),
913 ('/swarming/api/v1/bot/task_error', BotTaskErrorHandler), 929 ('/swarming/api/v1/bot/task_error', BotTaskErrorHandler),
914 ('/swarming/api/v1/bot/task_error/<task_id:[a-f0-9]+>', 930 ('/swarming/api/v1/bot/task_error/<task_id:[a-f0-9]+>',
915 BotTaskErrorHandler), 931 BotTaskErrorHandler),
916 ] 932 ]
917 return [webapp2.Route(*i) for i in routes] 933 return [webapp2.Route(*i) for i in routes]
OLDNEW
« no previous file with comments | « no previous file | appengine/swarming/handlers_bot_test.py » ('j') | appengine/swarming/server/bot_groups_config.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698