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

Unified Diff: appengine/swarming/server/bot_groups_config.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 side-by-side diff with in-line comments
Download patch
Index: appengine/swarming/server/bot_groups_config.py
diff --git a/appengine/swarming/server/bot_groups_config.py b/appengine/swarming/server/bot_groups_config.py
index 962a36087159b45a6dc360a5e357410a9ba8def0..1be560ac9d2587ca80a5ec70f415024d3abfe726 100644
--- a/appengine/swarming/server/bot_groups_config.py
+++ b/appengine/swarming/server/bot_groups_config.py
@@ -7,6 +7,7 @@
import collections
import hashlib
import logging
+import os
import re
from components import auth
@@ -47,6 +48,10 @@ BotGroupConfig = collections.namedtuple('BotGroupConfig', [
# dimension from that set, the list of value for it will be empty. Key and
# values are unicode strings.
'dimensions',
+
+ # Name of the supplemental bot_config.py to inject to the bot during
+ # handshake.
+ 'bot_config_script',
])
@@ -71,7 +76,8 @@ _DEFAULT_BOT_GROUPS = _BotGroups(
require_service_account=None,
ip_whitelist=auth.BOTS_IP_WHITELIST,
owners=(),
- dimensions={}))
+ dimensions={},
+ bot_config_script=''))
def _gen_version(fields):
@@ -145,7 +151,8 @@ def _bot_group_proto_to_tuple(msg, trusted_dimensions):
require_service_account=auth_cfg.require_service_account,
ip_whitelist=auth_cfg.ip_whitelist,
owners=tuple(msg.owners),
- dimensions={k: sorted(v) for k, v in dimensions.iteritems()})
+ dimensions={k: sorted(v) for k, v in dimensions.iteritems()},
+ bot_config_script=msg.bot_config_script)
def _expand_bot_id_expr(expr):
@@ -392,6 +399,24 @@ def validate_settings(cfg, ctx):
if not local_config.validate_flat_dimension(dim):
ctx.error('bad dimension %r', dim)
+ # Validate 'bot_config_script': the supplemental bot_config.py.
+ if entry.bot_config_script:
+ # Another check confirms that the script itself is valid python.
+ if not entry.bot_config_script.endswith('.py'):
+ ctx.error('Invalid bot_config_script name')
+ if os.path.basename(entry.bot_config_script) != entry.bot_config_script:
+ ctx.error('Invalid bot_config_script name')
+ # The file must exist and must be valid non empty python script.
+ path = 'scripts/' + entry.bot_config_script
+ if not config.get_self_config(path, store_last_good=True)[1]:
+ # Work around a problem in luci-config, this will require a full RPC
+ # but better be safe than sorry.
+ logging.warning('failed to find cached %s', path)
+ if not config.get_self_config(path)[1]:
Vadim Sh. 2017/02/09 22:22:00 I think this will not generally work. Luci config
M-A Ruel 2017/02/09 23:47:02 Nodir can confirm if what I do is wrong. It's not
M-A Ruel 2017/02/10 18:33:26 I tested and confirmed it doesn't. Just removed th
nodir 2017/02/10 18:41:43 Sorry for being late, Vadim's reasoning is correct
M-A Ruel 2017/02/10 19:53:19 No big deal, the latest patchset is confirmed to w
+ ctx.error(
+ 'Referenced bot_config_script %s must exist in scripts/' %
+ entry.bot_config_script)
+
# Now verify bot_id_prefix is never a prefix of other prefix. It causes
# ambiguities.
for smaller, s_idx in bot_id_prefixes.iteritems():

Powered by Google App Engine
This is Rietveld 408576698