Esempio n. 1
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. 2
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 not None:
        res = session.get(constants.errata_get_build_url.format(id=nvr),
                          auth=HTTPKerberosAuth())
    else:
        res = requests.get(constants.errata_get_build_url.format(id=nvr),
                           auth=HTTPKerberosAuth())
    if res.status_code == 200:
        return Build(nvr=nvr, body=res.json(), product_version=product_version)
    else:
        raise exceptions.BrewBuildException("{build}: {msg}".format(
            build=nvr, msg=res.text))
Esempio n. 3
0
    def add_builds(self, builds=[]):
        """5.2.2.7. POST /api/v1/erratum/{id}/add_builds

        Add one or more brew builds to an advisory.

        Example request body:
            {"product_version": "RHEL-7", "build": "rhel-server-docker-7.0-23", "file_types": ["ks","tar"]}

        The request body is a single object or an array of objects
        specifying builds to add, along with the desired product
        version (or pdc release) and file type(s). Builds may be
        specified by ID or NVR.

        https://errata.devel.redhat.com/developer-guide/api-http-api.html#api-post-apiv1erratumidadd_builds

        :param list[Build] builds: List of Build objects to attach to
        an advisory

        :return: True if builds were added successfully

        :raises: exceptions.BrewBuildException if the builds could not be attached
        :raises: exceptions.ErrataToolUnauthenticatedException if the user is not authenticated to make the request
        """
        data = [b.to_json() for b in builds]

        res = requests.post(
            constants.errata_add_builds_url.format(id=self.advisory_id),
            auth=HTTPKerberosAuth(),
            json=data)

        print(res.status_code)
        print(res.text)

        if res.status_code == 422:
            # "Something" bad happened
            print(res.status_code)
            print(res.text)
            raise exceptions.BrewBuildException(str(res.json()))
        elif res.status_code == 401:
            raise exceptions.ErrataToolUnauthenticatedException(res.text)
        # TODO: Find the success return code
        else:
            return True
Esempio n. 4
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