示例#1
0
def test_delete_pool_invalid(valid_cluster_id, invalid_pool_id,
                             valid_session_credentials):
    """@pylatest api/ceph.delete_pool_invalid
        API-ceph: delete_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

        Description
        ===========
        Negative Delete from CRUD for pools.

        Delete ceph pool ``invalid_pool_id`` via API.

        .. test_step:: 1

                Connect to Tendrl API via DELETE request
                to ``APIURL/:cluster_id/CephDeletePool``
                Where cluster_id is set to predefined value.

        .. test_result:: 1

                Server should return response in JSON format:

                Return code should be **200** with data ``{"job_id":"_id_"}``.
                And then joib should fail.
                """

    api = cephapi.TendrlApiCeph(auth=valid_session_credentials)
    job_id = api.delete_pool(valid_cluster_id, invalid_pool_id)["job_id"]
    api.wait_for_job_status(job_id, status="failed")
示例#2
0
def test_update_pool_invalid(valid_cluster_id, valid_pool_id,
                             valid_session_credentials, invalid_pool_name,
                             invalid_size, invalid_minsize, invalid_pg_num):
    # TODO add quota support
    """@pylatest api/ceph.update_pool_invalid
        API-ceph: update_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

        Description
        ===========
        Negative Update from CRUD for pools.

        Update existing pool with invalid data via API.

        .. test_step:: 1

            Connect to Tendrl API via GET request
            to ``APIURL/:cluster_id/CephUpdatePool``
            Where cluster_id is set to predefined value.

        .. test_result:: 1

           Update should be declined.
            """

    api = cephapi.TendrlApiCeph(auth=valid_session_credentials)
    job_id = api.update_pool(valid_cluster_id, valid_pool_id,
                             invalid_pool_name, invalid_size, invalid_minsize,
                             invalid_pg_num)["job_id"]
    api.wait_for_job_status(job_id, status="failed")
示例#3
0
def valid_cluster_id(valid_session_credentials):
    """
    Generate valid id of imported cluster.
    """
    # TODO change
    api = cephapi.TendrlApiCeph(auth=valid_session_credentials)
    cluster_list = [
        cl for cl in api.get_cluster_list() if cl["sds_name"] == "ceph"
        and cl["cluster_name"] == pytest.config.getini("usm_ceph_cl_name")
    ]
    return cluster_list[0]["cluster_id"]
示例#4
0
def valid_pool_id(valid_session_credentials):
    """
    Generate valid id of a created volume.
    """
    # TODO change
    api = cephapi.TendrlApiCeph(auth=valid_session_credentials)
    cluster_list = [
        cl for cl in api.get_cluster_list() if cl["sds_name"] == "ceph"
        and cl["cluster_name"] == pytest.config.getini("usm_ceph_cl_name")
    ]
    pools = cluster_list[0]["pools"]
    return [
        pool["pool_id"] for pool in pools.values()
        if pool["pool_name"] == pytest.config.getini("usm_pool_name")
    ][0]
示例#5
0
def test_create_pool_invalid(valid_cluster_id, invalid_pool_name,
                             invalid_pg_num, invalid_minsize, invalid_size,
                             valid_session_credentials):
    """@pylatest api/ceph.create_pool_invalid
        API-ceph: create_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

        Description
        ===========
        Negative Create from CRUD for pools.

        .. test_step:: 1

                Connect to Tendrl API via POST request
                to ``APIURL/:cluster_id/CephCreatePool``
                Where cluster_id is set to predefined value.

        .. test_result:: 1

                Server should return response in JSON format:

                Return code should be **202** with data
                ``{"message": "Accepted"}``.
                Job should fail.
                """

    api = cephapi.TendrlApiCeph(auth=valid_session_credentials)

    job_id = api.create_pool(valid_cluster_id, invalid_pool_name,
                             invalid_pg_num, invalid_minsize, invalid_size)
    LOGGER.info("Create pool job_id: {}".format(job_id))
    # TODO check correctly server response or etcd job status
    api.wait_for_job_status(job_id["job_id"], status="failed")
