Esempio n. 1
0
def get_brew_build(nvr, product_version='', session=None):
    """5.2.2.1. GET /api/v1/build/{id_or_nvr}

    Get Brew build details.

    https://errata.devel.redhat.com/developer-guide/api-http-api.html#api-get-apiv1buildid_or_nvr

    :param str nvr: A name-version-release string of a brew rpm/image build
    :param str product_version: The product version tag as given to ET
    when attaching a build
    :param requests.Session session: A python-requests Session object,
    used for for connection pooling. Providing `session` object can
    yield a significant reduction in total query time when looking up
    many builds.

    http://docs.python-requests.org/en/master/user/advanced/#session-objects

    :return: An initialized Build object with the build details
    :raises exceptions.BrewBuildException: When build not found

    """
    if session is None:
        session = requests.session()

    res = session.get(constants.errata_get_build_url.format(id=nvr),
                      verify=ssl.get_default_verify_paths().openssl_cafile,
                      auth=HTTPKerberosAuth())

    if res.status_code == 200:
        return brew.Build(nvr=nvr,
                          body=res.json(),
                          product_version=product_version)
    else:
        raise exceptions.BrewBuildException("{build}: {msg}".format(
            build=nvr, msg=res.text))
Esempio n. 2
0
def get_brew_builds(errata_id, session=None):
    """5.2.2.1. GET /api/v1/erratum/{id}/builds

    Get Errata list of builds.

    https://errata.devel.redhat.com/developer-guide/api-http-api.html#api-get-apiv1erratumidbuilds
    :param str errata_id: the errata id
    :param requests.Session session: A python-requests Session object,
    used for for connection pooling. Providing `session` object can
    yield a significant reduction in total query time when looking up
    many builds.

    http://docs.python-requests.org/en/master/user/advanced/#session-objects

    :return: A List of initialized Build object with the build details
    :raises exceptions.BrewBuildException: When erratum return errors

    """
    if session is None:
        session = requests.session()

    res = session.get(constants.errata_get_builds_url.format(id=errata_id),
                      verify=ssl.get_default_verify_paths().openssl_cafile,
                      auth=HTTPKerberosAuth())
    brew_list = []
    if res.status_code == 200:
        jlist = res.json()
        for key in jlist.keys():
            for obj in jlist[key]['builds']:
                brew_list.append(
                    brew.Build(nvr=list(obj.keys())[0], product_version=key))
        return brew_list
    else:
        raise exceptions.BrewBuildException(
            "fetch builds from {id}: {msg}".format(id=errata_id, msg=res.text))
Esempio n. 3
0
    def refresh(self):
        """Refresh or build initial list of brew builds

        :return: True if builds could be found for the given tag

        :raises: Exception if there is an error looking up builds
        """
        rc, stdout, stderr = get_tagged_rpm_builds(self.tag)

        print("Refreshing for tag: {tag}".format(tag=self.tag))

        if rc != 0:
            raise exceptions.BrewBuildException(
                "Failed to get brew builds for tag: {tag} - {err}".format(
                    tag=self.tag, err=stderr))
        else:
            builds = set(stdout.splitlines())
            for b in builds:
                # The results come back with the build arch (.src)
                # appended. Remove that if it is in the string.
                try:
                    self.builds.add(b[:b.index('.src')])
                except ValueError:
                    # Raised if the given substring is not found
                    self.builds.add(b)

        return True
Esempio n. 4
0
def get_nvr_arch_log(name, version, release, arch='x86_64'):
    log_url = '{host}/packages/{name}/{version}/{release}/data/logs/{arch}.log'.format(
        host=constants.BREW_DOWNLOAD_URL,
        name=name,
        version=version,
        release=release,
        arch=arch,
    )

    logger.debug(f"Trying {log_url}")
    res = requests.get(log_url, verify=ssl.get_default_verify_paths().openssl_cafile)
    if res.status_code != 200:
        raise exceptions.BrewBuildException(f"Could not get {arch}.log for {name}-{version}-{release}")
    return res.text
Esempio n. 5
0
def get_nvr_root_log(name, version, release, arch='x86_64'):
    root_log_url = '{host}/vol/rhel-{rhel_version}/packages/{name}/{version}/{release}/data/logs/{arch}/root.log'.format(
        host=constants.BREW_DOWNLOAD_URL,
        rhel_version=(7 if 'el7' in release else 8),
        name=name,
        version=version,
        release=release,
        arch=arch,
    )

    logger.debug(f"Trying {root_log_url}")
    res = requests.get(root_log_url, verify=ssl.get_default_verify_paths().openssl_cafile)
    if res.status_code != 200:
        raise exceptions.BrewBuildException("Could not get root.log for {}-{}-{}".format(name, version, release))
    return res.text
Esempio n. 6
0
    def refresh(self):
        """Refresh or build initial list of brew builds

        :return: True if builds could be found for the given tag

        :raises: Exception if there is an error looking up builds
        """
        rc, stdout, stderr = get_tagged_image_builds(self.tag)

        print("Refreshing for tag: {tag}".format(tag=self.tag))

        if rc != 0:
            raise exceptions.BrewBuildException(
                "Failed to get brew builds for tag: {tag} - {err}".format(
                    tag=self.tag, err=stderr))
        else:
            builds = set(stdout.splitlines())
            for b in builds:
                self.builds.add(b.split()[0])

        return True