@@ -29,6 +29,26 @@ import (
2929 . "github.com/onsi/gomega"
3030)
3131
32+ func isNodeCapabilitySupported (c csi.NodeClient ,
33+ capType csi.NodeServiceCapability_RPC_Type ,
34+ ) bool {
35+
36+ caps , err := c .NodeGetCapabilities (
37+ context .Background (),
38+ & csi.NodeGetCapabilitiesRequest {})
39+ Expect (err ).NotTo (HaveOccurred ())
40+ Expect (caps ).NotTo (BeNil ())
41+ Expect (caps .GetCapabilities ()).NotTo (BeNil ())
42+
43+ for _ , cap := range caps .GetCapabilities () {
44+ Expect (cap .GetRpc ()).NotTo (BeNil ())
45+ if cap .GetRpc ().GetType () == capType {
46+ return true
47+ }
48+ }
49+ return false
50+ }
51+
3252var _ = Describe ("NodeGetCapabilities [Node Server]" , func () {
3353 var (
3454 c csi.NodeClient
@@ -53,6 +73,7 @@ var _ = Describe("NodeGetCapabilities [Node Server]", func() {
5373
5474 switch cap .GetRpc ().GetType () {
5575 case csi .NodeServiceCapability_RPC_UNKNOWN :
76+ case csi .NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME :
5677 default :
5778 Fail (fmt .Sprintf ("Unknown capability: %v\n " , cap .GetRpc ().GetType ()))
5879 }
@@ -85,14 +106,16 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
85106 s csi.ControllerClient
86107 c csi.NodeClient
87108 controllerPublishSupported bool
109+ nodeStageSupported bool
88110 )
89111
90112 BeforeEach (func () {
91113 s = csi .NewControllerClient (conn )
92114 c = csi .NewNodeClient (conn )
93- controllerPublishSupported = isCapabilitySupported (
115+ controllerPublishSupported = isControllerCapabilitySupported (
94116 s ,
95117 csi .ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME )
118+ nodeStageSupported = isNodeCapabilitySupported (c , csi .NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME )
96119 })
97120
98121 It ("should fail when no volume id is provided" , func () {
@@ -189,6 +212,29 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
189212 Expect (err ).NotTo (HaveOccurred ())
190213 Expect (conpubvol ).NotTo (BeNil ())
191214 }
215+ // NodeStageVolume
216+ if nodeStageSupported {
217+ By ("node staging volume" )
218+ nodeStageVolReq := & csi.NodeStageVolumeRequest {
219+ VolumeId : vol .GetVolume ().GetId (),
220+ VolumeCapability : & csi.VolumeCapability {
221+ AccessType : & csi.VolumeCapability_Mount {
222+ Mount : & csi.VolumeCapability_MountVolume {},
223+ },
224+ AccessMode : & csi.VolumeCapability_AccessMode {
225+ Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
226+ },
227+ },
228+ StagingTargetPath : stagingTargetPath ,
229+ }
230+ if controllerPublishSupported {
231+ nodeStageVolReq .PublishInfo = conpubvol .GetPublishInfo ()
232+ }
233+ nodestagevol , err := c .NodeStageVolume (
234+ context .Background (), nodeStageVolReq )
235+ Expect (err ).NotTo (HaveOccurred ())
236+ Expect (nodestagevol ).NotTo (BeNil ())
237+ }
192238 // NodePublishVolume
193239 By ("publishing the volume on a node" )
194240 nodepubvolRequest := & csi.NodePublishVolumeRequest {
@@ -203,6 +249,9 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
203249 },
204250 },
205251 }
252+ if nodeStageSupported {
253+ nodepubvolRequest .StagingTargetPath = stagingTargetPath
254+ }
206255 if controllerPublishSupported {
207256 nodepubvolRequest .PublishInfo = conpubvol .GetPublishInfo ()
208257 }
@@ -245,17 +294,13 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
245294
246295var _ = Describe ("NodeUnpublishVolume [Node Server]" , func () {
247296 var (
248- s csi.ControllerClient
249- c csi.NodeClient
250- controllerPublishSupported bool
297+ s csi.ControllerClient
298+ c csi.NodeClient
251299 )
252300
253301 BeforeEach (func () {
254302 s = csi .NewControllerClient (conn )
255303 c = csi .NewNodeClient (conn )
256- controllerPublishSupported = isCapabilitySupported (
257- s ,
258- csi .ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME )
259304 })
260305
261306 It ("should fail when no volume id is provided" , func () {
@@ -283,106 +328,6 @@ var _ = Describe("NodeUnpublishVolume [Node Server]", func() {
283328 Expect (ok ).To (BeTrue ())
284329 Expect (serverError .Code ()).To (Equal (codes .InvalidArgument ))
285330 })
286-
287- It ("should return appropriate values (no optional values added)" , func () {
288-
289- // Create Volume First
290- By ("creating a single node writer volume" )
291- name := "sanity"
292- vol , err := s .CreateVolume (
293- context .Background (),
294- & csi.CreateVolumeRequest {
295- Name : name ,
296- VolumeCapabilities : []* csi.VolumeCapability {
297- {
298- AccessType : & csi.VolumeCapability_Mount {
299- Mount : & csi.VolumeCapability_MountVolume {},
300- },
301- AccessMode : & csi.VolumeCapability_AccessMode {
302- Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
303- },
304- },
305- },
306- })
307- Expect (err ).NotTo (HaveOccurred ())
308- Expect (vol ).NotTo (BeNil ())
309- Expect (vol .GetVolume ()).NotTo (BeNil ())
310- Expect (vol .GetVolume ().GetId ()).NotTo (BeEmpty ())
311-
312- // ControllerPublishVolume
313- var conpubvol * csi.ControllerPublishVolumeResponse
314- if controllerPublishSupported {
315- By ("calling controllerpublish on the volume" )
316- conpubvol , err = s .ControllerPublishVolume (
317- context .Background (),
318- & csi.ControllerPublishVolumeRequest {
319- VolumeId : vol .GetVolume ().GetId (),
320- NodeId : "io.kubernetes.storage.mock" ,
321- VolumeCapability : & csi.VolumeCapability {
322- AccessType : & csi.VolumeCapability_Mount {
323- Mount : & csi.VolumeCapability_MountVolume {},
324- },
325- AccessMode : & csi.VolumeCapability_AccessMode {
326- Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
327- },
328- },
329- Readonly : false ,
330- })
331- Expect (err ).NotTo (HaveOccurred ())
332- Expect (conpubvol ).NotTo (BeNil ())
333- }
334-
335- // NodePublishVolume
336- By ("publishing the volume on a node" )
337- nodepubvolRequest := & csi.NodePublishVolumeRequest {
338- VolumeId : vol .GetVolume ().GetId (),
339- TargetPath : csiTargetPath ,
340- VolumeCapability : & csi.VolumeCapability {
341- AccessType : & csi.VolumeCapability_Mount {
342- Mount : & csi.VolumeCapability_MountVolume {},
343- },
344- AccessMode : & csi.VolumeCapability_AccessMode {
345- Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
346- },
347- },
348- }
349- if controllerPublishSupported {
350- nodepubvolRequest .PublishInfo = conpubvol .GetPublishInfo ()
351- }
352- nodepubvol , err := c .NodePublishVolume (context .Background (), nodepubvolRequest )
353- Expect (err ).NotTo (HaveOccurred ())
354- Expect (nodepubvol ).NotTo (BeNil ())
355-
356- // NodeUnpublishVolume
357- nodeunpubvol , err := c .NodeUnpublishVolume (
358- context .Background (),
359- & csi.NodeUnpublishVolumeRequest {
360- VolumeId : vol .GetVolume ().GetId (),
361- TargetPath : csiTargetPath ,
362- })
363- Expect (err ).NotTo (HaveOccurred ())
364- Expect (nodeunpubvol ).NotTo (BeNil ())
365-
366- if controllerPublishSupported {
367- By ("cleaning up unpublishing the volume" )
368- nodeunpubvol , err := c .NodeUnpublishVolume (
369- context .Background (),
370- & csi.NodeUnpublishVolumeRequest {
371- VolumeId : vol .GetVolume ().GetId (),
372- TargetPath : csiTargetPath ,
373- })
374- Expect (err ).NotTo (HaveOccurred ())
375- Expect (nodeunpubvol ).NotTo (BeNil ())
376- }
377-
378- By ("cleaning up deleting the volume" )
379- _ , err = s .DeleteVolume (
380- context .Background (),
381- & csi.DeleteVolumeRequest {
382- VolumeId : vol .GetVolume ().GetId (),
383- })
384- Expect (err ).NotTo (HaveOccurred ())
385- })
386331})
387332
388333// TODO: Tests for NodeStageVolume/NodeUnstageVolume
0 commit comments