示例#1
0
    def test_cmd_assert_success(self):
        """
        """
        (flexmock(exectools.pushd.Dir).should_receive("getcwd").and_return(
            "/my/path"))

        proc_mock = flexmock(returncode=0)
        proc_mock.should_receive("communicate").once().and_return(
            (b"out", b"err"))

        (flexmock(
            exectools.subprocess).should_receive("Popen").and_return(proc_mock)
         )

        (flexmock(exectools.logger).should_receive("debug").with_args(
            'Executing:cmd_gather [cwd=/my/path]: ["/bin/true"]').once().
         ordered())

        (flexmock(exectools.logger).should_receive("debug").with_args(
            'Process [cwd=/my/path]: ["/bin/true"]: exited with: 0\nstdout>>out<<\nstderr>>err<<\n'
        ).once().ordered())

        (flexmock(exectools.logger).should_receive("debug").with_args(
            "cmd_assert: Final result = 0 in 0 tries.").once().ordered())

        try:
            exectools.cmd_assert("/bin/true")
        except IOError as error:
            self.Fail("/bin/truereturned failure: {}".format(error))
示例#2
0
文件: rhcos.py 项目: vfreex/elliott
def get_build_from_payload(payload_pullspec):
    rhcos_tag = 'machine-os-content'
    out, err = exectools.cmd_assert([
        "oc", "adm", "release", "info", "--image-for", rhcos_tag, "--",
        payload_pullspec
    ])
    if err:
        raise Exception(f"Error running oc adm: {err}")
    rhcos_pullspec = out.split('\n')[0]
    out, err = exectools.cmd_assert(
        ["oc", "image", "info", "-o", "json", rhcos_pullspec])
    if err:
        raise Exception(f"Error running oc adm: {err}")
    image_info = json.loads(out)
    build_id = image_info["config"]["config"]["Labels"]["version"]
    arch = image_info["config"]["config"]["Labels"]["architecture"]
    return build_id, arch
示例#3
0
def get_build_id_from_rhcos_pullspec(pullspec, logger):
    logger.info(f"Looking up BuildID from RHCOS pullspec: {pullspec}")
    image_info_str, _ = exectools.cmd_assert(
        f'oc image info -o json {pullspec}', retries=3)
    image_info = json.loads(image_info_str)
    build_id = image_info['config']['config']['Labels']['version']
    if not build_id:
        raise Exception(
            f'Unable to determine build_id from: {pullspec}. Retrieved image info: {image_info_str}'
        )
    return build_id
def _nvr_for_operand_pullspec(runtime, spec):
    # spec should just be the part after the final "/" e.g. "ose-kube-rbac-proxy@sha256:9211b70..."
    # we can look it up in the internal proxy.
    urls = runtime.group_config.urls
    spec = f"{urls.brew_image_host}/{urls.brew_image_namespace}/openshift-{spec}"
    info = exectools.cmd_assert(
        f"oc image info -o json --filter-by-os=linux/amd64 {spec}",
        retries=3,
        pollrate=5,
        text_mode=True,
    )[0]
    labels = json.loads(info)["config"]["config"]["Labels"]
    return f"{labels['com.redhat.component']}-{labels['version']}-{labels['release']}"
示例#5
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)