From 865a83b3fe8aad28e5993daeec5a75b0057da2e8 Mon Sep 17 00:00:00 2001 From: edisonxiang Date: Wed, 24 Jan 2018 15:01:36 +0800 Subject: [PATCH 1/2] Add test for ControllerPublishVolume --- pkg/sanity/controller.go | 121 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index 3ffc4eb5..6545a1ec 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -29,6 +29,10 @@ import ( . "github.com/onsi/gomega" ) +var ( + csiNodeID = "foobar" +) + func verifyVolumeInfo(v *csi.VolumeInfo) { Expect(v).NotTo(BeNil()) Expect(v.GetId()).NotTo(BeEmpty()) @@ -473,3 +477,120 @@ var _ = Describe("ValidateVolumeCapabilities [Controller Server]", func() { Expect(valivolcap.GetSupported()).To(BeTrue()) }) }) + +var _ = Describe("ControllerPublishVolume [Controller Server]", func() { + var ( + c csi.ControllerClient + ) + + BeforeEach(func() { + c = csi.NewControllerClient(conn) + + if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) { + Skip("ControllerPublishVolume not supported") + } + }) + + It("should fail when no version is provided", func() { + + _, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{}) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should fail when no volume id is provided", func() { + + _, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + Version: csiClientVersion, + }) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should fail when no node id is provided", func() { + + _, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: "id", + }) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should fail when no volume capability is provided", func() { + + _, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: "id", + NodeId: csiNodeID, + }) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should return appropriate values (no optional values added)", func() { + + // Create Volume First + name := "sanity" + vol, err := c.CreateVolume( + context.Background(), + &csi.CreateVolumeRequest{ + Version: csiClientVersion, + Name: name, + VolumeCapabilities: []*csi.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(vol).NotTo(BeNil()) + Expect(vol.GetVolumeInfo()).NotTo(BeNil()) + Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty()) + + // ControllerPublishVolume + conpubvol, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + NodeId: csiNodeID, + 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()) + }) +}) From 8ef9687feadfe803a4b2ae98b6e212efbbd76aee Mon Sep 17 00:00:00 2001 From: edisonxiang Date: Wed, 24 Jan 2018 15:14:18 +0800 Subject: [PATCH 2/2] Add test for ControllerUnpublishVolume --- pkg/sanity/controller.go | 98 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index 6545a1ec..3ae06335 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -594,3 +594,101 @@ var _ = Describe("ControllerPublishVolume [Controller Server]", func() { Expect(conpubvol).NotTo(BeNil()) }) }) + +var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() { + var ( + c csi.ControllerClient + ) + + BeforeEach(func() { + c = csi.NewControllerClient(conn) + + if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) { + Skip("ControllerUnpublishVolume not supported") + } + }) + + It("should fail when no version is provided", func() { + + _, err := c.ControllerUnpublishVolume( + context.Background(), + &csi.ControllerUnpublishVolumeRequest{}) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should fail when no volume id is provided", func() { + + _, err := c.ControllerUnpublishVolume( + context.Background(), + &csi.ControllerUnpublishVolumeRequest{ + Version: csiClientVersion, + }) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should return appropriate values (no optional values added)", func() { + + // Create Volume First + name := "sanity" + vol, err := c.CreateVolume( + context.Background(), + &csi.CreateVolumeRequest{ + Version: csiClientVersion, + Name: name, + VolumeCapabilities: []*csi.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(vol).NotTo(BeNil()) + Expect(vol.GetVolumeInfo()).NotTo(BeNil()) + Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty()) + + // ControllerPublishVolume + conpubvol, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + NodeId: csiNodeID, + 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()) + + // ControllerUnpublishVolume + conunpubvol, err := c.ControllerUnpublishVolume( + context.Background(), + &csi.ControllerUnpublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + // NodeID is optional in ControllerUnpublishVolume + NodeId: csiNodeID, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(conunpubvol).NotTo(BeNil()) + }) +})