Skip to content

Commit f55588f

Browse files
committed
e2e_storage:stop using deprecated framework.ExpectError
Signed-off-by: liyuerich <[email protected]>
1 parent 7947052 commit f55588f

File tree

11 files changed

+78
-31
lines changed

11 files changed

+78
-31
lines changed

test/e2e/framework/expect.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,6 @@ func (f *FailureError) backtrace() {
293293
// }
294294
var ErrFailure error = FailureError{}
295295

296-
// ExpectError expects an error happens, otherwise an exception raises
297-
//
298-
// Deprecated: use gomega.Expect().To(gomega.HaveOccurred()) or (better!) check
299-
// specifically for the error that is expected with
300-
// gomega.Expect().To(gomega.MatchError(gomega.ContainSubstring()))
301-
func ExpectError(err error, explain ...interface{}) {
302-
gomega.ExpectWithOffset(1, err).To(gomega.HaveOccurred(), explain...)
303-
}
304-
305296
// ExpectNoError checks if "err" is set, and if so, fails assertion while logging the error.
306297
func ExpectNoError(err error, explain ...interface{}) {
307298
ExpectNoErrorWithOffset(1, err, explain...)

test/e2e/storage/csimock/csi_attach_volume.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/onsi/ginkgo/v2"
2525
"github.com/onsi/gomega"
26+
2627
v1 "k8s.io/api/core/v1"
2728
apierrors "k8s.io/apimachinery/pkg/api/errors"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -101,7 +102,7 @@ var _ = utils.SIGDescribe("CSI Mock volume attach", func() {
101102
}
102103
}
103104
if test.disableAttach {
104-
framework.ExpectError(err, "Unexpected VolumeAttachment found")
105+
gomega.Expect(err).To(gomega.MatchError(apierrors.IsNotFound, "Unexpected VolumeAttachment found"))
105106
}
106107
})
107108

test/e2e/storage/csimock/csi_snapshot.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"time"
2323

2424
"github.com/onsi/ginkgo/v2"
25+
"github.com/onsi/gomega"
26+
2527
"google.golang.org/grpc/codes"
2628
"google.golang.org/grpc/status"
2729
v1 "k8s.io/api/core/v1"
@@ -430,7 +432,7 @@ func deleteSnapshot(cs clientset.Interface, config *storageframework.PerTestConf
430432

431433
// check if the snapshot is deleted
432434
_, err = dc.Resource(utils.SnapshotGVR).Get(context.TODO(), snapshot.GetName(), metav1.GetOptions{})
433-
framework.ExpectError(err)
435+
gomega.Expect(err).To(gomega.MatchError(apierrors.IsNotFound, "the snapshot is not deleted"))
434436
}
435437

436438
type snapshotMetricsTestConfig struct {

test/e2e/storage/csimock/csi_volume_expansion.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
csipbv1 "github.com/container-storage-interface/spec/lib/go/csi"
2525
"github.com/onsi/ginkgo/v2"
2626
"github.com/onsi/gomega"
27+
2728
"google.golang.org/grpc/codes"
2829
"google.golang.org/grpc/status"
2930
v1 "k8s.io/api/core/v1"
@@ -151,11 +152,10 @@ var _ = utils.SIGDescribe("CSI Mock volume expansion", func() {
151152
framework.Failf("error updating pvc size %q", pvc.Name)
152153
}
153154
if test.expectFailure {
154-
err = testsuites.WaitForResizingCondition(ctx, pvc, m.cs, csiResizingConditionWait)
155-
framework.ExpectError(err, "unexpected resizing condition on PVC")
155+
gomega.Consistently(ctx, framework.GetObject(m.cs.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get, pvc.Name, metav1.GetOptions{})).WithTimeout(csiResizingConditionWait).
156+
ShouldNot(gomega.HaveField("Status.Conditions", gomega.ContainElement(gomega.HaveField("Type", gomega.Equal("PersistentVolumeClaimResizing")))), "unexpected resizing condition on PVC")
156157
return
157158
}
158-
159159
ginkgo.By("Waiting for persistent volume resize to finish")
160160
err = testsuites.WaitForControllerVolumeResize(ctx, pvc, m.cs, csiResizeWaitPeriod)
161161
framework.ExpectNoError(err, "While waiting for CSI PV resize to finish")

test/e2e/storage/persistent_volumes-local.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ var _ = utils.SIGDescribe("PersistentVolumes-local", func() {
325325
}
326326
ginkgo.By("Creating local PVC and PV")
327327
createLocalPVCsPVs(ctx, config, []*localTestVolume{testVol}, immediateMode)
328-
pod, err := createLocalPod(ctx, config, testVol, nil)
329-
framework.ExpectError(err)
330-
err = e2epod.WaitTimeoutForPodRunningInNamespace(ctx, config.client, pod.Name, pod.Namespace, f.Timeouts.PodStart)
331-
framework.ExpectError(err)
328+
// createLocalPod will create a pod and wait for it to be running. In this case,
329+
// It's expected that the Pod fails to start.
330+
_, err := createLocalPod(ctx, config, testVol, nil)
331+
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring("is not Running")))
332332
cleanupLocalPVCsPVs(ctx, config, []*localTestVolume{testVol})
333333
})
334334

