Пример #1
0
    def test_get_corresponding_flaw_bugs_jira(self):
        product = 'Security Response'
        component = 'vulnerability'
        valid_flaw = BugzillaBug(flexmock(product=product, component=component, id=9999))
        invalid_flaw = BugzillaBug(flexmock(product=product, component='foo', id=9998))
        flaw_bugs = [valid_flaw, invalid_flaw]

        tracker_bugs = [
            JIRABug(flexmock(key='OCPBUGS-1', fields=flexmock(labels=[f"flaw:bz#{valid_flaw.id}",
                                                                      f"flaw:bz#{invalid_flaw.id}"]))),
            JIRABug(flexmock(key='OCPBUGS-2', fields=flexmock(labels=[f"flaw:bz#{invalid_flaw.id}"]))),
            JIRABug(flexmock(key='OCPBUGS-3', fields=flexmock(labels=[f"flaw:bz#{valid_flaw.id}"])))
        ]

        flexmock(BugzillaBugTracker).should_receive("login").and_return(None)
        flexmock(JIRABugTracker).should_receive("login").and_return(None)
        flexmock(BugzillaBugTracker).should_receive("get_bugs").and_return(flaw_bugs)
        bug_tracker = JIRABugTracker({})
        flaw_bug_tracker = BugzillaBugTracker({})

        expected = (
            {'OCPBUGS-1': [valid_flaw.id], 'OCPBUGS-2': [], 'OCPBUGS-3': [valid_flaw.id]},
            {valid_flaw.id: valid_flaw}
        )
        actual = bug_tracker.get_corresponding_flaw_bugs(tracker_bugs, flaw_bug_tracker)
        self.assertEqual(expected, actual)
Пример #2
0
 def bug_trackers(self):
     if self._bug_trackers:
         return self._bug_trackers
     if not self.only_jira:
         self._bug_trackers['bugzilla'] = BugzillaBugTracker(BugzillaBugTracker.get_config(self))
     if self.use_jira or self.only_jira:
         self._bug_trackers['jira'] = JIRABugTracker(JIRABugTracker.get_config(self))
     return self._bug_trackers
Пример #3
0
    def test_update_bug_status(self):
        bug = flexmock(id=123, status="status1")
        flexmock(JIRABugTracker).should_receive("login").and_return(None)
        client = flexmock()
        client.should_receive("transition_issue").with_args(bug.id, 'status2')

        jira = JIRABugTracker({})
        jira._client = client
        jira.update_bug_status(bug, target_status='status2', log_comment=False)
Пример #4
0
    def test_update_bug_status_with_comment(self):
        bug = flexmock(id=123, status="status1")
        flexmock(JIRABugTracker).should_receive("login").and_return(None)
        client = flexmock()
        client.should_receive("transition_issue").with_args(bug.id, 'status2')
        comment = 'Elliott changed bug status from status1 to status2.\ncomment'
        flexmock(JIRABugTracker).should_receive("add_comment").with_args(
            bug.id, comment, private=True, noop=False)

        jira = JIRABugTracker({})
        jira._client = client
        jira.update_bug_status(bug, target_status='status2', comment='comment')
Пример #5
0
    def test_add_comment_private(self):
        bug = flexmock(id=123)
        flexmock(JIRABugTracker).should_receive("login").and_return(None)
        client = flexmock()
        client.should_receive("add_comment").with_args(bug.id,
                                                       'comment',
                                                       visibility={
                                                           'type':
                                                           'group',
                                                           'value':
                                                           'Red Hat Employee'
                                                       })

        jira = JIRABugTracker({})
        jira._client = client
        jira.add_comment(bug.id, 'comment', private=True)
Пример #6
0
 def test_get_config(self):
     config = {'foo': 1, 'jira_config': {'bar': 2}}
     runtime = flexmock(
         gitdata=flexmock(load_data=flexmock(data=config)),
         get_major_minor=lambda: (4, 9)
     )
     actual = JIRABugTracker.get_config(runtime)
     expected = {'foo': 1, 'bar': 2}
     self.assertEqual(actual, expected)
Пример #7
0
    def test_update_bug_status_same(self):
        bug = flexmock(id=123, status="status1")
        flexmock(JIRABugTracker).should_receive("login").and_return(None)

        jira = JIRABugTracker({})
        jira.update_bug_status(bug, target_status='status1')
Пример #8
0
def repair_bugs_cli(runtime, advisory, auto, id, original_state, new_state,
                    comment, close_placeholder, noop, default_advisory_type):
    """Move bugs attached to the advisory from one state to another
state. This is useful if the bugs have changed states *after* they
were attached. Similar to `find-bugs` but in reverse. `repair-bugs`
begins by reading bugs from an advisory, whereas `find-bugs` reads
from bugzilla.

This looks at attached bugs in the provided --from state and moves
them to the provided --to state.

\b
    Background: This is intended for bugs which went to MODIFIED, were
    attached to advisories, set to ON_QA, and then failed
    testing. When this happens their state is reset back to ASSIGNED.

Using --use-default-advisory without a value set for the matching key
in the build-data will cause an error and elliott will exit in a
non-zero state. Most likely you will only want to use the `rpm` state,
but that could change in the future. Use of this option conflicts with
providing an advisory with the -a/--advisory option.

    Move bugs on 123456 FROM the MODIFIED state back TO ON_QA state:

\b
    $ elliott --group=openshift-4.1 repair-bugs --auto --advisory 123456 --from MODIFIED --to ON_QA

    As above, but using the default RPM advisory defined in ocp-build-data:

\b
    $ elliott --group=openshift-4.1 repair-bugs --auto --use-default-advisory rpm --from MODIFIED --to ON_QA

    The previous examples could also be ran like this (MODIFIED and ON_QA are both defaults):

\b
    $ elliott --group=openshift-4.1 repair-bugs --auto --use-default-advisory rpm

    Bug ids may be given manually instead of using --auto:

\b
    $ elliott --group=openshift-4.1 repair-bugs --id 170899 --id 8675309 --use-default-advisory rpm
"""
    if auto and len(id) > 0:
        raise click.BadParameter(
            "Combining the automatic and manual bug modification options is not supported"
        )

    if not auto and len(id) == 0:
        # No bugs were provided
        raise click.BadParameter(
            "If not using --auto then one or more --id's must be provided")

    if advisory and default_advisory_type:
        raise click.BadParameter(
            "Use only one of --use-default-advisory or --advisory")

    if len(id) == 0 and advisory is None and default_advisory_type is None:
        # error, no bugs, advisory, or default selected
        raise click.BadParameter(
            "No input provided: Must use one of --id, --advisory, or --use-default-advisory"
        )

    # Load bugzilla information and get a reference to the api
    runtime.initialize()
    if runtime.use_jira:
        repair_bugs(runtime, advisory, auto, id, original_state, new_state,
                    comment, close_placeholder, True, noop,
                    default_advisory_type,
                    JIRABugTracker(JIRABugTracker.get_config(runtime)))
    repair_bugs(runtime, advisory, auto, id, original_state, new_state,
                comment, close_placeholder, False, noop, default_advisory_type,
                BugzillaBugTracker(BugzillaBugTracker.get_config(runtime)))