Skip to content
Merged
Show file tree
Hide file tree
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
117 changes: 109 additions & 8 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ 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 @@ -249,6 +245,8 @@ var _ = Describe("CreateVolume [Controller Server]", func() {
})

It("should return appropriate values SingleNodeWriter NoCapacity Type:Mount", func() {

By("creating a volume")
name := "sanity"
vol, err := c.CreateVolume(
context.Background(),
Expand All @@ -270,10 +268,21 @@ var _ = Describe("CreateVolume [Controller Server]", func() {
Expect(vol).NotTo(BeNil())
Expect(vol.GetVolumeInfo()).NotTo(BeNil())
Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty())

By("cleaning up deleting the volume")
_, err = c.DeleteVolume(
context.Background(),
&csi.DeleteVolumeRequest{
Version: csiClientVersion,
VolumeId: vol.GetVolumeInfo().GetId(),
})
Expect(err).NotTo(HaveOccurred())
})

// Pending fix in mock file
It("[MOCKERRORS] should return appropriate values SingleNodeWriter WithCapacity 1Gi Type:Mount", func() {

By("creating a volume")
name := "sanity"
size := uint64(1 * 1024 * 1024 * 1024)
vol, err := c.CreateVolume(
Expand All @@ -300,6 +309,15 @@ var _ = Describe("CreateVolume [Controller Server]", func() {
Expect(vol.GetVolumeInfo()).NotTo(BeNil())
Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty())
Expect(vol.GetVolumeInfo().GetCapacityBytes()).To(Equal(size))

By("cleaning up deleting the volume")
_, err = c.DeleteVolume(
context.Background(),
&csi.DeleteVolumeRequest{
Version: csiClientVersion,
VolumeId: vol.GetVolumeInfo().GetId(),
})
Expect(err).NotTo(HaveOccurred())
})
})

Expand Down Expand Up @@ -342,9 +360,21 @@ var _ = Describe("DeleteVolume [Controller Server]", func() {
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
})

It("should succeed when an invalid volume id is used", func() {

_, err := c.DeleteVolume(
context.Background(),
&csi.DeleteVolumeRequest{
Version: csiClientVersion,
VolumeId: "reallyfakevolumeid",
})
Expect(err).NotTo(HaveOccurred())
})

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

// Create Volume First
By("creating a volume")
name := "sanity"
vol, err := c.CreateVolume(
context.Background(),
Expand All @@ -369,6 +399,7 @@ var _ = Describe("DeleteVolume [Controller Server]", func() {
Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty())

// Delete Volume
By("deleting a volume")
_, err = c.DeleteVolume(
context.Background(),
&csi.DeleteVolumeRequest{
Expand Down Expand Up @@ -432,6 +463,7 @@ var _ = Describe("ValidateVolumeCapabilities [Controller Server]", func() {
It("should return appropriate values (no optional values added)", func() {

// Create Volume First
By("creating a single node writer volume")
name := "sanity"
vol, err := c.CreateVolume(
context.Background(),
Expand All @@ -456,6 +488,7 @@ var _ = Describe("ValidateVolumeCapabilities [Controller Server]", func() {
Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty())

// ValidateVolumeCapabilities
By("validating volume capabilities")
valivolcap, err := c.ValidateVolumeCapabilities(
context.Background(),
&csi.ValidateVolumeCapabilitiesRequest{
Expand All @@ -475,16 +508,27 @@ var _ = Describe("ValidateVolumeCapabilities [Controller Server]", func() {
Expect(err).NotTo(HaveOccurred())
Expect(valivolcap).NotTo(BeNil())
Expect(valivolcap.GetSupported()).To(BeTrue())

By("cleaning up deleting the volume")
_, err = c.DeleteVolume(
context.Background(),
&csi.DeleteVolumeRequest{
Version: csiClientVersion,
VolumeId: vol.GetVolumeInfo().GetId(),
})
Expect(err).NotTo(HaveOccurred())
})
})

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

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

if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) {
Skip("ControllerPublishVolume not supported")
Expand Down Expand Up @@ -539,7 +583,7 @@ var _ = Describe("ControllerPublishVolume [Controller Server]", func() {
&csi.ControllerPublishVolumeRequest{
Version: csiClientVersion,
VolumeId: "id",
NodeId: csiNodeID,
NodeId: "fakenode",
})
Expect(err).To(HaveOccurred())

Expand All @@ -551,6 +595,7 @@ var _ = Describe("ControllerPublishVolume [Controller Server]", func() {
It("should return appropriate values (no optional values added)", func() {

// Create Volume First
By("creating a single node writer volume")
name := "sanity"
vol, err := c.CreateVolume(
context.Background(),
Expand All @@ -573,13 +618,24 @@ var _ = Describe("ControllerPublishVolume [Controller Server]", func() {
Expect(vol.GetVolumeInfo()).NotTo(BeNil())
Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty())

By("getting a node id")
nid, err := n.GetNodeID(
context.Background(),
&csi.GetNodeIDRequest{
Version: csiClientVersion,
})
Expect(err).NotTo(HaveOccurred())
Expect(nid).NotTo(BeNil())
Expect(nid.GetNodeId()).NotTo(BeEmpty())

// ControllerPublishVolume
By("calling controllerpublish on that volume")
conpubvol, err := c.ControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{
Version: csiClientVersion,
VolumeId: vol.GetVolumeInfo().GetId(),
NodeId: csiNodeID,
NodeId: nid.GetNodeId(),
VolumeCapability: &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
Expand All @@ -592,16 +648,39 @@ var _ = Describe("ControllerPublishVolume [Controller Server]", func() {
})
Expect(err).NotTo(HaveOccurred())
Expect(conpubvol).NotTo(BeNil())

By("cleaning up unpublishing the volume")
conunpubvol, err := c.ControllerUnpublishVolume(
context.Background(),
&csi.ControllerUnpublishVolumeRequest{
Version: csiClientVersion,
VolumeId: vol.GetVolumeInfo().GetId(),
// NodeID is optional in ControllerUnpublishVolume
NodeId: nid.GetNodeId(),
})
Expect(err).NotTo(HaveOccurred())
Expect(conunpubvol).NotTo(BeNil())

By("cleaning up deleting the volume")
_, err = c.DeleteVolume(
context.Background(),
&csi.DeleteVolumeRequest{
Version: csiClientVersion,
VolumeId: vol.GetVolumeInfo().GetId(),
})
Expect(err).NotTo(HaveOccurred())
})
})

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

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

if !isCapabilitySupported(c, csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME) {
Skip("ControllerUnpublishVolume not supported")
Expand Down Expand Up @@ -637,6 +716,7 @@ var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() {
It("should return appropriate values (no optional values added)", func() {

// Create Volume First
By("creating a single node writer volume")
name := "sanity"
vol, err := c.CreateVolume(
context.Background(),
Expand All @@ -659,13 +739,24 @@ var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() {
Expect(vol.GetVolumeInfo()).NotTo(BeNil())
Expect(vol.GetVolumeInfo().GetId()).NotTo(BeEmpty())

By("getting a node id")
nid, err := n.GetNodeID(
context.Background(),
&csi.GetNodeIDRequest{
Version: csiClientVersion,
})
Expect(err).NotTo(HaveOccurred())
Expect(nid).NotTo(BeNil())
Expect(nid.GetNodeId()).NotTo(BeEmpty())

// ControllerPublishVolume
By("calling controllerpublish on that volume")
conpubvol, err := c.ControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{
Version: csiClientVersion,
VolumeId: vol.GetVolumeInfo().GetId(),
NodeId: csiNodeID,
NodeId: nid.GetNodeId(),
VolumeCapability: &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
Expand All @@ -680,15 +771,25 @@ var _ = Describe("ControllerUnpublishVolume [Controller Server]", func() {
Expect(conpubvol).NotTo(BeNil())

// ControllerUnpublishVolume
By("calling controllerunpublish on that volume")
conunpubvol, err := c.ControllerUnpublishVolume(
context.Background(),
&csi.ControllerUnpublishVolumeRequest{
Version: csiClientVersion,
VolumeId: vol.GetVolumeInfo().GetId(),
// NodeID is optional in ControllerUnpublishVolume
NodeId: csiNodeID,
NodeId: nid.GetNodeId(),
})
Expect(err).NotTo(HaveOccurred())
Expect(conunpubvol).NotTo(BeNil())

By("cleaning up deleting the volume")
_, err = c.DeleteVolume(
context.Background(),
&csi.DeleteVolumeRequest{
Version: csiClientVersion,
VolumeId: vol.GetVolumeInfo().GetId(),
})
Expect(err).NotTo(HaveOccurred())
})
})
Loading