diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index ea5f831f..caf579ee 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -1065,92 +1065,6 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) }) - // CSI spec poses no specific requirements for the cluster/storage setups that a SP MUST support. To perform - // meaningful checks the following test assumes that topology-aware provisioning on a single node setup is supported - It("should return appropriate values (no optional values added)", func() { - - By("getting node information") - ni, err := n.NodeGetInfo( - context.Background(), - &csi.NodeGetInfoRequest{}) - Expect(err).NotTo(HaveOccurred()) - Expect(ni).NotTo(BeNil()) - Expect(ni.GetNodeId()).NotTo(BeEmpty()) - - var accReqs *csi.TopologyRequirement - if ni.AccessibleTopology != nil { - // Topology requirements are honored if provided by the driver - accReqs = &csi.TopologyRequirement{ - Requisite: []*csi.Topology{ni.AccessibleTopology}, - } - } - - // Create Volume First - By("creating a single node writer volume") - name := UniqueString("sanity-controller-publish") - - vol, err := c.CreateVolume( - 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, - }, - ) - Expect(err).NotTo(HaveOccurred()) - Expect(vol).NotTo(BeNil()) - Expect(vol.GetVolume()).NotTo(BeNil()) - Expect(vol.GetVolume().GetVolumeId()).NotTo(BeEmpty()) - cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId()}) - - // ControllerPublishVolume - By("calling controllerpublish on that volume") - - conpubvol, err := c.ControllerPublishVolume( - context.Background(), - &csi.ControllerPublishVolumeRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - NodeId: ni.GetNodeId(), - VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - Readonly: false, - Secrets: sc.Secrets.ControllerPublishVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) - cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId(), NodeID: ni.GetNodeId()}) - Expect(conpubvol).NotTo(BeNil()) - - By("cleaning up unpublishing the volume") - - conunpubvol, err := c.ControllerUnpublishVolume( - context.Background(), - &csi.ControllerUnpublishVolumeRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - // NodeID is optional in ControllerUnpublishVolume - NodeId: ni.GetNodeId(), - Secrets: sc.Secrets.ControllerUnpublishVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) - Expect(conunpubvol).NotTo(BeNil()) - - By("cleaning up deleting the volume") - - _, err = c.DeleteVolume( - context.Background(), - &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - Secrets: sc.Secrets.DeleteVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) - cl.UnregisterVolume(name) - }) - It("should fail when publishing more volumes than the node max attach limit", func() { if !sc.Config.TestNodeVolumeAttachLimit { Skip("testnodevolumeattachlimit not enabled") @@ -1360,6 +1274,22 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo }) }) + Describe("volume lifecycle", func() { + BeforeEach(func() { + if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) { + Skip("Controller Publish, UnpublishVolume not supported") + } + }) + + It("should work", func() { + VolumeLifecycle(n, c, sc, cl, 1) + }) + + It("should be idempotent", func() { + VolumeLifecycle(n, c, sc, cl, sc.Config.IdempotentCount) + }) + }) + Describe("ControllerUnpublishVolume", func() { BeforeEach(func() { if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) { @@ -1381,93 +1311,6 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo Expect(ok).To(BeTrue()) Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) }) - - // CSI spec poses no specific requirements for the cluster/storage setups that a SP MUST support. To perform - // meaningful checks the following test assumes that topology-aware provisioning on a single node setup is supported - It("should return appropriate values (no optional values added)", func() { - - // Create Volume First - By("creating a single node writer volume") - name := UniqueString("sanity-controller-unpublish") - - By("getting node information") - ni, err := n.NodeGetInfo( - context.Background(), - &csi.NodeGetInfoRequest{}) - Expect(err).NotTo(HaveOccurred()) - Expect(ni).NotTo(BeNil()) - Expect(ni.GetNodeId()).NotTo(BeEmpty()) - - var accReqs *csi.TopologyRequirement - if ni.AccessibleTopology != nil { - // Topology requirements are honored if provided by the driver - accReqs = &csi.TopologyRequirement{ - Requisite: []*csi.Topology{ni.AccessibleTopology}, - } - } - - vol, err := c.CreateVolume( - 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, - }, - ) - Expect(err).NotTo(HaveOccurred()) - Expect(vol).NotTo(BeNil()) - Expect(vol.GetVolume()).NotTo(BeNil()) - Expect(vol.GetVolume().GetVolumeId()).NotTo(BeEmpty()) - cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId()}) - - // ControllerPublishVolume - By("calling controllerpublish on that volume") - - conpubvol, err := c.ControllerPublishVolume( - context.Background(), - &csi.ControllerPublishVolumeRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - NodeId: ni.GetNodeId(), - VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - Readonly: false, - Secrets: sc.Secrets.ControllerPublishVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) - cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId(), NodeID: ni.GetNodeId()}) - Expect(conpubvol).NotTo(BeNil()) - - // ControllerUnpublishVolume - By("calling controllerunpublish on that volume") - - conunpubvol, err := c.ControllerUnpublishVolume( - context.Background(), - &csi.ControllerUnpublishVolumeRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - // NodeID is optional in ControllerUnpublishVolume - NodeId: ni.GetNodeId(), - Secrets: sc.Secrets.ControllerUnpublishVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) - Expect(conunpubvol).NotTo(BeNil()) - - By("cleaning up deleting the volume") - - _, err = c.DeleteVolume( - context.Background(), - &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - Secrets: sc.Secrets.DeleteVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) - cl.UnregisterVolume(name) - }) }) }) @@ -2152,3 +1995,92 @@ func ControllerUnpublishAndDeleteVolume(sc *TestContext, c csi.ControllerClient, Expect(err).NotTo(HaveOccurred()) return err } + +// VolumeLifecycle performs Create-Publish-Unpublish-Delete, with optional repeat count to test idempotency. +func VolumeLifecycle(n csi.NodeClient, c csi.ControllerClient, sc *TestContext, cl *Cleanup, count int) { + // CSI spec poses no specific requirements for the cluster/storage setups that a SP MUST support. To perform + // meaningful checks the following test assumes that topology-aware provisioning on a single node setup is supported + By("getting node information") + ni, err := n.NodeGetInfo( + context.Background(), + &csi.NodeGetInfoRequest{}) + Expect(err).NotTo(HaveOccurred()) + Expect(ni).NotTo(BeNil()) + Expect(ni.GetNodeId()).NotTo(BeEmpty()) + + var accReqs *csi.TopologyRequirement + if ni.AccessibleTopology != nil { + // Topology requirements are honored if provided by the driver + accReqs = &csi.TopologyRequirement{ + Requisite: []*csi.Topology{ni.AccessibleTopology}, + } + } + + // Create Volume First + By("creating a single node writer volume") + name := UniqueString("sanity-controller-publish") + + vol, err := c.CreateVolume( + 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, + }, + ) + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolume()).NotTo(BeNil()) + Expect(vol.GetVolume().GetVolumeId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId()}) + + // ControllerPublishVolume + for i := 0; i < count; i++ { + By("calling controllerpublish on that volume") + conpubvol, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + VolumeId: vol.GetVolume().GetVolumeId(), + NodeId: ni.GetNodeId(), + VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), + Readonly: false, + Secrets: sc.Secrets.ControllerPublishVolumeSecret, + }, + ) + Expect(err).NotTo(HaveOccurred()) + Expect(conpubvol).NotTo(BeNil()) + } + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId(), NodeID: ni.GetNodeId()}) + + for i := 0; i < count; i++ { + By("cleaning up unpublishing the volume") + conunpubvol, err := c.ControllerUnpublishVolume( + context.Background(), + &csi.ControllerUnpublishVolumeRequest{ + VolumeId: vol.GetVolume().GetVolumeId(), + // NodeID is optional in ControllerUnpublishVolume + NodeId: ni.GetNodeId(), + Secrets: sc.Secrets.ControllerUnpublishVolumeSecret, + }, + ) + Expect(err).NotTo(HaveOccurred()) + Expect(conunpubvol).NotTo(BeNil()) + } + + for i := 0; i < count; i++ { + By("cleaning up deleting the volume") + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetVolumeId(), + Secrets: sc.Secrets.DeleteVolumeSecret, + }, + ) + Expect(err).NotTo(HaveOccurred()) + } + cl.UnregisterVolume(name) +} diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index 643e8f6f..cd759101 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -66,6 +66,183 @@ func isPluginCapabilitySupported(c csi.IdentityClient, return false } +func runControllerTest(sc *TestContext, c csi.NodeClient, s csi.ControllerClient, cl *Cleanup, controllerPublishSupported bool, nodeStageSupported bool, nodeVolumeStatsSupported bool, count int) { + + name := UniqueString("sanity-node-full") + + By("getting node information") + ni, err := c.NodeGetInfo( + context.Background(), + &csi.NodeGetInfoRequest{}) + Expect(err).NotTo(HaveOccurred()) + Expect(ni).NotTo(BeNil()) + Expect(ni.GetNodeId()).NotTo(BeEmpty()) + + var accReqs *csi.TopologyRequirement + if ni.AccessibleTopology != nil { + // Topology requirements are honored if provided by the driver + accReqs = &csi.TopologyRequirement{ + Requisite: []*csi.Topology{ni.AccessibleTopology}, + } + } + + // Create Volume First + By("creating a single node writer volume") + vol, err := s.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, + AccessibilityRequirements: accReqs, + }, + ) + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolume()).NotTo(BeNil()) + Expect(vol.GetVolume().GetVolumeId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId()}) + + var conpubvol *csi.ControllerPublishVolumeResponse + if controllerPublishSupported { + By("controller publishing volume") + + conpubvol, err = s.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + VolumeId: vol.GetVolume().GetVolumeId(), + NodeId: ni.GetNodeId(), + VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), + VolumeContext: vol.GetVolume().GetVolumeContext(), + Readonly: false, + Secrets: sc.Secrets.ControllerPublishVolumeSecret, + }, + ) + Expect(err).NotTo(HaveOccurred()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId(), NodeID: ni.GetNodeId()}) + Expect(conpubvol).NotTo(BeNil()) + } + // NodeStageVolume + if nodeStageSupported { + for i := 0; i < count; i++ { + By("node staging volume") + nodestagevol, err := c.NodeStageVolume( + context.Background(), + &csi.NodeStageVolumeRequest{ + VolumeId: vol.GetVolume().GetVolumeId(), + VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), + StagingTargetPath: sc.StagingPath, + VolumeContext: vol.GetVolume().GetVolumeContext(), + PublishContext: conpubvol.GetPublishContext(), + Secrets: sc.Secrets.NodeStageVolumeSecret, + }, + ) + Expect(err).NotTo(HaveOccurred()) + Expect(nodestagevol).NotTo(BeNil()) + } + } + // NodePublishVolume + var stagingPath string + if nodeStageSupported { + stagingPath = sc.StagingPath + } + for i := 0; i < count; i++ { + By("publishing the volume on a node") + nodepubvol, err := c.NodePublishVolume( + context.Background(), + &csi.NodePublishVolumeRequest{ + VolumeId: vol.GetVolume().GetVolumeId(), + TargetPath: sc.TargetPath + "/target", + StagingTargetPath: stagingPath, + VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), + VolumeContext: vol.GetVolume().GetVolumeContext(), + PublishContext: conpubvol.GetPublishContext(), + Secrets: sc.Secrets.NodePublishVolumeSecret, + }, + ) + Expect(err).NotTo(HaveOccurred()) + Expect(nodepubvol).NotTo(BeNil()) + } + + // NodeGetVolumeStats + if nodeVolumeStatsSupported { + By("Get node volume stats") + statsResp, err := c.NodeGetVolumeStats( + context.Background(), + &csi.NodeGetVolumeStatsRequest{ + VolumeId: vol.GetVolume().GetVolumeId(), + VolumePath: sc.TargetPath + "/target", + }, + ) + Expect(err).ToNot(HaveOccurred()) + Expect(statsResp.GetUsage()).ToNot(BeNil()) + } + + // NodeUnpublishVolume + for i := 0; i < count; i++ { + By("cleaning up calling nodeunpublish") + nodeunpubvol, err := c.NodeUnpublishVolume( + context.Background(), + &csi.NodeUnpublishVolumeRequest{ + VolumeId: vol.GetVolume().GetVolumeId(), + TargetPath: sc.TargetPath + "/target", + }) + Expect(err).NotTo(HaveOccurred()) + Expect(nodeunpubvol).NotTo(BeNil()) + } + + if nodeStageSupported { + for i := 0; i < count; i++ { + By("cleaning up calling nodeunstage") + nodeunstagevol, err := c.NodeUnstageVolume( + context.Background(), + &csi.NodeUnstageVolumeRequest{ + VolumeId: vol.GetVolume().GetVolumeId(), + StagingTargetPath: sc.StagingPath, + }, + ) + Expect(err).NotTo(HaveOccurred()) + Expect(nodeunstagevol).NotTo(BeNil()) + } + } + + if controllerPublishSupported { + for i := 0; i < count; i++ { + By("cleaning up calling controllerunpublishing") + + controllerunpubvol, err := s.ControllerUnpublishVolume( + context.Background(), + &csi.ControllerUnpublishVolumeRequest{ + VolumeId: vol.GetVolume().GetVolumeId(), + NodeId: ni.GetNodeId(), + Secrets: sc.Secrets.ControllerUnpublishVolumeSecret, + }, + ) + Expect(err).NotTo(HaveOccurred()) + Expect(controllerunpubvol).NotTo(BeNil()) + } + } + + for i := 0; i < count; i++ { + By("cleaning up deleting the volume") + + _, err = s.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetVolumeId(), + Secrets: sc.Secrets.DeleteVolumeSecret, + }, + ) + Expect(err).NotTo(HaveOccurred()) + } +} + var _ = DescribeSanity("Node Service", func(sc *TestContext) { var ( cl *Cleanup @@ -618,167 +795,18 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) { if !providesControllerService { Skip("Controller Service not provided: CreateVolume not supported") } - - name := UniqueString("sanity-node-full") - - By("getting node information") - ni, err := c.NodeGetInfo( - context.Background(), - &csi.NodeGetInfoRequest{}) - Expect(err).NotTo(HaveOccurred()) - Expect(ni).NotTo(BeNil()) - Expect(ni.GetNodeId()).NotTo(BeEmpty()) - - var accReqs *csi.TopologyRequirement - if ni.AccessibleTopology != nil { - // Topology requirements are honored if provided by the driver - accReqs = &csi.TopologyRequirement{ - Requisite: []*csi.Topology{ni.AccessibleTopology}, - } - } - - // Create Volume First - By("creating a single node writer volume") - vol, err := s.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, - AccessibilityRequirements: accReqs, - }, - ) - Expect(err).NotTo(HaveOccurred()) - Expect(vol).NotTo(BeNil()) - Expect(vol.GetVolume()).NotTo(BeNil()) - Expect(vol.GetVolume().GetVolumeId()).NotTo(BeEmpty()) - cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId()}) - - var conpubvol *csi.ControllerPublishVolumeResponse - if controllerPublishSupported { - By("controller publishing volume") - - conpubvol, err = s.ControllerPublishVolume( - context.Background(), - &csi.ControllerPublishVolumeRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - NodeId: ni.GetNodeId(), - VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - VolumeContext: vol.GetVolume().GetVolumeContext(), - Readonly: false, - Secrets: sc.Secrets.ControllerPublishVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) - cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId(), NodeID: ni.GetNodeId()}) - Expect(conpubvol).NotTo(BeNil()) - } - // NodeStageVolume - if nodeStageSupported { - By("node staging volume") - nodestagevol, err := c.NodeStageVolume( - context.Background(), - &csi.NodeStageVolumeRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - StagingTargetPath: sc.StagingPath, - VolumeContext: vol.GetVolume().GetVolumeContext(), - PublishContext: conpubvol.GetPublishContext(), - Secrets: sc.Secrets.NodeStageVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) - Expect(nodestagevol).NotTo(BeNil()) - } - // NodePublishVolume - By("publishing the volume on a node") - var stagingPath string - if nodeStageSupported { - stagingPath = sc.StagingPath - } - nodepubvol, err := c.NodePublishVolume( - context.Background(), - &csi.NodePublishVolumeRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - TargetPath: sc.TargetPath + "/target", - StagingTargetPath: stagingPath, - VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER), - VolumeContext: vol.GetVolume().GetVolumeContext(), - PublishContext: conpubvol.GetPublishContext(), - Secrets: sc.Secrets.NodePublishVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) - Expect(nodepubvol).NotTo(BeNil()) - - // NodeGetVolumeStats - if nodeVolumeStatsSupported { - By("Get node volume stats") - statsResp, err := c.NodeGetVolumeStats( - context.Background(), - &csi.NodeGetVolumeStatsRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - VolumePath: sc.TargetPath + "/target", - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(statsResp.GetUsage()).ToNot(BeNil()) - } - - // NodeUnpublishVolume - By("cleaning up calling nodeunpublish") - nodeunpubvol, err := c.NodeUnpublishVolume( - context.Background(), - &csi.NodeUnpublishVolumeRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - TargetPath: sc.TargetPath + "/target", - }) - Expect(err).NotTo(HaveOccurred()) - Expect(nodeunpubvol).NotTo(BeNil()) - - if nodeStageSupported { - By("cleaning up calling nodeunstage") - nodeunstagevol, err := c.NodeUnstageVolume( - context.Background(), - &csi.NodeUnstageVolumeRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - StagingTargetPath: sc.StagingPath, - }, - ) - Expect(err).NotTo(HaveOccurred()) - Expect(nodeunstagevol).NotTo(BeNil()) + By("runControllerTest") + runControllerTest(sc, c, s, cl, controllerPublishSupported, nodeStageSupported, nodeVolumeStatsSupported, 1) + }) + It("should be idempotent", func() { + if !providesControllerService { + Skip("Controller Service not provided: CreateVolume not supported") } - - if controllerPublishSupported { - By("cleaning up calling controllerunpublishing") - - controllerunpubvol, err := s.ControllerUnpublishVolume( - context.Background(), - &csi.ControllerUnpublishVolumeRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - NodeId: ni.GetNodeId(), - Secrets: sc.Secrets.ControllerUnpublishVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) - Expect(controllerunpubvol).NotTo(BeNil()) + if sc.Config.IdempotentCount <= 0 { + Skip("Config.IdempotentCount is zero or negative, skip tests") } - - By("cleaning up deleting the volume") - - _, err = s.DeleteVolume( - context.Background(), - &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetVolumeId(), - Secrets: sc.Secrets.DeleteVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) + count := sc.Config.IdempotentCount + By("runControllerTest with Idempotent count") + runControllerTest(sc, c, s, cl, controllerPublishSupported, nodeStageSupported, nodeVolumeStatsSupported, count) }) }) diff --git a/pkg/sanity/sanity.go b/pkg/sanity/sanity.go index b3c482a9..3b6fa6e6 100644 --- a/pkg/sanity/sanity.go +++ b/pkg/sanity/sanity.go @@ -156,6 +156,14 @@ type TestConfig struct { // generator for valid Volume and Node IDs. Defaults to // DefaultIDGenerator. IDGen IDGenerator + + // Repeat count for Volume operations to test idempotency requirements. + // some tests can optionally run repeated variants for those Volume operations + // that are required to be idempotent, based on this count value. + // <= 0: skip idempotency tests + // n > 0: repeat each call n times + // NewTestConfig() by default enables idempotency testing. + IdempotentCount int } // TestContext gets initialized by the sanity package before each test @@ -185,6 +193,7 @@ func NewTestConfig() TestConfig { TestVolumeSize: 10 * 1024 * 1024 * 1024, // 10 GiB TestVolumeAccessType: "mount", IDGen: &DefaultIDGenerator{}, + IdempotentCount: 10, DialOptions: []grpc.DialOption{grpc.WithInsecure()}, ControllerDialOptions: []grpc.DialOption{grpc.WithInsecure()},