Skip to content

Commit 4923457

Browse files
committed
sanity: Add tests for NodeStageVolume/NodeUnstageVolume
1 parent 134de10 commit 4923457

File tree

1 file changed

+325
-0
lines changed

1 file changed

+325
-0
lines changed

pkg/sanity/node.go

Lines changed: 325 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,328 @@ func testFullWorkflowSuccess(s csi.ControllerClient, c csi.NodeClient, controlle
364364
})
365365
Expect(err).NotTo(HaveOccurred())
366366
}
367+
368+
var _ = Describe("NodeStageVolume [Node Server]", func() {
369+
var (
370+
s csi.ControllerClient
371+
c csi.NodeClient
372+
controllerPublishSupported bool
373+
nodeStageSupported bool
374+
)
375+
376+
BeforeEach(func() {
377+
s = csi.NewControllerClient(conn)
378+
c = csi.NewNodeClient(conn)
379+
controllerPublishSupported = isControllerCapabilitySupported(
380+
s,
381+
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME)
382+
nodeStageSupported = isNodeCapabilitySupported(c, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME)
383+
if nodeStageSupported {
384+
err := createMountTargetLocation(config.StagingPath)
385+
Expect(err).NotTo(HaveOccurred())
386+
}
387+
})
388+
389+
It("should fail when no volume id is provided", func() {
390+
391+
_, err := c.NodeStageVolume(
392+
context.Background(),
393+
&csi.NodeStageVolumeRequest{})
394+
Expect(err).To(HaveOccurred())
395+
396+
serverError, ok := status.FromError(err)
397+
Expect(ok).To(BeTrue())
398+
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
399+
})
400+
401+
It("should fail when no staging target path is provided", func() {
402+
403+
_, err := c.NodeStageVolume(
404+
context.Background(),
405+
&csi.NodeStageVolumeRequest{
406+
VolumeId: "id",
407+
})
408+
Expect(err).To(HaveOccurred())
409+
410+
serverError, ok := status.FromError(err)
411+
Expect(ok).To(BeTrue())
412+
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
413+
})
414+
415+
It("should fail when no volume capability is provided", func() {
416+
417+
_, err := c.NodeStageVolume(
418+
context.Background(),
419+
&csi.NodeStageVolumeRequest{
420+
VolumeId: "id",
421+
StagingTargetPath: config.StagingPath,
422+
})
423+
Expect(err).To(HaveOccurred())
424+
425+
serverError, ok := status.FromError(err)
426+
Expect(ok).To(BeTrue())
427+
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
428+
})
429+
430+
It("should return appropriate values (no optional values added)", func() {
431+
432+
// Create Volume First
433+
By("creating a single node writer volume")
434+
name := "sanity"
435+
vol, err := s.CreateVolume(
436+
context.Background(),
437+
&csi.CreateVolumeRequest{
438+
Name: name,
439+
VolumeCapabilities: []*csi.VolumeCapability{
440+
{
441+
AccessType: &csi.VolumeCapability_Mount{
442+
Mount: &csi.VolumeCapability_MountVolume{},
443+
},
444+
AccessMode: &csi.VolumeCapability_AccessMode{
445+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
446+
},
447+
},
448+
},
449+
})
450+
Expect(err).NotTo(HaveOccurred())
451+
Expect(vol).NotTo(BeNil())
452+
Expect(vol.GetVolume()).NotTo(BeNil())
453+
Expect(vol.GetVolume().GetId()).NotTo(BeEmpty())
454+
455+
By("getting a node id")
456+
nid, err := c.NodeGetId(
457+
context.Background(),
458+
&csi.NodeGetIdRequest{})
459+
Expect(err).NotTo(HaveOccurred())
460+
Expect(nid).NotTo(BeNil())
461+
Expect(nid.GetNodeId()).NotTo(BeEmpty())
462+
var conpubvol *csi.ControllerPublishVolumeResponse
463+
if controllerPublishSupported {
464+
By("controller publishing volume")
465+
conpubvol, err = s.ControllerPublishVolume(
466+
context.Background(),
467+
&csi.ControllerPublishVolumeRequest{
468+
VolumeId: vol.GetVolume().GetId(),
469+
NodeId: nid.GetNodeId(),
470+
VolumeCapability: &csi.VolumeCapability{
471+
AccessType: &csi.VolumeCapability_Mount{
472+
Mount: &csi.VolumeCapability_MountVolume{},
473+
},
474+
AccessMode: &csi.VolumeCapability_AccessMode{
475+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
476+
},
477+
},
478+
Readonly: false,
479+
})
480+
Expect(err).NotTo(HaveOccurred())
481+
Expect(conpubvol).NotTo(BeNil())
482+
}
483+
484+
By("calling nodestage on that volume")
485+
nodeStageVolReq := &csi.NodeStageVolumeRequest{
486+
VolumeId: vol.GetVolume().GetId(),
487+
VolumeCapability: &csi.VolumeCapability{
488+
AccessType: &csi.VolumeCapability_Mount{
489+
Mount: &csi.VolumeCapability_MountVolume{},
490+
},
491+
AccessMode: &csi.VolumeCapability_AccessMode{
492+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
493+
},
494+
},
495+
StagingTargetPath: config.StagingPath,
496+
}
497+
if controllerPublishSupported {
498+
nodeStageVolReq.PublishInfo = conpubvol.GetPublishInfo()
499+
}
500+
nodestagevol, err := c.NodeStageVolume(
501+
context.Background(), nodeStageVolReq)
502+
Expect(err).NotTo(HaveOccurred())
503+
Expect(nodestagevol).NotTo(BeNil())
504+
505+
By("cleaning up calling nodeunstage")
506+
nodeunstagevol, err := c.NodeUnstageVolume(
507+
context.Background(),
508+
&csi.NodeUnstageVolumeRequest{
509+
VolumeId: vol.GetVolume().GetId(),
510+
StagingTargetPath: config.StagingPath,
511+
},
512+
)
513+
Expect(err).NotTo(HaveOccurred())
514+
Expect(nodeunstagevol).NotTo(BeNil())
515+
516+
if controllerPublishSupported {
517+
By("cleaning up calling controllerunpublishing")
518+
controllerunpubvol, err := s.ControllerUnpublishVolume(
519+
context.Background(),
520+
&csi.ControllerUnpublishVolumeRequest{
521+
VolumeId: vol.GetVolume().GetId(),
522+
NodeId: nid.GetNodeId(),
523+
})
524+
Expect(err).NotTo(HaveOccurred())
525+
Expect(controllerunpubvol).NotTo(BeNil())
526+
}
527+
528+
By("cleaning up deleting the volume")
529+
_, err = s.DeleteVolume(
530+
context.Background(),
531+
&csi.DeleteVolumeRequest{
532+
VolumeId: vol.GetVolume().GetId(),
533+
})
534+
Expect(err).NotTo(HaveOccurred())
535+
})
536+
})
537+
538+
var _ = Describe("NodeUnstageVolume [Node Server]", func() {
539+
var (
540+
s csi.ControllerClient
541+
c csi.NodeClient
542+
controllerPublishSupported bool
543+
nodeStageSupported bool
544+
)
545+
546+
BeforeEach(func() {
547+
s = csi.NewControllerClient(conn)
548+
c = csi.NewNodeClient(conn)
549+
controllerPublishSupported = isControllerCapabilitySupported(
550+
s,
551+
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME)
552+
nodeStageSupported = isNodeCapabilitySupported(c, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME)
553+
if nodeStageSupported {
554+
err := createMountTargetLocation(config.StagingPath)
555+
Expect(err).NotTo(HaveOccurred())
556+
}
557+
})
558+
559+
It("should fail when no volume id is provided", func() {
560+
561+
_, err := c.NodeUnstageVolume(
562+
context.Background(),
563+
&csi.NodeUnstageVolumeRequest{})
564+
Expect(err).To(HaveOccurred())
565+
566+
serverError, ok := status.FromError(err)
567+
Expect(ok).To(BeTrue())
568+
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
569+
})
570+
571+
It("should fail when no staging target path is provided", func() {
572+
573+
_, err := c.NodeUnstageVolume(
574+
context.Background(),
575+
&csi.NodeUnstageVolumeRequest{
576+
VolumeId: "id",
577+
})
578+
Expect(err).To(HaveOccurred())
579+
580+
serverError, ok := status.FromError(err)
581+
Expect(ok).To(BeTrue())
582+
Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
583+
})
584+
585+
It("should return appropriate values (no optional values added)", func() {
586+
587+
// Create Volume First
588+
By("creating a single node writer volume")
589+
name := "sanity"
590+
vol, err := s.CreateVolume(
591+
context.Background(),
592+
&csi.CreateVolumeRequest{
593+
Name: name,
594+
VolumeCapabilities: []*csi.VolumeCapability{
595+
{
596+
AccessType: &csi.VolumeCapability_Mount{
597+
Mount: &csi.VolumeCapability_MountVolume{},
598+
},
599+
AccessMode: &csi.VolumeCapability_AccessMode{
600+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
601+
},
602+
},
603+
},
604+
})
605+
Expect(err).NotTo(HaveOccurred())
606+
Expect(vol).NotTo(BeNil())
607+
Expect(vol.GetVolume()).NotTo(BeNil())
608+
Expect(vol.GetVolume().GetId()).NotTo(BeEmpty())
609+
610+
By("getting a node id")
611+
nid, err := c.NodeGetId(
612+
context.Background(),
613+
&csi.NodeGetIdRequest{})
614+
Expect(err).NotTo(HaveOccurred())
615+
Expect(nid).NotTo(BeNil())
616+
Expect(nid.GetNodeId()).NotTo(BeEmpty())
617+
var conpubvol *csi.ControllerPublishVolumeResponse
618+
if controllerPublishSupported {
619+
By("controller publishing volume")
620+
conpubvol, err = s.ControllerPublishVolume(
621+
context.Background(),
622+
&csi.ControllerPublishVolumeRequest{
623+
VolumeId: vol.GetVolume().GetId(),
624+
NodeId: nid.GetNodeId(),
625+
VolumeCapability: &csi.VolumeCapability{
626+
AccessType: &csi.VolumeCapability_Mount{
627+
Mount: &csi.VolumeCapability_MountVolume{},
628+
},
629+
AccessMode: &csi.VolumeCapability_AccessMode{
630+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
631+
},
632+
},
633+
Readonly: false,
634+
})
635+
Expect(err).NotTo(HaveOccurred())
636+
Expect(conpubvol).NotTo(BeNil())
637+
}
638+
639+
By("calling nodestage on that volume")
640+
nodeStageVolReq := &csi.NodeStageVolumeRequest{
641+
VolumeId: vol.GetVolume().GetId(),
642+
VolumeCapability: &csi.VolumeCapability{
643+
AccessType: &csi.VolumeCapability_Mount{
644+
Mount: &csi.VolumeCapability_MountVolume{},
645+
},
646+
AccessMode: &csi.VolumeCapability_AccessMode{
647+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
648+
},
649+
},
650+
StagingTargetPath: config.StagingPath,
651+
}
652+
if controllerPublishSupported {
653+
nodeStageVolReq.PublishInfo = conpubvol.GetPublishInfo()
654+
}
655+
nodestagevol, err := c.NodeStageVolume(
656+
context.Background(), nodeStageVolReq)
657+
Expect(err).NotTo(HaveOccurred())
658+
Expect(nodestagevol).NotTo(BeNil())
659+
660+
By("cleaning up calling nodeunstage")
661+
nodeunstagevol, err := c.NodeUnstageVolume(
662+
context.Background(),
663+
&csi.NodeUnstageVolumeRequest{
664+
VolumeId: vol.GetVolume().GetId(),
665+
StagingTargetPath: config.StagingPath,
666+
},
667+
)
668+
Expect(err).NotTo(HaveOccurred())
669+
Expect(nodeunstagevol).NotTo(BeNil())
670+
671+
if controllerPublishSupported {
672+
By("cleaning up calling controllerunpublishing")
673+
controllerunpubvol, err := s.ControllerUnpublishVolume(
674+
context.Background(),
675+
&csi.ControllerUnpublishVolumeRequest{
676+
VolumeId: vol.GetVolume().GetId(),
677+
NodeId: nid.GetNodeId(),
678+
})
679+
Expect(err).NotTo(HaveOccurred())
680+
Expect(controllerunpubvol).NotTo(BeNil())
681+
}
682+
683+
By("cleaning up deleting the volume")
684+
_, err = s.DeleteVolume(
685+
context.Background(),
686+
&csi.DeleteVolumeRequest{
687+
VolumeId: vol.GetVolume().GetId(),
688+
})
689+
Expect(err).NotTo(HaveOccurred())
690+
})
691+
})

0 commit comments

Comments
 (0)