Fix storage e2e snapshot test deletion order

This commit is contained in:
Jiawei Wang 2021-02-17 11:42:02 -08:00
parent 2a05c78600
commit c4dfee6262
3 changed files with 23 additions and 5 deletions

View File

@ -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()))

View File

@ -269,8 +269,17 @@ 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:

View File

@ -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
}