From 02392811f0e5dea17132d99fa1ab5679829f3b7a Mon Sep 17 00:00:00 2001 From: Chris AtLee Date: Tue, 25 Feb 2014 16:25:12 -0500 Subject: [PATCH] Bug 976752: Handle case where master doesn't exist in production-masters.json r=dustin --- buildapi/lib/helpers.py | 10 +++++++--- buildapi/templates/running.mako | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/buildapi/lib/helpers.py b/buildapi/lib/helpers.py index 927d123..67340cc 100644 --- a/buildapi/lib/helpers.py +++ b/buildapi/lib/helpers.py @@ -99,8 +99,8 @@ def __init__(self): time_format = '%a, %d %b %Y %H:%M:%S %z (%Z)' def pacific_time(timestamp, format=time_format): - """Convert a time expressed in seconds since the epoch to a string - representing Pacific time. If secs is not provided or None, the current + """Convert a time expressed in seconds since the epoch to a string + representing Pacific time. If secs is not provided or None, the current time as returned by time() is used. """ if not timestamp: @@ -110,7 +110,7 @@ def pacific_time(timestamp, format=time_format): return dt.strftime(format) -# Matches a master from production-masters.json, to the corresponding +# Matches a master from production-masters.json, to the corresponding # build pool, by looking at the 'role' field ROLE_MASTERS_POOLS = { 'build': BUILDPOOL, @@ -204,6 +204,8 @@ def addr_for_master(claimed_by_name): """Returns the fully qualified domain name and port for the master indicated by claimed_by_name""" get_masters() + if claimed_by_name not in _masters_by_dbname: + return None, None fqdn = _masters_by_dbname[claimed_by_name]['hostname'] port = _masters_by_dbname[claimed_by_name]['http_port'] @@ -221,6 +223,8 @@ def convert_master(m): * master_url, eg 'http://buildbot-master1.build.mozilla.org:8011' """ fqdn, port = addr_for_master(m) + if fqdn is None: + return None pretty_name = '%s:%i' % (fqdn.split(".")[0], port) master_url = 'http://%(fqdn)s:%(port)i' % locals() diff --git a/buildapi/templates/running.mako b/buildapi/templates/running.mako index a545f05..0e21995 100644 --- a/buildapi/templates/running.mako +++ b/buildapi/templates/running.mako @@ -47,8 +47,12 @@ $(document).ready(function() { build['start_time_human'] = datetime.fromtimestamp(build['start_time']).strftime('%Y-%m-%d %H:%M:%S') build['running_for'] = now - datetime.fromtimestamp(build['start_time']) m = h.convert_master(build['claimed_by_name']) - build['master'] = m['pretty_name'] - build['url'] = h.url_for_build(m['master_addr'], build['buildername'], build['number']) + if m: + build['master'] = m['pretty_name'] + build['url'] = h.url_for_build(m['master_addr'], build['buildername'], build['number']) + else: + build['master'] = '' + build['url'] = '#' %> ${branch}${revision}