Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Controller Publish/UnPublish Volume #34

Merged
merged 2 commits into from
Jan 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
})
})