示例#6
0
def test_create_pool_valid(valid_cluster_id, valid_pool_name, valid_pg_num,
                           valid_minsize, valid_size,
                           valid_session_credentials):
    """@pylatest api/ceph.create_pool_valid
        API-ceph: create_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

        Description
        ===========
        Positive Create and Read from CRUD for pools.

        .. test_step:: 1

                Connect to Tendrl API via POST request
                to ``APIURL/:cluster_id/CephCreatePool``
                Where cluster_id is set to predefined value.

        .. test_result:: 1

                Server should return response in JSON format:

                Return code should be **202** with data
                ``{"message": "Accepted"}``.
                job should finish.
                """

    api = cephapi.TendrlApiCeph(auth=valid_session_credentials)

    job_id = api.create_pool(valid_cluster_id, valid_pool_name, valid_pg_num,
                             valid_minsize, valid_size)["job_id"]
    LOGGER.info("Create pool job_id: {}".format(job_id))
    api.wait_for_job_status(job_id)
    """@pylatest api/ceph.create_pool_valid
        API-ceph: create_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

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

        Check if there is created pool in ceph cluster via CLI.

        .. test_step:: 2

            Connect to ceph monitor machine via ssh and run
            ``ceph --format json --cluster *clustername* osd pool ls detail``

        .. test_result:: 2

            There should be listed ceph pool named ``valid_pool_name``.

            """
    # TODO get proper cluster name from configuration
    storage = ceph_cluster.CephCluster(
        pytest.config.getini("usm_ceph_cl_name"))
    pools = storage.osd.pool_ls(detail=True)
    LOGGER.info("List of Ceph pools:{}".format(pools))
    selected_pools = [
        pool for pool in pools if pool["pool_name"] == valid_pool_name
    ]
    pytest.check(
        len(selected_pools) == 1,
        "Pool {} should be created in Ceph cluster {}.".format(
            valid_pool_name, pytest.config.getini("usm_ceph_cl_name")))
    """@pylatest api/ceph.create_pool_valid
        API-ceph: create_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

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

        Check if there is created pool in ceph cluster via API.

        .. test_step:: 3

            Connect to Tendrl API via GET request
            to ``APIURL/:cluster_id/CephPoolList``
            Where cluster_id is set to predefined value.

        .. test_result:: 3

            There should be listed ceph pool named ``valid_pool_name``.

            """

    if len(selected_pools) == 1:
        pool = selected_pools[0]
        storage_pool_attributes = {
            "erasure_code_profile":
            pool["erasure_code_profile"],
            "min_size":
            pool["min_size"],
            "percent_used":
            "0",  # newly created pool
            "pg_num":
            pool["pg_num"],
            "pool_id":
            pool["auid"],
            "pool_name":
            pool["pool_name"],
            "quota_enabled":
            pool["quota_max_bytes"] == 0 and pool["quota_max_objects"] == 0,
            "quota_max_bytes":
            pool["quota_max_bytes"],
            "quota_max_objects":
            pool["quota_max_objects"],
            "size":
            pool["size"],
            "type":
            "replicated" if pool["type"] == 1 else "ecpool",  # TODO
            "used":
            "0"  # newly created pool
        }

        pool_tendrl = [
            pool_t for pool_t in api.get_pool_list(valid_cluster_id)
            if pool_t["pool_name"] == valid_pool_name
        ][0]
        # remove Tendrl specific keys
        pool_tendrl.pop("deleted")
        pool_tendrl.pop("hash")
        pool_tendrl.pop("updated_at")

        pytest.check(
            pool_tendrl == storage_pool_attributes,
            "Storage pool attributes: {} "
            "Tendrl pool attributes: {} "
            "These should be the same.".format(pool_tendrl,
                                               storage_pool_attributes))
示例#7
0
def test_delete_pool_valid(valid_cluster_id, valid_pool_id,
                           valid_session_credentials):

    api = cephapi.TendrlApiCeph(auth=valid_session_credentials)
    """@pylatest api/ceph.delete_pool
        API-ceph: delete_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

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

        Get pool name from API because it was changed in *update* test.

        .. test_step:: 1

            Connect to Tendrl API via GET request
            to ``APIURL/:cluster_id/CephPoolList``
            Where cluster_id is set to predefined value.

        .. test_result:: 1

            There should be listed ceph pool with id == ``valid_pool_id``.

            """

    api_pool_name = [
        list(pool_t.values())[0]["pool_name"]
        for pool_t in api.get_pool_list(valid_cluster_id)
        if "1" in pool_t.keys()
    ][0]
    """@pylatest api/ceph.delete_pool
        API-ceph: delete_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

        Description
        ===========
        Positive Delete from CRUD for pools.

        Delete ceph pool ``valid_pool_id`` via API.

        .. test_step:: 2

                Connect to Tendrl API via POST request
                to ``APIURL/:cluster_id/CephDeletePool``
                Where cluster_id is set to predefined value.

        .. test_result:: 2

                Server should return response in JSON format:

                Return code should be **200** with data ``{"job_id":"_id_"}``.
                And then job should finish.
                """

    job_id = api.delete_pool(valid_cluster_id, valid_pool_id)["job_id"]
    LOGGER.info("Delete pool job_id: {}".format(job_id))
    api.wait_for_job_status(
        job_id, issue="https://github.com/Tendrl/ceph-integration/issues/224")
    """@pylatest api/ceph.delete_pool
        API-ceph: delete_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

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

        Check if there is not deleted pool in ceph cluster via CLI.

        .. test_step:: 3

            Connect to ceph monitor machine via ssh and run
            ``ceph --cluster *clustername* pool status``

        .. test_result:: 3

            There should not be listed ceph pool named ``api_pool_name``.

            """
    storage = ceph_cluster.CephCluster(
        pytest.config.getini("usm_ceph_cl_name"))
    pytest.check(api_pool_name not in storage.osd.pool_ls(),
                 "Pool {} should not be in Ceph \
                 cluster {} after deletion.".format(
                     api_pool_name, pytest.config.getini("usm_ceph_cl_name")),
                 issue="https://github.com/Tendrl/ceph-integration/issues/224")
