def _SetupScheduleSuiteMocks(self, mock_bug_id): """Setup mocks needed for SuiteSchedulerBug testing. @param mock_bug_id: An integer representing a bug id that should be returned by Reporter._create_bug_report None if _create_bug_report is supposed to fail. """ self.mox.StubOutWithMock(reporting.Reporter, '__init__') self.mox.StubOutWithMock(reporting.Reporter, '_create_bug_report') self.mox.StubOutWithMock(reporting.Reporter, '_check_tracker') self.mox.StubOutWithMock(reporting.Reporter, '_find_issue_by_marker') self.mox.StubOutWithMock(site_utils, 'get_sheriffs') self.scheduler._file_bug = True # Lab is UP! self._SetupLabStatus(self._BUILD) # A similar suite has not already been scheduled. self.afe.get_jobs(name__istartswith=self._BUILD, name__iendswith='control.' + self._SUITE, created_on__gte=mox.IgnoreArg(), min_rpc_timeout=mox.IgnoreArg()).AndReturn([]) message = 'Control file not found.' exception = error.ControlFileNotFound(message) site_utils.get_sheriffs(lab_only=True).AndReturn( ['deputy1', 'deputy2']) self.afe.run('create_suite_job', name=self._SUITE, board=self._BOARD, builds=self._BUILDS, check_hosts=False, pool=self._POOL, num=self._NUM, priority=self._PRIORITY, test_source_build=None, timeout=self._TIMEOUT, max_runtime_mins=self._TIMEOUT_MINS, timeout_mins=self._TIMEOUT_MINS, file_bugs=False, wait_for_results=False, job_retry=False, delay_minutes=0, run_prod_code=False, min_rpc_timeout=mox.IgnoreArg()).AndRaise(exception) reporting.Reporter.__init__() reporting.Reporter._check_tracker().AndReturn(True) (reporting.Reporter._find_issue_by_marker( mox.IgnoreArg()).AndReturn(None)) reporting.Reporter._create_bug_report(mox.IgnoreArg(), {}, []).AndReturn(mock_bug_id)
def __init__(self, suite, build, board, control_file_exception): self._suite = suite self._build = build self._board = board self._exception = control_file_exception # TODO(fdeng): fix get_sheriffs crbug.com/483254 lab_deputies = site_utils.get_sheriffs(lab_only=True) self.owner = lab_deputies[0] if lab_deputies else '' self.labels = self._SUITE_SCHEDULER_LABELS self.cc = lab_deputies[1:] if lab_deputies else []
def _get_lab_error_template(self): """Return the lab error template. @return: A dictionary representing the bug options for an issue that requires investigation from the lab team. """ lab_sheriff = site_utils.get_sheriffs(lab_only=True) return { 'labels': ['Build-HardwareLab'], 'owner': lab_sheriff[0] if lab_sheriff else '', }
def report(self, bug, bug_template={}, ignore_duplicate=False): """Report an issue to the bug tracker. If this issue has happened before, post a comment on the existing bug about it occurring again, and update the 'autofiled-count' label. If this is a new issue, create a new bug for it. @param bug A Bug instance about the issue. @param bug_template A template dictionary specifying the default bug filing options for an issue with this suite. @param ignore_duplicate: If True, when a duplicate is found, simply ignore the new one rather than posting an update. @return A 2-tuple of the issue id of the issue that was either created or modified, and a count of the number of times the bug has been updated. For a new bug, the count is 1. If we could not file a bug for some reason, the count is 0. """ if not self._check_tracker(): logging.error("Can't file %s", bug.title()) return None, 0 project_label = self._get_project_label_from_title(bug.title()) issue = None try: issue = self._dedupe_issue(bug.search_marker()) except expat.ExpatError as e: # If our search string sends python's xml module into a # state which it believes will lead to an xml syntax # error, it will give up and throw an exception. This # might happen with aborted jobs that contain weird # escape characters in their reason fields. We'd rather # create a new issue than fail in deduplicating such cases. logging.warning('Unable to deduplicate, creating new issue: %s', str(e)) if issue and ignore_duplicate: logging.debug('Duplicate found for %s, not filing as requested.', bug.search_marker()) _, bug_count = self._get_count_labels_and_max(issue) return issue.id, bug_count if issue: comment = '%s\n\n%s' % (bug.title(), self._anchor_summary(bug)) label_update, bug_count = ( self._create_autofiled_count_update(issue)) if project_label: label_update.append(project_label) self.modify_bug_report(issue.id, comment, label_update) return issue.id, bug_count sheriffs = [] # TODO(beeps): crbug.com/254256 try: if bug.lab_error and bug.suite == 'bvt': lab_error_template = self._get_lab_error_template() if bug_template.get('labels'): lab_error_template['labels'] += bug_template.get('labels') bug_template = lab_error_template elif bug.suite == 'bvt': sheriffs = site_utils.get_sheriffs() except AttributeError: pass if project_label: bug_template.get('labels', []).append(project_label) bug_id = self._create_bug_report(bug, bug_template, sheriffs) bug_count = 1 if bug_id else 0 return bug_id, bug_count