Skip to content

Commit

Permalink
Link to testgrid from build result pages. (Fixes #272)
Browse files Browse the repository at this point in the history
If there is a testgrid page for the job being considered, link to:
- the testgrid tab showing all results for the job
- the testgrid tab, filtered to only show results for a failing test
  • Loading branch information
Ryan Hitchman committed Aug 11, 2016
1 parent ecee883 commit ce0bd74
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
7 changes: 7 additions & 0 deletions gubernator/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ def do_select(seq, pred):
return filter(pred, seq)


def do_tg_url(testgrid_query, test_name=''):
if test_name:
regex = '^Overall$|' + re.escape(test_name)
testgrid_query += '&include-filter-by-regex=%s' % urllib.quote(regex)
return 'https://k8s-testgrid.appspot.com/%s' % testgrid_query


do_basename = os.path.basename
do_dirname = os.path.dirname
do_quote_plus = urllib.quote_plus
Expand Down
10 changes: 10 additions & 0 deletions gubernator/filters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import re
import unittest
import urllib

import filters

Expand Down Expand Up @@ -101,6 +102,15 @@ def expect(payload, expected, user=''):
expect({'attn': {'foo': 'Needs Rebase'}}, 'Needs Rebase', user='foo')
expect({'attn': {'foo': 'Needs Rebase'}, 'labels': {'lgtm'}}, 'LGTM', user='foo')

def test_tg_url(self):
self.assertEqual(
filters.do_tg_url('a#b'),
'https://k8s-testgrid.appspot.com/a#b')
self.assertEqual(
filters.do_tg_url('a#b', '[low] test'),
'https://k8s-testgrid.appspot.com/a#b&include-filter-by-regex=%s' %
urllib.quote('^Overall$|\\[low\\]\\ test'))


if __name__ == '__main__':
unittest.main()
6 changes: 6 additions & 0 deletions gubernator/templates/build.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ <h1>{% if pr %}<a href="/pr/{{pr}}">PR #{{pr}}</a> {% endif %}<a href="/builds{{
<p>Build Result: {{finished['result'] if finished else 'Not Finished'}}
<p><a href="https://console.cloud.google.com/storage/browser{{build_dir}}">artifacts</a>
<a href="https://storage.googleapis.com{{build_dir}}/build-log.txt">build-log.txt</a>
% if testgrid_query
<p><a href="{{testgrid_query|tg_url}}">Testgrid history for this job</a>
% endif
</div>
<div id="failures">
% if failures
Expand All @@ -41,6 +44,9 @@ <h3><a class="anchor" id="{{name|slugify}}" href="#{{name|slugify}}">{{name}}<sp
% else
<p>Filter through <a href="/build{{build_dir}}/nodelog?junit={{filename|basename}}&wrap=on">log files</a>
% endif
% if testgrid_query
| View <a href="{{testgrid_query|tg_url(name)}}">test history</a> on testgrid
% endif
% else
<span class="inset-filename">from <a href="https://storage.googleapis.com{{filename}}">{{filename|basename}}</a></span>
% endif
Expand Down
6 changes: 4 additions & 2 deletions gubernator/view_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import gcs_async
from github import models
import log_parser
import testgrid
import view_base



def parse_junit(xml, filename):
"""Generate failed tests as a series of (name, duration, text, filename) tuples."""
tree = ET.fromstring(xml)
Expand Down Expand Up @@ -102,6 +102,7 @@ class BuildHandler(view_base.BaseHandler):
def get(self, prefix, job, build):
self.check_bucket(prefix)
job_dir = '/%s/%s/' % (prefix, job)
testgrid_query = testgrid.path_to_query(job_dir)
build_dir = job_dir + build
details = build_details(build_dir)
if not details:
Expand All @@ -124,7 +125,8 @@ def get(self, prefix, job, build):
self.render('build.html', dict(
job_dir=job_dir, build_dir=build_dir, job=job, build=build,
commit=commit, started=started, finished=finished,
failures=failures, build_log=build_log, pr=pr, pr_digest=pr_digest))
failures=failures, build_log=build_log, pr=pr, pr_digest=pr_digest,
testgrid_query=testgrid_query))


class BuildListHandler(view_base.BaseHandler):
Expand Down
9 changes: 9 additions & 0 deletions gubernator/view_build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import main_test
import gcs_async_test
import testgrid_test
import view_pr

app = main_test.app
Expand Down Expand Up @@ -63,6 +64,7 @@ class BuildTest(main_test.TestBase):
def setUp(self):
self.init_stubs()
init_build(self.BUILD_DIR)
testgrid_test.write_config()

def get_build_page(self):
return app.get('/build' + self.BUILD_DIR)
Expand Down Expand Up @@ -128,6 +130,13 @@ def test_build_show_log(self):
self.assertIn('ERROR</span>: test', response)
self.assertNotIn('blah', response)

def test_build_testgrid_links(self):
response = self.get_build_page()
base = 'https://k8s-testgrid.appspot.com/k8s#ajob'
self.assertIn('a href="%s"' % base, response)
option = '&amp;include-filter-by-regex=%5EOverall%24%7CThird'
self.assertIn('a href="%s%s"' % (base, option), response)

def test_build_failure_no_text(self):
# Some failures don't have any associated text.
write(self.BUILD_DIR + 'artifacts/junit_01.xml', '''
Expand Down

0 comments on commit ce0bd74

Please sign in to comment.