示例#8
0
def test_update_pool_valid(valid_cluster_id, valid_pool_id,
                           valid_session_credentials, valid_pool_name,
                           valid_size, valid_minsize, valid_pg_num):
    # TODO add quota support
    """@pylatest api/ceph.update_pool_valid
        API-ceph: update_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

        Description
        ===========
        Negative Update from CRUD for pools.

        Update existing pool with valid data via API.

        .. test_step:: 1

            Connect to Tendrl API via GET request
            to ``APIURL/:cluster_id/CephUpdatePool``
            Where cluster_id is set to predefined value.

        .. test_result:: 1

           Update job should pass.
            """
    valid_pool_name = valid_pool_name + "_updated"
    valid_size = valid_size + 1
    valid_minsize = valid_minsize + 1
    valid_pg_num = valid_pg_num * 2
    api = cephapi.TendrlApiCeph(auth=valid_session_credentials)
    job_id = api.update_pool(valid_cluster_id,
                             valid_pool_id,
                             size=valid_size,
                             min_size=valid_minsize,
                             pg_num=valid_pg_num)["job_id"]
    api.wait_for_job_status(
        job_id, issue="https://github.com/Tendrl/ceph-integration/issues/225")
    """@pylatest api/ceph.update_pool_valid
        API-ceph: update_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

        .. test_step:: 2

            Check if changes are made in Ceph pool.

        .. test_result:: 2

           Pool is updated.
            """

    storage = ceph_cluster.CephCluster(
        pytest.config.getini("usm_ceph_cl_name"))
    pools = storage.osd.pool_ls(detail=True)
    LOGGER.info("List of Ceph pools:{}".format(pools))
    selected_pools = [
        pool for pool in pools if pool["pool_name"] == valid_pool_name
    ]
    pytest.check(len(selected_pools) == 1,
                 "Pool {} should be updated in Ceph cluster {}.".format(
                     valid_pool_name,
                     pytest.config.getini("usm_ceph_cl_name")),
                 issue="https://github.com/Tendrl/ceph-integration/issues/225")
    """@pylatest api/ceph.update_pool_valid
        API-ceph: update_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

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

        Check if there is updated pool in ceph cluster via API.

        .. test_step:: 3

            Connect to Tendrl API via GET request
            to ``APIURL/:cluster_id/CephPoolList``
            Where cluster_id is set to predefined value.

        .. test_result:: 3

            There should be listed ceph pool named ``valid_pool_name``.

            """

    if len(selected_pools) == 1:
        pool = selected_pools[0]
        storage_pool_attributes = {
            "erasure_code_profile":
            pool["erasure_code_profile"],
            "min_size":
            pool["min_size"],
            "percent_used":
            "0",  # newly created pool
            "pg_num":
            pool["pg_num"],
            "pool_id":
            pool["auid"],
            "pool_name":
            pool["pool_name"],
            "quota_enabled":
            pool["quota_max_bytes"] == 0 and pool["quota_max_objects"] == 0,
            "quota_max_bytes":
            pool["quota_max_bytes"],
            "quota_max_objects":
            pool["quota_max_objects"],
            "size":
            pool["size"],
            "type":
            "replicated" if pool["type"] == 1 else "ecpool",  # TODO
            "used":
            "0"  # newly created pool
        }

        pool_tendrl = [
            pool_t for pool_t in api.get_pool_list(valid_cluster_id)
            if pool_t["pool_name"] == valid_pool_name
        ][0]
        # remove Tendrl specific keys
        pool_tendrl.pop("deleted")
        pool_tendrl.pop("hash")
        pool_tendrl.pop("updated_at")

        pytest.check(
            pool_tendrl == storage_pool_attributes,
            "Storage pool attributes: {} "
            "Tendrl pool attributes: {} "
            "These should be the same.".format(pool_tendrl,
                                               storage_pool_attributes))
