def SchedulerDBPollerByRevision(revision, branch, scheduler_db, autoland_db, flagcheck, config, dry_run=False): message = None posted_to_bug = False buildrequests = scheduler_db.GetBuildRequests(revision, branch) type = ProcessPushType(revision, buildrequests, autoland_db, flagcheck) bugs = GetBugNumbers(buildrequests) status, is_complete = CalculateBuildRequestStatus(buildrequests) log.debug("RESULTS: %s BUGS: %s TYPE: %s IS_COMPLETE: %s" % (status, bugs, type, is_complete)) if is_complete and type == "try" and len(bugs) > 0: results = CalculateResults(buildrequests) # Now check report for oranges to be retried message = GenerateResultReportMessage(revision, results, GetSingleAuthor(buildrequests)) log.debug("MESSAGE: %s" % message) for bug in bugs: api = config.get('bz_api', 'url') username = config.get('bz_api', 'username') password = config.get('bz_api', 'password') has_revision, post = CheckBugCommentTimeout(revision) if has_revision and not post: log.debug("NOT POSTING TO BUG %s, ALREADY POSTED RECENTLY" % bug) else: if message != None: # Comment in the bug r = bz_utils.bz_notify_bug(api, bug, message, username, password) if r and not has_revision: WriteToBuglist(revision, bug) log.debug("BZ POST SUCCESS bug:%s" % bug) posted_to_bug = True else: log.debug("BZ POST FAILED message: %s bug: %s, couldn't notify bug. Try again later." % (message, bug)) else: log.debug("Something is not matching up:\nis_complete: %s\ntype: %s\nbugs: %s" % (is_complete, type, bugs)) return (message, posted_to_bug)
def SchedulerDBPollerByTimeRange(scheduler_db, branch, starttime, endtime, autoland_db, flagcheck, config, dry_run=False, cache_filename=None): cache_filename = branch + "_cache" # Get all the unique revisions in the specified timeframe range rev_report = GetRevisions(scheduler_db, branch, starttime, endtime) # Add in any revisions currently in cache for a complete list to poll schedulerdb about if os.path.exists(cache_filename): rev_report.update(LoadCache(cache_filename)) # Check each revision's buildrequests to determine: completeness, type for revision in rev_report.keys(): buildrequests = scheduler_db.GetBuildRequests(revision, branch) rev_report[revision]['bugs'] = GetBugNumbers(buildrequests) rev_report[revision]['push_type'] = ProcessPushType(revision, buildrequests, autoland_db, flagcheck) (rev_report[revision]['status'], rev_report[revision]['is_complete']) = CalculateBuildRequestStatus(buildrequests) # For completed runs, generate a bug comment message if there are bugs if rev_report[revision]['is_complete'] and len(rev_report[revision]['bugs']) > 0: rev_report[revision]['results'] = CalculateResults(buildrequests) rev_report[revision]['message'] = GenerateResultReportMessage(revision, rev_report[revision]['results'], GetSingleAuthor(buildrequests)) else: rev_report[revision]['message'] = None # Process the completed rev_report for this run, gather incomplete revisions and writing to cache incomplete = {} for revision,info in rev_report.items(): log.debug("PROCESSING --- REV: %s: INFO: %s" % (revision, info)) # Incomplete gets added to dict for later processing if not info['is_complete']: incomplete[revision] = {'status': info['status'], 'bugs': info['bugs'], } # For completed buildruns determine handling for the completed revision: # PushToTry with bug(s) gets a bug post or log print depending on --dry-run if info['is_complete'] and info['push_type'] == "try" and len(info['bugs']) > 0: for bug in info['bugs']: api = config.get('bz_api', 'url') username = config.get('bz_api', 'username') password = config.get('bz_api', 'password') has_revision, post = CheckBugCommentTimeout(revision) if dry_run: if has_revision and not post: log.debug("DRY-RUN: NOT POSTING TO BUG %s, ALREADY POSTED RECENTLY" % bug) else: log.debug("DRY-RUN: POST TO BUG: %s\n%s" % (bug, info['message'])) if not has_revision: WriteToBuglist(revision, bug) else: if has_revision and not post: log.debug("NOT POSTING TO BUG %s, ALREADY POSTED RECENTLY" % bug) else: # Comment in the bug r = bz_utils.bz_notify_bug(api, bug, info['message'], username, password) if r and not has_revision: WriteToBuglist(revision, bug) log.debug("BZ POST SUCCESS bugs:%s" % info['bugs']) elif not r: log.debug("BZ POST FAIL bugs:%s, putting into cache and will retry later" % info['bugs']) # put it back (only once per revision) into the cache file to try again later if not incomplete.has_key(revision): incomplete[revision] = {'status': info['status'], 'bugs': info['bugs'], } # PushToTry but no bug number(s) gets discarded with log note for debugging elif info['is_complete'] and info['push_type'] == "try" and not len(info['bugs']) > 0: log.debug("Push to try for %s is not requesting bug post - moving along..." % revision) # Autoland revision is complete, send message to the BugCommenter queue elif info['is_complete'] and info['push_type'] == "auto": # TODO - send message with mq here to AutolandDB log.debug("Autoland wants to know about %s - bug commenter message sent" % revision) # Complete but neither PushToTry nor Autoland, throw it away elif info['is_complete'] and info['push_type'] == None: log.debug("Nothing to do for %s - no one cares about it" % revision) WriteToCache(cache_filename, incomplete) return incomplete