Exemple #1
0
def cluster_reuse(valid_session_credentials):
    """
    Returns imported or created cluster identified
    by one of machine from cluster.
    Returned cluster can be used for further testing.
    Function uses Tendrl API(GetNodeList and GetClusterList).
    In case there is need to identify cluster directly
    by storage tools this function should be split.
    """
    id_hostname = pytest.config.getini("usm_id_fqdn")
    api = TendrlApi(auth=valid_session_credentials)
    node_list = api.get_nodes()
    hash_hostname = [node for node in node_list["nodes"]
                     if node["fqdn"] == id_hostname
                     ]
    if len(hash_hostname) != 1:
        raise Exception("There is not one node with FQDN = {}.".format(id_hostname))
    hash_hostname = hash_hostname[0]["node_id"]
    clusters = api.get_cluster_list()
    clusters = [cluster for cluster in clusters
                if hash_hostname in cluster["nodes"].keys()
                ]
    if len(clusters) != 1:
        raise Exception("There is not one cluster which includes node"
                        " with FQDN == {}.".format(id_hostname))
    return clusters[0]
Exemple #2
0
def test_session_invalid(invalid_session_credentials):
    asserts = {
        "cookies": None,
        "ok": False,
        "reason": 'Unauthorized',
        "status": 401,
        }
    api = TendrlApi(auth=invalid_session_credentials)
    api.jobs(asserts_in=asserts)
Exemple #3
0
def test_login_invalid():
    asserts = {
        "cookies": None,
        "ok": False,
        "reason": 'Unauthorized',
        "status": 401,
        }
    auth = login("invalid_user", "invalid_password", asserts_in=asserts)
    api = TendrlApi(auth)
    api.jobs(asserts_in=asserts)
Exemple #4
0
def test_session_unauthorized():
    asserts = {
        "cookies": None,
        "ok": False,
        "reason": 'Unauthorized',
        "status": 401,
        }
    # passing auth=None would result in api requests to be done without Tendrl
    # auth header
    api = TendrlApi(auth=None)
    api.jobs(asserts_in=asserts)
Exemple #5
0
def unmanaged_cluster(valid_session_credentials):
    """
    Return cluster information from Tendrl API and make sure that returned
    cluster is not *managed*.
    """
    cluster_reuse = get_cluster_reuse(valid_session_credentials)
    if cluster_reuse["is_managed"] == "yes":
        api = TendrlApi(auth=valid_session_credentials)
        job_id = api.unmanage_cluster(cluster_reuse["cluster_id"])["job_id"]
        api.wait_for_job_status(job_id)
        return get_cluster_reuse(valid_session_credentials)
    else:
        return cluster_reuse
Exemple #6
0
def test_ping():
    """
    Positive ping test.
    """
    test = TendrlApi()
    # TODO(fbalak): add valid returned json to docstring and test them
    """
    :step:
      Call USM API via GET request with pattern ``APIURL/ping``.
    :result:
      Return code should be **200** with data ``{"status": "OK"}``.
    """
    test.ping()
Exemple #7
0
def managed_cluster(valid_session_credentials):
    """
    Return cluster information from Tendrl API and make sure that returned
    cluster is *managed*.
    """
    cluster_reuse = get_cluster_reuse(valid_session_credentials)
    if cluster_reuse["is_managed"] != "yes":
        api = TendrlApi(auth=valid_session_credentials)
        job_id = api.import_cluster(cluster_reuse["cluster_id"],
                                    profiling="enable")["job_id"]
        api.wait_for_job_status(job_id)
        return get_cluster_reuse(valid_session_credentials)
    else:
        return cluster_reuse
