Module tests.test_statefulset
Functions
def create_and_test_backups(api, cli, pod_info)
-
Create backups for all Pods in a StatefulSet and tests that all the backups have the correct attributes.
Args
api
- An instance of CoreV1Api.
cli
- A Longhorn client instance.
pod_info
- A List of Pods with names and volume information. This List can be generated using the get_statefulset_pod_info function located in common.py.
def test_statefulset_backup(set_random_backupstore, client, core_api, storage_class, statefulset)
-
Test that backups on StatefulSet volumes work properly.
- Create a StatefulSet with VolumeClaimTemplate and Longhorn.
- Wait for pods to run.
Then create backup using following steps for each pod:
- Create a snapshot
- Write some data into it
- Create another snapshot
backup_snapshot
- Create a third snapshot
- Backup the snapshot
backup_snapshot
- Wait for backup to show up. 1 Verify the backup information
def test_statefulset_mount(client, core_api, storage_class, statefulset)
-
Tests that volumes provisioned for a StatefulSet can be properly created, mounted, unmounted, and deleted on the Kubernetes cluster.
- Create a StatefulSet using dynamic provisioned Longhorn volume.
- Wait for pods to become running
- Check volume properties are consistent with the StorageClass
def test_statefulset_pod_deletion(core_api, storage_class, statefulset)
-
Test that a StatefulSet can spin up a new Pod with the same data after a previous Pod has been deleted.
- Create a StatefulSet with VolumeClaimTemplate and Longhorn.
- Wait for pods to run.
- Write some data to one of the pod.
- Delete that pod.
- Wait for the StatefulSet to recreate the pod
- Verify the data in the pod.
def test_statefulset_recurring_backup(set_random_backupstore, client, core_api, storage_class, statefulset)
-
Scenario : test recurring backups on StatefulSets
Given 1 default backup recurring jobs created.
When create a statefulset. And write data to every statefulset pod. And wait for 5 minutes.
Then 2 snapshots created for every statefulset pod.
def test_statefulset_restore(set_random_backupstore, client, core_api, storage_class, statefulset)
-
Test that data can be restored into volumes usable by a StatefulSet.
- Create a StatefulSet with VolumeClaimTemplate and Longhorn.
- Wait for pods to run.
- Create a backup for each pod.
- Delete the StatefulSet, including the Longhorn volumes.
- Create volumes and PV/PVC using previous backups from each Pod.
- PVs will be created using the previous names.
- PVCs will be created using previous name + "-2" due to statefulset has a naming policy for what should be PVC name for them.
- Create a new StatefulSet using the previous name + "-2"
- Wait for pods to be up. . Verify the pods contain the previous backed up data
def test_statefulset_scaling(client, core_api, storage_class, statefulset)
-
Test that scaling up a StatefulSet successfully provisions new volumes.
- Create a StatefulSet with VolumeClaimTemplate and Longhorn.
- Wait for pods to run.
- Verify the properties of volumes.
- Scale the StatefulSet to 3 replicas
- Wait for the new pod to become ready.
- Verify the new volume properties.