Skip to content

Commit

Permalink
Use real volumes when testing no capabilities
Browse files Browse the repository at this point in the history
Negative tests that expect the plugin to return InvalidArgument because
no capabilities were supplied must use a real volume, otherwise plugins
might return NotFound instead.
  • Loading branch information
bswartz committed Feb 11, 2019
1 parent 4bf669f commit df2aef9
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 @@ -603,16 +603,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 df2aef9

Please sign in to comment.