@@ -348,8 +348,8 @@ var _ = utils.SIGDescribe("PersistentVolumes-local", func() {
348348
pod, err := config.client.CoreV1().Pods(config.ns).Create(ctx, pod, metav1.CreateOptions{})
349349
framework.ExpectNoError(err)
350350

351-
err = e2epod.WaitTimeoutForPodRunningInNamespace(ctx, config.client, pod.Name, pod.Namespace, f.Timeouts.PodStart)
352-
framework.ExpectError(err)
351+
getPod := e2epod.Get(f.ClientSet, pod)
352+
gomega.Consistently(ctx, getPod, f.Timeouts.PodStart, 2*time.Second).ShouldNot(e2epod.BeInPhase(v1.PodRunning))
353353

354354
cleanupLocalVolumes(ctx, config, []*localTestVolume{testVol})
355355
})

test/e2e/storage/testsuites/provisioning.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ func (t StorageClassTest) TestBindingWaitForFirstConsumerMultiPVC(ctx context.Co
10041004
// Wait for ClaimProvisionTimeout (across all PVCs in parallel) and make sure the phase did not become Bound i.e. the Wait errors out
10051005
ginkgo.By("checking the claims are in pending state")
10061006
err = e2epv.WaitForPersistentVolumeClaimsPhase(ctx, v1.ClaimBound, t.Client, namespace, claimNames, 2*time.Second /* Poll */, t.Timeouts.ClaimProvisionShort, true)
1007-
framework.ExpectError(err)
1007+
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring("not all in phase Bound")))
10081008
verifyPVCsPending(ctx, t.Client, createdClaims)
10091009

10101010
ginkgo.By("creating a pod referring to the claims")

test/e2e/storage/testsuites/snapshottable.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,12 @@ func deleteVolumeSnapshot(ctx context.Context, f *framework.Framework, dc dynami
410410
switch pattern.SnapshotDeletionPolicy {
411411
case storageframework.DeleteSnapshot:
412412
ginkgo.By("checking the SnapshotContent has been deleted")
413-
err = storageutils.WaitForGVRDeletion(ctx, dc, storageutils.SnapshotContentGVR, vscontent.GetName(), framework.Poll, f.Timeouts.SnapshotDelete)
413+
err = storageutils.EnsureGVRDeletion(ctx, dc, storageutils.SnapshotContentGVR, vscontent.GetName(), framework.Poll, f.Timeouts.SnapshotDelete, "")
414414
framework.ExpectNoError(err)
415415
case storageframework.RetainSnapshot:
416416
ginkgo.By("checking the SnapshotContent has not been deleted")
417-
err = storageutils.WaitForGVRDeletion(ctx, dc, storageutils.SnapshotContentGVR, vscontent.GetName(), 1*time.Second /* poll */, 30*time.Second /* timeout */)
418-
framework.ExpectError(err)
417+
err = storageutils.EnsureNoGVRDeletion(ctx, dc, storageutils.SnapshotContentGVR, vscontent.GetName(), 1*time.Second /* poll */, 30*time.Second /* timeout */, "")
418+
framework.ExpectNoError(err)
419419
}
420420
}
421421

test/e2e/storage/testsuites/volume_expand.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/onsi/gomega"
2626

