def main(): parser = optparse.OptionParser() parser.add_option('-b', '--buildbot_json', help='path to buildbot_json.py') parser.add_option( '-u', '--url', default='http://build.chromium.org/p/tryserver.chromium/', help='server url, default: %default') parser.add_option('-H', '--horizon', default=100, type='int') options, args = parser.parse_args(None) if args: parser.error('Unsupported args: %s' % args) if options.horizon < 10 or options.horizon > 2000: parser.error('Use reasonable --horizon value') if options.buildbot_json: options.buildbot_json = os.path.abspath(options.buildbot_json) if not os.path.isdir(options.buildbot_json): parser.error('Pass a valid directory path to --buildbot_json') sys.path.insert(0, options.buildbot_json) try: import buildbot_json # pylint: disable=F0401 except ImportError: parser.error('Pass a directory path to buildbot_json.py with -b') b = buildbot_json.Buildbot(options.url) parse(b, options.horizon) return 0
def testCurrentBuilds(self): b = buildbot_json.Buildbot( 'http://build.chromium.org/p/tryserver.chromium') actual = [] for builder in b.builders: self.assertEquals([], list(builder.current_builds.cached_children)) i = 0 last_build = None for c in builder.current_builds: self.assertEquals(builder, c.builder) actual.append(str(c)) i += 1 last_build = c if i: self.assertEquals(last_build.number, builder.builds[-1].number) self.assertEquals( i, len(list(builder.current_builds.cached_children))) builder.current_builds.discard() self.assertEquals([], list(builder.current_builds.cached_children)) filepath = os.path.join(self.datadir, self.test_id) + '_expected.json' if self.training or not os.path.isfile(filepath): json.dump(actual, open(filepath, 'w')) expected = json.load(open(filepath)) self.assertEquals(expected, actual)
def test_build_results(self): b = buildbot_json.Buildbot('http://build.chromium.org/p/tryserver.chromium') # builds.data['results'] is not present. self.assertEqual( buildbot_json.SUCCESS, b.builders['linux_clang'].builds[1638].result) self.assertEqual( buildbot_json.SUCCESS, b.builders['linux_clang'].builds[1638].steps[0].result)
def test_contains(self): b = buildbot_json.Buildbot('http://build.chromium.org/p/tryserver.chromium') self.assertTrue('linux' in b.builders) self.assertEqual(3, len(list(b.builders.cached_children))) try: # The dereference of an invalid key when keys are cached will throw an # exception. # pylint: disable=W0104 b.builders['non_existent'] self.fail() except KeyError: pass
def main(): usage = """%prog [options] <master> Sample usage: %prog t.c -d 3h Note: t is replaced with 'tryserver', 'c' with chromium' and co with 'chromiumos'. Only the slave names are printed on stdout, making it bash-friendly. """ parser = optparse.OptionParser(usage=usage) parser.add_option( '-b', '--builder', action='append', default=[], help='Specify builders (use multiple times), otherwise selects all') parser.add_option( '-d', '--duration', help='Only builds of specific duration or more, formated') parser.add_option('-v', '--verbose', action='count', default=0) options, args = parser.parse_args() if len(args) != 1: parser.error('Unsupported args %s' % ' '.join(args)) levels = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG] logging.basicConfig(level=levels[min(len(levels) - 1, options.verbose)]) url = 'http://build.chromium.org/p/%s' % slaves.ProcessShortName(args[0]) buildbot = buildbot_json.Buildbot(url) if options.builder: builders = [buildbot.builders[b] for b in options.builder] else: builders = buildbot.builders if options.duration: options.duration = from_time(options.duration) now = time.time() for builder in builders: for build in builder.current_builds: start, end = build.data['times'] if end: continue duration = now - start if not options.duration or duration > options.duration: print build.slave.name logging.warn( '%s(%d) elapsed:%s' % (builder.name, build.number, format_time(duration)))
def __init__(self, context_obj, try_server_url, commit_user, builders_and_tests, ignored_steps, extra_flags, lkgr, solution): super(TryRunner, self).__init__(context_obj) self.commit_user = commit_user self.try_server_url = try_server_url self.builders_and_tests = builders_and_tests self.ignored_steps = set(ignored_steps) self.extra_flags = extra_flags or [] self.status = buildbot_json.Buildbot(self.try_server_url) self.step_db = StepDb(self.builders_and_tests.keys(), self.status, self.context.checkout) self.last_update = time.time() - self.update_latency self.lkgr = lkgr self.solution = solution
def test_builds_reverse(self): # Check the 2 last builds from 'linux' using iterall() instead of # __iter__(). The test also confirms that the build object itself is not # loaded. b = buildbot_json.Buildbot('http://build.chromium.org/p/tryserver.chromium') actual = [] for b in b.builders['linux'].builds.iterall(): actual.append(b.number) # When using iterall() the Build data is delay loaded: assert b._data is None # pylint: disable=W0212 if len(actual) == 2: break filepath = os.path.join(self.datadir, self.test_id) + '_expected.json' if self.training or not os.path.isfile(filepath): json.dump(actual, open(filepath, 'w')) expected = json.load(open(filepath)) self.assertEqual(expected, actual)
def test_build_step_cached_data(self): b = buildbot_json.Buildbot('http://build.chromium.org/p/tryserver.chromium') build = 30157 self.assertEqual( None, b.builders['linux'].current_builds[build].steps[0].cached_data) b.builders['linux'].current_builds[build].steps[0].cache() self.assertEqual( 'update_scripts', b.builders['linux'].current_builds[build].steps[0].name) self.assertEqual( ['browser_tests', 'ui_tests'], b.builders['linux'].current_builds[build].steps.failed) self.assertEqual( 2, b.builders['linux'].current_builds[build].steps[2 ].cached_data['step_number']) b.refresh() # cache_keys() does the same thing as cache(). b.builders['linux'].current_builds[build].steps.cache_keys()
def test_build_steps_keys(self): b = buildbot_json.Buildbot('http://build.chromium.org/p/tryserver.chromium') build = b.builders['linux_clang'].builds[1638] #self.assertEqual([0, 1, 2, 3], build.steps.keys) # Grab cached version. There is none. actual = [step for step in build.steps.cached_children] self.assertEqual([], actual) # Force load. actual = [step for step in build.steps] self.assertEqual( [buildbot_json.SUCCESS] * 4, [step.result for step in actual]) self.assertEqual( [True] * 4, [step.simplified_result for step in actual]) self.assertEqual(4, len(actual)) # Grab cached version. actual = [step for step in build.steps.cached_children] self.assertEqual( [buildbot_json.SUCCESS] * 4, [step.result for step in actual]) self.assertEqual(4, len(actual))
def _update_jobs_from_rietveld(self, pending, jobs, handle, now): """Grabs data from Rietveld and pass it to RietveldTryJobs.update_jobs_from_rietveld(). NOTE: While it is tagged as immutable, it is because it doesn't mutate TryRunnerRietveld itself but note that it does mutate 'pending'. Warning: This function is called from a background thread. """ status = buildbot_json.Buildbot(self.try_server_url) data = self.context.rietveld.get_patchset_properties( pending.issue, pending.patchset) # Update the RietvedTryJobs object. keys = jobs.update_jobs_from_rietveld(pending.owner, pending.issue, data, status, self.context.checkout, now) if handle: for updated_key in keys: job = jobs.try_jobs[updated_key] self._update_dashboard(pending, job, status) jobs.signal_as_failed_if_needed(job, self._build_status_url(job), now)
def test_slaves(self): b = buildbot_json.Buildbot('http://build.chromium.org/p/tryserver.chromium') self.assertEqual(11, len(b.slaves.names)) self.assertEqual(False, b.slaves['mini34-m4'].connected)
def test_refresh(self): b = buildbot_json.Buildbot('http://build.chromium.org/p/tryserver.chromium') self.assertEqual(True, b.refresh())
def test_repr(self): b = buildbot_json.Buildbot('http://build.chromium.org/p/tryserver.chromium') self.assertEqual('<Builder key=linux>', repr(b.builders['linux'])) self.assertEqual("<Builders keys=['linux']>", repr(b.builders))