Exemplo n.º 1
0
def query_remote_install(server, uuid, login, password, package):
    """ This function installs package into guest system via Katello request.
        Basically, it tells Katello "Hey, Katello, install these packages into machine with that UUID"

    :param server: Remote Katello server
    :type server: ``str``
    :param uuid: Target machine UUID
    :type uuid: ``str``
    :param login: Login name into Katello server
    :type login: ``str``
    :param password: Login password into Katello server
    :type password: ``str``
    :param package: Package to install into system
    :type package: ``str``

    :raises: pytest.Failed    
    """
    # Prepare the request
    request = net.make_auth_request("https://%s/katello/api/systems/%s/packages" % (server, uuid), login, password)
    request.add_header("content-type", "application/json")
    body = json.dumps({"packages": [package]})
    request.add_header("content-length", str(len(body)))
    request.add_data(body)
    # send the request
    response = None
    try:
        response = urlopen(request)
    except HTTPError, e:
        if int(e.code) in [202]:
            response = e # To work in RHEL5
        else:
            pytest.fail(msg="Error when querying installation of package %s with HTTP code %d and reason '%s'!" % (package, int(e.code), e.reason))
Exemplo n.º 2
0
def poll_task_state(server, task_uuid, login, password):
    """ This function returns state of task with given UUID.
        Useful when polling certain task if finished or not.

    :param server: Katello server to poll on.
    :type server: ``str``
    :param task_uuid: Checked task's unique ID
    :type task_uuid: ``str``
    :param password: Login password into Katello server
    :type password: ``str``
    :param package: Package to install into system
    :type package: ``str``

    :returns: Reported task state
    :rtype: ``str``
    """
    request = net.make_auth_request("https://%s/katello/api/systems/tasks/%s" % (server, task_uuid), login, password)
    response = urlopen(request)
    data = json.loads("\n".join(response.readlines()))
    return str(data["state"])