From c4dfee62628beee01707b2a1abf08b6a4936cb0d Mon Sep 17 00:00:00 2001 From: Jiawei Wang Date: Wed, 17 Feb 2021 11:42:02 -0800 Subject: [PATCH] Fix storage e2e snapshot test deletion order --- test/e2e/storage/csi_mock_volume.go | 2 +- test/e2e/storage/testsuites/snapshottable.go | 11 ++++++++++- test/e2e/storage/utils/snapshot.go | 15 ++++++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/test/e2e/storage/csi_mock_volume.go b/test/e2e/storage/csi_mock_volume.go index 28d1c9c09b09..73f14f6f3f35 100644 --- a/test/e2e/storage/csi_mock_volume.go +++ b/test/e2e/storage/csi_mock_volume.go @@ -1303,7 +1303,7 @@ var _ = utils.SIGDescribe("CSI mock volume", func() { framework.Logf("PVC not found. Continuing to test VolumeSnapshotContent finalizer") } if claim != nil && claim.DeletionTimestamp == nil { - framework.Failf("Expected deletion timestamp to be set on PVC %s", claim.Name) + framework.Failf("Expected deletion timestamp to be set on PVC: %v", claim) } ginkgo.By(fmt.Sprintf("Get VolumeSnapshotContent bound to VolumeSnapshot %s", snapshot.GetName())) diff --git a/test/e2e/storage/testsuites/snapshottable.go b/test/e2e/storage/testsuites/snapshottable.go index 00685621cfb3..c82a47895eda 100644 --- a/test/e2e/storage/testsuites/snapshottable.go +++ b/test/e2e/storage/testsuites/snapshottable.go @@ -269,9 +269,18 @@ func (s *snapshottableTestSuite) DefineTests(driver storageframework.TestDriver, framework.ExpectNoError(err) ginkgo.By("should delete the VolumeSnapshotContent according to its deletion policy") - err = storageutils.DeleteAndWaitSnapshot(dc, vs.GetNamespace(), vs.GetName(), framework.Poll, f.Timeouts.SnapshotDelete) + + // Delete both Snapshot and PVC at the same time because different storage systems + // have different ordering of deletion. Some may require delete PVC first before + // Snapshot deletion and some are opposite. + err = storageutils.DeleteSnapshotWithoutWaiting(dc, vs.GetNamespace(), vs.GetName()) + framework.ExpectNoError(err) + err = cs.CoreV1().PersistentVolumeClaims(restoredPVC.Namespace).Delete(context.TODO(), restoredPVC.Name, metav1.DeleteOptions{}) framework.ExpectNoError(err) + // Wait for the Snapshot to be actually deleted from API server + err = storageutils.WaitForNamespacedGVRDeletion(dc, storageutils.SnapshotGVR, vs.GetNamespace(), vs.GetNamespace(), framework.Poll, f.Timeouts.SnapshotDelete) + switch pattern.SnapshotDeletionPolicy { case storageframework.DeleteSnapshot: ginkgo.By("checking the SnapshotContent has been deleted") diff --git a/test/e2e/storage/utils/snapshot.go b/test/e2e/storage/utils/snapshot.go index a62ab06b645b..33548aa1dde1 100644 --- a/test/e2e/storage/utils/snapshot.go +++ b/test/e2e/storage/utils/snapshot.go @@ -100,12 +100,21 @@ func GetSnapshotContentFromSnapshot(dc dynamic.Interface, snapshot *unstructured } +// DeleteSnapshotWithoutWaiting deletes a VolumeSnapshot and return directly without waiting +func DeleteSnapshotWithoutWaiting(dc dynamic.Interface, ns string, snapshotName string) error { + ginkgo.By("deleting the snapshot") + err := dc.Resource(SnapshotGVR).Namespace(ns).Delete(context.TODO(), snapshotName, metav1.DeleteOptions{}) + if err != nil && !apierrors.IsNotFound(err) { + return err + } + return nil +} + // DeleteAndWaitSnapshot deletes a VolumeSnapshot and waits for it to be deleted or until timeout occurs, whichever comes first func DeleteAndWaitSnapshot(dc dynamic.Interface, ns string, snapshotName string, poll, timeout time.Duration) error { var err error - ginkgo.By("deleting the snapshot") - err = dc.Resource(SnapshotGVR).Namespace(ns).Delete(context.TODO(), snapshotName, metav1.DeleteOptions{}) - if err != nil && !apierrors.IsNotFound(err) { + err = DeleteSnapshotWithoutWaiting(dc, ns, snapshotName) + if err != nil { return err }