From 6ef1312b83dabfc0db3c2d5c5ea7b64d408c8d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E7=8E=AE=E6=96=87?= Date: Tue, 2 Apr 2024 18:04:22 +0800 Subject: [PATCH 1/2] typo: Create{Volume => Snapshot}Request --- pkg/sanity/sanity.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/sanity/sanity.go b/pkg/sanity/sanity.go index 53511cb7..b57d76dc 100644 --- a/pkg/sanity/sanity.go +++ b/pkg/sanity/sanity.go @@ -98,7 +98,7 @@ type TestConfig struct { TestNodeVolumeAttachLimit bool TestVolumeAccessType string - // TestSnapshotParametersFile for setting CreateVolumeRequest.Parameters. + // TestSnapshotParametersFile for setting CreateSnapshotRequest.Parameters. TestSnapshotParametersFile string TestSnapshotParameters map[string]string From 54b1a9f3f85adfd6cc51172c7e49e79b106b930e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E7=8E=AE=E6=96=87?= Date: Tue, 2 Apr 2024 18:03:21 +0800 Subject: [PATCH 2/2] use MakeCreateVolumeReq() Use MakeCreateVolumeReq for all tests that does not care how volumes are created. This fixes several places where TestVolumeSize is not considered. MakeCreateVolumeReq() itself is modified to not pass LimitBytes, to match most existing cases. --- pkg/sanity/controller.go | 213 +++++---------------------------------- pkg/sanity/node.go | 46 +-------- 2 files changed, 31 insertions(+), 228 deletions(-) diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index cf23d903..17b09d30 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -217,15 +217,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo name := "sanity" // Create a new volume. - req := &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - } - + req := MakeCreateVolumeReq(sc, name) vol := r.MustCreateVolume(context.Background(), req) // List volumes and check for the newly created volume. @@ -291,15 +283,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo By("creating required new volumes") for i := initialTotalVols; i < minVolCount; i++ { name := "sanity" + strconv.Itoa(i) - req := &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - } - + req := MakeCreateVolumeReq(sc, name) vol, err := r.CreateVolume(context.Background(), req) Expect(err).NotTo(HaveOccurred()) Expect(vol).NotTo(BeNil()) @@ -335,15 +319,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo } By("creating a new volume") - req := &csi.CreateVolumeRequest{ - Name: "new-addition", - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - } - vol := r.MustCreateVolume(context.Background(), req) + vol := r.MustCreateVolume(context.Background(), MakeCreateVolumeReq(sc, "new-addition")) existing_vols[vol.Volume.VolumeId] = true vols, err = r.ListVolumes( @@ -399,21 +375,11 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo By("creating a volume") name := UniqueString("sanity-controller-create-single-no-capacity") + req := MakeCreateVolumeReq(sc, name) + // req.CapacityRange = nil + // FIXME: We should set it to nil, but this may break existing tests - r.MustCreateVolume( - context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: TestVolumeSize(sc), - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, - ) + r.MustCreateVolume(context.Background(), req) }) It("should return appropriate values SingleNodeWriter WithCapacity 1Gi", func() { @@ -423,17 +389,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo vol, err := r.CreateVolume( context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: TestVolumeSize(sc), - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, + MakeCreateVolumeReq(sc, name), ) if serverError, ok := status.FromError(err); ok && (serverError.Code() == codes.OutOfRange || serverError.Code() == codes.Unimplemented) { @@ -454,34 +410,14 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo vol1 := r.MustCreateVolume( context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: size, - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, + MakeCreateVolumeReq(sc, name), ) Expect(vol1.GetVolume().GetCapacityBytes()).To(Or(BeNumerically(">=", size), BeZero())) vol2 := r.MustCreateVolume( context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: size, - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, + MakeCreateVolumeReq(sc, name), ) Expect(vol2.GetVolume().GetCapacityBytes()).To(Or(BeNumerically(">=", size), BeZero())) Expect(vol1.GetVolume().GetVolumeId()).To(Equal(vol2.GetVolume().GetVolumeId())) @@ -491,40 +427,17 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo By("creating a volume") name := UniqueString("sanity-controller-create-twice-different") - size1 := TestVolumeSize(sc) r.MustCreateVolume( context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: size1, - LimitBytes: size1, - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, + MakeCreateVolumeReq(sc, name), ) - size2 := 2 * TestVolumeSize(sc) - rsp, err := r.CreateVolume( - context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: size2, - LimitBytes: size2, - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, - ) + req2 := MakeCreateVolumeReq(sc, name) + req2.CapacityRange = &csi.CapacityRange{ + RequiredBytes: TestVolumeSize(sc) * 2, + } + rsp, err := r.CreateVolume(context.Background(), req2) ExpectErrorCode(rsp, err, codes.AlreadyExists) }) @@ -535,17 +448,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo vol := r.MustCreateVolume( context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: size, - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, + MakeCreateVolumeReq(sc, name), ) Expect(vol.GetVolume().GetCapacityBytes()).To(Or(BeNumerically(">=", size), BeZero())) }) @@ -714,17 +617,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo vol := r.MustCreateVolume( context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: TestVolumeSize(sc), - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, + MakeCreateVolumeReq(sc, name), ) // Delete Volume @@ -760,17 +653,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo vol := r.MustCreateVolume( context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: TestVolumeSize(sc), - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, + MakeCreateVolumeReq(sc, name), ) rsp, err := r.ValidateVolumeCapabilities( @@ -791,17 +674,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo vol := r.MustCreateVolume( context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: TestVolumeSize(sc), - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, + MakeCreateVolumeReq(sc, name), ) // ValidateVolumeCapabilities @@ -949,14 +822,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo vol := r.MustCreateVolume( context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, + MakeCreateVolumeReq(sc, name), ) // ControllerPublishVolume @@ -991,14 +857,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo vol := r.MustCreateVolume( context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, + MakeCreateVolumeReq(sc, name), ) By("getting a node id") @@ -1503,17 +1362,7 @@ var _ = DescribeSanity("ExpandVolume [Controller Server]", func(sc *TestContext) name := UniqueString("sanity-expand-volume") // Create a new volume. - req := &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - Parameters: sc.Config.TestVolumeParameters, - Secrets: sc.Secrets.CreateVolumeSecret, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: TestVolumeSize(sc), - }, - } + req := MakeCreateVolumeReq(sc, name) vol := r.MustCreateVolume(context.Background(), req) By("expanding the volume") @@ -1640,7 +1489,6 @@ func MakeCreateVolumeReq(sc *TestContext, name string) *csi.CreateVolumeRequest }, CapacityRange: &csi.CapacityRange{ RequiredBytes: size1, - LimitBytes: size1, }, Parameters: sc.Config.TestVolumeParameters, } @@ -1754,19 +1602,10 @@ func VolumeLifecycle(r *Resources, sc *TestContext, count int) { // Create Volume First By("creating a single node writer volume") name := UniqueString(fmt.Sprintf("sanity-controller-publish-%d", count)) + req := MakeCreateVolumeReq(sc, name) + req.AccessibilityRequirements = accReqs - vol := r.MustCreateVolume( - context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - AccessibilityRequirements: accReqs, - }, - ) + vol := r.MustCreateVolume(context.Background(), req) // ControllerPublishVolume for i := 0; i < count; i++ { diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index 9ab3ad69..0071d6d3 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -86,21 +86,9 @@ func runControllerTest(sc *TestContext, r *Resources, controllerPublishSupported // Create Volume First By("creating a single node writer volume") - vol := r.MustCreateVolume( - context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: TestVolumeSize(sc), - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - AccessibilityRequirements: accReqs, - }, - ) + req := MakeCreateVolumeReq(sc, name) + req.AccessibilityRequirements = accReqs + vol := r.MustCreateVolume(context.Background(), req) var conpubvol *csi.ControllerPublishVolumeResponse if controllerPublishSupported { @@ -193,17 +181,7 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) { By("creating a single node writer volume for expansion") return r.MustCreateVolume( context.Background(), - &csi.CreateVolumeRequest{ - Name: volumeName, - VolumeCapabilities: []*csi.VolumeCapability{ - TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: TestVolumeSize(sc), - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, + MakeCreateVolumeReq(sc, volumeName), ) } @@ -538,21 +516,7 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) { vol := r.MustCreateVolume( context.Background(), - &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - { - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, - }, - }, - }, - Secrets: sc.Secrets.CreateVolumeSecret, - Parameters: sc.Config.TestVolumeParameters, - }, + MakeCreateVolumeReq(sc, name), ) rsp, err := r.NodeStageVolume(