Esempio n. 1
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
Esempio n. 2
0
 def test_get_config(self):
     config = {'foo': 1, 'bugzilla_config': {'bar': 2}}
     runtime = flexmock(
         gitdata=flexmock(load_data=flexmock(data=config)),
         get_major_minor=lambda: (4, 9)
     )
     actual = BugzillaBugTracker.get_config(runtime)
     expected = {'foo': 1, 'bar': 2}
     self.assertEqual(actual, expected)
Esempio n. 3
0
def create_cli(ctx, runtime, errata_type, kind, impetus, date, assigned_to,
               manager, package_owner, with_placeholder, with_liveid, yes,
               bugs):
    """Create a new advisory. The kind of advisory must be specified with
'--kind'. Valid choices are 'rpm' and 'image'.

    You MUST specify a group (ex: "openshift-3.9") manually using the
    --group option. See examples below.

You must set a Release Date by providing a YYYY-Mon-DD formatted string to the
--date option.

The default behavior for this command is to show what the generated
advisory would look like. The raw JSON used to create the advisory
will be printed to the screen instead of posted to the Errata Tool
API.

The impetus option only affects the metadata added to the new
advisory and its synopsis.

The --assigned-to, --manager and --package-owner options are required.
They are the email addresses of the parties responsible for managing and
approving the advisory.

Adding a list of bug ids with one or more --bugs arguments attaches those bugs to the
advisory on creation.

Provide the '--yes' or '-y' option to confirm creation of the
advisory.

    PREVIEW an RPM Advisory 21 days from now (the default release date) for OSE 3.9:

    $ elliott --group openshift-3.9 create

    CREATE Image Advisory for the 3.5 series on the first Monday in March:

\b
    $ elliott --group openshift-3.5 create --yes -k image --date 2018-Mar-05
"""
    runtime.initialize()

    et_data = runtime.gitdata.load_data(key='erratatool').data

    # User entered a valid value for --date, set the release date
    release_date = datetime.datetime.strptime(date, YMD)

    ######################################################################

    unique_bugs = set(bugs)

    if bugs:
        bug_tracker = BugzillaBugTracker(
            BugzillaBugTracker.get_config(runtime))
        LOGGER.info("Fetching bugs {} from Bugzilla...".format(" ".join(
            map(str, bugs))))
        bug_objects = bug_tracker.get_bugs(bugs)
        # assert bugs are viable for a new advisory.
        _assert_bugs_are_viable(bugs, bug_objects)

    ######################################################################

    try:
        erratum = elliottlib.errata.new_erratum(
            et_data,
            errata_type=errata_type,
            kind=kind,
            boilerplate_name=(impetus if impetus != "standard" else kind),
            release_date=release_date.strftime(YMD),
            assigned_to=assigned_to,
            manager=manager,
            package_owner=package_owner)
    except elliottlib.exceptions.ErrataToolUnauthorizedException:
        exit_unauthorized()
    except elliottlib.exceptions.ErrataToolError as ex:
        raise ElliottFatalError(getattr(ex, 'message', repr(ex)))

    erratum.addBugs(unique_bugs)

    if yes:
        erratum.commit()
        green_prefix("Created new advisory: ")
        click.echo(str(erratum))

        # This is a little strange, I grant you that. For reference you
        # may wish to review the click docs
        #
        # http://click.pocoo.org/5/advanced/#invoking-other-commands
        #
        # You may be thinking, "But, add_metadata doesn't take keyword
        # arguments!" and that would be correct. However, we're not
        # calling that function directly. We actually use the context
        # 'invoke' method to call the _command_ (remember, it's wrapped
        # with click to create a 'command'). 'invoke' ensures the correct
        # options/arguments are mapped to the right parameters.
        ctx.invoke(add_metadata_cli,
                   kind=kind,
                   impetus=impetus,
                   advisory=erratum.errata_id)
        click.echo(str(erratum))

        if with_placeholder:
            click.echo("Creating and attaching placeholder bug...")
            ctx.invoke(create_placeholder_cli,
                       kind=kind,
                       advisory=erratum.errata_id)

        if with_liveid:
            click.echo("Requesting Live ID...")
            base_url = "https://errata.devel.redhat.com/errata/set_live_advisory_name"
            cmd_assert(
                f"curl -X POST --fail --negotiate -u : {base_url}/{erratum.errata_id}",
                retries=3,
                pollrate=10,
            )

    else:
        green_prefix("Would have created advisory: ")
        click.echo("")
        click.echo(erratum)
Esempio n. 4
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)))