Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#34 from edisonxiang/addtestsforcont…
Browse files Browse the repository at this point in the history
…roller

Add tests for Controller Publish/UnPublish Volume
  • Loading branch information
lpabon authored Jan 24, 2018
2 parents 7285cdc + 8ef9687 commit b4e4237
Showing 1 changed file with 219 additions and 0 deletions.
219 changes: 219 additions & 0 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import (
. "github.com/onsi/gomega"
)

var (
csiNodeID = "foobar"
)

func verifyVolumeInfo(v *csi.VolumeInfo) {
Expect(v).NotTo(BeNil())
Expect(v.GetId()).NotTo(BeEmpty())
Expand Down Expand Up @@ -473,3 +477,218 @@ var _ = Describe("ValidateVolumeCapabilities [Controller Server]", func() {
Expect(valivolcap.GetSupported()).To(BeTrue())
})
})

var _ = Describe("ControllerPublishVolume [Controller Server]", func() {
var (
c csi.ControllerClient
)

BeforeEach(func() {
c = csi.NewControllerClient(conn)

if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) {
Skip("ControllerPublishVolume not supported")
}
})

It("should fail when no version is provided", func() {

_, err := c.ControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{})
Expect(err).To(HaveOccurred())

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
})

It("should fail when no volume id is provided", func() {

_, err := c.ControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{
Version: csiClientVersion,
})
Expect(err).To(HaveOccurred())

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
})

It("should fail when no node id is provided", func() {

_, err := c.ControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{
Version: csiClientVersion,
VolumeId: "id",
})
Expect(err).To(HaveOccurred())

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
})

It("should fail when no volume capability is provided", func() {

_, err := c.ControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{
Version: csiClientVersion,
VolumeId: "id",
NodeId: csiNodeID,
})
Expect(err).To(HaveOccurred())

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
})

It("should return appropriate values (no optional values added)", func() {

// Create Volume First
name := "sanity"
vol, err := c.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Version: csiClientVersion,
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
&csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
},
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
},
})
Expect(err).NotTo(HaveOccurred())
Expect(vol).NotTo(BeNil())
Expect(vol.GetVolumeInfo()).NotTo(BeNil())
Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty())

// ControllerPublishVolume
conpubvol, err := c.ControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{
Version: csiClientVersion,
VolumeId: vol.GetVolumeInfo().GetId(),
NodeId: csiNodeID,
VolumeCapability: &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
},
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
Readonly: false,
})
Expect(err).NotTo(HaveOccurred())
Expect(conpubvol).NotTo(BeNil())
})
})

var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() {
var (
c csi.ControllerClient
)

BeforeEach(func() {
c = csi.NewControllerClient(conn)

if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) {
Skip("ControllerUnpublishVolume not supported")
}
})

It("should fail when no version is provided", func() {

_, err := c.ControllerUnpublishVolume(
context.Background(),
&csi.ControllerUnpublishVolumeRequest{})
Expect(err).To(HaveOccurred())

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
})

It("should fail when no volume id is provided", func() {

_, err := c.ControllerUnpublishVolume(
context.Background(),
&csi.ControllerUnpublishVolumeRequest{
Version: csiClientVersion,
})
Expect(err).To(HaveOccurred())

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
})

It("should return appropriate values (no optional values added)", func() {

// Create Volume First
name := "sanity"
vol, err := c.CreateVolume(
context.Background(),
&csi.CreateVolumeRequest{
Version: csiClientVersion,
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
&csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
},
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
},
})
Expect(err).NotTo(HaveOccurred())
Expect(vol).NotTo(BeNil())
Expect(vol.GetVolumeInfo()).NotTo(BeNil())
Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty())

// ControllerPublishVolume
conpubvol, err := c.ControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{
Version: csiClientVersion,
VolumeId: vol.GetVolumeInfo().GetId(),
NodeId: csiNodeID,
VolumeCapability: &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
},
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
},
Readonly: false,
})
Expect(err).NotTo(HaveOccurred())
Expect(conpubvol).NotTo(BeNil())

// ControllerUnpublishVolume
conunpubvol, err := c.ControllerUnpublishVolume(
context.Background(),
&csi.ControllerUnpublishVolumeRequest{
Version: csiClientVersion,
VolumeId: vol.GetVolumeInfo().GetId(),
// NodeID is optional in ControllerUnpublishVolume
NodeId: csiNodeID,
})
Expect(err).NotTo(HaveOccurred())
Expect(conunpubvol).NotTo(BeNil())
})
})

0 comments on commit b4e4237

Please sign in to comment.