From 19290b38b192e3ae9a704db14c411ecd6d35a9c3 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 5 Jul 2018 12:26:15 +0200 Subject: [PATCH 01/10] pkg/sanity: use different volume names Within the test suite, each name is now unique. That simplifies debugging and when one test fails to remove its volume, the other tests are not affected. It also allows running tests in parallel. In addition, a random suffix gets added to also prevent collisions between different test runs. The random suffix gets reused for tests running inside the same process, but will be different for a single test run when running with "gingko -p". Related-to: kubernetes-csi/csi-test#89. --- pkg/sanity/controller.go | 20 ++++++++++---------- pkg/sanity/node.go | 15 +++++++++------ pkg/sanity/sanity.go | 21 +++++++++++++++++++++ 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index 568d78b8..f253543f 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -218,7 +218,7 @@ var _ = DescribeSanity("CreateVolume [Controller Server]", func(sc *SanityContex It("should return appropriate values SingleNodeWriter NoCapacity Type:Mount", func() { By("creating a volume") - name := "sanity" + name := uniqueString("sanity-controller-create-single-no-capacity") req := &csi.CreateVolumeRequest{ Name: name, @@ -261,7 +261,7 @@ var _ = DescribeSanity("CreateVolume [Controller Server]", func(sc *SanityContex It("should return appropriate values SingleNodeWriter WithCapacity 1Gi Type:Mount", func() { By("creating a volume") - name := "sanity" + name := uniqueString("sanity-controller-create-single-with-capacity") req := &csi.CreateVolumeRequest{ Name: name, @@ -315,7 +315,7 @@ var _ = DescribeSanity("CreateVolume [Controller Server]", func(sc *SanityContex It("should not fail when requesting to create a volume with already exisiting name and same capacity.", func() { By("creating a volume") - name := "sanity" + name := uniqueString("sanity-controller-create-twice") size := TestVolumeSize(sc) req := &csi.CreateVolumeRequest{ @@ -391,7 +391,7 @@ var _ = DescribeSanity("CreateVolume [Controller Server]", func(sc *SanityContex It("should fail when requesting to create a volume with already exisiting name and different capacity.", func() { By("creating a volume") - name := "sanity" + name := uniqueString("sanity-controller-create-twice-different") size1 := TestVolumeSize(sc) req := &csi.CreateVolumeRequest{ @@ -513,7 +513,7 @@ var _ = DescribeSanity("DeleteVolume [Controller Server]", func(sc *SanityContex // Create Volume First By("creating a volume") - name := "sanity" + name := uniqueString("sanity-controller-create-appropriate") createReq := &csi.CreateVolumeRequest{ Name: name, @@ -595,7 +595,7 @@ var _ = DescribeSanity("ValidateVolumeCapabilities [Controller Server]", func(sc // Create Volume First By("creating a single node writer volume") - name := "sanity" + name := uniqueString("sanity-controller-validate") req := &csi.CreateVolumeRequest{ Name: name, @@ -754,7 +754,7 @@ var _ = DescribeSanity("ControllerPublishVolume [Controller Server]", func(sc *S // Create Volume First By("creating a single node writer volume") - name := "sanity" + name := uniqueString("sanity-controller-publish") req := &csi.CreateVolumeRequest{ Name: name, VolumeCapabilities: []*csi.VolumeCapability{ @@ -877,7 +877,7 @@ var _ = DescribeSanity("ControllerPublishVolume [Controller Server]", func(sc *S // Create Volume First By("creating a single node writer volume") - name := "sanity" + name := uniqueString("sanity-controller-wrong-node") req := &csi.CreateVolumeRequest{ Name: name, VolumeCapabilities: []*csi.VolumeCapability{ @@ -949,7 +949,7 @@ var _ = DescribeSanity("ControllerPublishVolume [Controller Server]", func(sc *S // Create Volume First By("creating a single node writer volume") - name := "sanity" + name := uniqueString("sanity-controller-published-incompatible") req := &csi.CreateVolumeRequest{ Name: name, VolumeCapabilities: []*csi.VolumeCapability{ @@ -1084,7 +1084,7 @@ var _ = DescribeSanity("ControllerUnpublishVolume [Controller Server]", func(sc // Create Volume First By("creating a single node writer volume") - name := "sanity" + name := uniqueString("sanity-controller-unpublish") req := &csi.CreateVolumeRequest{ Name: name, diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index 117d317a..536d217a 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -223,7 +223,8 @@ var _ = DescribeSanity("NodePublishVolume [Node Server]", func(sc *SanityContext }) It("should return appropriate values (no optional values added)", func() { - testFullWorkflowSuccess(sc, s, c, controllerPublishSupported, nodeStageSupported) + name := uniqueString("sanity-node-publish") + testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) }) }) @@ -275,15 +276,15 @@ var _ = DescribeSanity("NodeUnpublishVolume [Node Server]", func(sc *SanityConte }) It("should return appropriate values (no optional values added)", func() { - testFullWorkflowSuccess(sc, s, c, controllerPublishSupported, nodeStageSupported) + name := uniqueString("sanity-node-unpublish") + testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) }) }) // TODO: Tests for NodeStageVolume/NodeUnstageVolume -func testFullWorkflowSuccess(sc *SanityContext, s csi.ControllerClient, c csi.NodeClient, controllerPublishSupported, nodeStageSupported bool) { +func testFullWorkflowSuccess(sc *SanityContext, s csi.ControllerClient, c csi.NodeClient, name string, controllerPublishSupported, nodeStageSupported bool) { // Create Volume First By("creating a single node writer volume") - name := "sanity" req := &csi.CreateVolumeRequest{ Name: name, VolumeCapabilities: []*csi.VolumeCapability{ @@ -558,7 +559,8 @@ var _ = DescribeSanity("NodeStageVolume [Node Server]", func(sc *SanityContext) }) It("should return appropriate values (no optional values added)", func() { - testFullWorkflowSuccess(sc, s, c, controllerPublishSupported, nodeStageSupported) + name := uniqueString("sanity-node-stage") + testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) }) }) @@ -614,6 +616,7 @@ var _ = DescribeSanity("NodeUnstageVolume [Node Server]", func(sc *SanityContext }) It("should return appropriate values (no optional values added)", func() { - testFullWorkflowSuccess(sc, s, c, controllerPublishSupported, nodeStageSupported) + name := uniqueString("sanity-node-unstage") + testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) }) }) diff --git a/pkg/sanity/sanity.go b/pkg/sanity/sanity.go index 3e57e611..320fa1ad 100644 --- a/pkg/sanity/sanity.go +++ b/pkg/sanity/sanity.go @@ -17,6 +17,7 @@ limitations under the License. package sanity import ( + "crypto/rand" "fmt" "io/ioutil" "os" @@ -138,3 +139,23 @@ func loadSecrets(path string) (*CSISecrets, error) { return &creds, nil } + +var uniqueSuffix = "-" + pseudoUUID() + +// pseudoUUID returns a unique string generated from random +// bytes, empty string in case of error. +func pseudoUUID() string { + b := make([]byte, 8) + if _, err := rand.Read(b); err != nil { + // Shouldn't happen?! + return "" + } + return fmt.Sprintf("%08X-%08X", b[0:4], b[4:8]) +} + +// uniqueString returns a unique string by appending a random +// number. In case of an error, just the prefix is returned, so it +// alone should already be fairly unique. +func uniqueString(prefix string) string { + return prefix + uniqueSuffix +} From 2d4ff96f43f93340f852cb76627e406fbc31c980 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 10 Jul 2018 17:55:47 +0200 Subject: [PATCH 02/10] pkg/sanity: reorganize suite Instead of testing individual functions of each service, the reorganized suite tests three services and for each service the functions that it provides. This allows removing code duplication in the common BeforeEach functions and enables further enhancements (common cleanup code, not duplicating the same test multiple times). While at it, the term "services" is now used consistently instead of "server", because that is what the CSI spec describes. --- pkg/sanity/controller.go | 1628 +++++++++++++++++++------------------- pkg/sanity/identity.go | 114 ++- pkg/sanity/node.go | 599 +++++++------- 3 files changed, 1118 insertions(+), 1223 deletions(-) diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index f253543f..21edb8b9 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -77,556 +77,499 @@ func isControllerCapabilitySupported( return false } -var _ = DescribeSanity("ControllerGetCapabilities [Controller Server]", func(sc *SanityContext) { +var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { var ( c csi.ControllerClient + n csi.NodeClient ) BeforeEach(func() { c = csi.NewControllerClient(sc.Conn) + n = csi.NewNodeClient(sc.Conn) }) - It("should return appropriate capabilities", func() { - caps, err := c.ControllerGetCapabilities( - context.Background(), - &csi.ControllerGetCapabilitiesRequest{}) + Describe("ControllerGetCapabilities", func() { + It("should return appropriate capabilities", func() { + caps, err := c.ControllerGetCapabilities( + context.Background(), + &csi.ControllerGetCapabilitiesRequest{}) - By("checking successful response") - Expect(err).NotTo(HaveOccurred()) - Expect(caps).NotTo(BeNil()) - Expect(caps.GetCapabilities()).NotTo(BeNil()) - - for _, cap := range caps.GetCapabilities() { - Expect(cap.GetRpc()).NotTo(BeNil()) - - switch cap.GetRpc().GetType() { - case csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME: - case csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME: - case csi.ControllerServiceCapability_RPC_LIST_VOLUMES: - case csi.ControllerServiceCapability_RPC_GET_CAPACITY: - case csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT: - case csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS: - default: - Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetRpc().GetType())) + By("checking successful response") + Expect(err).NotTo(HaveOccurred()) + Expect(caps).NotTo(BeNil()) + Expect(caps.GetCapabilities()).NotTo(BeNil()) + + for _, cap := range caps.GetCapabilities() { + Expect(cap.GetRpc()).NotTo(BeNil()) + + switch cap.GetRpc().GetType() { + case csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME: + case csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME: + case csi.ControllerServiceCapability_RPC_LIST_VOLUMES: + case csi.ControllerServiceCapability_RPC_GET_CAPACITY: + case csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT: + case csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS: + default: + Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetRpc().GetType())) + } } - } + }) }) -}) -var _ = DescribeSanity("GetCapacity [Controller Server]", func(sc *SanityContext) { - var ( - c csi.ControllerClient - ) - - BeforeEach(func() { - c = csi.NewControllerClient(sc.Conn) - - if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_GET_CAPACITY) { - Skip("GetCapacity not supported") - } - }) + Describe("GetCapacity", func() { + BeforeEach(func() { + if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_GET_CAPACITY) { + Skip("GetCapacity not supported") + } + }) - It("should return capacity (no optional values added)", func() { - _, err := c.GetCapacity( - context.Background(), - &csi.GetCapacityRequest{}) - Expect(err).NotTo(HaveOccurred()) + It("should return capacity (no optional values added)", func() { + _, err := c.GetCapacity( + context.Background(), + &csi.GetCapacityRequest{}) + Expect(err).NotTo(HaveOccurred()) - // Since capacity is int64 we will not be checking it - // The value of zero is a possible value. + // Since capacity is int64 we will not be checking it + // The value of zero is a possible value. + }) }) -}) -var _ = DescribeSanity("ListVolumes [Controller Server]", func(sc *SanityContext) { - var ( - c csi.ControllerClient - ) + Describe("ListVolumes", func() { + BeforeEach(func() { + if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_LIST_VOLUMES) { + Skip("ListVolumes not supported") + } + }) - BeforeEach(func() { - c = csi.NewControllerClient(sc.Conn) + It("should return appropriate values (no optional values added)", func() { + vols, err := c.ListVolumes( + context.Background(), + &csi.ListVolumesRequest{}) + Expect(err).NotTo(HaveOccurred()) + Expect(vols).NotTo(BeNil()) - if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_LIST_VOLUMES) { - Skip("ListVolumes not supported") - } - }) + for _, vol := range vols.GetEntries() { + verifyVolumeInfo(vol.GetVolume()) + } + }) - It("should return appropriate values (no optional values added)", func() { - vols, err := c.ListVolumes( - context.Background(), - &csi.ListVolumesRequest{}) - Expect(err).NotTo(HaveOccurred()) - Expect(vols).NotTo(BeNil()) + // TODO: Add test to test for tokens - for _, vol := range vols.GetEntries() { - verifyVolumeInfo(vol.GetVolume()) - } + // TODO: Add test which checks list of volume is there when created, + // and not there when deleted. }) - // TODO: Add test to test for tokens - - // TODO: Add test which checks list of volume is there when created, - // and not there when deleted. -}) - -var _ = DescribeSanity("CreateVolume [Controller Server]", func(sc *SanityContext) { - var ( - c csi.ControllerClient - ) - - BeforeEach(func() { - c = csi.NewControllerClient(sc.Conn) - - if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME) { - Skip("CreateVolume not supported") - } - }) + Describe("CreateVolume", func() { + BeforeEach(func() { + if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME) { + Skip("CreateVolume not supported") + } + }) - It("should fail when no name is provided", func() { + It("should fail when no name is provided", func() { - req := &csi.CreateVolumeRequest{} + req := &csi.CreateVolumeRequest{} - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } + if sc.Secrets != nil { + req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } - _, err := c.CreateVolume(context.Background(), req) - Expect(err).To(HaveOccurred()) + _, err := c.CreateVolume(context.Background(), req) + Expect(err).To(HaveOccurred()) - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) - }) + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) - It("should fail when no volume capabilities are provided", func() { + It("should fail when no volume capabilities are provided", func() { - req := &csi.CreateVolumeRequest{ - Name: "name", - } + req := &csi.CreateVolumeRequest{ + Name: "name", + } - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } + if sc.Secrets != nil { + req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } - _, err := c.CreateVolume(context.Background(), req) - Expect(err).To(HaveOccurred()) + _, err := c.CreateVolume(context.Background(), req) + Expect(err).To(HaveOccurred()) - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) - }) + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) - It("should return appropriate values SingleNodeWriter NoCapacity Type:Mount", func() { + It("should return appropriate values SingleNodeWriter NoCapacity Type:Mount", func() { - By("creating a volume") - name := uniqueString("sanity-controller-create-single-no-capacity") + By("creating a volume") + name := uniqueString("sanity-controller-create-single-no-capacity") - req := &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, + req := &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, + }, }, }, - }, - } + } - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } + if sc.Secrets != nil { + req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } - vol, err := c.CreateVolume(context.Background(), req) - Expect(err).NotTo(HaveOccurred()) - Expect(vol).NotTo(BeNil()) - Expect(vol.GetVolume()).NotTo(BeNil()) - Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + vol, err := c.CreateVolume(context.Background(), req) + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolume()).NotTo(BeNil()) + Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) - By("cleaning up deleting the volume") + By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } + delReq := &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + } - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } + if sc.Secrets != nil { + delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret + } - _, err = c.DeleteVolume(context.Background(), delReq) - Expect(err).NotTo(HaveOccurred()) - }) + _, err = c.DeleteVolume(context.Background(), delReq) + Expect(err).NotTo(HaveOccurred()) + }) - It("should return appropriate values SingleNodeWriter WithCapacity 1Gi Type:Mount", func() { + It("should return appropriate values SingleNodeWriter WithCapacity 1Gi Type:Mount", func() { - By("creating a volume") - name := uniqueString("sanity-controller-create-single-with-capacity") + By("creating a volume") + name := uniqueString("sanity-controller-create-single-with-capacity") - req := &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, + req := &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, + }, }, }, - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: TestVolumeSize(sc), - }, - } + CapacityRange: &csi.CapacityRange{ + RequiredBytes: TestVolumeSize(sc), + }, + } - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } + if sc.Secrets != nil { + req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } - vol, err := c.CreateVolume(context.Background(), req) - if serverError, ok := status.FromError(err); ok { - if serverError.Code() == codes.OutOfRange || serverError.Code() == codes.Unimplemented { - Skip("Required bytes not supported") + vol, err := c.CreateVolume(context.Background(), req) + if serverError, ok := status.FromError(err); ok { + if serverError.Code() == codes.OutOfRange || serverError.Code() == codes.Unimplemented { + Skip("Required bytes not supported") + } else { + Expect(err).NotTo(HaveOccurred()) + } } else { + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolume()).NotTo(BeNil()) + Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + Expect(vol.GetVolume().GetCapacityBytes()).To(BeNumerically(">=", TestVolumeSize(sc))) } - } else { + By("cleaning up deleting the volume") - Expect(err).NotTo(HaveOccurred()) - Expect(vol).NotTo(BeNil()) - Expect(vol.GetVolume()).NotTo(BeNil()) - Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) - Expect(vol.GetVolume().GetCapacityBytes()).To(BeNumerically(">=", TestVolumeSize(sc))) - } - By("cleaning up deleting the volume") - - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } + delReq := &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + } - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } + if sc.Secrets != nil { + delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret + } - _, err = c.DeleteVolume(context.Background(), delReq) - Expect(err).NotTo(HaveOccurred()) - }) - It("should not fail when requesting to create a volume with already exisiting name and same capacity.", func() { + _, err = c.DeleteVolume(context.Background(), delReq) + Expect(err).NotTo(HaveOccurred()) + }) + It("should not fail when requesting to create a volume with already exisiting name and same capacity.", func() { - By("creating a volume") - name := uniqueString("sanity-controller-create-twice") - size := TestVolumeSize(sc) + By("creating a volume") + name := uniqueString("sanity-controller-create-twice") + size := TestVolumeSize(sc) - req := &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, + req := &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, + }, }, }, - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: size, - }, - } + CapacityRange: &csi.CapacityRange{ + RequiredBytes: size, + }, + } - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } + if sc.Secrets != nil { + req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } - vol1, err := c.CreateVolume(context.Background(), req) - Expect(err).NotTo(HaveOccurred()) - Expect(vol1).NotTo(BeNil()) - Expect(vol1.GetVolume()).NotTo(BeNil()) - Expect(vol1.GetVolume().GetId()).NotTo(BeEmpty()) - Expect(vol1.GetVolume().GetCapacityBytes()).To(BeNumerically(">=", size)) - - req2 := &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, + vol1, err := c.CreateVolume(context.Background(), req) + Expect(err).NotTo(HaveOccurred()) + Expect(vol1).NotTo(BeNil()) + Expect(vol1.GetVolume()).NotTo(BeNil()) + Expect(vol1.GetVolume().GetId()).NotTo(BeEmpty()) + Expect(vol1.GetVolume().GetCapacityBytes()).To(BeNumerically(">=", size)) + + req2 := &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, + }, }, }, - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: size, - }, - } + CapacityRange: &csi.CapacityRange{ + RequiredBytes: size, + }, + } - if sc.Secrets != nil { - req2.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } + if sc.Secrets != nil { + req2.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } - vol2, err := c.CreateVolume(context.Background(), req2) - Expect(err).NotTo(HaveOccurred()) - Expect(vol2).NotTo(BeNil()) - Expect(vol2.GetVolume()).NotTo(BeNil()) - Expect(vol2.GetVolume().GetId()).NotTo(BeEmpty()) - Expect(vol2.GetVolume().GetCapacityBytes()).To(BeNumerically(">=", size)) - Expect(vol1.GetVolume().GetId()).To(Equal(vol2.GetVolume().GetId())) + vol2, err := c.CreateVolume(context.Background(), req2) + Expect(err).NotTo(HaveOccurred()) + Expect(vol2).NotTo(BeNil()) + Expect(vol2.GetVolume()).NotTo(BeNil()) + Expect(vol2.GetVolume().GetId()).NotTo(BeEmpty()) + Expect(vol2.GetVolume().GetCapacityBytes()).To(BeNumerically(">=", size)) + Expect(vol1.GetVolume().GetId()).To(Equal(vol2.GetVolume().GetId())) - By("cleaning up deleting the volume") + By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol1.GetVolume().GetId(), - } + delReq := &csi.DeleteVolumeRequest{ + VolumeId: vol1.GetVolume().GetId(), + } - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } + if sc.Secrets != nil { + delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret + } - _, err = c.DeleteVolume(context.Background(), delReq) - Expect(err).NotTo(HaveOccurred()) - }) - It("should fail when requesting to create a volume with already exisiting name and different capacity.", func() { + _, err = c.DeleteVolume(context.Background(), delReq) + Expect(err).NotTo(HaveOccurred()) + }) + It("should fail when requesting to create a volume with already exisiting name and different capacity.", func() { - By("creating a volume") - name := uniqueString("sanity-controller-create-twice-different") - size1 := TestVolumeSize(sc) + By("creating a volume") + name := uniqueString("sanity-controller-create-twice-different") + size1 := TestVolumeSize(sc) - req := &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, + req := &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, + }, }, }, - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: size1, - LimitBytes: size1, - }, - } + CapacityRange: &csi.CapacityRange{ + RequiredBytes: size1, + LimitBytes: size1, + }, + } - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } + if sc.Secrets != nil { + req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } - vol1, err := c.CreateVolume(context.Background(), req) - Expect(err).ToNot(HaveOccurred()) - Expect(vol1).NotTo(BeNil()) - Expect(vol1.GetVolume()).NotTo(BeNil()) - Expect(vol1.GetVolume().GetId()).NotTo(BeEmpty()) - size2 := 2 * TestVolumeSize(sc) - - req2 := &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, + vol1, err := c.CreateVolume(context.Background(), req) + Expect(err).ToNot(HaveOccurred()) + Expect(vol1).NotTo(BeNil()) + Expect(vol1.GetVolume()).NotTo(BeNil()) + Expect(vol1.GetVolume().GetId()).NotTo(BeEmpty()) + size2 := 2 * TestVolumeSize(sc) + + req2 := &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, + }, }, }, - }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: size2, - LimitBytes: size2, - }, - } + CapacityRange: &csi.CapacityRange{ + RequiredBytes: size2, + LimitBytes: size2, + }, + } - if sc.Secrets != nil { - req2.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } + if sc.Secrets != nil { + req2.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } - _, err = c.CreateVolume(context.Background(), req2) - Expect(err).To(HaveOccurred()) - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.AlreadyExists)) + _, err = c.CreateVolume(context.Background(), req2) + Expect(err).To(HaveOccurred()) + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.AlreadyExists)) - By("cleaning up deleting the volume") + By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol1.GetVolume().GetId(), - } + delReq := &csi.DeleteVolumeRequest{ + VolumeId: vol1.GetVolume().GetId(), + } - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } + if sc.Secrets != nil { + delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret + } - _, err = c.DeleteVolume(context.Background(), delReq) - Expect(err).NotTo(HaveOccurred()) + _, err = c.DeleteVolume(context.Background(), delReq) + Expect(err).NotTo(HaveOccurred()) + }) }) -}) -var _ = DescribeSanity("DeleteVolume [Controller Server]", func(sc *SanityContext) { - var ( - c csi.ControllerClient - ) - - BeforeEach(func() { - c = csi.NewControllerClient(sc.Conn) - - if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME) { - Skip("DeleteVolume not supported") - } - }) + Describe("DeleteVolume", func() { + BeforeEach(func() { + if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME) { + Skip("DeleteVolume not supported") + } + }) - It("should fail when no volume id is provided", func() { + It("should fail when no volume id is provided", func() { - req := &csi.DeleteVolumeRequest{} + req := &csi.DeleteVolumeRequest{} - if sc.Secrets != nil { - req.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } + if sc.Secrets != nil { + req.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret + } - _, err := c.DeleteVolume(context.Background(), req) - Expect(err).To(HaveOccurred()) + _, err := c.DeleteVolume(context.Background(), req) + Expect(err).To(HaveOccurred()) - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) - }) + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) - It("should succeed when an invalid volume id is used", func() { + It("should succeed when an invalid volume id is used", func() { - req := &csi.DeleteVolumeRequest{ - VolumeId: "reallyfakevolumeid", - } + req := &csi.DeleteVolumeRequest{ + VolumeId: "reallyfakevolumeid", + } - if sc.Secrets != nil { - req.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } + if sc.Secrets != nil { + req.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret + } - _, err := c.DeleteVolume(context.Background(), req) - Expect(err).NotTo(HaveOccurred()) - }) + _, err := c.DeleteVolume(context.Background(), req) + Expect(err).NotTo(HaveOccurred()) + }) - It("should return appropriate values (no optional values added)", func() { + It("should return appropriate values (no optional values added)", func() { - // Create Volume First - By("creating a volume") - name := uniqueString("sanity-controller-create-appropriate") + // Create Volume First + By("creating a volume") + name := uniqueString("sanity-controller-create-appropriate") - createReq := &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, + createReq := &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, + }, }, }, - }, - } - - if sc.Secrets != nil { - createReq.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol, err := c.CreateVolume(context.Background(), createReq) - - Expect(err).NotTo(HaveOccurred()) - Expect(vol).NotTo(BeNil()) - Expect(vol.GetVolume()).NotTo(BeNil()) - Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) - - // Delete Volume - By("deleting a volume") + } - req := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } + if sc.Secrets != nil { + createReq.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } - if sc.Secrets != nil { - req.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } + vol, err := c.CreateVolume(context.Background(), createReq) - _, err = c.DeleteVolume(context.Background(), req) - Expect(err).NotTo(HaveOccurred()) - }) -}) - -var _ = DescribeSanity("ValidateVolumeCapabilities [Controller Server]", func(sc *SanityContext) { - var ( - c csi.ControllerClient - ) + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolume()).NotTo(BeNil()) + Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) - BeforeEach(func() { - c = csi.NewControllerClient(sc.Conn) - }) + // Delete Volume + By("deleting a volume") - It("should fail when no volume id is provided", func() { + req := &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + } - _, err := c.ValidateVolumeCapabilities( - context.Background(), - &csi.ValidateVolumeCapabilitiesRequest{}) - Expect(err).To(HaveOccurred()) + if sc.Secrets != nil { + req.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret + } - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + _, err = c.DeleteVolume(context.Background(), req) + Expect(err).NotTo(HaveOccurred()) + }) }) - It("should fail when no volume capabilities are provided", func() { + Describe("ValidateVolumeCapabilities", func() { + It("should fail when no volume id is provided", func() { - _, err := c.ValidateVolumeCapabilities( - context.Background(), - &csi.ValidateVolumeCapabilitiesRequest{ - VolumeId: "id", - }) - Expect(err).To(HaveOccurred()) + _, err := c.ValidateVolumeCapabilities( + context.Background(), + &csi.ValidateVolumeCapabilitiesRequest{}) + Expect(err).To(HaveOccurred()) - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) - }) + 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() { + It("should fail when no volume capabilities are provided", func() { - // Create Volume First - By("creating a single node writer volume") - name := uniqueString("sanity-controller-validate") + _, err := c.ValidateVolumeCapabilities( + context.Background(), + &csi.ValidateVolumeCapabilitiesRequest{ + VolumeId: "id", + }) + Expect(err).To(HaveOccurred()) - req := &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, - }, - }, - }, - } + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } + It("should return appropriate values (no optional values added)", func() { - vol, err := c.CreateVolume(context.Background(), req) - Expect(err).NotTo(HaveOccurred()) - Expect(vol).NotTo(BeNil()) - Expect(vol.GetVolume()).NotTo(BeNil()) - Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + // Create Volume First + By("creating a single node writer volume") + name := uniqueString("sanity-controller-validate") - // ValidateVolumeCapabilities - By("validating volume capabilities") - valivolcap, err := c.ValidateVolumeCapabilities( - context.Background(), - &csi.ValidateVolumeCapabilitiesRequest{ - VolumeId: vol.GetVolume().GetId(), + req := &csi.CreateVolumeRequest{ + Name: name, VolumeCapabilities: []*csi.VolumeCapability{ { AccessType: &csi.VolumeCapability_Mount{ @@ -637,128 +580,183 @@ var _ = DescribeSanity("ValidateVolumeCapabilities [Controller Server]", func(sc }, }, }, - }) - Expect(err).NotTo(HaveOccurred()) - Expect(valivolcap).NotTo(BeNil()) - Expect(valivolcap.GetSupported()).To(BeTrue()) + } - By("cleaning up deleting the volume") + if sc.Secrets != nil { + req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } + vol, err := c.CreateVolume(context.Background(), req) + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolume()).NotTo(BeNil()) + Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } + // ValidateVolumeCapabilities + By("validating volume capabilities") + valivolcap, err := c.ValidateVolumeCapabilities( + context.Background(), + &csi.ValidateVolumeCapabilitiesRequest{ + VolumeId: vol.GetVolume().GetId(), + VolumeCapabilities: []*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(valivolcap).NotTo(BeNil()) + Expect(valivolcap.GetSupported()).To(BeTrue()) - _, err = c.DeleteVolume(context.Background(), delReq) - Expect(err).NotTo(HaveOccurred()) - }) + By("cleaning up deleting the volume") - It("should fail when the requested volume does not exist", func() { + delReq := &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + } - _, err := c.ValidateVolumeCapabilities( - context.Background(), - &csi.ValidateVolumeCapabilitiesRequest{ - VolumeId: "some-vol-id", - VolumeCapabilities: []*csi.VolumeCapability{ - { - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + if sc.Secrets != nil { + delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret + } + + _, err = c.DeleteVolume(context.Background(), delReq) + Expect(err).NotTo(HaveOccurred()) + }) + + It("should fail when the requested volume does not exist", func() { + + _, err := c.ValidateVolumeCapabilities( + context.Background(), + &csi.ValidateVolumeCapabilitiesRequest{ + VolumeId: "some-vol-id", + VolumeCapabilities: []*csi.VolumeCapability{ + { + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, }, }, }, - }, - ) - Expect(err).To(HaveOccurred()) + ) + Expect(err).To(HaveOccurred()) - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.NotFound)) + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.NotFound)) + }) }) -}) -var _ = DescribeSanity("ControllerPublishVolume [Controller Server]", func(sc *SanityContext) { - var ( - c csi.ControllerClient - n csi.NodeClient - ) + Describe("ControllerPublishVolume", func() { + BeforeEach(func() { + if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) { + Skip("ControllerPublishVolume not supported") + } + }) - BeforeEach(func() { - c = csi.NewControllerClient(sc.Conn) - n = csi.NewNodeClient(sc.Conn) + It("should fail when no volume id is provided", func() { - if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) { - Skip("ControllerPublishVolume not supported") - } - }) + req := &csi.ControllerPublishVolumeRequest{} - It("should fail when no volume id is provided", func() { + if sc.Secrets != nil { + req.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret + } - req := &csi.ControllerPublishVolumeRequest{} + _, err := c.ControllerPublishVolume(context.Background(), req) + Expect(err).To(HaveOccurred()) - if sc.Secrets != nil { - req.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) - _, err := c.ControllerPublishVolume(context.Background(), req) - Expect(err).To(HaveOccurred()) + It("should fail when no node id is provided", func() { - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) - }) + req := &csi.ControllerPublishVolumeRequest{ + VolumeId: "id", + } - It("should fail when no node id is provided", func() { + if sc.Secrets != nil { + req.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret + } - req := &csi.ControllerPublishVolumeRequest{ - VolumeId: "id", - } + _, err := c.ControllerPublishVolume(context.Background(), req) + Expect(err).To(HaveOccurred()) - if sc.Secrets != nil { - req.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) - _, err := c.ControllerPublishVolume(context.Background(), req) - Expect(err).To(HaveOccurred()) + It("should fail when no volume capability is provided", func() { - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) - }) + req := &csi.ControllerPublishVolumeRequest{ + VolumeId: "id", + NodeId: "fakenode", + } - It("should fail when no volume capability is provided", func() { + if sc.Secrets != nil { + req.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret + } - req := &csi.ControllerPublishVolumeRequest{ - VolumeId: "id", - NodeId: "fakenode", - } + _, err := c.ControllerPublishVolume(context.Background(), req) + Expect(err).To(HaveOccurred()) - if sc.Secrets != nil { - req.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) - _, err := c.ControllerPublishVolume(context.Background(), req) - Expect(err).To(HaveOccurred()) + It("should return appropriate values (no optional values added)", func() { - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) - }) + // Create Volume First + By("creating a single node writer volume") + name := uniqueString("sanity-controller-publish") + req := &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, + }, + }, + }, + } - It("should return appropriate values (no optional values added)", func() { + if sc.Secrets != nil { + req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } + + vol, err := c.CreateVolume(context.Background(), req) + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolume()).NotTo(BeNil()) + Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + + By("getting a node id") + nid, err := n.NodeGetId( + context.Background(), + &csi.NodeGetIdRequest{}) + Expect(err).NotTo(HaveOccurred()) + Expect(nid).NotTo(BeNil()) + Expect(nid.GetNodeId()).NotTo(BeEmpty()) + + // ControllerPublishVolume + By("calling controllerpublish on that volume") - // Create Volume First - By("creating a single node writer volume") - name := uniqueString("sanity-controller-publish") - req := &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - { + pubReq := &csi.ControllerPublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + NodeId: nid.GetNodeId(), + VolumeCapability: &csi.VolumeCapability{ AccessType: &csi.VolumeCapability_Mount{ Mount: &csi.VolumeCapability_MountVolume{}, }, @@ -766,122 +764,114 @@ var _ = DescribeSanity("ControllerPublishVolume [Controller Server]", func(sc *S Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - }, - } + Readonly: false, + } - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } + if sc.Secrets != nil { + pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret + } - vol, err := c.CreateVolume(context.Background(), req) - Expect(err).NotTo(HaveOccurred()) - Expect(vol).NotTo(BeNil()) - Expect(vol.GetVolume()).NotTo(BeNil()) - Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) + Expect(err).NotTo(HaveOccurred()) + Expect(conpubvol).NotTo(BeNil()) - By("getting a node id") - nid, err := n.NodeGetId( - context.Background(), - &csi.NodeGetIdRequest{}) - Expect(err).NotTo(HaveOccurred()) - Expect(nid).NotTo(BeNil()) - Expect(nid.GetNodeId()).NotTo(BeEmpty()) + By("cleaning up unpublishing the volume") - // ControllerPublishVolume - By("calling controllerpublish on that volume") + unpubReq := &csi.ControllerUnpublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + // NodeID is optional in ControllerUnpublishVolume + NodeId: nid.GetNodeId(), + } - pubReq := &csi.ControllerPublishVolumeRequest{ - VolumeId: vol.GetVolume().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, - } + if sc.Secrets != nil { + unpubReq.ControllerUnpublishSecrets = sc.Secrets.ControllerUnpublishVolumeSecret + } - if sc.Secrets != nil { - pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } + conunpubvol, err := c.ControllerUnpublishVolume(context.Background(), unpubReq) + Expect(err).NotTo(HaveOccurred()) + Expect(conunpubvol).NotTo(BeNil()) - conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) - Expect(err).NotTo(HaveOccurred()) - Expect(conpubvol).NotTo(BeNil()) + By("cleaning up deleting the volume") - By("cleaning up unpublishing the volume") + delReq := &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + } - unpubReq := &csi.ControllerUnpublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - // NodeID is optional in ControllerUnpublishVolume - NodeId: nid.GetNodeId(), - } + if sc.Secrets != nil { + delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret + } - if sc.Secrets != nil { - unpubReq.ControllerUnpublishSecrets = sc.Secrets.ControllerUnpublishVolumeSecret - } + _, err = c.DeleteVolume(context.Background(), delReq) + Expect(err).NotTo(HaveOccurred()) + }) - conunpubvol, err := c.ControllerUnpublishVolume(context.Background(), unpubReq) - Expect(err).NotTo(HaveOccurred()) - Expect(conunpubvol).NotTo(BeNil()) + It("should fail when the volume does not exist", func() { - By("cleaning up deleting the volume") + By("calling controller publish on a non-existent volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } + pubReq := &csi.ControllerPublishVolumeRequest{ + VolumeId: "some-vol-id", + NodeId: "some-node-id", + 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 sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } + if sc.Secrets != nil { + pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret + } - _, err = c.DeleteVolume(context.Background(), delReq) - Expect(err).NotTo(HaveOccurred()) - }) + conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) + Expect(err).To(HaveOccurred()) + Expect(conpubvol).To(BeNil()) - It("should fail when the volume does not exist", func() { + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.NotFound)) + }) - By("calling controller publish on a non-existent volume") + It("should fail when the node does not exist", func() { - pubReq := &csi.ControllerPublishVolumeRequest{ - VolumeId: "some-vol-id", - NodeId: "some-node-id", - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + // Create Volume First + By("creating a single node writer volume") + name := uniqueString("sanity-controller-wrong-node") + req := &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, + }, + }, }, - }, - Readonly: false, - } - - if sc.Secrets != nil { - pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } + } - conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) - Expect(err).To(HaveOccurred()) - Expect(conpubvol).To(BeNil()) + if sc.Secrets != nil { + req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.NotFound)) - }) + vol, err := c.CreateVolume(context.Background(), req) + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolume()).NotTo(BeNil()) + Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) - It("should fail when the node does not exist", func() { + // ControllerPublishVolume + By("calling controllerpublish on that volume") - // Create Volume First - By("creating a single node writer volume") - name := uniqueString("sanity-controller-wrong-node") - req := &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - { + pubReq := &csi.ControllerPublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + NodeId: "some-fake-node-id", + VolumeCapability: &csi.VolumeCapability{ AccessType: &csi.VolumeCapability_Mount{ Mount: &csi.VolumeCapability_MountVolume{}, }, @@ -889,71 +879,79 @@ var _ = DescribeSanity("ControllerPublishVolume [Controller Server]", func(sc *S Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - }, - } + Readonly: false, + } - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } + if sc.Secrets != nil { + pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret + } - vol, err := c.CreateVolume(context.Background(), req) - Expect(err).NotTo(HaveOccurred()) - Expect(vol).NotTo(BeNil()) - Expect(vol.GetVolume()).NotTo(BeNil()) - Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) + Expect(err).To(HaveOccurred()) + Expect(conpubvol).To(BeNil()) - // ControllerPublishVolume - By("calling controllerpublish on that volume") + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.NotFound)) - pubReq := &csi.ControllerPublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - NodeId: "some-fake-node-id", - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, - }, - }, - Readonly: false, - } + By("cleaning up deleting the volume") - if sc.Secrets != nil { - pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } + delReq := &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + } - conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) - Expect(err).To(HaveOccurred()) - Expect(conpubvol).To(BeNil()) + if sc.Secrets != nil { + delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret + } - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.NotFound)) + _, err = c.DeleteVolume(context.Background(), delReq) + Expect(err).NotTo(HaveOccurred()) + }) - By("cleaning up deleting the volume") + It("should fail when the volume is already published but is incompatible", func() { - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } + // Create Volume First + By("creating a single node writer volume") + name := uniqueString("sanity-controller-published-incompatible") + req := &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, + }, + }, + }, + } - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } + if sc.Secrets != nil { + req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } - _, err = c.DeleteVolume(context.Background(), delReq) - Expect(err).NotTo(HaveOccurred()) - }) + vol, err := c.CreateVolume(context.Background(), req) + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolume()).NotTo(BeNil()) + Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + + By("getting a node id") + nid, err := n.NodeGetId( + context.Background(), + &csi.NodeGetIdRequest{}) + Expect(err).NotTo(HaveOccurred()) + Expect(nid).NotTo(BeNil()) + Expect(nid.GetNodeId()).NotTo(BeEmpty()) - It("should fail when the volume is already published but is incompatible", func() { + // ControllerPublishVolume + By("calling controllerpublish on that volume") - // Create Volume First - By("creating a single node writer volume") - name := uniqueString("sanity-controller-published-incompatible") - req := &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - { + pubReq := &csi.ControllerPublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + NodeId: nid.GetNodeId(), + VolumeCapability: &csi.VolumeCapability{ AccessType: &csi.VolumeCapability_Mount{ Mount: &csi.VolumeCapability_MountVolume{}, }, @@ -961,135 +959,127 @@ var _ = DescribeSanity("ControllerPublishVolume [Controller Server]", func(sc *S Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - }, - } - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol, err := c.CreateVolume(context.Background(), req) - Expect(err).NotTo(HaveOccurred()) - Expect(vol).NotTo(BeNil()) - Expect(vol.GetVolume()).NotTo(BeNil()) - Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + Readonly: false, + } - By("getting a node id") - nid, err := n.NodeGetId( - context.Background(), - &csi.NodeGetIdRequest{}) - Expect(err).NotTo(HaveOccurred()) - Expect(nid).NotTo(BeNil()) - Expect(nid.GetNodeId()).NotTo(BeEmpty()) + if sc.Secrets != nil { + pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret + } - // ControllerPublishVolume - By("calling controllerpublish on that volume") + conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) + Expect(err).NotTo(HaveOccurred()) + Expect(conpubvol).NotTo(BeNil()) - pubReq := &csi.ControllerPublishVolumeRequest{ - VolumeId: vol.GetVolume().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, - } + // Publish again with different attributes. + pubReq.Readonly = true - if sc.Secrets != nil { - pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } + conpubvol, err = c.ControllerPublishVolume(context.Background(), pubReq) + Expect(err).To(HaveOccurred()) + Expect(conpubvol).To(BeNil()) - conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) - Expect(err).NotTo(HaveOccurred()) - Expect(conpubvol).NotTo(BeNil()) + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.AlreadyExists)) - // Publish again with different attributes. - pubReq.Readonly = true + By("cleaning up unpublishing the volume") - conpubvol, err = c.ControllerPublishVolume(context.Background(), pubReq) - Expect(err).To(HaveOccurred()) - Expect(conpubvol).To(BeNil()) + unpubReq := &csi.ControllerUnpublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + // NodeID is optional in ControllerUnpublishVolume + NodeId: nid.GetNodeId(), + } - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.AlreadyExists)) + if sc.Secrets != nil { + unpubReq.ControllerUnpublishSecrets = sc.Secrets.ControllerUnpublishVolumeSecret + } - By("cleaning up unpublishing the volume") + conunpubvol, err := c.ControllerUnpublishVolume(context.Background(), unpubReq) + Expect(err).NotTo(HaveOccurred()) + Expect(conunpubvol).NotTo(BeNil()) - unpubReq := &csi.ControllerUnpublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - // NodeID is optional in ControllerUnpublishVolume - NodeId: nid.GetNodeId(), - } + By("cleaning up deleting the volume") - if sc.Secrets != nil { - unpubReq.ControllerUnpublishSecrets = sc.Secrets.ControllerUnpublishVolumeSecret - } + delReq := &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + } - conunpubvol, err := c.ControllerUnpublishVolume(context.Background(), unpubReq) - Expect(err).NotTo(HaveOccurred()) - Expect(conunpubvol).NotTo(BeNil()) + if sc.Secrets != nil { + delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret + } - By("cleaning up deleting the volume") + _, err = c.DeleteVolume(context.Background(), delReq) + Expect(err).NotTo(HaveOccurred()) + }) + }) - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } + Describe("ControllerUnpublishVolume", func() { + BeforeEach(func() { + if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) { + Skip("ControllerUnpublishVolume not supported") + } + }) - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } + It("should fail when no volume id is provided", func() { - _, err = c.DeleteVolume(context.Background(), delReq) - Expect(err).NotTo(HaveOccurred()) - }) -}) + req := &csi.ControllerUnpublishVolumeRequest{} -var _ = DescribeSanity("ControllerUnpublishVolume [Controller Server]", func(sc *SanityContext) { - var ( - c csi.ControllerClient - n csi.NodeClient - ) + if sc.Secrets != nil { + req.ControllerUnpublishSecrets = sc.Secrets.ControllerUnpublishVolumeSecret + } - BeforeEach(func() { - c = csi.NewControllerClient(sc.Conn) - n = csi.NewNodeClient(sc.Conn) + _, err := c.ControllerUnpublishVolume(context.Background(), req) + Expect(err).To(HaveOccurred()) - if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) { - Skip("ControllerUnpublishVolume not supported") - } - }) + 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() { + It("should return appropriate values (no optional values added)", func() { - req := &csi.ControllerUnpublishVolumeRequest{} + // Create Volume First + By("creating a single node writer volume") + name := uniqueString("sanity-controller-unpublish") - if sc.Secrets != nil { - req.ControllerUnpublishSecrets = sc.Secrets.ControllerUnpublishVolumeSecret - } + req := &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, + }, + }, + }, + } - _, err := c.ControllerUnpublishVolume(context.Background(), req) - Expect(err).To(HaveOccurred()) + if sc.Secrets != nil { + req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret + } - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) - }) + vol, err := c.CreateVolume(context.Background(), req) + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolume()).NotTo(BeNil()) + Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) - It("should return appropriate values (no optional values added)", func() { + By("getting a node id") + nid, err := n.NodeGetId( + context.Background(), + &csi.NodeGetIdRequest{}) + Expect(err).NotTo(HaveOccurred()) + Expect(nid).NotTo(BeNil()) + Expect(nid.GetNodeId()).NotTo(BeEmpty()) - // Create Volume First - By("creating a single node writer volume") - name := uniqueString("sanity-controller-unpublish") + // ControllerPublishVolume + By("calling controllerpublish on that volume") - req := &csi.CreateVolumeRequest{ - Name: name, - VolumeCapabilities: []*csi.VolumeCapability{ - { + pubReq := &csi.ControllerPublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + NodeId: nid.GetNodeId(), + VolumeCapability: &csi.VolumeCapability{ AccessType: &csi.VolumeCapability_Mount{ Mount: &csi.VolumeCapability_MountVolume{}, }, @@ -1097,81 +1087,47 @@ var _ = DescribeSanity("ControllerUnpublishVolume [Controller Server]", func(sc Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - }, - } - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol, err := c.CreateVolume(context.Background(), req) - Expect(err).NotTo(HaveOccurred()) - Expect(vol).NotTo(BeNil()) - Expect(vol.GetVolume()).NotTo(BeNil()) - Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) - - By("getting a node id") - nid, err := n.NodeGetId( - context.Background(), - &csi.NodeGetIdRequest{}) - Expect(err).NotTo(HaveOccurred()) - Expect(nid).NotTo(BeNil()) - Expect(nid.GetNodeId()).NotTo(BeEmpty()) - - // ControllerPublishVolume - By("calling controllerpublish on that volume") - - pubReq := &csi.ControllerPublishVolumeRequest{ - VolumeId: vol.GetVolume().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, - } + Readonly: false, + } - if sc.Secrets != nil { - pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } + if sc.Secrets != nil { + pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret + } - conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) - Expect(err).NotTo(HaveOccurred()) - Expect(conpubvol).NotTo(BeNil()) + conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) + Expect(err).NotTo(HaveOccurred()) + Expect(conpubvol).NotTo(BeNil()) - // ControllerUnpublishVolume - By("calling controllerunpublish on that volume") + // ControllerUnpublishVolume + By("calling controllerunpublish on that volume") - unpubReq := &csi.ControllerUnpublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - // NodeID is optional in ControllerUnpublishVolume - NodeId: nid.GetNodeId(), - } + unpubReq := &csi.ControllerUnpublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + // NodeID is optional in ControllerUnpublishVolume + NodeId: nid.GetNodeId(), + } - if sc.Secrets != nil { - unpubReq.ControllerUnpublishSecrets = sc.Secrets.ControllerUnpublishVolumeSecret - } + if sc.Secrets != nil { + unpubReq.ControllerUnpublishSecrets = sc.Secrets.ControllerUnpublishVolumeSecret + } - conunpubvol, err := c.ControllerUnpublishVolume(context.Background(), unpubReq) - Expect(err).NotTo(HaveOccurred()) - Expect(conunpubvol).NotTo(BeNil()) + conunpubvol, err := c.ControllerUnpublishVolume(context.Background(), unpubReq) + Expect(err).NotTo(HaveOccurred()) + Expect(conunpubvol).NotTo(BeNil()) - By("cleaning up deleting the volume") + By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } + delReq := &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + } - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } + if sc.Secrets != nil { + delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret + } - _, err = c.DeleteVolume(context.Background(), delReq) - Expect(err).NotTo(HaveOccurred()) + _, err = c.DeleteVolume(context.Background(), delReq) + Expect(err).NotTo(HaveOccurred()) + }) }) }) diff --git a/pkg/sanity/identity.go b/pkg/sanity/identity.go index 2d3e1e3e..8c826a7a 100644 --- a/pkg/sanity/identity.go +++ b/pkg/sanity/identity.go @@ -30,7 +30,7 @@ import ( . "github.com/onsi/gomega" ) -var _ = DescribeSanity("GetPluginCapabilities [Identity Service]", func(sc *SanityContext) { +var _ = DescribeSanity("Identity Service", func(sc *SanityContext) { var ( c csi.IdentityClient ) @@ -39,75 +39,61 @@ var _ = DescribeSanity("GetPluginCapabilities [Identity Service]", func(sc *Sani c = csi.NewIdentityClient(sc.Conn) }) - It("should return appropriate capabilities", func() { - req := &csi.GetPluginCapabilitiesRequest{} - res, err := c.GetPluginCapabilities(context.Background(), req) - Expect(err).NotTo(HaveOccurred()) - Expect(res).NotTo(BeNil()) - - By("checking successful response") - Expect(res.GetCapabilities()).NotTo(BeNil()) - for _, cap := range res.GetCapabilities() { - switch cap.GetService().GetType() { - case csi.PluginCapability_Service_CONTROLLER_SERVICE: - case csi.PluginCapability_Service_ACCESSIBILITY_CONSTRAINTS: - default: - Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetService().GetType())) + Describe("GetPluginCapabilities", func() { + It("should return appropriate capabilities", func() { + req := &csi.GetPluginCapabilitiesRequest{} + res, err := c.GetPluginCapabilities(context.Background(), req) + Expect(err).NotTo(HaveOccurred()) + Expect(res).NotTo(BeNil()) + + By("checking successful response") + Expect(res.GetCapabilities()).NotTo(BeNil()) + for _, cap := range res.GetCapabilities() { + switch cap.GetService().GetType() { + case csi.PluginCapability_Service_CONTROLLER_SERVICE: + case csi.PluginCapability_Service_ACCESSIBILITY_CONSTRAINTS: + default: + Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetService().GetType())) + } } - } - }) - -}) - -var _ = DescribeSanity("Probe [Identity Service]", func(sc *SanityContext) { - var ( - c csi.IdentityClient - ) + }) - BeforeEach(func() { - c = csi.NewIdentityClient(sc.Conn) }) - It("should return appropriate information", func() { - req := &csi.ProbeRequest{} - res, err := c.Probe(context.Background(), req) - Expect(err).NotTo(HaveOccurred()) - Expect(res).NotTo(BeNil()) - - By("verifying return status") - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code() == codes.FailedPrecondition || - serverError.Code() == codes.OK).To(BeTrue()) - - if res.GetReady() != nil { - Expect(res.GetReady().GetValue() == true || - res.GetReady().GetValue() == false).To(BeTrue()) - } - }) -}) - -var _ = DescribeSanity("GetPluginInfo [Identity Server]", func(sc *SanityContext) { - var ( - c csi.IdentityClient - ) - - BeforeEach(func() { - c = csi.NewIdentityClient(sc.Conn) + Describe("Probe", func() { + It("should return appropriate information", func() { + req := &csi.ProbeRequest{} + res, err := c.Probe(context.Background(), req) + Expect(err).NotTo(HaveOccurred()) + Expect(res).NotTo(BeNil()) + + By("verifying return status") + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code() == codes.FailedPrecondition || + serverError.Code() == codes.OK).To(BeTrue()) + + if res.GetReady() != nil { + Expect(res.GetReady().GetValue() == true || + res.GetReady().GetValue() == false).To(BeTrue()) + } + }) }) - It("should return appropriate information", func() { - req := &csi.GetPluginInfoRequest{} - res, err := c.GetPluginInfo(context.Background(), req) - Expect(err).NotTo(HaveOccurred()) - Expect(res).NotTo(BeNil()) - - By("verifying name size and characters") - Expect(res.GetName()).ToNot(HaveLen(0)) - Expect(len(res.GetName())).To(BeNumerically("<=", 63)) - Expect(regexp. - MustCompile("^[a-zA-Z][A-Za-z0-9-\\.\\_]{0,61}[a-zA-Z]$"). - MatchString(res.GetName())).To(BeTrue()) + Describe("GetPluginInfo", func() { + It("should return appropriate information", func() { + req := &csi.GetPluginInfoRequest{} + res, err := c.GetPluginInfo(context.Background(), req) + Expect(err).NotTo(HaveOccurred()) + Expect(res).NotTo(BeNil()) + + By("verifying name size and characters") + Expect(res.GetName()).ToNot(HaveLen(0)) + Expect(len(res.GetName())).To(BeNumerically("<=", 63)) + Expect(regexp. + MustCompile("^[a-zA-Z][A-Za-z0-9-\\.\\_]{0,61}[a-zA-Z]$"). + MatchString(res.GetName())).To(BeTrue()) + }) }) }) diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index 536d217a..4e562313 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -68,216 +68,337 @@ func isPluginCapabilitySupported(c csi.IdentityClient, return false } -var _ = DescribeSanity("NodeGetCapabilities [Node Server]", func(sc *SanityContext) { +var _ = DescribeSanity("Node Service", func(sc *SanityContext) { var ( c csi.NodeClient + s csi.ControllerClient + + controllerPublishSupported bool + nodeStageSupported bool ) BeforeEach(func() { c = csi.NewNodeClient(sc.Conn) + s = csi.NewControllerClient(sc.Conn) + + controllerPublishSupported = isControllerCapabilitySupported( + s, + csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) + nodeStageSupported = isNodeCapabilitySupported(c, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME) }) - It("should return appropriate capabilities", func() { - caps, err := c.NodeGetCapabilities( - context.Background(), - &csi.NodeGetCapabilitiesRequest{}) + Describe("NodeGetCapabilities", func() { + It("should return appropriate capabilities", func() { + caps, err := c.NodeGetCapabilities( + context.Background(), + &csi.NodeGetCapabilitiesRequest{}) - By("checking successful response") - Expect(err).NotTo(HaveOccurred()) - Expect(caps).NotTo(BeNil()) + By("checking successful response") + Expect(err).NotTo(HaveOccurred()) + Expect(caps).NotTo(BeNil()) - for _, cap := range caps.GetCapabilities() { - Expect(cap.GetRpc()).NotTo(BeNil()) + for _, cap := range caps.GetCapabilities() { + Expect(cap.GetRpc()).NotTo(BeNil()) - switch cap.GetRpc().GetType() { - case csi.NodeServiceCapability_RPC_UNKNOWN: - case csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME: - default: - Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetRpc().GetType())) + switch cap.GetRpc().GetType() { + case csi.NodeServiceCapability_RPC_UNKNOWN: + case csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME: + default: + Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetRpc().GetType())) + } } - } + }) }) -}) -var _ = DescribeSanity("NodeGetId [Node Server]", func(sc *SanityContext) { - var ( - c csi.NodeClient - ) + Describe("NodeGetId", func() { + It("should return appropriate values", func() { + nid, err := c.NodeGetId( + context.Background(), + &csi.NodeGetIdRequest{}) - BeforeEach(func() { - c = csi.NewNodeClient(sc.Conn) + Expect(err).NotTo(HaveOccurred()) + Expect(nid).NotTo(BeNil()) + Expect(nid.GetNodeId()).NotTo(BeEmpty()) + }) }) - It("should return appropriate values", func() { - nid, err := c.NodeGetId( - context.Background(), - &csi.NodeGetIdRequest{}) + Describe("NodeGetInfo", func() { + var ( + i csi.IdentityClient + accessibilityConstraintSupported bool + ) - Expect(err).NotTo(HaveOccurred()) - Expect(nid).NotTo(BeNil()) - Expect(nid.GetNodeId()).NotTo(BeEmpty()) - }) -}) + BeforeEach(func() { + i = csi.NewIdentityClient(sc.Conn) + accessibilityConstraintSupported = isPluginCapabilitySupported(i, csi.PluginCapability_Service_ACCESSIBILITY_CONSTRAINTS) + }) -var _ = DescribeSanity("NodeGetInfo [Node Server]", func(sc *SanityContext) { - var ( - c csi.NodeClient - i csi.IdentityClient - accessibilityConstraintSupported bool - ) + It("should return approproate values", func() { + ninfo, err := c.NodeGetInfo( + context.Background(), + &csi.NodeGetInfoRequest{}) - BeforeEach(func() { - c = csi.NewNodeClient(sc.Conn) - i = csi.NewIdentityClient(sc.Conn) - accessibilityConstraintSupported = isPluginCapabilitySupported(i, csi.PluginCapability_Service_ACCESSIBILITY_CONSTRAINTS) + Expect(err).NotTo(HaveOccurred()) + Expect(ninfo).NotTo(BeNil()) + Expect(ninfo.GetNodeId()).NotTo(BeEmpty()) + Expect(ninfo.GetMaxVolumesPerNode()).NotTo(BeNumerically("<", 0)) + + if accessibilityConstraintSupported { + Expect(ninfo.GetAccessibleTopology()).NotTo(BeNil()) + } + }) }) - It("should return approproate values", func() { - ninfo, err := c.NodeGetInfo( - context.Background(), - &csi.NodeGetInfoRequest{}) + Describe("NodePublishVolume", func() { + BeforeEach(func() { + if nodeStageSupported { + err := createMountTargetLocation(sc.Config.StagingPath) + Expect(err).NotTo(HaveOccurred()) + } + }) - Expect(err).NotTo(HaveOccurred()) - Expect(ninfo).NotTo(BeNil()) - Expect(ninfo.GetNodeId()).NotTo(BeEmpty()) - Expect(ninfo.GetMaxVolumesPerNode()).NotTo(BeNumerically("<", 0)) + It("should fail when no volume id is provided", func() { - if accessibilityConstraintSupported { - Expect(ninfo.GetAccessibleTopology()).NotTo(BeNil()) - } - }) -}) + req := &csi.NodePublishVolumeRequest{} -var _ = DescribeSanity("NodePublishVolume [Node Server]", func(sc *SanityContext) { - var ( - s csi.ControllerClient - c csi.NodeClient - controllerPublishSupported bool - nodeStageSupported bool - ) + if sc.Secrets != nil { + req.NodePublishSecrets = sc.Secrets.NodePublishVolumeSecret + } - BeforeEach(func() { - s = csi.NewControllerClient(sc.Conn) - c = csi.NewNodeClient(sc.Conn) - controllerPublishSupported = isControllerCapabilitySupported( - s, - csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) - nodeStageSupported = isNodeCapabilitySupported(c, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME) - if nodeStageSupported { - err := createMountTargetLocation(sc.Config.StagingPath) - Expect(err).NotTo(HaveOccurred()) - } - }) + _, err := c.NodePublishVolume(context.Background(), req) + Expect(err).To(HaveOccurred()) - It("should fail when no volume id is provided", func() { + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) - req := &csi.NodePublishVolumeRequest{} + It("should fail when no target path is provided", func() { - if sc.Secrets != nil { - req.NodePublishSecrets = sc.Secrets.NodePublishVolumeSecret - } + req := &csi.NodePublishVolumeRequest{ + VolumeId: "id", + } - _, err := c.NodePublishVolume(context.Background(), req) - Expect(err).To(HaveOccurred()) + if sc.Secrets != nil { + req.NodePublishSecrets = sc.Secrets.NodePublishVolumeSecret + } - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) - }) + _, err := c.NodePublishVolume(context.Background(), req) + Expect(err).To(HaveOccurred()) - It("should fail when no target path is provided", func() { + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) - req := &csi.NodePublishVolumeRequest{ - VolumeId: "id", - } + It("should fail when no volume capability is provided", func() { - if sc.Secrets != nil { - req.NodePublishSecrets = sc.Secrets.NodePublishVolumeSecret - } + req := &csi.NodePublishVolumeRequest{ + VolumeId: "id", + TargetPath: sc.Config.TargetPath, + } - _, err := c.NodePublishVolume(context.Background(), req) - Expect(err).To(HaveOccurred()) + if sc.Secrets != nil { + req.NodePublishSecrets = sc.Secrets.NodePublishVolumeSecret + } + + _, err := c.NodePublishVolume(context.Background(), req) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) - 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() { + name := uniqueString("sanity-node-publish") + testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) + }) }) - It("should fail when no volume capability is provided", func() { + Describe("NodeUnpublishVolume", func() { + BeforeEach(func() { + if nodeStageSupported { + err := createMountTargetLocation(sc.Config.StagingPath) + Expect(err).NotTo(HaveOccurred()) + } + }) - req := &csi.NodePublishVolumeRequest{ - VolumeId: "id", - TargetPath: sc.Config.TargetPath, - } + It("should fail when no volume id is provided", func() { - if sc.Secrets != nil { - req.NodePublishSecrets = sc.Secrets.NodePublishVolumeSecret - } + _, err := c.NodeUnpublishVolume( + context.Background(), + &csi.NodeUnpublishVolumeRequest{}) + Expect(err).To(HaveOccurred()) - _, err := c.NodePublishVolume(context.Background(), req) - Expect(err).To(HaveOccurred()) + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) - serverError, ok := status.FromError(err) - Expect(ok).To(BeTrue()) - Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) - }) + It("should fail when no target path is provided", func() { - It("should return appropriate values (no optional values added)", func() { - name := uniqueString("sanity-node-publish") - testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) - }) -}) + _, err := c.NodeUnpublishVolume( + context.Background(), + &csi.NodeUnpublishVolumeRequest{ + VolumeId: "id", + }) + Expect(err).To(HaveOccurred()) -var _ = DescribeSanity("NodeUnpublishVolume [Node Server]", func(sc *SanityContext) { - var ( - s csi.ControllerClient - c csi.NodeClient - controllerPublishSupported bool - nodeStageSupported bool - ) + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) - BeforeEach(func() { - s = csi.NewControllerClient(sc.Conn) - c = csi.NewNodeClient(sc.Conn) - controllerPublishSupported = isControllerCapabilitySupported( - s, - csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) - nodeStageSupported = isNodeCapabilitySupported(c, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME) - if nodeStageSupported { - err := createMountTargetLocation(sc.Config.StagingPath) - Expect(err).NotTo(HaveOccurred()) - } + It("should return appropriate values (no optional values added)", func() { + name := uniqueString("sanity-node-unpublish") + testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) + }) }) - It("should fail when no volume id is provided", func() { + Describe("NodeStageVolume", func() { + var ( + device string + ) - _, err := c.NodeUnpublishVolume( - context.Background(), - &csi.NodeUnpublishVolumeRequest{}) - Expect(err).To(HaveOccurred()) + BeforeEach(func() { + device = "/dev/mock" + if nodeStageSupported { + err := createMountTargetLocation(sc.Config.StagingPath) + Expect(err).NotTo(HaveOccurred()) + } else { + Skip("NodeStageVolume not supported") + } + }) - 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() { - It("should fail when no target path is provided", func() { + req := &csi.NodeStageVolumeRequest{ + StagingTargetPath: sc.Config.StagingPath, + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + PublishInfo: map[string]string{ + "device": device, + }, + } - _, err := c.NodeUnpublishVolume( - context.Background(), - &csi.NodeUnpublishVolumeRequest{ + if sc.Secrets != nil { + req.NodeStageSecrets = sc.Secrets.NodeStageVolumeSecret + } + + _, err := c.NodeStageVolume(context.Background(), req) + 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 staging target path is provided", func() { + + req := &csi.NodeStageVolumeRequest{ VolumeId: "id", - }) - Expect(err).To(HaveOccurred()) + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + PublishInfo: map[string]string{ + "device": device, + }, + } + + if sc.Secrets != nil { + req.NodeStageSecrets = sc.Secrets.NodeStageVolumeSecret + } + + _, err := c.NodeStageVolume(context.Background(), req) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) - 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() { + + req := &csi.NodeStageVolumeRequest{ + VolumeId: "id", + StagingTargetPath: sc.Config.StagingPath, + PublishInfo: map[string]string{ + "device": device, + }, + } + + if sc.Secrets != nil { + req.NodeStageSecrets = sc.Secrets.NodeStageVolumeSecret + } + + _, err := c.NodeStageVolume(context.Background(), req) + 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() { + name := uniqueString("sanity-node-stage") + testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) + }) }) - It("should return appropriate values (no optional values added)", func() { - name := uniqueString("sanity-node-unpublish") - testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) + Describe("NodeUnstageVolume", func() { + BeforeEach(func() { + if nodeStageSupported { + err := createMountTargetLocation(sc.Config.StagingPath) + Expect(err).NotTo(HaveOccurred()) + } else { + Skip("NodeUnstageVolume not supported") + } + }) + + It("should fail when no volume id is provided", func() { + + _, err := c.NodeUnstageVolume( + context.Background(), + &csi.NodeUnstageVolumeRequest{ + StagingTargetPath: sc.Config.StagingPath, + }) + 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 staging target path is provided", func() { + + _, err := c.NodeUnstageVolume( + context.Background(), + &csi.NodeUnstageVolumeRequest{ + VolumeId: "id", + }) + 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() { + name := uniqueString("sanity-node-unstage") + testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) + }) }) }) @@ -452,171 +573,3 @@ func testFullWorkflowSuccess(sc *SanityContext, s csi.ControllerClient, c csi.No _, err = s.DeleteVolume(context.Background(), delReq) Expect(err).NotTo(HaveOccurred()) } - -var _ = DescribeSanity("NodeStageVolume [Node Server]", func(sc *SanityContext) { - var ( - s csi.ControllerClient - c csi.NodeClient - controllerPublishSupported bool - nodeStageSupported bool - device string - ) - - BeforeEach(func() { - s = csi.NewControllerClient(sc.Conn) - c = csi.NewNodeClient(sc.Conn) - device = "/dev/mock" - controllerPublishSupported = isControllerCapabilitySupported( - s, - csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) - nodeStageSupported = isNodeCapabilitySupported(c, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME) - if nodeStageSupported { - err := createMountTargetLocation(sc.Config.StagingPath) - Expect(err).NotTo(HaveOccurred()) - } else { - Skip("NodeStageVolume not supported") - } - }) - - It("should fail when no volume id is provided", func() { - - req := &csi.NodeStageVolumeRequest{ - StagingTargetPath: sc.Config.StagingPath, - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, - }, - }, - PublishInfo: map[string]string{ - "device": device, - }, - } - - if sc.Secrets != nil { - req.NodeStageSecrets = sc.Secrets.NodeStageVolumeSecret - } - - _, err := c.NodeStageVolume(context.Background(), req) - 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 staging target path is provided", func() { - - req := &csi.NodeStageVolumeRequest{ - VolumeId: "id", - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, - }, - }, - PublishInfo: map[string]string{ - "device": device, - }, - } - - if sc.Secrets != nil { - req.NodeStageSecrets = sc.Secrets.NodeStageVolumeSecret - } - - _, err := c.NodeStageVolume(context.Background(), req) - 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() { - - req := &csi.NodeStageVolumeRequest{ - VolumeId: "id", - StagingTargetPath: sc.Config.StagingPath, - PublishInfo: map[string]string{ - "device": device, - }, - } - - if sc.Secrets != nil { - req.NodeStageSecrets = sc.Secrets.NodeStageVolumeSecret - } - - _, err := c.NodeStageVolume(context.Background(), req) - 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() { - name := uniqueString("sanity-node-stage") - testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) - }) -}) - -var _ = DescribeSanity("NodeUnstageVolume [Node Server]", func(sc *SanityContext) { - var ( - s csi.ControllerClient - c csi.NodeClient - controllerPublishSupported bool - nodeStageSupported bool - ) - - BeforeEach(func() { - s = csi.NewControllerClient(sc.Conn) - c = csi.NewNodeClient(sc.Conn) - controllerPublishSupported = isControllerCapabilitySupported( - s, - csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) - nodeStageSupported = isNodeCapabilitySupported(c, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME) - if nodeStageSupported { - err := createMountTargetLocation(sc.Config.StagingPath) - Expect(err).NotTo(HaveOccurred()) - } else { - Skip("NodeUnstageVolume not supported") - } - }) - - It("should fail when no volume id is provided", func() { - - _, err := c.NodeUnstageVolume( - context.Background(), - &csi.NodeUnstageVolumeRequest{ - StagingTargetPath: sc.Config.StagingPath, - }) - 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 staging target path is provided", func() { - - _, err := c.NodeUnstageVolume( - context.Background(), - &csi.NodeUnstageVolumeRequest{ - VolumeId: "id", - }) - 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() { - name := uniqueString("sanity-node-unstage") - testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) - }) -}) From e67e163f98a365935ee578b94d31533e35095988 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 10 Jul 2018 18:07:39 +0200 Subject: [PATCH 03/10] pkg/sanity: avoid running the same test four times The full workflow test was done four times under different names. That's unnecessary and potentially confusing. Now it gets run once alongside the more specific function tests. --- pkg/sanity/node.go | 54 +++++++++++----------------------------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index 4e562313..25ed606d 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -85,6 +85,10 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { s, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) nodeStageSupported = isNodeCapabilitySupported(c, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME) + if nodeStageSupported { + err := createMountTargetLocation(sc.Config.StagingPath) + Expect(err).NotTo(HaveOccurred()) + } }) Describe("NodeGetCapabilities", func() { @@ -150,13 +154,6 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { }) Describe("NodePublishVolume", func() { - BeforeEach(func() { - if nodeStageSupported { - err := createMountTargetLocation(sc.Config.StagingPath) - Expect(err).NotTo(HaveOccurred()) - } - }) - It("should fail when no volume id is provided", func() { req := &csi.NodePublishVolumeRequest{} @@ -209,21 +206,9 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { Expect(ok).To(BeTrue()) Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) }) - - It("should return appropriate values (no optional values added)", func() { - name := uniqueString("sanity-node-publish") - testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) - }) }) Describe("NodeUnpublishVolume", func() { - BeforeEach(func() { - if nodeStageSupported { - err := createMountTargetLocation(sc.Config.StagingPath) - Expect(err).NotTo(HaveOccurred()) - } - }) - It("should fail when no volume id is provided", func() { _, err := c.NodeUnpublishVolume( @@ -249,11 +234,6 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { Expect(ok).To(BeTrue()) Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) }) - - It("should return appropriate values (no optional values added)", func() { - name := uniqueString("sanity-node-unpublish") - testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) - }) }) Describe("NodeStageVolume", func() { @@ -262,13 +242,11 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { ) BeforeEach(func() { - device = "/dev/mock" - if nodeStageSupported { - err := createMountTargetLocation(sc.Config.StagingPath) - Expect(err).NotTo(HaveOccurred()) - } else { + if !nodeStageSupported { Skip("NodeStageVolume not supported") } + + device = "/dev/mock" }) It("should fail when no volume id is provided", func() { @@ -350,19 +328,11 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { Expect(ok).To(BeTrue()) Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) }) - - It("should return appropriate values (no optional values added)", func() { - name := uniqueString("sanity-node-stage") - testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) - }) }) Describe("NodeUnstageVolume", func() { BeforeEach(func() { - if nodeStageSupported { - err := createMountTargetLocation(sc.Config.StagingPath) - Expect(err).NotTo(HaveOccurred()) - } else { + if !nodeStageSupported { Skip("NodeUnstageVolume not supported") } }) @@ -394,11 +364,11 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { Expect(ok).To(BeTrue()) Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) }) + }) - It("should return appropriate values (no optional values added)", func() { - name := uniqueString("sanity-node-unstage") - testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) - }) + It("should work", func() { + name := uniqueString("sanity-node-full") + testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) }) }) From 2fdc9c87148f7577e7f477272a8acf2aceff6789 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 11 Jul 2018 14:33:16 +0200 Subject: [PATCH 04/10] pkg/sanity: avoid if check around GetPublishInfo GetPublishInfo returns nil when called for a nil ControllerPublishVolumeResponse, therefore the if check is redundant. Always setting PublishInfo is another step towards inlining the parameter constructions. --- pkg/sanity/node.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index 25ed606d..8385cd9f 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -449,9 +449,7 @@ func testFullWorkflowSuccess(sc *SanityContext, s csi.ControllerClient, c csi.No }, StagingTargetPath: sc.Config.StagingPath, VolumeAttributes: vol.GetVolume().GetAttributes(), - } - if controllerPublishSupported { - nodeStageVolReq.PublishInfo = conpubvol.GetPublishInfo() + PublishInfo: conpubvol.GetPublishInfo(), } if sc.Secrets != nil { nodeStageVolReq.NodeStageSecrets = sc.Secrets.NodeStageVolumeSecret @@ -475,13 +473,11 @@ func testFullWorkflowSuccess(sc *SanityContext, s csi.ControllerClient, c csi.No }, }, VolumeAttributes: vol.GetVolume().GetAttributes(), + PublishInfo: conpubvol.GetPublishInfo(), } if nodeStageSupported { nodepubvolRequest.StagingTargetPath = sc.Config.StagingPath } - if controllerPublishSupported { - nodepubvolRequest.PublishInfo = conpubvol.GetPublishInfo() - } if sc.Secrets != nil { nodepubvolRequest.NodePublishSecrets = sc.Secrets.NodePublishVolumeSecret } From 810850082c106c0cc871892a2188d826ca72ecca Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 11 Jul 2018 14:12:34 +0200 Subject: [PATCH 05/10] pkg/sanity: avoid if checks around secrets By ensuring that we always have a valid CSISecrets, even if it only contains nil pointers, we can get rid of all the "if != nil" checks and the separate construction of the parameter structure. --- pkg/sanity/controller.go | 872 ++++++++++++++++++--------------------- pkg/sanity/node.go | 309 +++++++------- pkg/sanity/sanity.go | 2 + 3 files changed, 545 insertions(+), 638 deletions(-) diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index 21edb8b9..ae8bcc1d 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -167,14 +167,12 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }) It("should fail when no name is provided", func() { - - req := &csi.CreateVolumeRequest{} - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - _, err := c.CreateVolume(context.Background(), req) + _, err := c.CreateVolume( + context.Background(), + &csi.CreateVolumeRequest{ + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, + }, + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -183,16 +181,13 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }) It("should fail when no volume capabilities are provided", func() { - - req := &csi.CreateVolumeRequest{ - Name: "name", - } - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - _, err := c.CreateVolume(context.Background(), req) + _, err := c.CreateVolume( + context.Background(), + &csi.CreateVolumeRequest{ + Name: "name", + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, + }, + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -205,25 +200,23 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { By("creating a volume") name := uniqueString("sanity-controller-create-single-no-capacity") - req := &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, + vol, err := c.CreateVolume( + 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, + }, }, }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - } - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol, err := c.CreateVolume(context.Background(), req) + ) Expect(err).NotTo(HaveOccurred()) Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) @@ -231,15 +224,13 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } - - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } - - _, err = c.DeleteVolume(context.Background(), delReq) + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) }) @@ -248,28 +239,26 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { By("creating a volume") name := uniqueString("sanity-controller-create-single-with-capacity") - req := &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, + vol, err := c.CreateVolume( + 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, + }, }, }, + CapacityRange: &csi.CapacityRange{ + RequiredBytes: TestVolumeSize(sc), + }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: TestVolumeSize(sc), - }, - } - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol, err := c.CreateVolume(context.Background(), req) + ) if serverError, ok := status.FromError(err); ok { if serverError.Code() == codes.OutOfRange || serverError.Code() == codes.Unimplemented { Skip("Required bytes not supported") @@ -286,15 +275,13 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { } By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } - - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } - - _, err = c.DeleteVolume(context.Background(), delReq) + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) }) It("should not fail when requesting to create a volume with already exisiting name and same capacity.", func() { @@ -303,56 +290,52 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { name := uniqueString("sanity-controller-create-twice") size := TestVolumeSize(sc) - req := &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, + vol1, err := c.CreateVolume( + 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, + }, }, }, + CapacityRange: &csi.CapacityRange{ + RequiredBytes: size, + }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: size, - }, - } - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol1, err := c.CreateVolume(context.Background(), req) + ) Expect(err).NotTo(HaveOccurred()) Expect(vol1).NotTo(BeNil()) Expect(vol1.GetVolume()).NotTo(BeNil()) Expect(vol1.GetVolume().GetId()).NotTo(BeEmpty()) Expect(vol1.GetVolume().GetCapacityBytes()).To(BeNumerically(">=", size)) - req2 := &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, + vol2, err := c.CreateVolume( + 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, + }, }, }, + CapacityRange: &csi.CapacityRange{ + RequiredBytes: size, + }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: size, - }, - } - - if sc.Secrets != nil { - req2.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol2, err := c.CreateVolume(context.Background(), req2) + ) Expect(err).NotTo(HaveOccurred()) Expect(vol2).NotTo(BeNil()) Expect(vol2.GetVolume()).NotTo(BeNil()) @@ -362,15 +345,13 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol1.GetVolume().GetId(), - } - - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } - - _, err = c.DeleteVolume(context.Background(), delReq) + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol1.GetVolume().GetId(), + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) }) It("should fail when requesting to create a volume with already exisiting name and different capacity.", func() { @@ -379,58 +360,54 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { name := uniqueString("sanity-controller-create-twice-different") size1 := TestVolumeSize(sc) - req := &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, + vol1, err := c.CreateVolume( + 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, + }, }, }, + CapacityRange: &csi.CapacityRange{ + RequiredBytes: size1, + LimitBytes: size1, + }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: size1, - LimitBytes: size1, - }, - } - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol1, err := c.CreateVolume(context.Background(), req) + ) Expect(err).ToNot(HaveOccurred()) Expect(vol1).NotTo(BeNil()) Expect(vol1.GetVolume()).NotTo(BeNil()) Expect(vol1.GetVolume().GetId()).NotTo(BeEmpty()) size2 := 2 * TestVolumeSize(sc) - req2 := &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, + _, err = c.CreateVolume( + 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, + }, }, }, + CapacityRange: &csi.CapacityRange{ + RequiredBytes: size2, + LimitBytes: size2, + }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - CapacityRange: &csi.CapacityRange{ - RequiredBytes: size2, - LimitBytes: size2, - }, - } - - if sc.Secrets != nil { - req2.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - _, err = c.CreateVolume(context.Background(), req2) + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) Expect(ok).To(BeTrue()) @@ -438,15 +415,13 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol1.GetVolume().GetId(), - } - - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } - - _, err = c.DeleteVolume(context.Background(), delReq) + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol1.GetVolume().GetId(), + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) }) }) @@ -460,13 +435,12 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { It("should fail when no volume id is provided", func() { - req := &csi.DeleteVolumeRequest{} - - if sc.Secrets != nil { - req.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } - - _, err := c.DeleteVolume(context.Background(), req) + _, err := c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -476,15 +450,13 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { It("should succeed when an invalid volume id is used", func() { - req := &csi.DeleteVolumeRequest{ - VolumeId: "reallyfakevolumeid", - } - - if sc.Secrets != nil { - req.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } - - _, err := c.DeleteVolume(context.Background(), req) + _, err := c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: "reallyfakevolumeid", + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) }) @@ -494,26 +466,23 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { By("creating a volume") name := uniqueString("sanity-controller-create-appropriate") - createReq := &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, + vol, err := c.CreateVolume( + 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, + }, }, }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - } - - if sc.Secrets != nil { - createReq.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol, err := c.CreateVolume(context.Background(), createReq) - + ) Expect(err).NotTo(HaveOccurred()) Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) @@ -522,15 +491,13 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { // Delete Volume By("deleting a volume") - req := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } - - if sc.Secrets != nil { - req.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } - - _, err = c.DeleteVolume(context.Background(), req) + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) }) }) @@ -568,25 +535,23 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { By("creating a single node writer volume") name := uniqueString("sanity-controller-validate") - req := &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, + vol, err := c.CreateVolume( + 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, + }, }, }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - } - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol, err := c.CreateVolume(context.Background(), req) + ) Expect(err).NotTo(HaveOccurred()) Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) @@ -615,15 +580,13 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } - - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } - - _, err = c.DeleteVolume(context.Background(), delReq) + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) }) @@ -662,13 +625,12 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { It("should fail when no volume id is provided", func() { - req := &csi.ControllerPublishVolumeRequest{} - - if sc.Secrets != nil { - req.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } - - _, err := c.ControllerPublishVolume(context.Background(), req) + _, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + ControllerPublishSecrets: sc.Secrets.ControllerPublishVolumeSecret, + }, + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -678,15 +640,13 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { It("should fail when no node id is provided", func() { - req := &csi.ControllerPublishVolumeRequest{ - VolumeId: "id", - } - - if sc.Secrets != nil { - req.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } - - _, err := c.ControllerPublishVolume(context.Background(), req) + _, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + VolumeId: "id", + ControllerPublishSecrets: sc.Secrets.ControllerPublishVolumeSecret, + }, + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -696,16 +656,14 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { It("should fail when no volume capability is provided", func() { - req := &csi.ControllerPublishVolumeRequest{ - VolumeId: "id", - NodeId: "fakenode", - } - - if sc.Secrets != nil { - req.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } - - _, err := c.ControllerPublishVolume(context.Background(), req) + _, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + VolumeId: "id", + NodeId: "fakenode", + ControllerPublishSecrets: sc.Secrets.ControllerPublishVolumeSecret, + }, + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -718,25 +676,24 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { // Create Volume First By("creating a single node writer volume") name := uniqueString("sanity-controller-publish") - req := &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, + + vol, err := c.CreateVolume( + 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, + }, }, }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - } - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol, err := c.CreateVolume(context.Background(), req) + ) Expect(err).NotTo(HaveOccurred()) Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) @@ -753,55 +710,49 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { // ControllerPublishVolume By("calling controllerpublish on that volume") - pubReq := &csi.ControllerPublishVolumeRequest{ - VolumeId: vol.GetVolume().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, + conpubvol, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + VolumeId: vol.GetVolume().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, + ControllerPublishSecrets: sc.Secrets.ControllerPublishVolumeSecret, }, - Readonly: false, - } - - if sc.Secrets != nil { - pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } - - conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) + ) Expect(err).NotTo(HaveOccurred()) Expect(conpubvol).NotTo(BeNil()) By("cleaning up unpublishing the volume") - unpubReq := &csi.ControllerUnpublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - // NodeID is optional in ControllerUnpublishVolume - NodeId: nid.GetNodeId(), - } - - if sc.Secrets != nil { - unpubReq.ControllerUnpublishSecrets = sc.Secrets.ControllerUnpublishVolumeSecret - } - - conunpubvol, err := c.ControllerUnpublishVolume(context.Background(), unpubReq) + conunpubvol, err := c.ControllerUnpublishVolume( + context.Background(), + &csi.ControllerUnpublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + // NodeID is optional in ControllerUnpublishVolume + NodeId: nid.GetNodeId(), + ControllerUnpublishSecrets: sc.Secrets.ControllerUnpublishVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) Expect(conunpubvol).NotTo(BeNil()) By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } - - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } - - _, err = c.DeleteVolume(context.Background(), delReq) + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) }) @@ -809,25 +760,23 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { By("calling controller publish on a non-existent volume") - pubReq := &csi.ControllerPublishVolumeRequest{ - VolumeId: "some-vol-id", - NodeId: "some-node-id", - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + conpubvol, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + VolumeId: "some-vol-id", + NodeId: "some-node-id", + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, }, + Readonly: false, + ControllerPublishSecrets: sc.Secrets.ControllerPublishVolumeSecret, }, - Readonly: false, - } - - if sc.Secrets != nil { - pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } - - conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) + ) Expect(err).To(HaveOccurred()) Expect(conpubvol).To(BeNil()) @@ -841,25 +790,24 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { // Create Volume First By("creating a single node writer volume") name := uniqueString("sanity-controller-wrong-node") - req := &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, + + vol, err := c.CreateVolume( + 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, + }, }, }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - } - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol, err := c.CreateVolume(context.Background(), req) + ) Expect(err).NotTo(HaveOccurred()) Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) @@ -868,25 +816,23 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { // ControllerPublishVolume By("calling controllerpublish on that volume") - pubReq := &csi.ControllerPublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - NodeId: "some-fake-node-id", - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + conpubvol, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + NodeId: "some-fake-node-id", + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, }, + Readonly: false, + ControllerPublishSecrets: sc.Secrets.ControllerPublishVolumeSecret, }, - Readonly: false, - } - - if sc.Secrets != nil { - pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } - - conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) + ) Expect(err).To(HaveOccurred()) Expect(conpubvol).To(BeNil()) @@ -896,15 +842,13 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } - - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } - - _, err = c.DeleteVolume(context.Background(), delReq) + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) }) @@ -913,25 +857,24 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { // Create Volume First By("creating a single node writer volume") name := uniqueString("sanity-controller-published-incompatible") - req := &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, + + vol, err := c.CreateVolume( + 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, + }, }, }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - } - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol, err := c.CreateVolume(context.Background(), req) + ) Expect(err).NotTo(HaveOccurred()) Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) @@ -959,11 +902,8 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - Readonly: false, - } - - if sc.Secrets != nil { - pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret + Readonly: false, + ControllerPublishSecrets: sc.Secrets.ControllerPublishVolumeSecret, } conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) @@ -983,31 +923,28 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { By("cleaning up unpublishing the volume") - unpubReq := &csi.ControllerUnpublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - // NodeID is optional in ControllerUnpublishVolume - NodeId: nid.GetNodeId(), - } - - if sc.Secrets != nil { - unpubReq.ControllerUnpublishSecrets = sc.Secrets.ControllerUnpublishVolumeSecret - } + conunpubvol, err := c.ControllerUnpublishVolume( + context.Background(), + &csi.ControllerUnpublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + // NodeID is optional in ControllerUnpublishVolume + NodeId: nid.GetNodeId(), + ControllerUnpublishSecrets: sc.Secrets.ControllerUnpublishVolumeSecret, + }, + ) - conunpubvol, err := c.ControllerUnpublishVolume(context.Background(), unpubReq) Expect(err).NotTo(HaveOccurred()) Expect(conunpubvol).NotTo(BeNil()) By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } - - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } - - _, err = c.DeleteVolume(context.Background(), delReq) + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) }) }) @@ -1021,13 +958,12 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { It("should fail when no volume id is provided", func() { - req := &csi.ControllerUnpublishVolumeRequest{} - - if sc.Secrets != nil { - req.ControllerUnpublishSecrets = sc.Secrets.ControllerUnpublishVolumeSecret - } - - _, err := c.ControllerUnpublishVolume(context.Background(), req) + _, err := c.ControllerUnpublishVolume( + context.Background(), + &csi.ControllerUnpublishVolumeRequest{ + ControllerUnpublishSecrets: sc.Secrets.ControllerUnpublishVolumeSecret, + }, + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -1041,25 +977,23 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { By("creating a single node writer volume") name := uniqueString("sanity-controller-unpublish") - req := &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, + vol, err := c.CreateVolume( + 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, + }, }, }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - } - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } - - vol, err := c.CreateVolume(context.Background(), req) + ) Expect(err).NotTo(HaveOccurred()) Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) @@ -1076,56 +1010,50 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { // ControllerPublishVolume By("calling controllerpublish on that volume") - pubReq := &csi.ControllerPublishVolumeRequest{ - VolumeId: vol.GetVolume().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, + conpubvol, err := c.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + VolumeId: vol.GetVolume().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, + ControllerPublishSecrets: sc.Secrets.ControllerPublishVolumeSecret, }, - Readonly: false, - } - - if sc.Secrets != nil { - pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } - - conpubvol, err := c.ControllerPublishVolume(context.Background(), pubReq) + ) Expect(err).NotTo(HaveOccurred()) Expect(conpubvol).NotTo(BeNil()) // ControllerUnpublishVolume By("calling controllerunpublish on that volume") - unpubReq := &csi.ControllerUnpublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - // NodeID is optional in ControllerUnpublishVolume - NodeId: nid.GetNodeId(), - } - - if sc.Secrets != nil { - unpubReq.ControllerUnpublishSecrets = sc.Secrets.ControllerUnpublishVolumeSecret - } - - conunpubvol, err := c.ControllerUnpublishVolume(context.Background(), unpubReq) + conunpubvol, err := c.ControllerUnpublishVolume( + context.Background(), + &csi.ControllerUnpublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + // NodeID is optional in ControllerUnpublishVolume + NodeId: nid.GetNodeId(), + ControllerUnpublishSecrets: sc.Secrets.ControllerUnpublishVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) Expect(conunpubvol).NotTo(BeNil()) By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } - - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } - - _, err = c.DeleteVolume(context.Background(), delReq) + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) }) }) diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index 8385cd9f..395fb6e3 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -155,14 +155,12 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { Describe("NodePublishVolume", func() { It("should fail when no volume id is provided", func() { - - req := &csi.NodePublishVolumeRequest{} - - if sc.Secrets != nil { - req.NodePublishSecrets = sc.Secrets.NodePublishVolumeSecret - } - - _, err := c.NodePublishVolume(context.Background(), req) + _, err := c.NodePublishVolume( + context.Background(), + &csi.NodePublishVolumeRequest{ + NodePublishSecrets: sc.Secrets.NodePublishVolumeSecret, + }, + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -171,16 +169,13 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { }) It("should fail when no target path is provided", func() { - - req := &csi.NodePublishVolumeRequest{ - VolumeId: "id", - } - - if sc.Secrets != nil { - req.NodePublishSecrets = sc.Secrets.NodePublishVolumeSecret - } - - _, err := c.NodePublishVolume(context.Background(), req) + _, err := c.NodePublishVolume( + context.Background(), + &csi.NodePublishVolumeRequest{ + VolumeId: "id", + NodePublishSecrets: sc.Secrets.NodePublishVolumeSecret, + }, + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -189,17 +184,14 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { }) It("should fail when no volume capability is provided", func() { - - req := &csi.NodePublishVolumeRequest{ - VolumeId: "id", - TargetPath: sc.Config.TargetPath, - } - - if sc.Secrets != nil { - req.NodePublishSecrets = sc.Secrets.NodePublishVolumeSecret - } - - _, err := c.NodePublishVolume(context.Background(), req) + _, err := c.NodePublishVolume( + context.Background(), + &csi.NodePublishVolumeRequest{ + VolumeId: "id", + TargetPath: sc.Config.TargetPath, + NodePublishSecrets: sc.Secrets.NodePublishVolumeSecret, + }, + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -250,27 +242,24 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { }) It("should fail when no volume id is provided", func() { - - req := &csi.NodeStageVolumeRequest{ - StagingTargetPath: sc.Config.StagingPath, - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, + _, err := c.NodeStageVolume( + context.Background(), + &csi.NodeStageVolumeRequest{ + StagingTargetPath: sc.Config.StagingPath, + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + PublishInfo: map[string]string{ + "device": device, }, + NodeStageSecrets: sc.Secrets.NodeStageVolumeSecret, }, - PublishInfo: map[string]string{ - "device": device, - }, - } - - if sc.Secrets != nil { - req.NodeStageSecrets = sc.Secrets.NodeStageVolumeSecret - } - - _, err := c.NodeStageVolume(context.Background(), req) + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -279,27 +268,24 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { }) It("should fail when no staging target path is provided", func() { - - req := &csi.NodeStageVolumeRequest{ - VolumeId: "id", - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, + _, err := c.NodeStageVolume( + context.Background(), + &csi.NodeStageVolumeRequest{ + VolumeId: "id", + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + PublishInfo: map[string]string{ + "device": device, }, + NodeStageSecrets: sc.Secrets.NodeStageVolumeSecret, }, - PublishInfo: map[string]string{ - "device": device, - }, - } - - if sc.Secrets != nil { - req.NodeStageSecrets = sc.Secrets.NodeStageVolumeSecret - } - - _, err := c.NodeStageVolume(context.Background(), req) + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -308,20 +294,17 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { }) It("should fail when no volume capability is provided", func() { - - req := &csi.NodeStageVolumeRequest{ - VolumeId: "id", - StagingTargetPath: sc.Config.StagingPath, - PublishInfo: map[string]string{ - "device": device, + _, err := c.NodeStageVolume( + context.Background(), + &csi.NodeStageVolumeRequest{ + VolumeId: "id", + StagingTargetPath: sc.Config.StagingPath, + PublishInfo: map[string]string{ + "device": device, + }, + NodeStageSecrets: sc.Secrets.NodeStageVolumeSecret, }, - } - - if sc.Secrets != nil { - req.NodeStageSecrets = sc.Secrets.NodeStageVolumeSecret - } - - _, err := c.NodeStageVolume(context.Background(), req) + ) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -376,25 +359,24 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { func testFullWorkflowSuccess(sc *SanityContext, s csi.ControllerClient, c csi.NodeClient, name string, controllerPublishSupported, nodeStageSupported bool) { // Create Volume First By("creating a single node writer volume") - req := &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, + vol, err := s.CreateVolume( + 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, + }, }, }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - } - - if sc.Secrets != nil { - req.ControllerCreateSecrets = sc.Secrets.CreateVolumeSecret - } + ) - vol, err := s.CreateVolume(context.Background(), req) Expect(err).NotTo(HaveOccurred()) Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) @@ -411,77 +393,76 @@ func testFullWorkflowSuccess(sc *SanityContext, s csi.ControllerClient, c csi.No if controllerPublishSupported { By("controller publishing volume") - pubReq := &csi.ControllerPublishVolumeRequest{ - VolumeId: vol.GetVolume().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, + conpubvol, err = s.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + VolumeId: vol.GetVolume().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, + }, }, + VolumeAttributes: vol.GetVolume().GetAttributes(), + Readonly: false, + ControllerPublishSecrets: sc.Secrets.ControllerPublishVolumeSecret, }, - VolumeAttributes: vol.GetVolume().GetAttributes(), - Readonly: false, - } - - if sc.Secrets != nil { - pubReq.ControllerPublishSecrets = sc.Secrets.ControllerPublishVolumeSecret - } - - conpubvol, err = s.ControllerPublishVolume(context.Background(), pubReq) + ) Expect(err).NotTo(HaveOccurred()) Expect(conpubvol).NotTo(BeNil()) } // NodeStageVolume if nodeStageSupported { By("node staging volume") - nodeStageVolReq := &csi.NodeStageVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + nodestagevol, err := c.NodeStageVolume( + context.Background(), + &csi.NodeStageVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, }, + StagingTargetPath: sc.Config.StagingPath, + VolumeAttributes: vol.GetVolume().GetAttributes(), + PublishInfo: conpubvol.GetPublishInfo(), + NodeStageSecrets: sc.Secrets.NodeStageVolumeSecret, }, - StagingTargetPath: sc.Config.StagingPath, - VolumeAttributes: vol.GetVolume().GetAttributes(), - PublishInfo: conpubvol.GetPublishInfo(), - } - if sc.Secrets != nil { - nodeStageVolReq.NodeStageSecrets = sc.Secrets.NodeStageVolumeSecret - } - nodestagevol, err := c.NodeStageVolume( - context.Background(), nodeStageVolReq) + ) Expect(err).NotTo(HaveOccurred()) Expect(nodestagevol).NotTo(BeNil()) } // NodePublishVolume By("publishing the volume on a node") - nodepubvolRequest := &csi.NodePublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - TargetPath: sc.Config.TargetPath, - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, - }, - }, - VolumeAttributes: vol.GetVolume().GetAttributes(), - PublishInfo: conpubvol.GetPublishInfo(), - } + var stagingPath string if nodeStageSupported { - nodepubvolRequest.StagingTargetPath = sc.Config.StagingPath + stagingPath = sc.Config.StagingPath } - if sc.Secrets != nil { - nodepubvolRequest.NodePublishSecrets = sc.Secrets.NodePublishVolumeSecret - } - nodepubvol, err := c.NodePublishVolume(context.Background(), nodepubvolRequest) + nodepubvol, err := c.NodePublishVolume( + context.Background(), + &csi.NodePublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + TargetPath: sc.Config.TargetPath, + StagingTargetPath: stagingPath, + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + VolumeAttributes: vol.GetVolume().GetAttributes(), + PublishInfo: conpubvol.GetPublishInfo(), + NodePublishSecrets: sc.Secrets.NodePublishVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) Expect(nodepubvol).NotTo(BeNil()) @@ -512,30 +493,26 @@ func testFullWorkflowSuccess(sc *SanityContext, s csi.ControllerClient, c csi.No if controllerPublishSupported { By("cleaning up calling controllerunpublishing") - unpubReq := &csi.ControllerUnpublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - NodeId: nid.GetNodeId(), - } - - if sc.Secrets != nil { - unpubReq.ControllerUnpublishSecrets = sc.Secrets.ControllerUnpublishVolumeSecret - } - - controllerunpubvol, err := s.ControllerUnpublishVolume(context.Background(), unpubReq) + controllerunpubvol, err := s.ControllerUnpublishVolume( + context.Background(), + &csi.ControllerUnpublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + NodeId: nid.GetNodeId(), + ControllerUnpublishSecrets: sc.Secrets.ControllerUnpublishVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) Expect(controllerunpubvol).NotTo(BeNil()) } By("cleaning up deleting the volume") - delReq := &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - } - - if sc.Secrets != nil { - delReq.ControllerDeleteSecrets = sc.Secrets.DeleteVolumeSecret - } - - _, err = s.DeleteVolume(context.Background(), delReq) + _, err = s.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) Expect(err).NotTo(HaveOccurred()) } diff --git a/pkg/sanity/sanity.go b/pkg/sanity/sanity.go index 320fa1ad..9a4de8be 100644 --- a/pkg/sanity/sanity.go +++ b/pkg/sanity/sanity.go @@ -88,6 +88,8 @@ func (sc *SanityContext) setup() { if len(sc.Config.SecretsFile) > 0 { sc.Secrets, err = loadSecrets(sc.Config.SecretsFile) Expect(err).NotTo(HaveOccurred()) + } else { + sc.Secrets = &CSISecrets{} } By("connecting to CSI driver") From 183e16e75c4ec5fdb832544acaafa2a7ba9f6131 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 11 Jul 2018 14:15:45 +0200 Subject: [PATCH 06/10] simplify imports There's no need to rename the csi spec, the package name already is "csi". Same for "gmock". The "context" module has been part of the Go standard library for quite a while now, we should use that directly. --- driver/driver.go | 4 ++-- pkg/sanity/controller.go | 2 +- pkg/sanity/identity.go | 4 ++-- pkg/sanity/node.go | 4 ++-- test/co_test.go | 6 +++--- test/driver_test.go | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/driver/driver.go b/driver/driver.go index c3bad11f..a8cd796f 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -19,7 +19,7 @@ limitations under the License. package driver import ( - context "context" + "context" "errors" "net" "sync" @@ -27,7 +27,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - csi "github.com/container-storage-interface/spec/lib/go/csi/v0" + "github.com/container-storage-interface/spec/lib/go/csi/v0" "google.golang.org/grpc" "google.golang.org/grpc/reflection" ) diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index ae8bcc1d..07259a72 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -17,13 +17,13 @@ limitations under the License. package sanity import ( + "context" "fmt" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "github.com/container-storage-interface/spec/lib/go/csi/v0" - "golang.org/x/net/context" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" diff --git a/pkg/sanity/identity.go b/pkg/sanity/identity.go index 8c826a7a..e60439b3 100644 --- a/pkg/sanity/identity.go +++ b/pkg/sanity/identity.go @@ -17,14 +17,14 @@ limitations under the License. package sanity import ( + "context" "fmt" "regexp" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - csi "github.com/container-storage-interface/spec/lib/go/csi/v0" - context "golang.org/x/net/context" + "github.com/container-storage-interface/spec/lib/go/csi/v0" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index 395fb6e3..c44044b1 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -17,13 +17,13 @@ limitations under the License. package sanity import ( + "context" "fmt" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - csi "github.com/container-storage-interface/spec/lib/go/csi/v0" - context "golang.org/x/net/context" + "github.com/container-storage-interface/spec/lib/go/csi/v0" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" diff --git a/test/co_test.go b/test/co_test.go index a8c17e97..5a2bbe27 100644 --- a/test/co_test.go +++ b/test/co_test.go @@ -16,16 +16,16 @@ limitations under the License. package test import ( + "context" "fmt" "reflect" "testing" - csi "github.com/container-storage-interface/spec/lib/go/csi/v0" - gomock "github.com/golang/mock/gomock" + "github.com/container-storage-interface/spec/lib/go/csi/v0" + "github.com/golang/mock/gomock" "github.com/golang/protobuf/proto" mock_driver "github.com/kubernetes-csi/csi-test/driver" mock_utils "github.com/kubernetes-csi/csi-test/utils" - "golang.org/x/net/context" ) func TestPluginInfoResponse(t *testing.T) { diff --git a/test/driver_test.go b/test/driver_test.go index 4b0122b6..82080eb3 100644 --- a/test/driver_test.go +++ b/test/driver_test.go @@ -21,7 +21,7 @@ import ( "sync" "testing" - csi "github.com/container-storage-interface/spec/lib/go/csi/v0" + "github.com/container-storage-interface/spec/lib/go/csi/v0" "github.com/kubernetes-csi/csi-test/utils" "google.golang.org/grpc" "google.golang.org/grpc/reflection" From 7d3ced6e2f006757260e6aa3ad2bacb79fb9dc29 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 11 Jul 2018 14:17:43 +0200 Subject: [PATCH 07/10] pkg/sanity: close connection last Ginkgo invokes AfterEach in the order in which they are defined, therefore we should define the AfterEach where the connection is closed as late as possible. That way the tests can have their own AfterEach where they can still use the connection. --- pkg/sanity/tests.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/sanity/tests.go b/pkg/sanity/tests.go index e11f0d76..47763b75 100644 --- a/pkg/sanity/tests.go +++ b/pkg/sanity/tests.go @@ -42,16 +42,15 @@ func DescribeSanity(text string, body func(*SanityContext)) bool { func registerTestsInGinkgo(sc *SanityContext) { for _, test := range tests { Describe(test.text, func() { - BeforeEach(func() { sc.setup() }) + test.body(sc) + AfterEach(func() { sc.teardown() }) - - test.body(sc) }) } } From 142c344a24811d14b748981d55177f6dd4320462 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 11 Jul 2018 14:20:18 +0200 Subject: [PATCH 08/10] pkg/sanity: track and delete volumes When a test fails, any volume operations that I may have done should be reversed. To achieve this, tests can register volumes for cleanup. To avoid unnecessary operations, volumes also get unregistered after a successful removal inside the test itself. Whether ControllerUnpublishVolume has to be called also gets tracked. For the sake of simplicity, NodeUnpublishVolume and (if supported) NodeUnstageVolume always get called. This is okay because they have to be idempotent and won't fail when called unnecessarily. testFullWorkflowSuccess gets inlined because that's easier than passing yet another parameter. Fixes: kubernetes-csi/csi-test#89. --- pkg/sanity/cleanup.go | 134 +++++++++++++++++++ pkg/sanity/controller.go | 65 ++++++--- pkg/sanity/node.go | 282 ++++++++++++++++++++------------------- 3 files changed, 329 insertions(+), 152 deletions(-) create mode 100644 pkg/sanity/cleanup.go diff --git a/pkg/sanity/cleanup.go b/pkg/sanity/cleanup.go new file mode 100644 index 00000000..699efe7b --- /dev/null +++ b/pkg/sanity/cleanup.go @@ -0,0 +1,134 @@ +/* +Copyright 2018 Intel Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package sanity + +import ( + "context" + "log" + + "github.com/container-storage-interface/spec/lib/go/csi/v0" + + . "github.com/onsi/ginkgo" +) + +// VolumeInfo keeps track of the information needed to delete a volume. +type VolumeInfo struct { + // Node on which the volume was published, empty if none + // or publishing is not supported. + NodeID string + + // Volume ID assigned by CreateVolume. + VolumeID string +} + +// Cleanup keeps track of resources, in particular volumes, which need +// to be freed when testing is done. +type Cleanup struct { + Context *SanityContext + ControllerClient csi.ControllerClient + NodeClient csi.NodeClient + ControllerPublishSupported bool + NodeStageSupported bool + + // Maps from volume name to the node ID for which the volume + // is published and the volume ID. + volumes map[string]VolumeInfo +} + +// RegisterVolume adds or updates an entry for the volume with the +// given name. +func (cl *Cleanup) RegisterVolume(name string, info VolumeInfo) { + if cl.volumes == nil { + cl.volumes = make(map[string]VolumeInfo) + } + cl.volumes[name] = info +} + +// MaybeRegisterVolume adds or updates an entry for the volume with +// the given name if CreateVolume was successful. +func (cl *Cleanup) MaybeRegisterVolume(name string, vol *csi.CreateVolumeResponse, err error) { + if err == nil && vol.GetVolume().GetId() != "" { + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId()}) + } +} + +// UnregisterVolume removes the entry for the volume with the +// given name, thus preventing all cleanup operations for it. +func (cl *Cleanup) UnregisterVolume(name string) { + if cl.volumes != nil { + delete(cl.volumes, name) + } +} + +// DeleteVolumes stops using the registered volumes and tries to delete all of them. +func (cl *Cleanup) DeleteVolumes() { + if cl.volumes == nil { + return + } + logger := log.New(GinkgoWriter, "cleanup: ", 0) + ctx := context.Background() + + for name, info := range cl.volumes { + logger.Printf("deleting %s = %s", name, info.VolumeID) + if _, err := cl.NodeClient.NodeUnpublishVolume( + ctx, + &csi.NodeUnpublishVolumeRequest{ + VolumeId: info.VolumeID, + TargetPath: cl.Context.Config.TargetPath, + }, + ); err != nil { + logger.Printf("warning: NodeUnpublishVolume: %s", err) + } + + if cl.NodeStageSupported { + if _, err := cl.NodeClient.NodeUnstageVolume( + ctx, + &csi.NodeUnstageVolumeRequest{ + VolumeId: info.VolumeID, + StagingTargetPath: cl.Context.Config.StagingPath, + }, + ); err != nil { + logger.Printf("warning: NodeUnstageVolume: %s", err) + } + } + + if cl.ControllerPublishSupported && info.NodeID != "" { + if _, err := cl.ControllerClient.ControllerUnpublishVolume( + ctx, + &csi.ControllerUnpublishVolumeRequest{ + VolumeId: info.VolumeID, + NodeId: info.NodeID, + ControllerUnpublishSecrets: cl.Context.Secrets.ControllerUnpublishVolumeSecret, + }, + ); err != nil { + logger.Printf("warning: ControllerUnpublishVolume: %s", err) + } + } + + if _, err := cl.ControllerClient.DeleteVolume( + ctx, + &csi.DeleteVolumeRequest{ + VolumeId: info.VolumeID, + ControllerDeleteSecrets: cl.Context.Secrets.DeleteVolumeSecret, + }, + ); err != nil { + logger.Printf("error: DeleteVolume: %s", err) + } + + cl.UnregisterVolume(name) + } +} diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index 07259a72..294a1e0d 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -81,11 +81,23 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { var ( c csi.ControllerClient n csi.NodeClient + + cl *Cleanup ) BeforeEach(func() { c = csi.NewControllerClient(sc.Conn) n = csi.NewNodeClient(sc.Conn) + + cl = &Cleanup{ + NodeClient: n, + ControllerClient: c, + Context: sc, + } + }) + + AfterEach(func() { + cl.DeleteVolumes() }) Describe("ControllerGetCapabilities", func() { @@ -167,12 +179,13 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }) It("should fail when no name is provided", func() { - _, err := c.CreateVolume( + vol, err := c.CreateVolume( context.Background(), &csi.CreateVolumeRequest{ ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, ) + cl.MaybeRegisterVolume("", vol, err) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -181,13 +194,15 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }) It("should fail when no volume capabilities are provided", func() { - _, err := c.CreateVolume( + name := uniqueString("sanity-controller-create-no-volume-capabilities") + vol, err := c.CreateVolume( context.Background(), &csi.CreateVolumeRequest{ - Name: "name", + Name: name, ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, ) + cl.MaybeRegisterVolume(name, vol, err) Expect(err).To(HaveOccurred()) serverError, ok := status.FromError(err) @@ -221,6 +236,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId()}) By("cleaning up deleting the volume") @@ -232,6 +248,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }, ) Expect(err).NotTo(HaveOccurred()) + cl.UnregisterVolume(name) }) It("should return appropriate values SingleNodeWriter WithCapacity 1Gi Type:Mount", func() { @@ -259,20 +276,17 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, ) - if serverError, ok := status.FromError(err); ok { - if serverError.Code() == codes.OutOfRange || serverError.Code() == codes.Unimplemented { - Skip("Required bytes not supported") - } else { - Expect(err).NotTo(HaveOccurred()) - } - } else { - - Expect(err).NotTo(HaveOccurred()) - Expect(vol).NotTo(BeNil()) - Expect(vol.GetVolume()).NotTo(BeNil()) - Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) - Expect(vol.GetVolume().GetCapacityBytes()).To(BeNumerically(">=", TestVolumeSize(sc))) + if serverError, ok := status.FromError(err); ok && + (serverError.Code() == codes.OutOfRange || serverError.Code() == codes.Unimplemented) { + Skip("Required bytes not supported") } + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolume()).NotTo(BeNil()) + Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId()}) + Expect(vol.GetVolume().GetCapacityBytes()).To(BeNumerically(">=", TestVolumeSize(sc))) + By("cleaning up deleting the volume") _, err = c.DeleteVolume( @@ -283,6 +297,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }, ) Expect(err).NotTo(HaveOccurred()) + cl.UnregisterVolume(name) }) It("should not fail when requesting to create a volume with already exisiting name and same capacity.", func() { @@ -314,6 +329,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { Expect(vol1).NotTo(BeNil()) Expect(vol1.GetVolume()).NotTo(BeNil()) Expect(vol1.GetVolume().GetId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol1.GetVolume().GetId()}) Expect(vol1.GetVolume().GetCapacityBytes()).To(BeNumerically(">=", size)) vol2, err := c.CreateVolume( @@ -353,6 +369,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }, ) Expect(err).NotTo(HaveOccurred()) + cl.UnregisterVolume(name) }) It("should fail when requesting to create a volume with already exisiting name and different capacity.", func() { @@ -385,6 +402,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { Expect(vol1).NotTo(BeNil()) Expect(vol1.GetVolume()).NotTo(BeNil()) Expect(vol1.GetVolume().GetId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol1.GetVolume().GetId()}) size2 := 2 * TestVolumeSize(sc) _, err = c.CreateVolume( @@ -423,6 +441,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }, ) Expect(err).NotTo(HaveOccurred()) + cl.UnregisterVolume(name) }) }) @@ -487,6 +506,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId()}) // Delete Volume By("deleting a volume") @@ -499,6 +519,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }, ) Expect(err).NotTo(HaveOccurred()) + cl.UnregisterVolume(name) }) }) @@ -556,6 +577,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId()}) // ValidateVolumeCapabilities By("validating volume capabilities") @@ -588,6 +610,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }, ) Expect(err).NotTo(HaveOccurred()) + cl.UnregisterVolume(name) }) It("should fail when the requested volume does not exist", func() { @@ -698,6 +721,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId()}) By("getting a node id") nid, err := n.NodeGetId( @@ -728,6 +752,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }, ) Expect(err).NotTo(HaveOccurred()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId(), NodeID: nid.GetNodeId()}) Expect(conpubvol).NotTo(BeNil()) By("cleaning up unpublishing the volume") @@ -754,6 +779,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }, ) Expect(err).NotTo(HaveOccurred()) + cl.UnregisterVolume(name) }) It("should fail when the volume does not exist", func() { @@ -812,6 +838,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId()}) // ControllerPublishVolume By("calling controllerpublish on that volume") @@ -850,6 +877,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }, ) Expect(err).NotTo(HaveOccurred()) + cl.UnregisterVolume(name) }) It("should fail when the volume is already published but is incompatible", func() { @@ -879,6 +907,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId()}) By("getting a node id") nid, err := n.NodeGetId( @@ -946,6 +975,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }, ) Expect(err).NotTo(HaveOccurred()) + cl.UnregisterVolume(name) }) }) @@ -998,6 +1028,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { Expect(vol).NotTo(BeNil()) Expect(vol.GetVolume()).NotTo(BeNil()) Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId()}) By("getting a node id") nid, err := n.NodeGetId( @@ -1028,6 +1059,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }, ) Expect(err).NotTo(HaveOccurred()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId(), NodeID: nid.GetNodeId()}) Expect(conpubvol).NotTo(BeNil()) // ControllerUnpublishVolume @@ -1055,6 +1087,7 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { }, ) Expect(err).NotTo(HaveOccurred()) + cl.UnregisterVolume(name) }) }) }) diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index c44044b1..a98f5151 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -70,8 +70,9 @@ func isPluginCapabilitySupported(c csi.IdentityClient, var _ = DescribeSanity("Node Service", func(sc *SanityContext) { var ( - c csi.NodeClient - s csi.ControllerClient + cl *Cleanup + c csi.NodeClient + s csi.ControllerClient controllerPublishSupported bool nodeStageSupported bool @@ -89,6 +90,17 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { err := createMountTargetLocation(sc.Config.StagingPath) Expect(err).NotTo(HaveOccurred()) } + cl = &Cleanup{ + Context: sc, + NodeClient: c, + ControllerClient: s, + ControllerPublishSupported: controllerPublishSupported, + NodeStageSupported: nodeStageSupported, + } + }) + + AfterEach(func() { + cl.DeleteVolumes() }) Describe("NodeGetCapabilities", func() { @@ -351,76 +363,102 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) { It("should work", func() { name := uniqueString("sanity-node-full") - testFullWorkflowSuccess(sc, s, c, name, controllerPublishSupported, nodeStageSupported) - }) -}) -// TODO: Tests for NodeStageVolume/NodeUnstageVolume -func testFullWorkflowSuccess(sc *SanityContext, s csi.ControllerClient, c csi.NodeClient, name string, controllerPublishSupported, nodeStageSupported bool) { - // Create Volume First - By("creating a single node writer volume") - vol, err := s.CreateVolume( - 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, + // Create Volume First + By("creating a single node writer volume") + vol, err := s.CreateVolume( + 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, + }, }, }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, }, - ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, - }, - ) + ) + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolume()).NotTo(BeNil()) + Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId()}) - Expect(err).NotTo(HaveOccurred()) - Expect(vol).NotTo(BeNil()) - Expect(vol.GetVolume()).NotTo(BeNil()) - Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + By("getting a node id") + nid, err := c.NodeGetId( + context.Background(), + &csi.NodeGetIdRequest{}) + Expect(err).NotTo(HaveOccurred()) + Expect(nid).NotTo(BeNil()) + Expect(nid.GetNodeId()).NotTo(BeEmpty()) - By("getting a node id") - nid, err := c.NodeGetId( - context.Background(), - &csi.NodeGetIdRequest{}) - Expect(err).NotTo(HaveOccurred()) - Expect(nid).NotTo(BeNil()) - Expect(nid.GetNodeId()).NotTo(BeEmpty()) - var conpubvol *csi.ControllerPublishVolumeResponse - if controllerPublishSupported { - By("controller publishing volume") + var conpubvol *csi.ControllerPublishVolumeResponse + if controllerPublishSupported { + By("controller publishing volume") - conpubvol, err = s.ControllerPublishVolume( - context.Background(), - &csi.ControllerPublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - NodeId: nid.GetNodeId(), - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, + conpubvol, err = s.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + VolumeId: vol.GetVolume().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, + }, }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + VolumeAttributes: vol.GetVolume().GetAttributes(), + Readonly: false, + ControllerPublishSecrets: sc.Secrets.ControllerPublishVolumeSecret, + }, + ) + Expect(err).NotTo(HaveOccurred()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId(), NodeID: nid.GetNodeId()}) + Expect(conpubvol).NotTo(BeNil()) + } + // NodeStageVolume + if nodeStageSupported { + By("node staging volume") + nodestagevol, err := c.NodeStageVolume( + context.Background(), + &csi.NodeStageVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, }, + StagingTargetPath: sc.Config.StagingPath, + VolumeAttributes: vol.GetVolume().GetAttributes(), + PublishInfo: conpubvol.GetPublishInfo(), + NodeStageSecrets: sc.Secrets.NodeStageVolumeSecret, }, - VolumeAttributes: vol.GetVolume().GetAttributes(), - Readonly: false, - ControllerPublishSecrets: sc.Secrets.ControllerPublishVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) - Expect(conpubvol).NotTo(BeNil()) - } - // NodeStageVolume - if nodeStageSupported { - By("node staging volume") - nodestagevol, err := c.NodeStageVolume( + ) + Expect(err).NotTo(HaveOccurred()) + Expect(nodestagevol).NotTo(BeNil()) + } + // NodePublishVolume + By("publishing the volume on a node") + var stagingPath string + if nodeStageSupported { + stagingPath = sc.Config.StagingPath + } + nodepubvol, err := c.NodePublishVolume( context.Background(), - &csi.NodeStageVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), + &csi.NodePublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + TargetPath: sc.Config.TargetPath, + StagingTargetPath: stagingPath, VolumeCapability: &csi.VolumeCapability{ AccessType: &csi.VolumeCapability_Mount{ Mount: &csi.VolumeCapability_MountVolume{}, @@ -429,90 +467,62 @@ func testFullWorkflowSuccess(sc *SanityContext, s csi.ControllerClient, c csi.No Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - StagingTargetPath: sc.Config.StagingPath, - VolumeAttributes: vol.GetVolume().GetAttributes(), - PublishInfo: conpubvol.GetPublishInfo(), - NodeStageSecrets: sc.Secrets.NodeStageVolumeSecret, + VolumeAttributes: vol.GetVolume().GetAttributes(), + PublishInfo: conpubvol.GetPublishInfo(), + NodePublishSecrets: sc.Secrets.NodePublishVolumeSecret, }, ) Expect(err).NotTo(HaveOccurred()) - Expect(nodestagevol).NotTo(BeNil()) - } - // NodePublishVolume - By("publishing the volume on a node") - var stagingPath string - if nodeStageSupported { - stagingPath = sc.Config.StagingPath - } - nodepubvol, err := c.NodePublishVolume( - context.Background(), - &csi.NodePublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - TargetPath: sc.Config.TargetPath, - StagingTargetPath: stagingPath, - VolumeCapability: &csi.VolumeCapability{ - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, - }, - }, - VolumeAttributes: vol.GetVolume().GetAttributes(), - PublishInfo: conpubvol.GetPublishInfo(), - NodePublishSecrets: sc.Secrets.NodePublishVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) - Expect(nodepubvol).NotTo(BeNil()) + Expect(nodepubvol).NotTo(BeNil()) - // NodeUnpublishVolume - By("cleaning up calling nodeunpublish") - nodeunpubvol, err := c.NodeUnpublishVolume( - context.Background(), - &csi.NodeUnpublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - TargetPath: sc.Config.TargetPath, - }) - Expect(err).NotTo(HaveOccurred()) - Expect(nodeunpubvol).NotTo(BeNil()) - - if nodeStageSupported { - By("cleaning up calling nodeunstage") - nodeunstagevol, err := c.NodeUnstageVolume( + // NodeUnpublishVolume + By("cleaning up calling nodeunpublish") + nodeunpubvol, err := c.NodeUnpublishVolume( context.Background(), - &csi.NodeUnstageVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - StagingTargetPath: sc.Config.StagingPath, - }, - ) + &csi.NodeUnpublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + TargetPath: sc.Config.TargetPath, + }) Expect(err).NotTo(HaveOccurred()) - Expect(nodeunstagevol).NotTo(BeNil()) - } + Expect(nodeunpubvol).NotTo(BeNil()) + + if nodeStageSupported { + By("cleaning up calling nodeunstage") + nodeunstagevol, err := c.NodeUnstageVolume( + context.Background(), + &csi.NodeUnstageVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + StagingTargetPath: sc.Config.StagingPath, + }, + ) + Expect(err).NotTo(HaveOccurred()) + Expect(nodeunstagevol).NotTo(BeNil()) + } + + if controllerPublishSupported { + By("cleaning up calling controllerunpublishing") + + controllerunpubvol, err := s.ControllerUnpublishVolume( + context.Background(), + &csi.ControllerUnpublishVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + NodeId: nid.GetNodeId(), + ControllerUnpublishSecrets: sc.Secrets.ControllerUnpublishVolumeSecret, + }, + ) + Expect(err).NotTo(HaveOccurred()) + Expect(controllerunpubvol).NotTo(BeNil()) + } - if controllerPublishSupported { - By("cleaning up calling controllerunpublishing") + By("cleaning up deleting the volume") - controllerunpubvol, err := s.ControllerUnpublishVolume( + _, err = s.DeleteVolume( context.Background(), - &csi.ControllerUnpublishVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - NodeId: nid.GetNodeId(), - ControllerUnpublishSecrets: sc.Secrets.ControllerUnpublishVolumeSecret, + &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, }, ) Expect(err).NotTo(HaveOccurred()) - Expect(controllerunpubvol).NotTo(BeNil()) - } - - By("cleaning up deleting the volume") - - _, err = s.DeleteVolume( - context.Background(), - &csi.DeleteVolumeRequest{ - VolumeId: vol.GetVolume().GetId(), - ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, - }, - ) - Expect(err).NotTo(HaveOccurred()) -} + }) +}) From 1a22b170d1674025aad7895769eefdeaccd05ee3 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 13 Jul 2018 14:42:11 +0200 Subject: [PATCH 09/10] move testing to Makefile The tests previously defined only for Travis CI are now invoked with "make test". e2e.sh assumed that the binaries are in the regular search path. This is no longer necessary and in addition, mock is no longer placed in the developers $GOPATH/bin by the script. --- .travis.yml | 5 +---- Makefile | 13 +++++++++++-- hack/e2e.sh | 10 +++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 414ec5fb..261662d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,7 @@ matrix: include: - go: 1.10.3 script: -- go fmt $(go list ./... | grep -v vendor) | wc -l | grep 0 -- go vet $(go list ./... | grep -v vendor) -- go test $(go list ./... | grep -v vendor | grep -v "cmd/csi-sanity") -- ./hack/e2e.sh +- make test after_success: - if [ "${TRAVIS_BRANCH}" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then docker login -u "${DOCKER_USERNAME}" -p "${DOCKER_PASSWORD}" quay.io; diff --git a/Makefile b/Makefile index b31541f6..95cc13b7 100644 --- a/Makefile +++ b/Makefile @@ -38,5 +38,14 @@ container: $(APP) push: container docker push $(IMAGE_NAME):$(IMAGE_VERSION) -.PHONY: all clean container push - +test: + if ! [ $$(go fmt $$(go list ./... | grep -v vendor) | wc -l) -eq 0 ]; then \ + echo "formatting errors:"; \ + go fmt $$(go list ./... | grep -v vendor); \ + false; \ + fi + go vet $$(go list ./... | grep -v vendor) + go test $$(go list ./... | grep -v vendor | grep -v "cmd/csi-sanity") + ./hack/e2e.sh + +.PHONY: all clean container push test diff --git a/hack/e2e.sh b/hack/e2e.sh index 81f3a02e..777250eb 100755 --- a/hack/e2e.sh +++ b/hack/e2e.sh @@ -11,10 +11,10 @@ CSI_MOCK_VERSION="master" # See https://github.com/grpc/grpc/blob/master/doc/naming.md runTest() { - CSI_ENDPOINT=$1 mock & + CSI_ENDPOINT=$1 ./bin/mock & local pid=$! - csi-sanity $TESTARGS --csi.endpoint=$2; ret=$? + ./cmd/csi-sanity/csi-sanity $TESTARGS --csi.endpoint=$2; ret=$? kill -9 $pid if [ $ret -ne 0 ] ; then @@ -24,10 +24,10 @@ runTest() runTestWithCreds() { - CSI_ENDPOINT=$1 CSI_ENABLE_CREDS=true mock & + CSI_ENDPOINT=$1 CSI_ENABLE_CREDS=true ./bin/mock & local pid=$! - csi-sanity $TESTARGS --csi.endpoint=$2 --csi.secrets=mock/mocksecret.yaml; ret=$? + ./cmd/csi-sanity/csi-sanity $TESTARGS --csi.endpoint=$2 --csi.secrets=mock/mocksecret.yaml; ret=$? kill -9 $pid if [ $ret -ne 0 ] ; then @@ -35,7 +35,7 @@ runTestWithCreds() fi } -go install ./mock || exit 1 +go build -o bin/mock ./mock || exit 1 cd cmd/csi-sanity make clean install || exit 1 From 275a08636f832aa67375d1abf957a25707833eae Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 20 Jul 2018 09:43:09 +0200 Subject: [PATCH 10/10] Makefile: fix format error reporting "go fmt" always fixes code in place. As a result, running it again to report formatting errors doesn't do anything. The original intention probably was to check for errors and then report them. This is what is done now, using gofmt directly and it's diff output mode. --- Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 95cc13b7..621cec71 100644 --- a/Makefile +++ b/Makefile @@ -39,11 +39,12 @@ push: container docker push $(IMAGE_NAME):$(IMAGE_VERSION) test: - if ! [ $$(go fmt $$(go list ./... | grep -v vendor) | wc -l) -eq 0 ]; then \ - echo "formatting errors:"; \ - go fmt $$(go list ./... | grep -v vendor); \ - false; \ - fi + files=$$(find ./ -name '*.go' | grep -v '^./vendor' ); \ + if [ $$(gofmt -d $$files | wc -l) -ne 0 ]; then \ + echo "formatting errors:"; \ + gofmt -d $$files; \ + false; \ + fi go vet $$(go list ./... | grep -v vendor) go test $$(go list ./... | grep -v vendor | grep -v "cmd/csi-sanity") ./hack/e2e.sh