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

Unified Diff: dashboard/dashboard/models/table_config.py

Issue 2648683004: Building the table for speed releasing. (Closed)
Patch Set: Added more logging Created 3 years, 11 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: dashboard/dashboard/models/table_config.py
diff --git a/dashboard/dashboard/models/table_config.py b/dashboard/dashboard/models/table_config.py
index d609bc1f1d946b30759b3ff36dd6f681a7e8f3e9..698762d4d715a864a8d96b312ed47bb9c807c332 100644
--- a/dashboard/dashboard/models/table_config.py
+++ b/dashboard/dashboard/models/table_config.py
@@ -31,9 +31,14 @@ import json
from google.appengine.ext import ndb
+from dashboard.common import utils
from dashboard.models import internal_only_model
+class BadRequestError(Exception):
+ """An error indicating that a 400 response status should be returned."""
+ pass
+
class TableConfig(internal_only_model.InternalOnlyModel):
# A list of bots the speed releasing report will contain.
@@ -65,42 +70,47 @@ def CreateTableConfig(name, bots, tests, layout, username):
of bad inputs), returns None, error message.
"""
internal_only = False
- error_message = ''
valid_bots = []
- for bot in bots:
- if '/' in bot:
- bot_name = bot.split('/')[1]
- master_name = bot.split('/')[0]
- entity_key = ndb.Key('Master', master_name, 'Bot', bot_name)
- entity = entity_key.get()
- if entity:
- valid_bots.append(entity_key)
- if entity.internal_only:
- internal_only = True
+ try:
+ for bot in bots:
+ if '/' in bot:
+ bot_name = bot.split('/')[1]
+ master_name = bot.split('/')[0]
+ entity_key = ndb.Key('Master', master_name, 'Bot', bot_name)
+ entity = entity_key.get()
+ if entity:
+ valid_bots.append(entity_key)
+ if entity.internal_only:
+ internal_only = True
+ else:
+ raise BadRequestError('Invalid Master/Bot: %s' % bot)
else:
- error_message = 'Invalid Master/Bot: %s' % bot
- return None, error_message
- else:
- error_message = 'Invalid Master/Bot: %s' % bot
- return None, error_message
+ raise BadRequestError('Invalid Master/Bot: %s' % bot)
+
+ table_check = ndb.Key('TableConfig', name).get()
+ if table_check:
+ raise BadRequestError('%s already exists.' % name)
+
+ for bot in bots:
+ for test in tests:
+ test_key = utils.TestMetadataKey(bot + '/' + test)
+ if not test_key.get():
+ raise BadRequestError('%s is not a valid test.' % test)
+
+ except BadRequestError as error:
+ raise BadRequestError(error.message)
try:
json.loads(layout)
# TODO(jessimb): Verify that the layout matches what is expected
except ValueError:
- error_message = 'Invalid JSON for table layout'
- return None, error_message
+ raise BadRequestError('Invalid JSON for table layout')
- table_check = ndb.Key('TableConfig', name).get()
- if table_check:
- error_message = '%s already exists.' % name
- return None, error_message
# Input validates, create table now.
- error_message = 'TableConfig created successfully.'
table_config = TableConfig(id=name, bots=valid_bots, tests=tests,
table_layout=layout, internal_only=internal_only,
username=username)
table_config.put()
- return table_config, error_message
+ return table_config

Powered by Google App Engine
This is Rietveld 408576698