diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index 3ae06335..33e999b7 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -29,10 +29,6 @@ import ( . "github.com/onsi/gomega" ) -var ( - csiNodeID = "foobar" -) - func verifyVolumeInfo(v *csi.VolumeInfo) { Expect(v).NotTo(BeNil()) Expect(v.GetId()).NotTo(BeEmpty()) @@ -249,6 +245,8 @@ var _ = Describe("CreateVolume [Controller Server]", func() { }) It("should return appropriate values SingleNodeWriter NoCapacity Type:Mount", func() { + + By("creating a volume") name := "sanity" vol, err := c.CreateVolume( context.Background(), @@ -270,10 +268,21 @@ var _ = Describe("CreateVolume [Controller Server]", func() { Expect(vol).NotTo(BeNil()) Expect(vol.GetVolumeInfo()).NotTo(BeNil()) Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty()) + + By("cleaning up deleting the volume") + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + }) + Expect(err).NotTo(HaveOccurred()) }) // Pending fix in mock file It("[MOCKERRORS] should return appropriate values SingleNodeWriter WithCapacity 1Gi Type:Mount", func() { + + By("creating a volume") name := "sanity" size := uint64(1 * 1024 * 1024 * 1024) vol, err := c.CreateVolume( @@ -300,6 +309,15 @@ var _ = Describe("CreateVolume [Controller Server]", func() { Expect(vol.GetVolumeInfo()).NotTo(BeNil()) Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty()) Expect(vol.GetVolumeInfo().GetCapacityBytes()).To(Equal(size)) + + By("cleaning up deleting the volume") + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + }) + Expect(err).NotTo(HaveOccurred()) }) }) @@ -342,9 +360,21 @@ var _ = Describe("DeleteVolume [Controller Server]", func() { Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) }) + It("should succeed when an invalid volume id is used", func() { + + _, err := c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + Version: csiClientVersion, + VolumeId: "reallyfakevolumeid", + }) + Expect(err).NotTo(HaveOccurred()) + }) + It("should return appropriate values (no optional values added)", func() { // Create Volume First + By("creating a volume") name := "sanity" vol, err := c.CreateVolume( context.Background(), @@ -369,6 +399,7 @@ var _ = Describe("DeleteVolume [Controller Server]", func() { Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty()) // Delete Volume + By("deleting a volume") _, err = c.DeleteVolume( context.Background(), &csi.DeleteVolumeRequest{ @@ -432,6 +463,7 @@ var _ = Describe("ValidateVolumeCapabilities [Controller Server]", func() { It("should return appropriate values (no optional values added)", func() { // Create Volume First + By("creating a single node writer volume") name := "sanity" vol, err := c.CreateVolume( context.Background(), @@ -456,6 +488,7 @@ var _ = Describe("ValidateVolumeCapabilities [Controller Server]", func() { Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty()) // ValidateVolumeCapabilities + By("validating volume capabilities") valivolcap, err := c.ValidateVolumeCapabilities( context.Background(), &csi.ValidateVolumeCapabilitiesRequest{ @@ -475,16 +508,27 @@ var _ = Describe("ValidateVolumeCapabilities [Controller Server]", func() { Expect(err).NotTo(HaveOccurred()) Expect(valivolcap).NotTo(BeNil()) Expect(valivolcap.GetSupported()).To(BeTrue()) + + By("cleaning up deleting the volume") + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + }) + Expect(err).NotTo(HaveOccurred()) }) }) var _ = Describe("ControllerPublishVolume [Controller Server]", func() { var ( c csi.ControllerClient + n csi.NodeClient ) BeforeEach(func() { c = csi.NewControllerClient(conn) + n = csi.NewNodeClient(conn) if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) { Skip("ControllerPublishVolume not supported") @@ -539,7 +583,7 @@ var _ = Describe("ControllerPublishVolume [Controller Server]", func() { &csi.ControllerPublishVolumeRequest{ Version: csiClientVersion, VolumeId: "id", - NodeId: csiNodeID, + NodeId: "fakenode", }) Expect(err).To(HaveOccurred()) @@ -551,6 +595,7 @@ var _ = Describe("ControllerPublishVolume [Controller Server]", func() { It("should return appropriate values (no optional values added)", func() { // Create Volume First + By("creating a single node writer volume") name := "sanity" vol, err := c.CreateVolume( context.Background(), @@ -573,13 +618,24 @@ var _ = Describe("ControllerPublishVolume [Controller Server]", func() { Expect(vol.GetVolumeInfo()).NotTo(BeNil()) Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty()) + By("getting a node id") + nid, err := n.GetNodeID( + context.Background(), + &csi.GetNodeIDRequest{ + Version: csiClientVersion, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(nid).NotTo(BeNil()) + Expect(nid.GetNodeId()).NotTo(BeEmpty()) + // ControllerPublishVolume + By("calling controllerpublish on that volume") conpubvol, err := c.ControllerPublishVolume( context.Background(), &csi.ControllerPublishVolumeRequest{ Version: csiClientVersion, VolumeId: vol.GetVolumeInfo().GetId(), - NodeId: csiNodeID, + NodeId: nid.GetNodeId(), VolumeCapability: &csi.VolumeCapability{ AccessType: &csi.VolumeCapability_Mount{ Mount: &csi.VolumeCapability_MountVolume{}, @@ -592,16 +648,39 @@ var _ = Describe("ControllerPublishVolume [Controller Server]", func() { }) Expect(err).NotTo(HaveOccurred()) Expect(conpubvol).NotTo(BeNil()) + + By("cleaning up unpublishing the volume") + conunpubvol, err := c.ControllerUnpublishVolume( + context.Background(), + &csi.ControllerUnpublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + // NodeID is optional in ControllerUnpublishVolume + NodeId: nid.GetNodeId(), + }) + Expect(err).NotTo(HaveOccurred()) + Expect(conunpubvol).NotTo(BeNil()) + + By("cleaning up deleting the volume") + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + }) + Expect(err).NotTo(HaveOccurred()) }) }) var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() { var ( c csi.ControllerClient + n csi.NodeClient ) BeforeEach(func() { c = csi.NewControllerClient(conn) + n = csi.NewNodeClient(conn) if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) { Skip("ControllerUnpublishVolume not supported") @@ -637,6 +716,7 @@ var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() { It("should return appropriate values (no optional values added)", func() { // Create Volume First + By("creating a single node writer volume") name := "sanity" vol, err := c.CreateVolume( context.Background(), @@ -659,13 +739,24 @@ var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() { Expect(vol.GetVolumeInfo()).NotTo(BeNil()) Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty()) + By("getting a node id") + nid, err := n.GetNodeID( + context.Background(), + &csi.GetNodeIDRequest{ + Version: csiClientVersion, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(nid).NotTo(BeNil()) + Expect(nid.GetNodeId()).NotTo(BeEmpty()) + // ControllerPublishVolume + By("calling controllerpublish on that volume") conpubvol, err := c.ControllerPublishVolume( context.Background(), &csi.ControllerPublishVolumeRequest{ Version: csiClientVersion, VolumeId: vol.GetVolumeInfo().GetId(), - NodeId: csiNodeID, + NodeId: nid.GetNodeId(), VolumeCapability: &csi.VolumeCapability{ AccessType: &csi.VolumeCapability_Mount{ Mount: &csi.VolumeCapability_MountVolume{}, @@ -680,15 +771,25 @@ var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() { Expect(conpubvol).NotTo(BeNil()) // ControllerUnpublishVolume + By("calling controllerunpublish on that volume") conunpubvol, err := c.ControllerUnpublishVolume( context.Background(), &csi.ControllerUnpublishVolumeRequest{ Version: csiClientVersion, VolumeId: vol.GetVolumeInfo().GetId(), // NodeID is optional in ControllerUnpublishVolume - NodeId: csiNodeID, + NodeId: nid.GetNodeId(), }) Expect(err).NotTo(HaveOccurred()) Expect(conunpubvol).NotTo(BeNil()) + + By("cleaning up deleting the volume") + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + }) + Expect(err).NotTo(HaveOccurred()) }) }) diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index 36a93ee7..2d4734df 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -144,13 +144,17 @@ var _ = Describe("GetNodeID [Node Server]", func() { var _ = Describe("NodePublishVolume [Node Server]", func() { var ( - s csi.ControllerClient - c csi.NodeClient + s csi.ControllerClient + c csi.NodeClient + controllerPublishSupported bool ) BeforeEach(func() { s = csi.NewControllerClient(conn) c = csi.NewNodeClient(conn) + controllerPublishSupported = isCapabilitySupported( + s, + csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) }) It("should fail when no version is provided", func() { @@ -213,6 +217,7 @@ var _ = Describe("NodePublishVolume [Node Server]", func() { It("should return appropriate values (no optional values added)", func() { // Create Volume First + By("creating a single node writer volume") name := "sanity" vol, err := s.CreateVolume( context.Background(), @@ -235,58 +240,110 @@ var _ = Describe("NodePublishVolume [Node Server]", func() { Expect(vol.GetVolumeInfo()).NotTo(BeNil()) Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty()) - // ControllerPublishVolume - conpubvol, err := s.ControllerPublishVolume( + By("getting a node id") + nid, err := c.GetNodeID( context.Background(), - &csi.ControllerPublishVolumeRequest{ - Version: csiClientVersion, - VolumeId: vol.GetVolumeInfo().GetId(), - NodeId: "foobar", - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + &csi.GetNodeIDRequest{ + Version: csiClientVersion, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(nid).NotTo(BeNil()) + Expect(nid.GetNodeId()).NotTo(BeEmpty()) + + var conpubvol *csi.ControllerPublishVolumeResponse + if controllerPublishSupported { + By("controller publishing volume") + conpubvol, err = s.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + NodeId: nid.GetNodeId(), + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, }, + Readonly: false, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(conpubvol).NotTo(BeNil()) + } + + // NodePublishVolume + By("publishing the volume on a node") + nodepubvolRequest := &csi.NodePublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + TargetPath: csiTargetPath, + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, - Readonly: false, + }, + } + if controllerPublishSupported { + nodepubvolRequest.PublishVolumeInfo = conpubvol.GetPublishVolumeInfo() + } + nodepubvol, err := c.NodePublishVolume(context.Background(), nodepubvolRequest) + Expect(err).NotTo(HaveOccurred()) + Expect(nodepubvol).NotTo(BeNil()) + + // NodeUnpublishVolume + By("cleaning up calling nodeunpublish") + nodeunpubvol, err := c.NodeUnpublishVolume( + context.Background(), + &csi.NodeUnpublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + TargetPath: csiTargetPath, }) Expect(err).NotTo(HaveOccurred()) - Expect(conpubvol).NotTo(BeNil()) + Expect(nodeunpubvol).NotTo(BeNil()) - // NodePublishVolume - nodepubvol, err := c.NodePublishVolume( + if controllerPublishSupported { + By("cleaning up calling controllerunpublishing the volume") + nodeunpubvol, err := c.NodeUnpublishVolume( + context.Background(), + &csi.NodeUnpublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + TargetPath: csiTargetPath, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(nodeunpubvol).NotTo(BeNil()) + } + + By("cleaning up deleting the volume") + _, err = s.DeleteVolume( context.Background(), - &csi.NodePublishVolumeRequest{ + &csi.DeleteVolumeRequest{ Version: csiClientVersion, VolumeId: vol.GetVolumeInfo().GetId(), - // PublishVolumeInfo is optional in NodePublishVolume - PublishVolumeInfo: conpubvol.GetPublishVolumeInfo(), - TargetPath: csiTargetPath, - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, - }, - }, }) Expect(err).NotTo(HaveOccurred()) - Expect(nodepubvol).NotTo(BeNil()) }) }) var _ = Describe("NodeUnpublishVolume [Node Server]", func() { var ( - s csi.ControllerClient - c csi.NodeClient + s csi.ControllerClient + c csi.NodeClient + controllerPublishSupported bool ) BeforeEach(func() { s = csi.NewControllerClient(conn) c = csi.NewNodeClient(conn) + controllerPublishSupported = isCapabilitySupported( + s, + csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) }) It("should fail when no version is provided", func() { @@ -333,6 +390,7 @@ var _ = Describe("NodeUnpublishVolume [Node Server]", func() { It("should return appropriate values (no optional values added)", func() { // Create Volume First + By("creating a single node writer volume") name := "sanity" vol, err := s.CreateVolume( context.Background(), @@ -356,43 +414,48 @@ var _ = Describe("NodeUnpublishVolume [Node Server]", func() { Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty()) // ControllerPublishVolume - conpubvol, err := s.ControllerPublishVolume( - context.Background(), - &csi.ControllerPublishVolumeRequest{ - Version: csiClientVersion, - VolumeId: vol.GetVolumeInfo().GetId(), - NodeId: "foobar", - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + var conpubvol *csi.ControllerPublishVolumeResponse + if controllerPublishSupported { + By("calling controllerpublish on the volume") + conpubvol, err = s.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + NodeId: "foobar", + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, }, - }, - Readonly: false, - }) - Expect(err).NotTo(HaveOccurred()) - Expect(conpubvol).NotTo(BeNil()) + Readonly: false, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(conpubvol).NotTo(BeNil()) + } // NodePublishVolume - nodepubvol, err := c.NodePublishVolume( - context.Background(), - &csi.NodePublishVolumeRequest{ - Version: csiClientVersion, - VolumeId: vol.GetVolumeInfo().GetId(), - // PublishVolumeInfo is optional in NodePublishVolume - PublishVolumeInfo: conpubvol.GetPublishVolumeInfo(), - TargetPath: csiTargetPath, - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, - }, + By("publishing the volume on a node") + nodepubvolRequest := &csi.NodePublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + TargetPath: csiTargetPath, + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, }, - }) + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + } + if controllerPublishSupported { + nodepubvolRequest.PublishVolumeInfo = conpubvol.GetPublishVolumeInfo() + } + nodepubvol, err := c.NodePublishVolume(context.Background(), nodepubvolRequest) Expect(err).NotTo(HaveOccurred()) Expect(nodepubvol).NotTo(BeNil()) @@ -406,5 +469,27 @@ var _ = Describe("NodeUnpublishVolume [Node Server]", func() { }) Expect(err).NotTo(HaveOccurred()) Expect(nodeunpubvol).NotTo(BeNil()) + + if controllerPublishSupported { + By("cleaning up unpublishing the volume") + nodeunpubvol, err := c.NodeUnpublishVolume( + context.Background(), + &csi.NodeUnpublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + TargetPath: csiTargetPath, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(nodeunpubvol).NotTo(BeNil()) + } + + By("cleaning up deleting the volume") + _, err = s.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + }) + Expect(err).NotTo(HaveOccurred()) }) })