Skip to content

Commit 7349b5a

Browse files
committed
Add STAGE_UNSTAGE in Node Capabilities & reuse testFullWorkflow
1 parent b43de19 commit 7349b5a

File tree

2 files changed

+48
-210
lines changed

2 files changed

+48
-210
lines changed

mock/service/node.go

+9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ func (s *service) NodeStageVolume(
4949

5050
// Check to see if the volume has already been staged.
5151
if v.Attributes[nodeStgPathKey] != "" {
52+
// TODO: Check for the capabilities to be equal. Return "ALREADY_EXISTS"
53+
// if the capabilities don't match.
5254
return &csi.NodeStageVolumeResponse{}, nil
5355
}
5456

@@ -199,6 +201,13 @@ func (s *service) NodeGetCapabilities(
199201
},
200202
},
201203
},
204+
{
205+
Type: &csi.NodeServiceCapability_Rpc{
206+
Rpc: &csi.NodeServiceCapability_RPC{
207+
Type: csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME,
208+
},
209+
},
210+
},
202211
},
203212
}, nil
204213
}

pkg/sanity/node.go

+39-210
Original file line numberDiff line numberDiff line change
@@ -371,26 +371,43 @@ var _ = Describe("NodeStageVolume [Node Server]", func() {
371371
c csi.NodeClient
372372
controllerPublishSupported bool
373373
nodeStageSupported bool
374+
device string
374375
)
375376

376377
BeforeEach(func() {
377378
s = csi.NewControllerClient(conn)
378379
c = csi.NewNodeClient(conn)
380+
device = "/dev/mock"
379381
controllerPublishSupported = isControllerCapabilitySupported(
380382
s,
381383
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME)
382384
nodeStageSupported = isNodeCapabilitySupported(c, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME)
383385
if nodeStageSupported {
384386
err := createMountTargetLocation(config.StagingPath)
385387
Expect(err).NotTo(HaveOccurred())
388+
} else {
389+
Skip("NodeStageVolume not supported")
386390
}
387391
})
388392

389393
It("should fail when no volume id is provided", func() {
390394

391395
_, err := c.NodeStageVolume(
392396
context.Background(),
393-
&csi.NodeStageVolumeRequest{})
397+
&csi.NodeStageVolumeRequest{
398+
StagingTargetPath: config.StagingPath,
399+
VolumeCapability: &csi.VolumeCapability{
400+
AccessType: &csi.VolumeCapability_Mount{
401+
Mount: &csi.VolumeCapability_MountVolume{},
402+
},
403+
AccessMode: &csi.VolumeCapability_AccessMode{
404+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
405+
},
406+
},
407+
PublishInfo: map[string]string{
408+
"device": device,
409+
},
410+
})
394411
Expect(err).To(HaveOccurred())
395412

396413
serverError, ok := status.FromError(err)
@@ -404,6 +421,17 @@ var _ = Describe("NodeStageVolume [Node Server]", func() {
404421
context.Background(),
405422
&csi.NodeStageVolumeRequest{
406423
VolumeId: "id",
424+
VolumeCapability: &csi.VolumeCapability{
425+
AccessType: &csi.VolumeCapability_Mount{
426+
Mount: &csi.VolumeCapability_MountVolume{},
427+
},
428+
AccessMode: &csi.VolumeCapability_AccessMode{
429+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
430+
},
431+
},
432+
PublishInfo: map[string]string{
433+
"device": device,
434+
},
407435
})
408436
Expect(err).To(HaveOccurred())
409437

@@ -419,6 +447,9 @@ var _ = Describe("NodeStageVolume [Node Server]", func() {
419447
&csi.NodeStageVolumeRequest{
420448
VolumeId: "id",
421449
StagingTargetPath: config.StagingPath,
450+
PublishInfo: map[string]string{
451+
"device": device,
452+
},
422453
})
423454
Expect(err).To(HaveOccurred())
424455

@@ -428,110 +459,7 @@ var _ = Describe("NodeStageVolume [Node Server]", func() {
428459
})
429460

430461
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())
462+
testFullWorkflowSuccess(s, c, controllerPublishSupported, nodeStageSupported)
535463
})
536464
})
537465

@@ -553,14 +481,18 @@ var _ = Describe("NodeUnstageVolume [Node Server]", func() {
553481
if nodeStageSupported {
554482
err := createMountTargetLocation(config.StagingPath)
555483
Expect(err).NotTo(HaveOccurred())
484+
} else {
485+
Skip("NodeUnstageVolume not supported")
556486
}
557487
})
558488

559489
It("should fail when no volume id is provided", func() {
560490

561491
_, err := c.NodeUnstageVolume(
562492
context.Background(),
563-
&csi.NodeUnstageVolumeRequest{})
493+
&csi.NodeUnstageVolumeRequest{
494+
StagingTargetPath: config.StagingPath,
495+
})
564496
Expect(err).To(HaveOccurred())
565497

566498
serverError, ok := status.FromError(err)
@@ -583,109 +515,6 @@ var _ = Describe("NodeUnstageVolume [Node Server]", func() {
583515
})
584516

585517
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())
518+
testFullWorkflowSuccess(s, c, controllerPublishSupported, nodeStageSupported)
690519
})
691520
})

0 commit comments

Comments
 (0)