Exemplo n.º 1
0
def check_vs_detail(vs_name, pvc_name, body_params, reason, created_objects):
    """
    checks volume snapshot vs_name exits , 
    checks volume snapshot content for vs_name is created
    check snapshot is created on spectrum scale
    """
    api_instance = client.CustomObjectsApi()
    try:
        api_response = api_instance.get_namespaced_custom_object(
            group="snapshot.storage.k8s.io",
            version="v1",
            plural="volumesnapshots",
            name=vs_name,
            namespace=namespace_value
        )
        LOGGER.debug(api_response)
        LOGGER.info(f"Volume Snapshot Check : volume snapshot {vs_name} has been created")
    except ApiException:
        LOGGER.info(f"Volume Snapshot Check : volume snapshot {vs_name} does not exists")
        clean_with_created_objects(created_objects)
        assert False

    if check_snapshot_status(vs_name):
        LOGGER.info("volume snapshot status ReadyToUse is true")
    else:
        LOGGER.error("volume snapshot status ReadyToUse is not true")
        if reason is not None:
            LOGGER.info("As failure reason is provided , passing the test")
            return
        clean_with_created_objects(created_objects)
        assert False
    LOGGER.debug(api_response)

    uid_name = api_response["metadata"]["uid"]
    snapcontent_name = "snapcontent-" + uid_name
    snapshot_name = "snapshot-" + uid_name
    time.sleep(2)

    if not(check_vs_content(snapcontent_name)):
        clean_with_created_objects(created_objects)
        assert False

    volume_name = get_pv_name(pvc_name, created_objects)

    if ff.check_snapshot(snapshot_name, volume_name):
        LOGGER.info(f"snapshot {snapshot_name} exists for {volume_name}")
    else:
        LOGGER.error(f"snapshot {snapshot_name} does not exists for {volume_name}")
        clean_with_created_objects(created_objects)
        assert False

    if body_params["deletionPolicy"] == "Retain":
        created_objects["vscontent"].append(snapcontent_name)
        created_objects["scalesnapshot"].append([snapshot_name,volume_name])
Exemplo n.º 2
0
    def test_static(self, value_sc, test_restore, value_vs_class=None, number_of_snapshots=None, restore_sc=None, restore_pvc=None):
        if value_vs_class is None:
            value_vs_class = self.value_vs_class
        if number_of_snapshots is None:
            number_of_snapshots = self.number_of_snapshots
        number_of_restore = 1

        for pvc_value in self.value_pvc:

            created_objects = get_cleanup_dict()
            LOGGER.info("-"*100)
            sc_name = d.get_random_name("sc")
            d.create_storage_class(value_sc, sc_name, created_objects)
            d.check_storage_class(sc_name)

            pvc_name = d.get_random_name("pvc")
            d.create_pvc(pvc_value, sc_name, pvc_name, created_objects)
            d.check_pvc(pvc_value, pvc_name, created_objects)

            pod_name = d.get_random_name("snap-start-pod")
            value_pod = {"mount_path": "/usr/share/nginx/html/scale", "read_only": "False"}
            d.create_pod(value_pod, pvc_name, pod_name, created_objects, self.image_name)
            d.check_pod(value_pod, pod_name, created_objects)
            d.create_file_inside_pod(value_pod, pod_name, created_objects)

            snapshot_name = d.get_random_name("snapshot")
            volume_name = snapshot.get_pv_name(pvc_name, created_objects)

            FSUID = ff.get_FSUID()
            cluster_id = self.cluster_id
            vs_content_name = d.get_random_name("vscontent")

            vs_name = d.get_random_name("vs")
            for num in range(0, number_of_snapshots):
                ff.create_snapshot(snapshot_name+"-"+str(num), volume_name, created_objects)
                if ff.check_snapshot(snapshot_name+"-"+str(num), volume_name):
                    LOGGER.info(f"snapshot {snapshot_name} exists for {volume_name}")
                else:
                    LOGGER.error(f"snapshot {snapshot_name} does not exists for {volume_name}")
                    cleanup.clean_with_created_objects(created_objects)
                    assert False

                snapshot_handle = cluster_id+';'+FSUID+';'+volume_name+';'+snapshot_name+"-"+str(num)
                body_params = {"deletionPolicy": "Retain", "snapshotHandle": snapshot_handle}
                snapshot.create_vs_content(vs_content_name+"-"+str(num), vs_name+"-"+str(num), body_params, created_objects)
                snapshot.check_vs_content(vs_content_name+"-"+str(num))

                snapshot.create_vs_from_content(vs_name+"-"+str(num), vs_content_name+"-"+str(num), created_objects)
                snapshot.check_vs_detail_for_static(vs_name+"-"+str(num), created_objects)

            if not(ff.feature_available("snapshot")):
                pvc_value["reason"] = "Min required Spectrum Scale version for snapshot support with CSI is 5.1.1-0"

            if test_restore:
                if restore_sc is not None:
                    sc_name = "restore-" + sc_name
                    d.create_storage_class(restore_sc, sc_name, created_objects)
                    d.check_storage_class(sc_name)
                if restore_pvc is not None:
                    pvc_value = restore_pvc

                for num in range(0, number_of_restore):
                    restored_pvc_name = "restored-pvc"+vs_name[2:]+"-"+str(num)
                    snap_pod_name = "snap-end-pod"+vs_name[2:]
                    d.create_pvc_from_snapshot(pvc_value, sc_name, restored_pvc_name, vs_name+"-"+str(num), created_objects)
                    val = d.check_pvc(pvc_value, restored_pvc_name, created_objects)
                    if val is True:
                        d.create_pod(value_pod, restored_pvc_name, snap_pod_name, created_objects, self.image_name)
                        d.check_pod(value_pod, snap_pod_name, created_objects)
                        d.check_file_inside_pod(value_pod, snap_pod_name, created_objects, volume_name)
                        cleanup.delete_pod(snap_pod_name, created_objects)
                        cleanup.check_pod_deleted(snap_pod_name, created_objects)
                    vol_name = cleanup.delete_pvc(restored_pvc_name, created_objects)
                    cleanup.check_pvc_deleted(restored_pvc_name, vol_name, created_objects)

            cleanup.clean_with_created_objects(created_objects)
