Skip to content

Commit df2aef9

Browse files
committed
Use real volumes when testing no capabilities
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.
1 parent 4bf669f commit df2aef9

File tree

2 files changed

+85
-4
lines changed

2 files changed

+85
-4
lines changed

pkg/sanity/controller.go

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,16 +603,56 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
603603

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

606-
_, err := c.ValidateVolumeCapabilities(
606+
// Create Volume First
607+
By("creating a single node writer volume")
608+
name := uniqueString("sanity-controller-validate-nocaps")
609+
610+
vol, err := c.CreateVolume(
611+
context.Background(),
612+
&csi.CreateVolumeRequest{
613+
Name: name,
614+
VolumeCapabilities: []*csi.VolumeCapability{
615+
{
616+
AccessType: &csi.VolumeCapability_Mount{
617+
Mount: &csi.VolumeCapability_MountVolume{},
618+
},
619+
AccessMode: &csi.VolumeCapability_AccessMode{
620+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
621+
},
622+
},
623+
},
624+
Secrets: sc.Secrets.CreateVolumeSecret,
625+
Parameters: sc.Config.TestVolumeParameters,
626+
},
627+
)
628+
Expect(err).NotTo(HaveOccurred())
629+
Expect(vol).NotTo(BeNil())
630+
Expect(vol.GetVolume()).NotTo(BeNil())
631+
Expect(vol.GetVolume().GetVolumeId()).NotTo(BeEmpty())
632+
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId()})
633+
634+
_, err = c.ValidateVolumeCapabilities(
607635
context.Background(),
608636
&csi.ValidateVolumeCapabilitiesRequest{
609-
VolumeId: "id",
637+
VolumeId: vol.GetVolume().GetVolumeId(),
610638
})
611639
Expect(err).To(HaveOccurred())
612640

613641
serverError, ok := status.FromError(err)
614642
Expect(ok).To(BeTrue())
615643
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
644+
645+
By("cleaning up deleting the volume")
646+
647+
_, err = c.DeleteVolume(
648+
context.Background(),
649+
&csi.DeleteVolumeRequest{
650+
VolumeId: vol.GetVolume().GetVolumeId(),
651+
Secrets: sc.Secrets.DeleteVolumeSecret,
652+
},
653+
)
654+
Expect(err).NotTo(HaveOccurred())
655+
cl.UnregisterVolume(name)
616656
})
617657

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

pkg/sanity/node.go

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,39 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
297297
})
298298

299299
It("should fail when no volume capability is provided", func() {
300-
_, err := c.NodeStageVolume(
300+
301+
// Create Volume First
302+
By("creating a single node writer volume")
303+
name := uniqueString("sanity-node-stage-nocaps")
304+
305+
vol, err := s.CreateVolume(
306+
context.Background(),
307+
&csi.CreateVolumeRequest{
308+
Name: name,
309+
VolumeCapabilities: []*csi.VolumeCapability{
310+
{
311+
AccessType: &csi.VolumeCapability_Mount{
312+
Mount: &csi.VolumeCapability_MountVolume{},
313+
},
314+
AccessMode: &csi.VolumeCapability_AccessMode{
315+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
316+
},
317+
},
318+
},
319+
Secrets: sc.Secrets.CreateVolumeSecret,
320+
Parameters: sc.Config.TestVolumeParameters,
321+
},
322+
)
323+
Expect(err).NotTo(HaveOccurred())
324+
Expect(vol).NotTo(BeNil())
325+
Expect(vol.GetVolume()).NotTo(BeNil())
326+
Expect(vol.GetVolume().GetVolumeId()).NotTo(BeEmpty())
327+
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetVolumeId()})
328+
329+
_, err = c.NodeStageVolume(
301330
context.Background(),
302331
&csi.NodeStageVolumeRequest{
303-
VolumeId: "id",
332+
VolumeId: vol.GetVolume().GetVolumeId(),
304333
StagingTargetPath: sc.Config.StagingPath,
305334
PublishContext: map[string]string{
306335
"device": device,
@@ -313,6 +342,18 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
313342
serverError, ok := status.FromError(err)
314343
Expect(ok).To(BeTrue())
315344
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
345+
346+
By("cleaning up deleting the volume")
347+
348+
_, err = s.DeleteVolume(
349+
context.Background(),
350+
&csi.DeleteVolumeRequest{
351+
VolumeId: vol.GetVolume().GetVolumeId(),
352+
Secrets: sc.Secrets.DeleteVolumeSecret,
353+
},
354+
)
355+
Expect(err).NotTo(HaveOccurred())
356+
cl.UnregisterVolume(name)
316357
})
317358
})
318359

0 commit comments

Comments
 (0)