| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright 2015 The Chromium Authors. All rights reserved. | 3 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Checks buildbot jobs by name.""" | 7 """Checks buildbot jobs by name.""" |
| 8 | 8 |
| 9 import json | 9 import json |
| 10 import os | 10 import os |
| 11 import subprocess | 11 import subprocess |
| 12 import sys | 12 import sys |
| 13 import time | 13 import time |
| 14 import urllib2 | 14 import urllib2 |
| 15 | 15 |
| 16 BASE_URL = ('https://build.chromium.org/p/%(master)s/json/builders/%(builder)s/' | 16 BASE_URL = ('https://build.chromium.org/p/%(master)s/json/builders/%(builder)s/' |
| 17 'builds/_all?as_text=1&filter=0') | 17 'builds/_all?as_text=1&filter=0') |
| 18 LINK_URL = ('https://build.chromium.org/p/%(master)s/builders/%(builder)s/' | 18 LINK_URL = ('https://build.chromium.org/p/%(master)s/builders/%(builder)s/' |
| 19 'builds/%(build_num)s') | 19 'builds/%(build_num)s') |
| 20 | 20 |
| 21 | 21 |
| 22 def _get_build_name(job): | 22 def _get_build_name(job): |
| 23 for property_tuple in job['properties']: | 23 for property_tuple in job['properties']: |
| 24 if property_tuple[0] == 'job_name': | 24 if property_tuple[0] == 'job_name': |
| 25 return property_tuple[1] | 25 return property_tuple[1] |
| 26 | 26 |
| 27 | 27 |
| 28 def main(argv): | 28 def main(config): |
| 29 if len(argv) < 4: | 29 """"Checks jobs on a buildbot builder. |
| 30 print 'Usage: %s <master> <builder> <job_name1> [<job_name2> [...]]' | |
| 31 print ' e.g. %s tryserver.chromium.perf linux_perf_bisector a012bc66ef98bb' | |
| 32 sys.exit(1) | |
| 33 | 30 |
| 34 master, builder = argv[1:3] | 31 Args: |
| 35 job_names = argv[3:] | 32 config (dict): a configuration in the following format. |
| 33 |
| 34 { |
| 35 "master": "tryserver.chromium.perf", |
| 36 "builder": "linux_perf_bisect", |
| 37 "job_names": [ "abc1234", "deadbeef000", "f00ba12"] |
| 38 } |
| 39 |
| 40 Returns: |
| 41 A dictionary containing a list of failed and/or a list of completed jobs and |
| 42 a mapping between failed jobs and their urls when available |
| 43 e.g. |
| 44 { |
| 45 "failed": ["deadbeef000"], |
| 46 "completed": ["abc1234"], |
| 47 "failed_job_urls": {"deadbeef000":"https://build....org/p/tryserver..."} |
| 48 } |
| 49 """ |
| 50 master = config['master'] |
| 51 builder = config['builder'] |
| 52 job_names = config['job_names'] |
| 53 results = {} |
| 54 completed_jobs = [] |
| 55 failed_jobs = [] |
| 56 job_urls = {} |
| 36 | 57 |
| 37 if 'TESTING_MASTER_HOST' in os.environ: | 58 if 'TESTING_MASTER_HOST' in os.environ: |
| 38 url = ('http://%(host)s:8041/json/builders/%(builder)s/' | 59 url = ('http://%(host)s:8041/json/builders/%(builder)s/' |
| 39 'builds/_all?as_text=1&filter=0') % { | 60 'builds/_all?as_text=1&filter=0') % { |
| 40 'host': os.environ['TESTING_MASTER_HOST'], | 61 'host': os.environ['TESTING_MASTER_HOST'], |
| 41 'builder': builder, | 62 'builder': builder, |
| 42 } | 63 } |
| 43 else: | 64 else: |
| 44 url = BASE_URL % {'master': master, 'builder': builder} | 65 url = BASE_URL % {'master': master, 'builder': builder} |
| 45 print 'Verifying buildbot jobs status at: ', url | 66 sys.stderr.write('Using the following url to check builds:' + url) |
| 67 sys.stderr.flush() |
| 46 builds_info = json.load(urllib2.urlopen(url)) | 68 builds_info = json.load(urllib2.urlopen(url)) |
| 47 | 69 |
| 48 for build_num in builds_info.keys(): | 70 for build_num in builds_info.keys(): |
| 49 build_name = _get_build_name(builds_info[build_num]) | 71 build_name = _get_build_name(builds_info[build_num]) |
| 50 if build_name in job_names: | 72 if build_name in job_names: |
| 51 if builds_info[build_num]['results'] in [2, 4]: | 73 if builds_info[build_num]['results'] in [2,3,4]: |
| 52 locator = 'bb:%s:%s:%s' % (master, builder, build_name) | 74 failed_jobs.append(build_name) |
| 53 print 'Failed build url: %(url)s\nBuild failed: %(locator)s' % { | 75 job_urls[build_name] = LINK_URL % { |
| 54 'locator': locator, | 76 'master': master, |
| 55 'url': LINK_URL % { | 77 'builder': builder, |
| 56 'master': master, | 78 'build_num': str(build_num), |
| 57 'builder': builder, | 79 } |
| 58 'build_num': build_num, | 80 elif builds_info[build_num]['results'] in [0, 1]: |
| 59 } | 81 job_urls[build_name] = LINK_URL % { |
| 60 } | 82 'master': master, |
| 61 return 1 | 83 'builder': builder, |
| 62 print 'The specified jobs are not failed.' | 84 'build_num': str(build_num), |
| 63 return 0 | 85 } |
| 86 completed_jobs.append(build_name) |
| 64 | 87 |
| 88 if completed_jobs: |
| 89 results['completed'] = completed_jobs |
| 90 if failed_jobs: |
| 91 results['failed'] = failed_jobs |
| 92 if job_urls: |
| 93 results['job_urls'] = job_urls |
| 94 return results |
| 65 | 95 |
| 66 | 96 |
| 67 if __name__ == '__main__': | 97 if __name__ == '__main__': |
| 68 sys.exit(main(sys.argv)) | 98 config = json.loads(sys.stdin.read()) |
| 99 print main(config) |
| 100 sys.exit(0) |
| OLD | NEW |