Module tests.test_kubernetes
Functions
def delete_and_wait_statefulset_only(api, ss)
def provision_and_wait_pv(client, core_api, storage_class, pvc)
-
Provision a new Longhorn Volume via Storage Class and wait for the Volume and its associated resources to be created.
This method also waits for the Kubernetes Status to be properly set on the Volume.
:param client: An instance of the Longhorn client. :param core_api: An instance of the Kubernetes CoreV1API client. :param storage_class: A dict representing a Storage Class spec. :param pvc: A dict representing a Persistent Volume Claim spec. :return: The Persistent Volume that was provisioned.
def test_backup_kubernetes_status(set_random_backupstore, client, core_api, pod, storage_class)
-
Test that Backups have KubernetesStatus stored properly when there is an associated PersistentVolumeClaim and Pod.
- Setup a random backupstore
- Set settings Longhorn Static StorageClass to
longhorn-test
- Create a volume and PV/PVC. Verify the StorageClass of PVC
- Create a Pod using the PVC.
- Check volume's Kubernetes status to reflect PV/PVC/Pod correctly.
- Create a backup for the volume.
- Verify the labels of created backup reflect PV/PVC/Pod status.
- Restore the backup to a volume. Wait for restoration to complete.
- Check the volume's Kubernetes Status
- Make sure the
lastPodRefAt
andlastPVCRefAt
is snapshot created time
- Make sure the
- Delete the backup and restored volume.
- Delete PV/PVC/Pod.
- Verify volume's Kubernetes Status updated to reflect history data.
- Attach the volume and create another backup. Verify the labels
- Verify the volume's Kubernetes status.
- Restore the previous backup to a new volume. Wait for restoration.
- Verify the restored volume's Kubernetes status.
- Make sure
lastPodRefAt
andlastPVCRefAt
matched volume on step 12
- Make sure
def test_csi_umount_when_longhorn_block_device_is_disconnected_unexpectedly(client, core_api, statefulset, storage_class)
-
Test CSI umount when Longhorn block device is disconnected unexpectedly
GitHub ticket: https://github.com/longhorn/longhorn/issues/3778
- Deloy a statefulset that has volumeClaimTemplates with volumeMode: Block
- Crash the engine process of the volume to simulate Longhorn block device is disconnected unexpectedly
- Delete the workload pod
- Verify that the pod is able to terminated and a new pod is able start
def test_delete_provisioned_pvc(client, core_api, storage_class, pvc)
-
Test that deleting the Persistent Volume Claim for a dynamically provisioned Volume properly deletes the Volume and the associated Kubernetes resources.
- Create a Storage Class to test with.
- Create a Persistent Volume Claim that requests a Volume from that Storage Class.
- Wait for the Volume to be provisioned and for the Kubernetes Status to be updated correctly.
- Attempt to delete the Persistent Volume Claim.
- Verify that the associated Volume and its resources have been deleted.
def test_delete_with_provisioned_pv(client, core_api, storage_class, pvc)
-
Test that deleting a Volume with dynamically provisioned Persistent Volume and Persistent Volume Claim resources successfully deletes the Volume and cleans up those resources.
- Create a Storage Class to test with.
- Create a Persistent Volume Claim that requests a Volume from that Storage Class.
- Wait for the Volume to be provisioned and for the Kubernetes Status to be updated correctly.
- Attempt to delete the Volume.
- Verify that the Volume and its associated resources have been deleted.
def test_delete_with_static_pv(client, core_api, volume_name)
-
Test that deleting a Volume with related static Persistent Volume and Persistent Volume Claim resources successfully deletes the Volume and cleans up those resources.
- Create a Volume in Longhorn.
- Create a static Persistent Volume and Persistent Volume Claim for the Volume through Longhorn.
- Wait for the Kubernetes Status to indicate the existence of these resources.
- Attempt deletion of the Volume.
- Verify that the Volume and its associated resources have been deleted.
def test_kubernetes_status(client, core_api, storage_class, statefulset, csi_pv, pvc, pod)
-
Test Volume feature: Kubernetes Status
- Create StorageClass with
reclaimPolicy = Retain
- Create a statefulset
kubernetes-status-test
with the StorageClass- The statefulset has scale of 2.
- Get the volume name from the SECOND pod of the StateufulSet pod and
create an
extra_pod
with the same volume on the same node - Check the volumes that used by the StatefulSet
- The volume used by the FIRST StatefulSet pod will have one workload
- The volume used by the SECOND StatefulSet pod will have two workloads
- Validate related status, e.g. pv/pod name/state, workload name/type
- Check the volumes again
- PV/PVC should still be bound
- The volume used by the FIRST pod should have history data
- The volume used by the SECOND and extra pod should have current data point to the extra pod
- Delete the extra pod
- Now all the volume's should only have history data(
lastPodRefAt
set)
- Now all the volume's should only have history data(
- Delete the PVC
- PVC should be updated with status
Released
and become history data
- PVC should be updated with status
- Delete PV
- All the Kubernetes status information should be cleaned up.
- Reuse the two Longhorn volumes to create new pods
- Since the
reclaimPolicy == Retain
, volume won't be deleted by Longhorn - Check the Kubernetes status now updated, with pod info but empty workload
- Default Longhorn Static StorageClass will remove the PV with PVC, but leave Longhorn volume
- Since the
- Create StorageClass with
def test_pv_creation(client, core_api)
-
Test creating PV using Longhorn API
- Create volume
- Create PV for the volume
- Try to create another PV for the same volume. It should fail.
- Check Kubernetes Status for the volume since PV is created.
def test_pvc_creation_with_default_sc_set(client, core_api, storage_class, pod)
-
Test creating PVC with default StorageClass set
The target is to make sure the newly create PV/PVC won't use default StorageClass, and if there is no default StorageClass, PV/PVC can still be created.
- Create a StorageClass and set it to be the default StorageClass
- Update static StorageClass to
longhorn-test
- Create volume then PV/PVC.
- Make sure the newly created PV/PVC using StorageClass
longhorn-test
- Create pod with PVC.
- Verify volume's Kubernetes Status
- Remove PVC and Pod.
- Verify volume's Kubernetes Status only contains current PV and history
- Wait for volume to detach (since pod is deleted)
- Reuse the volume on a new pod. Wait for the pod to start
- Verify volume's Kubernetes Status reflect the new pod.
- Delete PV/PVC/Pod.
- Verify volume's Kubernetes Status only contains history
- Delete the default StorageClass.
- Create PV/PVC for the volume.
- Make sure the PV's StorageClass is static StorageClass