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.

  1. Create a StatefulSet with VolumeClaimTemplate and Longhorn.
  2. Wait for pods to run.

Then create backup using following steps for each pod:

  1. Create a snapshot
  2. Write some data into it
  3. Create another snapshot backup_snapshot
  4. Create a third snapshot
  5. Backup the snapshot backup_snapshot
  6. 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.

  1. Create a StatefulSet using dynamic provisioned Longhorn volume.
  2. Wait for pods to become running
  3. 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.

  1. Create a StatefulSet with VolumeClaimTemplate and Longhorn.
  2. Wait for pods to run.
  3. Write some data to one of the pod.
  4. Delete that pod.
  5. Wait for the StatefulSet to recreate the pod
  6. 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.

  1. Create a StatefulSet with VolumeClaimTemplate and Longhorn.
  2. Wait for pods to run.
  3. Create a backup for each pod.
  4. Delete the StatefulSet, including the Longhorn volumes.
  5. Create volumes and PV/PVC using previous backups from each Pod.
    1. PVs will be created using the previous names.
    2. PVCs will be created using previous name + "-2" due to statefulset has a naming policy for what should be PVC name for them.
  6. Create a new StatefulSet using the previous name + "-2"
  7. 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.

  1. Create a StatefulSet with VolumeClaimTemplate and Longhorn.
  2. Wait for pods to run.
  3. Verify the properties of volumes.
  4. Scale the StatefulSet to 3 replicas
  5. Wait for the new pod to become ready.
  6. Verify the new volume properties.