def create_pvc_and_verify_pvc_exists(
    sc_name, cbp_name, desired_status=constants.STATUS_BOUND, wait=True
):
    """
    Create pvc, verify pvc is bound in state and
    pvc exists on ceph side
    """

    pvc_data = templating.load_yaml_to_dict(constants.CSI_PVC_YAML)
    pvc_data['metadata']['name'] = helpers.create_unique_resource_name(
        'test', 'pvc'
    )
    pvc_data['spec']['storageClassName'] = sc_name
    pvc_data['spec']['resources']['requests']['storage'] = "10Gi"
    pvc_obj = pvc.PVC(**pvc_data)
    pvc_obj.create()
    if wait:
        assert pvc_obj.ocp.wait_for_resource(
            condition=desired_status, resource_name=pvc_obj.name
        ), f"{pvc_obj.kind} {pvc_obj.name} failed to reach"
        f"status {desired_status}"
    pvc_obj.reload()

    # ToDo: Add validation to check pv exists on bcaekend
    # Commenting the below code: https://bugzilla.redhat.com/show_bug.cgi?id=1723656
    # Validate pv is created on ceph
    # logger.info(f"Verifying pv exists on backend")
    # ct_pod = pod.get_ceph_tools_pod()
    # pv_list = ct_pod.exec_ceph_cmd(
    #     ceph_cmd=f"rbd ls -p {cbp_name}", format='json'
    # )
    # _rc = pvc_obj.backed_pv in pv_list
    # assert _rc, f"pv doesn't exist on backend"
    # logger.info(f"pv {pvc_obj.backed_pv} exists on backend")
    return pvc_obj
示例#2
0
def create_pvc(sc_name,
               pvc_name=None,
               namespace=defaults.ROOK_CLUSTER_NAMESPACE,
               size=None,
               wait=True,
               access_mode=constants.ACCESS_MODE_RWO):
    """
    Create a PVC

    Args:
        sc_name (str): The name of the storage class for the PVC to be
            associated with
        pvc_name (str): The name of the PVC to create
        namespace (str): The namespace for the PVC creation
        size(str): Size of pvc to create
        wait (bool): True for wait for the PVC operation to complete, False otherwise
        access_mode (str): The access mode to be used for the PVC

    Returns:
        PVC: PVC instance
    """
    pvc_data = templating.load_yaml_to_dict(constants.CSI_PVC_YAML)
    pvc_data['metadata']['name'] = (pvc_name if pvc_name else
                                    create_unique_resource_name('test', 'pvc'))
    pvc_data['metadata']['namespace'] = namespace
    pvc_data['spec']['accessModes'] = [access_mode]
    pvc_data['spec']['storageClassName'] = sc_name
    if size:
        pvc_data['spec']['resources']['requests']['storage'] = size
    ocs_obj = pvc.PVC(**pvc_data)
    created_pvc = ocs_obj.create(do_reload=wait)
    assert created_pvc, f"Failed to create resource {pvc_name}"
    if wait:
        assert wait_for_resource_state(ocs_obj, constants.STATUS_BOUND)
        ocs_obj.reload()

    return ocs_obj
示例#3
0
文件: helpers.py 项目: gklein/ocs-ci
def create_pvc(sc_name,
               pvc_name=None,
               namespace=defaults.ROOK_CLUSTER_NAMESPACE,
               size=None,
               do_reload=True,
               access_mode=constants.ACCESS_MODE_RWO,
               volume_mode=None):
    """
    Create a PVC

    Args:
        sc_name (str): The name of the storage class for the PVC to be
            associated with
        pvc_name (str): The name of the PVC to create
        namespace (str): The namespace for the PVC creation
        size (str): Size of pvc to create
        do_reload (bool): True for wait for reloading PVC after its creation, False otherwise
        access_mode (str): The access mode to be used for the PVC
        volume_mode (str): Volume mode for rbd RWX pvc i.e. 'Block'

    Returns:
        PVC: PVC instance
    """
    pvc_data = templating.load_yaml(constants.CSI_PVC_YAML)
    pvc_data['metadata']['name'] = (pvc_name if pvc_name else
                                    create_unique_resource_name('test', 'pvc'))
    pvc_data['metadata']['namespace'] = namespace
    pvc_data['spec']['accessModes'] = [access_mode]
    pvc_data['spec']['storageClassName'] = sc_name
    if size:
        pvc_data['spec']['resources']['requests']['storage'] = size
    if volume_mode:
        pvc_data['spec']['volumeMode'] = volume_mode
    ocs_obj = pvc.PVC(**pvc_data)
    created_pvc = ocs_obj.create(do_reload=do_reload)
    assert created_pvc, f"Failed to create resource {pvc_name}"
    return ocs_obj