Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#162 from NetApp/fix-nocaps-tests
Browse files Browse the repository at this point in the history
Use real volumes when testing no capabilities
  • Loading branch information
k8s-ci-robot authored Feb 12, 2019
2 parents a25d0b1 + 55066f2 commit bf480f0
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 4 deletions.
44 changes: 42 additions & 2 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,16 +604,56 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {

It("should fail when no volume capabilities are provided", func() {

_, err := c.ValidateVolumeCapabilities(
// Create Volume First
By("creating a single node writer volume")
name := uniqueString("sanity-controller-validate-nocaps")

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,
},
},
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
)
Expect(err).NotTo(HaveOccurred())
Expect(vol).NotTo(BeNil())
Expect(vol.GetVolume()).NotTo(BeNil())
Expect(vol.GetVolume().GetVolumeId()).NotTo(BeEmpty())
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId()})

_, err = c.ValidateVolumeCapabilities(
context.Background(),
&csi.ValidateVolumeCapabilitiesRequest{
VolumeId: "id",
VolumeId: vol.GetVolume().GetVolumeId(),
})
Expect(err).To(HaveOccurred())

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

By("cleaning up deleting the volume")

_, err = c.DeleteVolume(
context.Background(),
&csi.DeleteVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
Secrets: sc.Secrets.DeleteVolumeSecret,
},
)
Expect(err).NotTo(HaveOccurred())
cl.UnregisterVolume(name)
})

It("should return appropriate values (no optional values added)", func() {
Expand Down
45 changes: 43 additions & 2 deletions pkg/sanity/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,39 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
})

It("should fail when no volume capability is provided", func() {
_, err := c.NodeStageVolume(

// Create Volume First
By("creating a single node writer volume")
name := uniqueString("sanity-node-stage-nocaps")

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,
},
},
},
Secrets: sc.Secrets.CreateVolumeSecret,
Parameters: sc.Config.TestVolumeParameters,
},
)
Expect(err).NotTo(HaveOccurred())
Expect(vol).NotTo(BeNil())
Expect(vol.GetVolume()).NotTo(BeNil())
Expect(vol.GetVolume().GetVolumeId()).NotTo(BeEmpty())
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId()})

_, err = c.NodeStageVolume(
context.Background(),
&csi.NodeStageVolumeRequest{
VolumeId: "id",
VolumeId: vol.GetVolume().GetVolumeId(),
StagingTargetPath: sc.Config.StagingPath,
PublishContext: map[string]string{
"device": device,
Expand All @@ -313,6 +342,18 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))

By("cleaning up deleting the volume")

_, err = s.DeleteVolume(
context.Background(),
&csi.DeleteVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
Secrets: sc.Secrets.DeleteVolumeSecret,
},
)
Expect(err).NotTo(HaveOccurred())
cl.UnregisterVolume(name)
})
})

Expand Down

0 comments on commit bf480f0

Please sign in to comment.