Module tests.test_cloning
def clone_pod(request)
-
def clone_pvc(request)
-
def test_cloning_basic(client, core_api, pvc, pod, clone_pvc, clone_pod, storage_class_name='longhorn')
-
- Create a PVC:
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: source-pvc
spec:
storageClassName: longhorn
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
- Specify the
source-pvc
in a pod yaml and start the pod
- Wait for the pod to be running, write some data to the mount
path of the volume
- Clone a volume by creating the PVC:
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cloned-pvc
spec:
storageClassName: longhorn
dataSource:
name: source-pvc
kind: PersistentVolumeClaim
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
- Wait for the
CloneStatus.State
in cloned-pvc
to be completed
- Clone volume should get detached after cloning completion, wait for it.
- Specify the
cloned-pvc
in a cloned pod yaml and deploy the cloned pod
- In 3-min retry loop, wait for the cloned pod to be running
- Verify the data in
cloned-pvc
is the same as in source-pvc
- In 2-min retry loop, verify the volume of the
clone-pvc
eventually
becomes healthy
def test_cloning_interrupted(client, core_api, pvc, pod, clone_pvc, clone_pod)
-
- Create a PVC:
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: source-pvc
spec:
storageClassName: longhorn
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
- Specify the
source-pvc
in a pod yaml and start the pod
- Wait for the pod to be running, write 500MB of data to the mount
path of the volume
- Clone a volume by creating the PVC:
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cloned-pvc
spec:
storageClassName: longhorn
dataSource:
name: source-pvc
kind: PersistentVolumeClaim
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
- Wait for the
CloneStatus.State
in cloned-pvc
to be initiated
- Kill all replicas process of the
source-pvc
- Wait for the
CloneStatus.State
in cloned-pvc
to be failed
- Clean up
clone-pvc
- Redeploy
cloned-pvc
and clone pod
- In 3-min retry loop, verify cloned pod become running
cloned-pvc
has the same data as source-pvc
- In 2-min retry loop, verify the volume of the
clone-pvc
eventually becomes healthy.
def test_cloning_with_backing_image(client, core_api, pvc, pod, clone_pvc, clone_pod, storage_class)
-
- Deploy a storage class that has backing image parameter
yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: longhorn-bi-parrot
provisioner: driver.longhorn.io
allowVolumeExpansion: true
parameters:
numberOfReplicas: "3"
staleReplicaTimeout: "2880" # 48 hours in minutes
backingImage: "bi-parrot"
backingImageDataSourceType: "download"
backing_image_data_source_parameters = (
'{"url": "https://backing-image-example.s3-region.amazonaws.com/'
'test-backing-image"}'
)
- Repeat the
test_cloning_without_backing_image()
test with
source-pvc
and cloned-pvc
use longhorn-bi-parrot
instead of
longhorn
storageclass
- Clean up the test
def test_cloning_with_detached_source_volume(client, core_api, pvc, clone_pvc)
-
- Create a PVC:
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: source-pvc
spec:
storageClassName: longhorn
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
- Wait for volume to be created and attach it to a node.
- Write some data to the mount path of the volume
- Detach the volume and wait for the volume to be in detached state.
- Clone a volume by creating the PVC:
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cloned-pvc
spec:
storageClassName: longhorn
dataSource:
name: source-pvc
kind: PersistentVolumeClaim
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
- Wait for the
CloneStatus.State
in cloned-pvc
to be completed
- Wait for
source-pvc
to be detached
- Attach the cloned volume to a node
- Verify the data in
cloned-pvc
is the same as in source-pvc
.
- In 2-min retry loop, verify the volume of the
clone-pvc
eventually becomes healthy.
- Verify snapshot created in
source-pvc
volume because of the clone