2727
v1 "k8s.io/api/core/v1"
28+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2829
"k8s.io/apimachinery/pkg/api/resource"
2930
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3031
"k8s.io/apimachinery/pkg/util/errors"
@@ -157,6 +158,24 @@ func (v *volumeExpandTestSuite) DefineTests(driver storageframework.TestDriver,
157158
ginkgo.DeferCleanup(cleanup)
158159

159160
var err error
161+
// create Pod with pvc
162+
ginkgo.By("Creating a pod with PVC")
163+
podConfig := e2epod.Config{
164+
NS: f.Namespace.Name,
165+
PVCs: []*v1.PersistentVolumeClaim{l.resource.Pvc},
166+
SeLinuxLabel: e2epod.GetLinuxLabel(),
167+
NodeSelection: l.config.ClientNodeSelection,
168+
ImageID: e2epod.GetDefaultTestImageID(),
169+
}
170+
l.pod, err = e2epod.CreateSecPodWithNodeSelection(ctx, f.ClientSet, &podConfig, f.Timeouts.PodStart)
171+
ginkgo.DeferCleanup(e2epod.DeletePodWithWait, f.ClientSet, l.pod)
172+
framework.ExpectNoError(err, "While creating pods for expanding")
173+
174+
// Waiting for pod to run
175+
ginkgo.By("Waiting for pod to run")
176+
err = e2epod.WaitTimeoutForPodRunningInNamespace(ctx, f.ClientSet, l.pod.Name, l.pod.Namespace, f.Timeouts.PodStart)
177+
framework.ExpectNoError(err)
178+
160179
gomega.Expect(l.resource.Sc.AllowVolumeExpansion).NotTo(gomega.BeNil())
161180
allowVolumeExpansion := *l.resource.Sc.AllowVolumeExpansion
162181
gomega.Expect(allowVolumeExpansion).To(gomega.BeFalse())
@@ -166,7 +185,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver storageframework.TestDriver,
166185
newSize.Add(resource.MustParse("1Gi"))
167186
framework.Logf("currentPvcSize %v, newSize %v", currentPvcSize, newSize)
168187
_, err = ExpandPVCSize(ctx, l.resource.Pvc, newSize, f.ClientSet)
169-
framework.ExpectError(err, "While updating non-expandable PVC")
188+
gomega.Expect(err).To(gomega.MatchError(apierrors.IsForbidden, "While updating non-expandable PVC"))
170189
})
171190
} else {
172191
ginkgo.It("Verify if offline PVC expansion works", func(ctx context.Context) {
@@ -316,7 +335,7 @@ func ExpandPVCSize(ctx context.Context, origPVC *v1.PersistentVolumeClaim, size
316335
return true, nil
317336
})
318337
if wait.Interrupted(waitErr) {
319-
return nil, fmt.Errorf("timed out attempting to update PVC size. last update error: %v", lastUpdateError)
338+
return nil, fmt.Errorf("timed out attempting to update PVC size. last update error: %w", lastUpdateError)
320339
}
321340
if waitErr != nil {
322341
return nil, fmt.Errorf("failed to expand PVC size (check logs for error): %v", waitErr)

test/e2e/storage/utils/utils.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,40 @@ func WaitForGVRDeletion(ctx context.Context, c dynamic.Interface, gvr schema.Gro
619619
return fmt.Errorf("%s %s is not deleted within %v", gvr.Resource, objectName, timeout)
620620
}
621621

622+
// EnsureGVRDeletion checks that no object as defined by the group/version/kind and name is ever found during the given time period
623+
func EnsureGVRDeletion(ctx context.Context, c dynamic.Interface, gvr schema.GroupVersionResource, objectName string, poll, timeout time.Duration, namespace string) error {
624+
var resourceClient dynamic.ResourceInterface
625+
if namespace != "" {
626+
resourceClient = c.Resource(gvr).Namespace(namespace)
627+
} else {
628+
resourceClient = c.Resource(gvr)
629+
}
630+
631+
err := framework.Gomega().Eventually(ctx, func(ctx context.Context) error {
632+
_, err := resourceClient.Get(ctx, objectName, metav1.GetOptions{})
633+
return err
634+
}).WithTimeout(timeout).WithPolling(poll).Should(gomega.MatchError(apierrors.IsNotFound, fmt.Sprintf("failed to delete %s %s", gvr, objectName)))
635+
return err
636+
}
637+
638+
// EnsureNoGVRDeletion checks that an object as defined by the group/version/kind and name has not been deleted during the given time period
639+
func EnsureNoGVRDeletion(ctx context.Context, c dynamic.Interface, gvr schema.GroupVersionResource, objectName string, poll, timeout time.Duration, namespace string) error {
640+
var resourceClient dynamic.ResourceInterface
641+
if namespace != "" {
642+
resourceClient = c.Resource(gvr).Namespace(namespace)
643+
} else {
644+
resourceClient = c.Resource(gvr)
645+
}
646+
err := framework.Gomega().Consistently(ctx, func(ctx context.Context) error {
647+
_, err := resourceClient.Get(ctx, objectName, metav1.GetOptions{})
648+
if err != nil {
649+
return fmt.Errorf("failed to get %s %s: %w", gvr.Resource, objectName, err)
650+
}
651+
return nil
652+
}).WithTimeout(timeout).WithPolling(poll).Should(gomega.Succeed())
653+
return err
654+
}
655+
622656
// WaitForNamespacedGVRDeletion waits until a namespaced object has been deleted
623657
func WaitForNamespacedGVRDeletion(ctx context.Context, c dynamic.Interface, gvr schema.GroupVersionResource, ns, objectName string, poll, timeout time.Duration) error {
624658
framework.Logf("Waiting up to %v for %s %s to be deleted", timeout, gvr.Resource, objectName)

test/e2e/storage/volume_metrics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ var _ = utils.SIGDescribe(framework.WithSerial(), "Volume metrics", func() {
194194
pod, err = c.CoreV1().Pods(ns).Create(ctx, pod, metav1.CreateOptions{})
195195
framework.ExpectNoError(err, "failed to create Pod %s/%s", pod.Namespace, pod.Name)
196196

197-
err = e2epod.WaitTimeoutForPodRunningInNamespace(ctx, c, pod.Name, pod.Namespace, f.Timeouts.PodStart)
198-
framework.ExpectError(err)
197+
getPod := e2epod.Get(f.ClientSet, pod)
198+
gomega.Consistently(ctx, getPod, f.Timeouts.PodStart, 2*time.Second).ShouldNot(e2epod.BeInPhase(v1.PodRunning))
199199

200200
framework.Logf("Deleting pod %q/%q", pod.Namespace, pod.Name)
201201
framework.ExpectNoError(e2epod.DeletePodWithWait(ctx, c, pod))

0 commit comments

Comments
 (0)