Exemplo n.º 3
0
def check_vs_detail(vs_name, pvc_name, body_params, reason, created_objects):
    """
    checks volume snapshot vs_name exits , 
    checks volume snapshot content for vs_name is created
    check snapshot is created on spectrum scale
    """
    api_instance = client.CustomObjectsApi()
    try:
        api_response = api_instance.get_namespaced_custom_object(
            group="snapshot.storage.k8s.io",
            version="v1",
            plural="volumesnapshots",
            name=vs_name,
            namespace=namespace_value)
        LOGGER.debug(api_response)
        LOGGER.info(
            f"Volume Snapshot Check : volume snapshot {vs_name} has been created"
        )
    except ApiException:
        LOGGER.info(
            f"Volume Snapshot Check : volume snapshot {vs_name} does not exists"
        )
        clean_with_created_objects(created_objects)
        assert False

    if check_snapshot_status(vs_name):
        LOGGER.info("volume snapshot status ReadyToUse is true")
    else:
        LOGGER.error("volume snapshot status ReadyToUse is not true")
        if reason is not None:
            api_instance_events = client.CoreV1Api()
            field = "involvedObject.name=" + vs_name
            failure_reason = api_instance_events.list_namespaced_event(
                namespace=namespace_value, pretty=True, field_selector=field)
            LOGGER.debug(failure_reason)
            search_result = None
            for item in failure_reason.items:
                search_result = re.search(reason, str(item.message))
                if search_result is not None:
                    LOGGER.info(
                        f"reason {reason} matched in volumesnapshot events, passing the test"
                    )
                    return

        LOGGER.error(
            f"reason {reason} did not matched in volumesnapshot events")
        clean_with_created_objects(created_objects)
        assert False

    uid_name = api_response["metadata"]["uid"]
    snapcontent_name = "snapcontent-" + uid_name
    snapshot_name = "snapshot-" + uid_name
    time.sleep(2)

    if not (check_vs_content(snapcontent_name)):
        clean_with_created_objects(created_objects)
        assert False

    volume_name = get_pv_name(pvc_name, created_objects)

    if ff.check_snapshot(snapshot_name, volume_name):
        LOGGER.info(f"snapshot {snapshot_name} exists for {volume_name}")
    else:
        LOGGER.error(
            f"snapshot {snapshot_name} does not exists for {volume_name}")
        clean_with_created_objects(created_objects)
        assert False

    if body_params["deletionPolicy"] == "Retain":
        created_objects["vscontent"].append(snapcontent_name)
        created_objects["scalesnapshot"].append([snapshot_name, volume_name])