Chromium Code Reviews| 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. | |
| 42 e.g. | |
| 43 { | |
| 44 "failed": ["deadbeef000"], | |
| 45 "completed": ["abc1234"] | |
| 46 } | |
| 47 """ | |
| 48 master = config['master'] | |
| 49 builder = config['builder'] | |
| 50 job_names = config['job_names'] | |
| 51 results = {} | |
| 52 completed_jobs = [] | |
| 53 failed_jobs = [] | |
| 36 | 54 |
| 37 if 'TESTING_MASTER_HOST' in os.environ: | 55 if 'TESTING_MASTER_HOST' in os.environ: |
| 38 url = ('http://%(host)s:8041/json/builders/%(builder)s/' | 56 url = ('http://%(host)s:8041/json/builders/%(builder)s/' |
| 39 'builds/_all?as_text=1&filter=0') % { | 57 'builds/_all?as_text=1&filter=0') % { |
| 40 'host': os.environ['TESTING_MASTER_HOST'], | 58 'host': os.environ['TESTING_MASTER_HOST'], |
| 41 'builder': builder, | 59 'builder': builder, |
| 42 } | 60 } |
| 43 else: | 61 else: |
| 44 url = BASE_URL % {'master': master, 'builder': builder} | 62 url = BASE_URL % {'master': master, 'builder': builder} |
| 45 print 'Verifying buildbot jobs status at: ', url | |
| 46 builds_info = json.load(urllib2.urlopen(url)) | 63 builds_info = json.load(urllib2.urlopen(url)) |
| 47 | 64 |
| 48 for build_num in builds_info.keys(): | 65 for build_num in builds_info.keys(): |
| 49 build_name = _get_build_name(builds_info[build_num]) | 66 build_name = _get_build_name(builds_info[build_num]) |
| 50 if build_name in job_names: | 67 if build_name in job_names: |
| 51 if builds_info[build_num]['results'] in [2, 4]: | 68 if builds_info[build_num]['results'] in [2,3,4]: |
| 52 locator = 'bb:%s:%s:%s' % (master, builder, build_name) | 69 failed_jobs.append(build_name) |
| 53 print 'Failed build url: %(url)s\nBuild failed: %(locator)s' % { | 70 elif builds_info[build_num]['results'] in [0, 1]: |
|
prasadv
2015/09/17 22:33:34
We need this build url to be a part of step link,
RobertoCN
2015/09/19 00:32:54
Done.
| |
| 54 'locator': locator, | 71 completed_jobs.append(build_name) |
| 55 'url': LINK_URL % { | |
| 56 'master': master, | |
| 57 'builder': builder, | |
| 58 'build_num': build_num, | |
| 59 } | |
| 60 } | |
| 61 return 1 | |
| 62 print 'The specified jobs are not failed.' | |
| 63 return 0 | |
| 64 | 72 |
| 73 if completed_jobs: | |
| 74 results['completed'] = completed_jobs | |
| 75 if failed_jobs: | |
| 76 results['failed_jobs'] = failed_jobs | |
| 77 return results | |
| 65 | 78 |
| 66 | 79 |
| 67 if __name__ == '__main__': | 80 if __name__ == '__main__': |
| 68 sys.exit(main(sys.argv)) | 81 config = json.loads(sys.stdin.read()) |
| 82 print main(config) | |
| 83 sys.exit(0) | |
| OLD | NEW |