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

Unified Diff: appengine/swarming/server/task_request.py

Issue 1778083002: Enforce users to specify a 'pool' dimension when triggering a task. (Closed) Base URL: git@github.com:luci/luci-py.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « appengine/swarming/handlers_bot.py ('k') | client/example/2_swarming_run.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/swarming/server/task_request.py
diff --git a/appengine/swarming/server/task_request.py b/appengine/swarming/server/task_request.py
index 19b4c78c0bf31403bbb4989a96d821a45473e156..c09d30270397c5cb93e931cf68fd4d0edf902bcd 100644
--- a/appengine/swarming/server/task_request.py
+++ b/appengine/swarming/server/task_request.py
@@ -433,11 +433,14 @@ class TaskRequest(ndb.Model):
elif self.priority == 0:
raise datastore_errors.BadValueError(
'priority 0 can only be used for terminate request')
- self.tags.append('priority:%s' % self.priority)
- self.tags.append('user:%s' % self.user)
- for key, value in self.properties.dimensions.iteritems():
- self.tags.append('%s:%s' % (key, value))
- self.tags = sorted(set(self.tags))
+
+ if not self.properties.dimensions:
+ raise datastore_errors.BadValueError('dimensions must be specified')
+ dim_keys = self.properties.dimensions.keys()
+ if 'pool' not in dim_keys and 'id' not in dim_keys:
+ raise datastore_errors.BadValueError(
+ 'At least one of \'id\' or \'pool\' must be used as dimensions')
+
if (self.pubsub_topic and
not pubsub.validate_full_name(self.pubsub_topic, 'topics')):
raise datastore_errors.BadValueError(
@@ -449,6 +452,12 @@ class TaskRequest(ndb.Model):
raise datastore_errors.BadValueError(
'pubsub_userdata requires pubsub_topic')
+ self.tags.append('priority:%s' % self.priority)
+ self.tags.append('user:%s' % self.user)
+ for key, value in self.properties.dimensions.iteritems():
+ self.tags.append('%s:%s' % (key, value))
+ self.tags = sorted(set(self.tags))
+
def _new_request_key():
"""Returns a valid ndb.Key for this entity.
« no previous file with comments | « appengine/swarming/handlers_bot.py ('k') | client/example/2_swarming_run.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698