Skip to content

Commit

Permalink
Link PR results to testgrid, too.
Browse files Browse the repository at this point in the history
Fix testgrid config loading for local testing and suppress a warmup
request warning.
  • Loading branch information
Ryan Hitchman committed Mar 23, 2018
1 parent 77cf48d commit 6f8d92b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
5 changes: 4 additions & 1 deletion gubernator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class Warmup(webapp2.RequestHandler):
"""Warms up gubernator."""
def get(self):
"""Receives the warmup request."""
self.app.config['github_client'] = secrets.get('github_client')
try:
self.app.config['github_client'] = secrets.get('github_client')
except KeyError:
pass # dev server, generally

self.response.headers['Content-Type'] = 'text/plain'
self.response.write('Warmup successful')
Expand Down
30 changes: 21 additions & 9 deletions gubernator/testgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

import logging
import re

import cloudstorage as gcs

Expand Down Expand Up @@ -63,7 +64,12 @@ def get_config():
"""
global _testgrid_config # pylint: disable=global-statement
if not _testgrid_config:
data = gcs.open('/k8s-testgrid/config').read()
try:
data = gcs.open('/k8s-testgrid/config').read()
except gcs.NotFoundError:
# Fallback to local files for development-- the k8s-testgrid bucket
# has restrictive ACLs that dev_appserver.py can't read.
data = open('tg-config').read()
_testgrid_config = pb_glance.parse_protobuf(data, CONFIG_PROTO_SCHEMA)
return _testgrid_config

Expand All @@ -75,14 +81,17 @@ def path_to_group_name(path):
Returns:
test_group_name: the group name in the config, or None if not found
"""
path = path.strip('/') # the config doesn't have leading/trailing slashes
try:
config = get_config()
except gcs.errors.Error:
logging.exception('unable to load testgrid config')
return None
path = path.strip('/') # the config doesn't have leading/trailing slashes
if '/pull/' in path: # translate PR to all-pr result form
path = re.sub(r'/pull/([^/]+/)?\d+/', '/directory/', path)
for test_group in config.get('test_groups', []):
if path in test_group['query']:
print test_group['query']
return test_group['name'][0]


Expand All @@ -106,16 +115,19 @@ def path_to_query(path):
for dashboard in get_config().get('dashboards', []):
dashboard_name = dashboard['name'][0]
tabs = dashboard['dashboard_tab']
for tab in tabs:
if 'base_options' in tab:
continue
if group in tab['test_group_name']:
query = '%s#%s' % (dashboard_name, tab['name'][0])
options[dashboard_name] = (-len(tabs), query)
for (skip_base_options, penalty) in ((True, 0), (False, 1000)):
for tab in tabs:
if 'base_options' in tab and skip_base_options:
continue
if group in tab['test_group_name']:
query = '%s#%s' % (dashboard_name, tab['name'][0])
options[dashboard_name] = (-len(tabs) + penalty, query)
if dashboard_name in options:
break
if 'k8s' in options:
return options['k8s'][1]
elif len(options) > 1:
logging.warning('ambiguous testgrid options: %s', options)
logging.info('ambiguous testgrid options: %s', options)
elif len(options) == 0:
return ''
return sorted(options.values())[0][1]
19 changes: 18 additions & 1 deletion gubernator/testgrid_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def test_path_to_query(self):
{'query': ['gce-soak-1.3'], 'name': ['gce-soak-1.3']},
{'query': ['gke'], 'name': ['gke']},
{'query': ['unusedgroup'], 'name': ['unused']},
{'query': ['pr-logs/directory/pull-gce'], 'name': ['pull-gce']},
{'query': ['pr-logs/directory/pull-ti-verify'], 'name': ['pull-ti-verify']},
],
'dashboards': [
{
Expand Down Expand Up @@ -98,7 +100,20 @@ def test_path_to_query(self):
{'test_group_name': ['gce-serial'], 'name': ['gce-serial'],
'base_options': ['include-filter-by-regex=Storage']}
]
}
},
{
'name': ['pull'],
'dashboard_tab': [
{'test_group_name': ['pull-gce'], 'name': ['gce'],
'base_options': ['width=10']},
]
},
{
'name': ['pull-ti'],
'dashboard_tab': [
{'test_group_name': ['pull-ti-verify'], 'name': ['verify']},
]
},
]
}
def expect(path, out):
Expand All @@ -110,6 +125,8 @@ def expect(path, out):
expect('unusedgroup', '')
expect('notarealpath', '')
expect('gke', 'gke#gke')
expect('pr-logs/pull/123/pull-gce/', 'pull#gce')
expect('pr-logs/pull/ti/123/pull-ti-verify/', 'pull-ti#verify')


class TestTestgridGCS(main_test.TestBase):
Expand Down

0 comments on commit 6f8d92b

Please sign in to comment.