From 1dfd22652735c01466baa53193b4ee8e18f2c79a Mon Sep 17 00:00:00 2001 From: edisonxiang Date: Wed, 24 Jan 2018 15:30:00 +0800 Subject: [PATCH 1/5] Add test for NodeGetCapabilities --- pkg/sanity/node.go | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 pkg/sanity/node.go diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go new file mode 100644 index 00000000..09b9ecf9 --- /dev/null +++ b/pkg/sanity/node.go @@ -0,0 +1,74 @@ +/* +Copyright 2017 Kubernetes Authors. + +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 ( + "fmt" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/container-storage-interface/spec/lib/go/csi" + context "golang.org/x/net/context" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("NodeGetCapabilities [Node Server]", func() { + var ( + c csi.NodeClient + ) + + BeforeEach(func() { + c = csi.NewNodeClient(conn) + }) + + It("should fail when no version is provided", func() { + _, err := c.NodeGetCapabilities( + context.Background(), + &csi.NodeGetCapabilitiesRequest{}) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should return appropriate capabilities", func() { + caps, err := c.NodeGetCapabilities( + context.Background(), + &csi.NodeGetCapabilitiesRequest{ + Version: csiClientVersion, + }) + + 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.NodeServiceCapability_RPC_UNKNOWN: + default: + Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetRpc().GetType())) + } + } + }) +}) From 9fe8f72852d3a6b44d6ca80f0eb0e46432ca2b65 Mon Sep 17 00:00:00 2001 From: edisonxiang Date: Wed, 24 Jan 2018 15:39:02 +0800 Subject: [PATCH 2/5] Add test for NodeProbe --- pkg/sanity/node.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index 09b9ecf9..c55cf020 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -72,3 +72,35 @@ var _ = Describe("NodeGetCapabilities [Node Server]", func() { } }) }) + +var _ = Describe("NodeProbe [Node Server]", func() { + var ( + c csi.NodeClient + ) + + BeforeEach(func() { + c = csi.NewNodeClient(conn) + }) + + It("should fail when no version is provided", func() { + _, err := c.NodeProbe( + context.Background(), + &csi.NodeProbeRequest{}) + 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", func() { + pro, err := c.NodeProbe( + context.Background(), + &csi.NodeProbeRequest{ + Version: csiClientVersion, + }) + + Expect(err).NotTo(HaveOccurred()) + Expect(pro).NotTo(BeNil()) + }) +}) From 005ee55ae75d2a41868e6542c6b55b97f372992d Mon Sep 17 00:00:00 2001 From: edisonxiang Date: Wed, 24 Jan 2018 15:44:44 +0800 Subject: [PATCH 3/5] Add test for GetNodeID --- pkg/sanity/node.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index c55cf020..24300293 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -104,3 +104,36 @@ var _ = Describe("NodeProbe [Node Server]", func() { Expect(pro).NotTo(BeNil()) }) }) + +var _ = Describe("GetNodeID [Node Server]", func() { + var ( + c csi.NodeClient + ) + + BeforeEach(func() { + c = csi.NewNodeClient(conn) + }) + + It("should fail when no version is provided", func() { + _, err := c.GetNodeID( + context.Background(), + &csi.GetNodeIDRequest{}) + 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", func() { + nid, err := c.GetNodeID( + context.Background(), + &csi.GetNodeIDRequest{ + Version: csiClientVersion, + }) + + Expect(err).NotTo(HaveOccurred()) + Expect(nid).NotTo(BeNil()) + Expect(nid.GetNodeId()).NotTo(BeEmpty()) + }) +}) From 2e25a636bfea315d1a1a48d91a65bcbfee52c9b2 Mon Sep 17 00:00:00 2001 From: edisonxiang Date: Wed, 24 Jan 2018 16:09:26 +0800 Subject: [PATCH 4/5] Add test for NodePublishVolume --- pkg/sanity/node.go | 140 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index 24300293..b260fef4 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -29,6 +29,10 @@ import ( . "github.com/onsi/gomega" ) +var ( + csiTargetPath = "/mnt/csi" +) + var _ = Describe("NodeGetCapabilities [Node Server]", func() { var ( c csi.NodeClient @@ -137,3 +141,139 @@ var _ = Describe("GetNodeID [Node Server]", func() { Expect(nid.GetNodeId()).NotTo(BeEmpty()) }) }) + +var _ = Describe("NodePublishVolume [Node Server]", func() { + var ( + s csi.ControllerClient + c csi.NodeClient + ) + + BeforeEach(func() { + s = csi.NewControllerClient(conn) + c = csi.NewNodeClient(conn) + }) + + It("should fail when no version is provided", func() { + + _, err := c.NodePublishVolume( + context.Background(), + &csi.NodePublishVolumeRequest{}) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should fail when no volume id is provided", func() { + + _, err := c.NodePublishVolume( + context.Background(), + &csi.NodePublishVolumeRequest{ + Version: csiClientVersion, + }) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should fail when no target path is provided", func() { + + _, err := c.NodePublishVolume( + context.Background(), + &csi.NodePublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: "id", + }) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should fail when no volume capability is provided", func() { + + _, err := c.NodePublishVolume( + context.Background(), + &csi.NodePublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: "id", + TargetPath: csiTargetPath, + }) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should return appropriate values (no optional values added)", func() { + + // Create Volume First + name := "sanity" + vol, err := s.CreateVolume( + context.Background(), + &csi.CreateVolumeRequest{ + Version: csiClientVersion, + Name: name, + VolumeCapabilities: []*csi.VolumeCapability{ + &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + }, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolumeInfo()).NotTo(BeNil()) + Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty()) + + // ControllerPublishVolume + conpubvol, err := s.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + NodeId: "foobar", + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + Readonly: false, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(conpubvol).NotTo(BeNil()) + + // NodePublishVolume + nodepubvol, err := c.NodePublishVolume( + context.Background(), + &csi.NodePublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + // PublishVolumeInfo is optional in NodePublishVolume + PublishVolumeInfo: conpubvol.GetPublishVolumeInfo(), + TargetPath: csiTargetPath, + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(nodepubvol).NotTo(BeNil()) + }) +}) From 0fb4394155350c10d73df3f253ce0ea424dad948 Mon Sep 17 00:00:00 2001 From: edisonxiang Date: Wed, 24 Jan 2018 16:17:56 +0800 Subject: [PATCH 5/5] Add test for NodeUnpublishVolume --- pkg/sanity/node.go | 131 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/pkg/sanity/node.go b/pkg/sanity/node.go index b260fef4..36a93ee7 100644 --- a/pkg/sanity/node.go +++ b/pkg/sanity/node.go @@ -277,3 +277,134 @@ var _ = Describe("NodePublishVolume [Node Server]", func() { Expect(nodepubvol).NotTo(BeNil()) }) }) + +var _ = Describe("NodeUnpublishVolume [Node Server]", func() { + var ( + s csi.ControllerClient + c csi.NodeClient + ) + + BeforeEach(func() { + s = csi.NewControllerClient(conn) + c = csi.NewNodeClient(conn) + }) + + It("should fail when no version is provided", func() { + + _, err := c.NodeUnpublishVolume( + context.Background(), + &csi.NodeUnpublishVolumeRequest{}) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should fail when no volume id is provided", func() { + + _, err := c.NodeUnpublishVolume( + context.Background(), + &csi.NodeUnpublishVolumeRequest{ + Version: csiClientVersion, + }) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should fail when no target path is provided", func() { + + _, err := c.NodeUnpublishVolume( + context.Background(), + &csi.NodeUnpublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: "id", + }) + Expect(err).To(HaveOccurred()) + + serverError, ok := status.FromError(err) + Expect(ok).To(BeTrue()) + Expect(serverError.Code()).To(Equal(codes.InvalidArgument)) + }) + + It("should return appropriate values (no optional values added)", func() { + + // Create Volume First + name := "sanity" + vol, err := s.CreateVolume( + context.Background(), + &csi.CreateVolumeRequest{ + Version: csiClientVersion, + Name: name, + VolumeCapabilities: []*csi.VolumeCapability{ + &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + }, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolumeInfo()).NotTo(BeNil()) + Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty()) + + // ControllerPublishVolume + conpubvol, err := s.ControllerPublishVolume( + context.Background(), + &csi.ControllerPublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + NodeId: "foobar", + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + Readonly: false, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(conpubvol).NotTo(BeNil()) + + // NodePublishVolume + nodepubvol, err := c.NodePublishVolume( + context.Background(), + &csi.NodePublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + // PublishVolumeInfo is optional in NodePublishVolume + PublishVolumeInfo: conpubvol.GetPublishVolumeInfo(), + TargetPath: csiTargetPath, + VolumeCapability: &csi.VolumeCapability{ + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(nodepubvol).NotTo(BeNil()) + + // NodeUnpublishVolume + nodeunpubvol, err := c.NodeUnpublishVolume( + context.Background(), + &csi.NodeUnpublishVolumeRequest{ + Version: csiClientVersion, + VolumeId: vol.GetVolumeInfo().GetId(), + TargetPath: csiTargetPath, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(nodeunpubvol).NotTo(BeNil()) + }) +})