コード例 #1
0
def get_filtered_list(filter_id=constants.errata_default_filter, limit=5):
    """return a list of Erratum() objects from results using the provided
filter_id

    :param filter_id: The ID number of the pre-defined filter
    :param int limit: How many erratum to list
    :return: A list of Erratum objects

    :raises exceptions.ErrataToolUnauthenticatedException: If the user is not authenticated to make the request
    :raises exceptions.ErrataToolError: If the given filter does not exist, and, any other unexpected error

    Note: Errata filters are defined in the ET web interface
    """
    filter_endpoint = constants.errata_filter_list_url.format(
        id=filter_id)
    res = requests.get(filter_endpoint,
                       auth=HTTPKerberosAuth())
    if res.status_code == 200:
        # When asked for an advisory list which does not exist
        # normally you would expect a code like '404' (not
        # found). However, the Errata Tool sadistically returns a 200
        # response code. That leaves us with one option: Decide that
        # successfully parsing the response as a JSONinfo object indicates
        # a successful API call.
        try:
            return [Erratum(body=advs) for advs in res.json()][:limit]
        except Exception:
            raise exceptions.ErrataToolError("Could not locate the given advisory filter: {fid}".format(
                fid=filter_id))
    elif res.status_code == 401:
        raise exceptions.ErrataToolUnauthenticatedException(res.text)
    else:
        raise exceptions.ErrataToolError("Other error (status_code={code}): {msg}".format(
            code=res.status_code,
            msg=res.text))
コード例 #2
0
    def change_state(self, state):
        """5.2.1.14. POST /api/v1/erratum/{id}/change_state

        Change the state of an advisory.
        Example request body:

            {"new_state": "QE"}

        Request body may contain:
            new_state: e.g. 'QE' (required)
            comment: a comment to post on the advisory (optional)

        :param str state: The state to change the advisory to
        :return: True on successful state change
        :raises: exceptions.ErrataToolUnauthenticatedException if the user is not authenticated to make the request

        https://errata.devel.redhat.com/developer-guide/api-http-api.html#api-post-apiv1erratumidchange_state
        """
        res = requests.post(constants.errata_change_state_url.format(id=self.advisory_id),
                            auth=HTTPKerberosAuth(),
                            data={"new_state": state})

        # You may receive this response when: Erratum isn't ready to
        # move to QE, no builds in erratum, erratum has no Bugzilla
        # bugs or JIRA issues.
        if res.status_code == 422:
            # Conditions not met
            raise exceptions.ErrataToolError("Can not change erratum state, preconditions not yet met. Error message: {msg}".format(
                msg=res.text))
        elif res.status_code == 401:
            raise exceptions.ErrataToolUnauthenticatedException(res.text)
        elif res.status_code == 201:
            # POST processed successfully
            self.refresh()
            return True
コード例 #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
コード例 #4
0
def get_erratum(id):
    """5.2.1.2. GET /api/v1/erratum/{id}

    Retrieve the advisory data.

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

    :return SUCCESS: An Erratum object
    :return FAILURE: :bool:False
    :raises: exceptions.ErrataToolUnauthenticatedException if the user is not authenticated to make the request
    """
    res = requests.get(constants.errata_get_erratum_url.format(id=id),
                       auth=HTTPKerberosAuth())

    if res.status_code == 200:
        return Erratum(body=res.json())
    elif res.status_code == 401:
        raise exceptions.ErrataToolUnauthenticatedException(res.text)
    else:
        return False
コード例 #5
0
def new_erratum(kind=None,
                release_date=None,
                create=False,
                minor='Y',
                assigned_to=None,
                manager=None,
                package_owner=None):
    """5.2.1.1. POST /api/v1/erratum

    Create a new advisory.
    Takes an unrealized advisory object and related attributes using the following format:

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

    :param string kind: One of 'rpm' or 'image', effects boilerplate text
    :param string release_date: A date in the form YYYY-MM-DD
    :param bool create: If true, create the erratum in the Errata
        tool, by default just the DATA we would have POSTed is
        returned
    :param str/int minor: The minor release to substitute into the
        errata boilerplate text (see:
        :mod:`constants`). E.g., if this is a '3.9'
        release, you would provide '9' as the value for 'minor'
    :param string assigned_to: The email address of the group responsible for
        examining and approving the advisory entries
    :param string manager: The email address of the manager responsible for
        managing the contents and status of this advisory
    :param string package_owner: The email address of the person who is handling
        the details and status of this advisory

    :return: An Erratum object
    :raises: exceptions.ErrataToolUnauthenticatedException if the user is not authenticated to make the request
    """
    if release_date is None:
        release_date = datetime.datetime.now() + datetime.timedelta(days=21)

    if kind is None:
        kind = 'rpm'

    body = copy.deepcopy(constants.errata_new_object)
    body['advisory']['publish_date_override'] = release_date
    body['advisory']['synopsis'] = constants.errata_synopsis[kind].format(
        Y=minor)

    # Fill in the minor version variables
    body['advisory']['description'] = body['advisory']['description'].format(
        Y=minor)
    body['advisory']['solution'] = body['advisory']['solution'].format(Y=minor)
    body['advisory']['synopsis'] = body['advisory']['synopsis'].format(Y=minor)
    body['advisory']['topic'] = body['advisory']['topic'].format(Y=minor)

    body['advisory']['assigned_to_email'] = assigned_to
    body['advisory']['manager_email'] = manager
    body['advisory']['package_owner_email'] = package_owner

    if create:
        # THIS IS NOT A DRILL
        res = requests.post(constants.errata_post_erratum_url,
                            auth=HTTPKerberosAuth(),
                            json=body)

        if res.status_code == 201:
            return Erratum(body=res.json())
        elif res.status_code == 401:
            raise exceptions.ErrataToolUnauthenticatedException(res.text)
        else:
            raise exceptions.ErrataToolError(
                "Other error (status_code={code}): {msg}".format(
                    code=res.status_code, msg=res.text))
    else:
        # This is a noop
        return json.dumps(body, indent=2)