示例#9
0
def test_update_pool_name_valid(valid_cluster_id, valid_pool_id,
                                valid_session_credentials, valid_pool_name):
    """@pylatest api/ceph.update_pool_name_valid
        API-ceph: update_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

        Description
        ===========
        Negative Update from CRUD for pools.

        Update existing pool with valid pool name via API.

        .. test_step:: 1

            Connect to Tendrl API via GET request
            to ``APIURL/:cluster_id/CephUpdatePool``
            Where cluster_id is set to predefined value.

        .. test_result:: 1

           Update job should pass.
            """
    valid_pool_name = valid_pool_name + "_updated"
    api = cephapi.TendrlApiCeph(auth=valid_session_credentials)
    job_id = api.update_pool(valid_cluster_id, valid_pool_id,
                             valid_pool_name)["job_id"]
    api.wait_for_job_status(
        job_id, issue="https://github.com/Tendrl/ceph-integration/issues/225")
    """@pylatest api/ceph.update_pool_name_valid
        API-ceph: update_pool
        ******************************

        :authors:
            - [email protected]
            - [email protected]

        .. test_step:: 2

            Check if changes are made in Ceph pool.

        .. test_result:: 2

           Updates are done in pool.
            """

    storage = ceph_cluster.CephCluster(
        pytest.config.getini("usm_ceph_cl_name"))
    pools = storage.osd.pool_ls(detail=True)
    LOGGER.info("List of Ceph pools:{}".format(pools))
    selected_pools = [
        pool for pool in pools if pool["pool_name"] == valid_pool_name
    ]
    pytest.check(len(selected_pools) == 1,
                 "Pool {} should be updated in Ceph cluster {}.".format(
                     valid_pool_name,
                     pytest.config.getini("usm_ceph_cl_name")),
                 issue="https://github.com/Tendrl/ceph-integration/issues/225")
示例#10
0
def test_cluster_import_valid(valid_session_credentials):
    """@pylatest api/ceph.cluster_import
        .. test_step:: 1

        Get list of ids of availible nodes.

        .. test_result:: 1

                Server should return response in JSON format:

                        {
                ...
                  {
                  "fqdn": hostname,
                  "machine_id": some_id,
                  "node_id": node_id
                  },
                ...
                        }

                Return code should be **200** with data ``{"message": "OK"}``.

        """
    api = cephapi.TendrlApiCeph(auth=valid_session_credentials)
    nodes = api.get_nodes()
    ceph_nodes = [
        node["node_id"] for node in nodes["nodes"] if "ceph" in node["tags"]
    ]
    LOGGER.debug("Nodes for importing: {}".format(ceph_nodes))
    """@pylatest api/ceph.cluster_import
        .. test_step:: 2

            Send POST request to Tendrl API ``APIURL/CephImportCluster

        .. test_result:: 2

            Server should return response in JSON format:

                {
                  "job_id": job_id
                }

            Return code should be **202**
                with data ``{"message": "Accepted"}``.

        """

    job_id = api.import_cluster(ceph_nodes)["job_id"]
    """@pylatest api/ceph.cluster_import
        .. test_step:: 3

            Wait till job is finished.

        .. test_result:: 3

            Job is succesfully finished.

        """

    api.wait_for_job_status(job_id)
    """@pylatest api/ceph.cluster_import
        .. test_step:: 4

            Check if cluster import status.

        .. test_result:: 4

            Cluster is properly imported and can be found in cluster list.

        """

    integration_id = api.get_job_attribute(
        job_id=job_id,
        attribute="TendrlContext.integration_id",
        section="parameters")

    LOGGER.debug("integration_id: %s" % integration_id)
    try:
        cl_list_id = [
            x for x in api.get_cluster_list()
            if x.get("integration_id", "") == integration_id
        ]
        pytest.check(
            "There should be only one integration_id '{}'".format(
                integration_id),
            len(cl_list_id) == 1)
        pytest.check(
            "Job list integration_id '{}' should be present in cluster list.".
            format(integration_id),
            integration_id in cl_list_id,
            issue="https://github.com/Tendrl/api/issues/154")
    except JSONDecodeError:
        pytest.check(
            False,
            "Job list integration_id '{}' should be present in cluster list.".
            format(integration_id),
            issue="https://github.com/Tendrl/api/issues/166")