Exemplo n.º 1
0
 def testAllBuildersFailed(self, mocked_sleep, mocked_fetch):
     mocked_fetch.side_effect = httplib2.HttpLib2Error
     build_data, failures = lkgr_lib.FetchBuildData(self.test_masters,
                                                    max_threads=1)
     self.assertEquals(failures, 2)
     self.assertEquals(build_data['master1']['builder1'], None)
     self.assertEquals(build_data['master1']['builder2'], None)
Exemplo n.º 2
0
    def testSomeBuildersFailed(self, mocked_sleep, mocked_fetch):
        def _raise_http_err(master, builder, **kwargs):
            if builder == 'builder1':
                return {'build1': 'success'}
            raise httplib2.HttpLib2Error()

        mocked_fetch.side_effect = _raise_http_err
        build_data, failures = lkgr_lib.FetchBuildData(self.test_masters,
                                                       max_threads=1)
        self.assertEquals(failures, 1)
        self.assertEquals(len(build_data['master1']), 2)
        self.assertEquals(build_data['master1']['builder1']['build1'],
                          'success')
        self.assertEquals(build_data['master1']['builder2'], None)
Exemplo n.º 3
0
 def testAllBuildersSucceeded(self, mocked_fetch):
     mocked_fetch.side_effect = iter([{
         'build1': 'success'
     }, {
         'build2': 'failure'
     }])
     build_data, failures = lkgr_lib.FetchBuildData(self.test_masters,
                                                    max_threads=1)
     self.assertEquals(failures, 0)
     self.assertEquals(len(build_data['master1']), 2)
     self.assertEquals(build_data['master1']['builder1']['build1'],
                       'success')
     self.assertEquals(build_data['master1']['builder2']['build2'],
                       'failure')
Exemplo n.º 4
0
def main(argv):
    # TODO(agable): Refactor this into multiple sequential helper functions.

    args, config_arg_names = ParseArgs(argv)

    global LOGGER
    logging.basicConfig(
        # %(levelname)s is formatted to min-width 8 since CRITICAL is 8 letters.
        format='%(asctime)s | %(levelname)8s | %(name)s | %(message)s',
        level=args.loglevel)
    LOGGER = logging.getLogger(__name__)
    LOGGER.addFilter(lkgr_lib.RunLogger())

    config = lkgr_lib.GetProjectConfig(args.project)
    for name in config_arg_names:
        cmd_line_config = getattr(args, name, NOTSET)
        if cmd_line_config is not NOTSET:
            config[name] = cmd_line_config

    # Calculate new candidate LKGR.
    LOGGER.info('Calculating LKGR for project %s', args.project)

    repo = lkgr_lib.GitWrapper(
        config['source_url'],
        os.path.join(os.path.dirname(os.path.abspath(__file__)), 'workdir',
                     args.project))

    monkeypatch_rev_map = config.get('monkeypatch_rev_map')
    if monkeypatch_rev_map:
        repo._position_cache.update(monkeypatch_rev_map)

    if args.manual:
        candidate = args.manual
        LOGGER.info('Using manually specified candidate %s', args.manual)
        if not repo.check_rev(candidate):
            LOGGER.fatal(
                'Manually specified revision %s is not a valid revision for'
                ' project %s' % (args.manual, args.project))
            return 1
    else:
        lkgr_builders = config['masters']
        if args.build_data:
            builds = lkgr_lib.ReadBuildData(args.build_data)
        else:
            builds, failures = lkgr_lib.FetchBuildData(lkgr_builders,
                                                       args.max_threads,
                                                       args.service_account)
            if failures > 0:
                return 1

        if args.dump_build_data:
            try:
                with open(args.dump_build_data, 'w') as fh:
                    json.dump(builds, fh, indent=2)
            except IOError, e:
                LOGGER.warn('Could not dump to %s:\n%s\n' %
                            (args.dump_build_data, repr(e)))

        (build_history,
         revisions) = lkgr_lib.CollateRevisionHistory(builds, lkgr_builders,
                                                      repo)

        status_gen = status_generator.StatusGeneratorStub()
        if args.html:
            viewvc = config.get('viewvc_url', config['source_url'] + '/+/%s')
            status_gen = status_generator.HTMLStatusGenerator(viewvc=viewvc)

        candidate = lkgr_lib.FindLKGRCandidate(build_history, revisions,
                                               repo.keyfunc, status_gen)

        if args.html:
            lkgr_lib.WriteHTML(status_gen, args.html, args.dry_run)