From 2158989d6f7d82c07ee2bbc898d6ad98d44dd205 Mon Sep 17 00:00:00 2001 From: Kenichi Omichi Date: Tue, 24 Mar 2020 22:54:07 +0000 Subject: [PATCH] Move WaitForPersistentVolumeDeleted() to e2epv The function is for persistent volumes and it doesn't have any reason why it stays in core test framework. So this moves the function into e2epv package for reducing e2e/framework/util.go code. --- test/e2e/framework/pv/pv.go | 18 ++++++++++++++++++ test/e2e/framework/util.go | 18 ------------------ test/e2e/storage/csi_mock_volume.go | 2 +- .../nfs_persistent_volume-disruptive.go | 2 +- test/e2e/storage/pv_protection.go | 4 ++-- test/e2e/storage/regional_pd.go | 2 +- test/e2e/storage/testsuites/base.go | 2 +- test/e2e/storage/testsuites/provisioning.go | 2 +- test/e2e/storage/volume_metrics.go | 2 +- test/e2e/storage/volume_provisioning.go | 4 ++-- test/e2e/storage/vsphere/pv_reclaimpolicy.go | 4 ++-- test/e2e/storage/vsphere/pvc_label_selector.go | 2 +- test/e2e/upgrades/storage/volume_mode.go | 2 +- 13 files changed, 32 insertions(+), 32 deletions(-) diff --git a/test/e2e/framework/pv/pv.go b/test/e2e/framework/pv/pv.go index a6ff32f5989..300abe3a4e0 100644 --- a/test/e2e/framework/pv/pv.go +++ b/test/e2e/framework/pv/pv.go @@ -821,3 +821,21 @@ func SkipIfNoDefaultStorageClass(c clientset.Interface) { e2eskipper.Skipf("error finding default storageClass : %v", err) } } + +// WaitForPersistentVolumeDeleted waits for a PersistentVolume to get deleted or until timeout occurs, whichever comes first. +func WaitForPersistentVolumeDeleted(c clientset.Interface, pvName string, Poll, timeout time.Duration) error { + framework.Logf("Waiting up to %v for PersistentVolume %s to get deleted", timeout, pvName) + for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) { + pv, err := c.CoreV1().PersistentVolumes().Get(context.TODO(), pvName, metav1.GetOptions{}) + if err == nil { + framework.Logf("PersistentVolume %s found and phase=%s (%v)", pvName, pv.Status.Phase, time.Since(start)) + continue + } + if apierrors.IsNotFound(err) { + framework.Logf("PersistentVolume %s was removed", pvName) + return nil + } + framework.Logf("Get persistent volume %s in failed, ignoring for %v: %v", pvName, Poll, err) + } + return fmt.Errorf("PersistentVolume %s still exists within %v", pvName, timeout) +} diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 52b3840f48e..84538da4f3b 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -304,24 +304,6 @@ func WaitForDefaultServiceAccountInNamespace(c clientset.Interface, namespace st return waitForServiceAccountInNamespace(c, namespace, "default", ServiceAccountProvisionTimeout) } -// WaitForPersistentVolumeDeleted waits for a PersistentVolume to get deleted or until timeout occurs, whichever comes first. -func WaitForPersistentVolumeDeleted(c clientset.Interface, pvName string, Poll, timeout time.Duration) error { - Logf("Waiting up to %v for PersistentVolume %s to get deleted", timeout, pvName) - for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) { - pv, err := c.CoreV1().PersistentVolumes().Get(context.TODO(), pvName, metav1.GetOptions{}) - if err == nil { - Logf("PersistentVolume %s found and phase=%s (%v)", pvName, pv.Status.Phase, time.Since(start)) - continue - } - if apierrors.IsNotFound(err) { - Logf("PersistentVolume %s was removed", pvName) - return nil - } - Logf("Get persistent volume %s in failed, ignoring for %v: %v", pvName, Poll, err) - } - return fmt.Errorf("PersistentVolume %s still exists within %v", pvName, timeout) -} - // findAvailableNamespaceName random namespace name starting with baseName. func findAvailableNamespaceName(baseName string, c clientset.Interface) (string, error) { var name string diff --git a/test/e2e/storage/csi_mock_volume.go b/test/e2e/storage/csi_mock_volume.go index 397201e8d50..1ed09acd6a3 100644 --- a/test/e2e/storage/csi_mock_volume.go +++ b/test/e2e/storage/csi_mock_volume.go @@ -188,7 +188,7 @@ var _ = utils.SIGDescribe("CSI mock volume", func() { claim, err := cs.CoreV1().PersistentVolumeClaims(claim.Namespace).Get(context.TODO(), claim.Name, metav1.GetOptions{}) if err == nil { cs.CoreV1().PersistentVolumeClaims(claim.Namespace).Delete(context.TODO(), claim.Name, metav1.DeleteOptions{}) - framework.WaitForPersistentVolumeDeleted(cs, claim.Spec.VolumeName, framework.Poll, 2*time.Minute) + e2epv.WaitForPersistentVolumeDeleted(cs, claim.Spec.VolumeName, framework.Poll, 2*time.Minute) } } diff --git a/test/e2e/storage/nfs_persistent_volume-disruptive.go b/test/e2e/storage/nfs_persistent_volume-disruptive.go index f95f081a26e..7083f2f3ccc 100644 --- a/test/e2e/storage/nfs_persistent_volume-disruptive.go +++ b/test/e2e/storage/nfs_persistent_volume-disruptive.go @@ -332,6 +332,6 @@ func tearDownTestCase(c clientset.Interface, f *framework.Framework, ns string, e2epv.DeletePersistentVolume(c, pv.Name) return } - err := framework.WaitForPersistentVolumeDeleted(c, pv.Name, 5*time.Second, 5*time.Minute) + err := e2epv.WaitForPersistentVolumeDeleted(c, pv.Name, 5*time.Second, 5*time.Minute) framework.ExpectNoError(err, "Persistent Volume %v not deleted by dynamic provisioner", pv.Name) } diff --git a/test/e2e/storage/pv_protection.go b/test/e2e/storage/pv_protection.go index 05f67513b72..f3826133127 100644 --- a/test/e2e/storage/pv_protection.go +++ b/test/e2e/storage/pv_protection.go @@ -100,7 +100,7 @@ var _ = utils.SIGDescribe("PV Protection", func() { ginkgo.By("Deleting the PV") err = client.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.Name, *metav1.NewDeleteOptions(0)) framework.ExpectNoError(err, "Error deleting PV") - framework.WaitForPersistentVolumeDeleted(client, pv.Name, framework.Poll, e2epv.PVDeletingTimeout) + e2epv.WaitForPersistentVolumeDeleted(client, pv.Name, framework.Poll, e2epv.PVDeletingTimeout) }) ginkgo.It("Verify that PV bound to a PVC is not removed immediately", func() { @@ -127,6 +127,6 @@ var _ = utils.SIGDescribe("PV Protection", func() { framework.ExpectNoError(err, "Error deleting PVC") ginkgo.By("Checking that the PV is automatically removed from the system because it's no longer bound to a PVC") - framework.WaitForPersistentVolumeDeleted(client, pv.Name, framework.Poll, e2epv.PVDeletingTimeout) + e2epv.WaitForPersistentVolumeDeleted(client, pv.Name, framework.Poll, e2epv.PVDeletingTimeout) }) }) diff --git a/test/e2e/storage/regional_pd.go b/test/e2e/storage/regional_pd.go index b6556502b1d..7763afaf6b1 100644 --- a/test/e2e/storage/regional_pd.go +++ b/test/e2e/storage/regional_pd.go @@ -210,7 +210,7 @@ func testZonalFailover(c clientset.Interface, ns string) { framework.ExpectNoError(c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(context.TODO(), pvc.Name, metav1.DeleteOptions{}), "Error deleting claim %s.", pvc.Name) if pvc.Spec.VolumeName != "" { - err = framework.WaitForPersistentVolumeDeleted(c, pvc.Spec.VolumeName, framework.Poll, pvDeletionTimeout) + err = e2epv.WaitForPersistentVolumeDeleted(c, pvc.Spec.VolumeName, framework.Poll, pvDeletionTimeout) if err != nil { framework.Logf("WARNING: PV %s is not yet deleted, and subsequent tests may be affected.", pvc.Spec.VolumeName) } diff --git a/test/e2e/storage/testsuites/base.go b/test/e2e/storage/testsuites/base.go index 31126a312e2..39bf405018e 100644 --- a/test/e2e/storage/testsuites/base.go +++ b/test/e2e/storage/testsuites/base.go @@ -292,7 +292,7 @@ func (r *VolumeResource) CleanupResource() error { cleanUpErrs = append(cleanUpErrs, errors.Wrapf(err, "Failed to delete PVC %v", r.Pvc.Name)) } if r.Pv != nil { - err = framework.WaitForPersistentVolumeDeleted(f.ClientSet, r.Pv.Name, 5*time.Second, 5*time.Minute) + err = e2epv.WaitForPersistentVolumeDeleted(f.ClientSet, r.Pv.Name, 5*time.Second, 5*time.Minute) if err != nil { cleanUpErrs = append(cleanUpErrs, errors.Wrapf(err, "Persistent Volume %v not deleted by dynamic provisioner", r.Pv.Name)) diff --git a/test/e2e/storage/testsuites/provisioning.go b/test/e2e/storage/testsuites/provisioning.go index eb6afe7b455..3828d1c2a97 100644 --- a/test/e2e/storage/testsuites/provisioning.go +++ b/test/e2e/storage/testsuites/provisioning.go @@ -369,7 +369,7 @@ func (t StorageClassTest) TestDynamicProvisioning() *v1.PersistentVolume { // hiccups. if pv != nil && pv.Spec.PersistentVolumeReclaimPolicy == v1.PersistentVolumeReclaimDelete { ginkgo.By(fmt.Sprintf("deleting the claim's PV %q", pv.Name)) - framework.ExpectNoError(framework.WaitForPersistentVolumeDeleted(client, pv.Name, 5*time.Second, 20*time.Minute)) + framework.ExpectNoError(e2epv.WaitForPersistentVolumeDeleted(client, pv.Name, 5*time.Second, 20*time.Minute)) } return pv diff --git a/test/e2e/storage/volume_metrics.go b/test/e2e/storage/volume_metrics.go index fa877ca8c57..9b7b320afb6 100644 --- a/test/e2e/storage/volume_metrics.go +++ b/test/e2e/storage/volume_metrics.go @@ -86,7 +86,7 @@ var _ = utils.SIGDescribe("[Serial] Volume metrics", func() { } else { e2epv.DeletePersistentVolumeClaim(c, newPvc.Name, newPvc.Namespace) if newPvc.Spec.VolumeName != "" { - err = framework.WaitForPersistentVolumeDeleted(c, newPvc.Spec.VolumeName, 5*time.Second, 5*time.Minute) + err = e2epv.WaitForPersistentVolumeDeleted(c, newPvc.Spec.VolumeName, 5*time.Second, 5*time.Minute) framework.ExpectNoError(err, "Persistent Volume %v not deleted by dynamic provisioner", newPvc.Spec.VolumeName) } } diff --git a/test/e2e/storage/volume_provisioning.go b/test/e2e/storage/volume_provisioning.go index 2e863677117..680b9841db1 100644 --- a/test/e2e/storage/volume_provisioning.go +++ b/test/e2e/storage/volume_provisioning.go @@ -415,7 +415,7 @@ var _ = utils.SIGDescribe("Dynamic Provisioning", func() { ginkgo.By(fmt.Sprintf("deleting the PV %q", pv.Name)) framework.ExpectNoError(e2epv.DeletePersistentVolume(c, pv.Name), "Failed to delete PV ", pv.Name) - framework.ExpectNoError(framework.WaitForPersistentVolumeDeleted(c, pv.Name, 1*time.Second, 30*time.Second)) + framework.ExpectNoError(e2epv.WaitForPersistentVolumeDeleted(c, pv.Name, 1*time.Second, 30*time.Second)) }) ginkgo.It("should not provision a volume in an unmanaged GCE zone.", func() { @@ -587,7 +587,7 @@ var _ = utils.SIGDescribe("Dynamic Provisioning", func() { framework.ExpectNoError(err) ginkgo.By("waiting for the PV to get deleted") - err = framework.WaitForPersistentVolumeDeleted(c, pv.Name, 5*time.Second, e2epv.PVDeletingTimeout) + err = e2epv.WaitForPersistentVolumeDeleted(c, pv.Name, 5*time.Second, e2epv.PVDeletingTimeout) framework.ExpectNoError(err) }) }) diff --git a/test/e2e/storage/vsphere/pv_reclaimpolicy.go b/test/e2e/storage/vsphere/pv_reclaimpolicy.go index c81e96f8f75..eb9929fb3ed 100644 --- a/test/e2e/storage/vsphere/pv_reclaimpolicy.go +++ b/test/e2e/storage/vsphere/pv_reclaimpolicy.go @@ -85,7 +85,7 @@ var _ = utils.SIGDescribe("PersistentVolumes [Feature:vsphere][Feature:ReclaimPo pvc = nil ginkgo.By("verify pv is deleted") - err = framework.WaitForPersistentVolumeDeleted(c, pv.Name, 3*time.Second, 300*time.Second) + err = e2epv.WaitForPersistentVolumeDeleted(c, pv.Name, 3*time.Second, 300*time.Second) framework.ExpectNoError(err) pv = nil @@ -143,7 +143,7 @@ var _ = utils.SIGDescribe("PersistentVolumes [Feature:vsphere][Feature:ReclaimPo framework.ExpectNoError(err) ginkgo.By("Verify PV should be deleted automatically") - framework.ExpectNoError(framework.WaitForPersistentVolumeDeleted(c, pv.Name, 1*time.Second, 30*time.Second)) + framework.ExpectNoError(e2epv.WaitForPersistentVolumeDeleted(c, pv.Name, 1*time.Second, 30*time.Second)) pv = nil volumePath = "" }) diff --git a/test/e2e/storage/vsphere/pvc_label_selector.go b/test/e2e/storage/vsphere/pvc_label_selector.go index ec5c4698d01..1fdbdd5c29b 100644 --- a/test/e2e/storage/vsphere/pvc_label_selector.go +++ b/test/e2e/storage/vsphere/pvc_label_selector.go @@ -97,7 +97,7 @@ var _ = utils.SIGDescribe("PersistentVolumes [Feature:vsphere][Feature:LabelSele framework.ExpectNoError(e2epv.DeletePersistentVolumeClaim(c, pvcSsd.Name, ns), "Failed to delete PVC ", pvcSsd.Name) ginkgo.By("verify pvSsd is deleted") - err = framework.WaitForPersistentVolumeDeleted(c, pvSsd.Name, 3*time.Second, 300*time.Second) + err = e2epv.WaitForPersistentVolumeDeleted(c, pvSsd.Name, 3*time.Second, 300*time.Second) framework.ExpectNoError(err) volumePath = "" diff --git a/test/e2e/upgrades/storage/volume_mode.go b/test/e2e/upgrades/storage/volume_mode.go index c961f03f20e..1a89c4842cf 100644 --- a/test/e2e/upgrades/storage/volume_mode.go +++ b/test/e2e/upgrades/storage/volume_mode.go @@ -129,5 +129,5 @@ func (t *VolumeModeDowngradeTest) Teardown(f *framework.Framework) { framework.ExpectNoError(f.ClientSet.CoreV1().PersistentVolumeClaims(t.pvc.Namespace).Delete(context.TODO(), t.pvc.Name, metav1.DeleteOptions{})) ginkgo.By("Waiting for the PV to be deleted") - framework.ExpectNoError(framework.WaitForPersistentVolumeDeleted(f.ClientSet, t.pv.Name, 5*time.Second, 20*time.Minute)) + framework.ExpectNoError(e2epv.WaitForPersistentVolumeDeleted(f.ClientSet, t.pv.Name, 5*time.Second, 20*time.Minute)) }