예제 #1
0
def _CreateIssueForFlake(issue_generator, target_flake, create_or_update_bug):
    """Creates a monorail bug for a single flake.

  This function is used to create bugs for detected flakes and flake analysis
  results.

  Args:
    create_or_update_bug (bool): True to create or update monorail bug,
      otherwise False. Should always look for existing bugs for flakes, even if
      cannot update the bug.
  """
    monorail_project = issue_generator.GetMonorailProject()

    # Re-uses an existing open bug if possible.
    issue_id = SearchOpenIssueIdForFlakyTest(target_flake.normalized_test_name,
                                             monorail_project)

    if not issue_id:
        # Reopens a recently closed bug if possible.
        issue_id = SearchRecentlyClosedIssueIdForFlakyTest(
            target_flake.normalized_test_name, monorail_project)

    if issue_id:
        logging.info('An existing issue %s was found, attach it to flake: %s.',
                     FlakeIssue.GetLinkForIssue(monorail_project, issue_id),
                     target_flake.key)
        _AssignIssueToFlake(issue_id, target_flake)

        if create_or_update_bug:
            monorail_util.UpdateIssueWithIssueGenerator(
                issue_id=issue_id,
                issue_generator=issue_generator,
                reopen=True)
        return issue_id

    if not create_or_update_bug:
        # No existing bug found, and cannot create bug, bail out.
        return None

    logging.info('No existing open issue was found, create a new one.')
    issue_id = monorail_util.CreateIssueWithIssueGenerator(
        issue_generator=issue_generator)

    if not issue_id:
        logging.warning('Failed to create monorail bug for flake: %s.',
                        target_flake.key)
        return None
    logging.info('%s was created for flake: %s.',
                 FlakeIssue.GetLinkForIssue(monorail_project, issue_id),
                 target_flake.key)
    _AssignIssueToFlake(issue_id, target_flake)
    return issue_id
예제 #2
0
def _CreateIssueForFlakeGroup(flake_group):
    """Creates an issue for a flake group.

  Args:
    flake_group (FlakeGroupByOccurrences): A flake group without an issue.

  Returns:
    Id of the issue that was eventually created or linked.
  """

    assert isinstance(flake_group, FlakeGroupByOccurrences), (
        'flake_group is not a FlakeGroupByOccurrences instance.')

    issue_generator = FlakeDetectionGroupIssueGenerator(
        flake_group.flakes,
        flake_group.num_occurrences,
        canonical_step_name=flake_group.canonical_step_name)
    issue_id = monorail_util.CreateIssueWithIssueGenerator(
        issue_generator=issue_generator)
    if not issue_id:
        logging.warning('Failed to create monorail bug for flake group: %s.',
                        flake_group.canonical_step_name)
        return None
    logging.info(
        '%s was created for flake_group: %s.',
        FlakeIssue.GetLinkForIssue(issue_generator.GetMonorailProject(),
                                   issue_id), flake_group.canonical_step_name)

    flake_issue = _AssignIssueToFlake(issue_id, flake_group.flakes[0])
    for i in xrange(1, len(flake_group.flakes)):
        flake = flake_group.flakes[i]
        flake.flake_issue_key = flake_issue.key
        flake.put()

    issue_generator.SetFlakeIssue(flake_issue)

    monorail_util.PostCommentOnMonorailBug(
        issue_id, issue_generator,
        issue_generator.GetFirstCommentWhenBugJustCreated())

    return issue_id
예제 #3
0
    def testCreateIssueWithIssueGeneratorWithPreviousTrackingBugId(
            self, mock_create_bug_fn, mock_update_bug_fn):
        test_issue_generator = TestIssueGenerator()
        test_issue_generator.SetPreviousTrackingBugId(56789)
        issue_id = monorail_util.CreateIssueWithIssueGenerator(
            issue_generator=test_issue_generator)

        self.assertTrue(mock_create_bug_fn.called)
        self.assertFalse(mock_update_bug_fn.called)
        self.assertEqual(12345, issue_id)
        issue = mock_create_bug_fn.call_args_list[0][0][0]
        self.assertEqual('Untriaged', issue.status)
        self.assertEqual('*/suite.test/* is flaky', issue.summary)
        self.assertEqual('description with previous tracking bug id: 56789.',
                         issue.description)
        self.assertEqual(['label1', 'Sheriff-Chromium', 'Pri-1'], issue.labels)
        self.assertEqual(1, len(issue.field_values))
        self.assertEqual('Flaky-Test',
                         issue.field_values[0].to_dict()['fieldName'])
        self.assertEqual('suite.test',
                         issue.field_values[0].to_dict()['fieldValue'])
예제 #4
0
    def testCreateIssueWithIssueGenerator(self, mock_create_bug_fn,
                                          mock_update_bug_fn, mock_owner):
        owner = '*****@*****.**'
        test_issue_generator = TestIssueGenerator()
        mock_owner.return_value = owner
        issue_id = monorail_util.CreateIssueWithIssueGenerator(
            issue_generator=test_issue_generator)

        self.assertTrue(mock_create_bug_fn.called)
        self.assertFalse(mock_update_bug_fn.called)
        self.assertEqual(12345, issue_id)
        issue = mock_create_bug_fn.call_args_list[0][0][0]
        self.assertEqual(owner, issue.owner)
        self.assertEqual('Untriaged', issue.status)
        self.assertEqual('*/suite.test/* is flaky', issue.summary)
        self.assertEqual('description without previous tracking bug id.',
                         issue.description)
        self.assertEqual(['label1', 'Sheriff-Chromium', 'Pri-1'], issue.labels)
        self.assertEqual(1, len(issue.field_values))
        self.assertEqual('Flaky-Test',
                         issue.field_values[0].to_dict()['fieldName'])
        self.assertEqual('suite.test',
                         issue.field_values[0].to_dict()['fieldValue'])