Exemple #8
0
def get_cluster_reuse(session_credentials):
    """
    Returns Gluster *trusted storage pool* (aka cluster) as identified by
    ``cluster_member`` machine (specified in usmqe config file).

    Returned cluster can be used for further testing.
    Function uses Tendrl API(clusters). In case there
    is need to identify cluster directly by storage
    tools this function should be split.
    """
    LOGGER = pytest.get_logger("cluster_reuse")
    id_hostname = CONF.config["usmqe"]["cluster_member"]
    api = TendrlApi(auth=session_credentials)

    retry_num = 12
    for i in range(retry_num):
        clusters = []
        for cluster in api.get_cluster_list():
            node_fqdn_list = cluster2node_fqdn_list(cluster)
            if id_hostname in node_fqdn_list:
                clusters.append(cluster)
                msg = "cluster member {} found in cluster {}"
            else:
                msg = "cluster member {} not found in cluster {}"
            LOGGER.debug(msg.format(id_hostname, node_fqdn_list))
        if len(clusters) == 1:
            cluster = clusters[0]
            LOGGER.info("using cluster: {}".format(
                cluster2node_fqdn_list(cluster)))
            return cluster
        else:
            LOGGER.warning(
                "unexpected number (!= 1) of clusters found: {}".format(
                    len(clusters)))
        # wait a bit before retrying again
        if i != retry_num - 1:
            LOGGER.info("retrying search for a cluster")
            time.sleep(5)

    raise Exception("There is no cluster which includes node"
                    " with FQDN == {}.".format(id_hostname))
Exemple #9
0
def cluster_reuse(valid_session_credentials):
    """
    Returns cluster identified by one of machines
    from cluster.
    Returned cluster can be used for further testing.
    Function uses Tendrl API(clusters). In case there
    is need to identify cluster directly by storage
    tools this function should be split.
    """
    id_hostname = pytest.config.getini("usm_cluster_member")
    api = TendrlApi(auth=valid_session_credentials)
    for _ in range(12):
        clusters = api.get_cluster_list()
        clusters = [
            cluster for cluster in clusters
            if id_hostname in [node["fqdn"] for node in cluster["nodes"]]
        ]
        if len(clusters) == 1:
            return clusters[0]
        time.sleep(5)

    raise Exception("There is not one cluster which includes node"
                    " with FQDN == {}.".format(id_hostname))
Exemple #10
0
def test_ping():
    """@pylatest api/ping
    API: ping
    **********************

    .. test_metadata:: author [email protected]

    Description
    ===========

    Positive ping test.
    """
    test = TendrlApi()
    # TODO(fbalak): add valid returned json to docstring and test them
    """@pylatest api/common.ping_valid
    .. test_step:: 1

        Call USM API via GET request with pattern ``APIURL/ping``.

    .. test_result:: 1

        Return code should be **200** with data ``{"status": "OK"}``.
    """
    test.ping()
Exemple #11
0
def test_login_multiple_sessions_twisted():
    asserts = {
        "cookies": None,
        "ok": False,
        "reason": 'Unauthorized',
        "status": 401,
        }
    api_one = TendrlApi(auth=login(
        pytest.config.getini("usm_username"),
        pytest.config.getini("usm_password")))
    api_two = TendrlApi(auth=login(
        pytest.config.getini("usm_username"),
        pytest.config.getini("usm_password")))
    api_one.jobs()
    api_two.jobs()
    logout(auth=api_one._auth)
    api_one.jobs(asserts_in=asserts)
    api_two.jobs()
    logout(auth=api_two._auth)
    api_one.jobs(asserts_in=asserts)
    api_two.jobs(asserts_in=asserts)
Exemple #12
0
def test_login_valid(valid_session_credentials):
    api = TendrlApi(auth=valid_session_credentials)
    api.jobs()
def test_login_multiple_sessions_twisted():
    asserts = {
        "cookies": None,
        "ok": False,
        "reason": 'Unauthorized',
        "status": 401,
    }
    api_one = TendrlApi(auth=login(CONF.config["usmqe"]["username"],
                                   CONF.config["usmqe"]["password"]))
    api_two = TendrlApi(auth=login(CONF.config["usmqe"]["username"],
                                   CONF.config["usmqe"]["password"]))
    api_one.jobs()
    api_two.jobs()
    logout(auth=api_one._auth)
    api_one.jobs(asserts_in=asserts)
    api_two.jobs()
    logout(auth=api_two._auth)
    api_one.jobs(asserts_in=asserts)
    api_two.jobs(asserts_in=asserts)