@@ -29,6 +29,26 @@ import (
29
29
. "github.com/onsi/gomega"
30
30
)
31
31
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
+
32
52
var _ = Describe ("NodeGetCapabilities [Node Server]" , func () {
33
53
var (
34
54
c csi.NodeClient
@@ -53,6 +73,7 @@ var _ = Describe("NodeGetCapabilities [Node Server]", func() {
53
73
54
74
switch cap .GetRpc ().GetType () {
55
75
case csi .NodeServiceCapability_RPC_UNKNOWN :
76
+ case csi .NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME :
56
77
default :
57
78
Fail (fmt .Sprintf ("Unknown capability: %v\n " , cap .GetRpc ().GetType ()))
58
79
}
@@ -85,14 +106,16 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
85
106
s csi.ControllerClient
86
107
c csi.NodeClient
87
108
controllerPublishSupported bool
109
+ nodeStageSupported bool
88
110
)
89
111
90
112
BeforeEach (func () {
91
113
s = csi .NewControllerClient (conn )
92
114
c = csi .NewNodeClient (conn )
93
- controllerPublishSupported = isCapabilitySupported (
115
+ controllerPublishSupported = isControllerCapabilitySupported (
94
116
s ,
95
117
csi .ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME )
118
+ nodeStageSupported = isNodeCapabilitySupported (c , csi .NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME )
96
119
})
97
120
98
121
It ("should fail when no volume id is provided" , func () {
@@ -189,6 +212,29 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
189
212
Expect (err ).NotTo (HaveOccurred ())
190
213
Expect (conpubvol ).NotTo (BeNil ())
191
214
}
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
+ }
192
238
// NodePublishVolume
193
239
By ("publishing the volume on a node" )
194
240
nodepubvolRequest := & csi.NodePublishVolumeRequest {
@@ -203,6 +249,9 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
203
249
},
204
250
},
205
251
}
252
+ if nodeStageSupported {
253
+ nodepubvolRequest .StagingTargetPath = stagingTargetPath
254
+ }
206
255
if controllerPublishSupported {
207
256
nodepubvolRequest .PublishInfo = conpubvol .GetPublishInfo ()
208
257
}
@@ -245,17 +294,11 @@ var _ = Describe("NodePublishVolume [Node Server]", func() {
245
294
246
295
var _ = Describe ("NodeUnpublishVolume [Node Server]" , func () {
247
296
var (
248
- s csi.ControllerClient
249
- c csi.NodeClient
250
- controllerPublishSupported bool
297
+ c csi.NodeClient
251
298
)
252
299
253
300
BeforeEach (func () {
254
- s = csi .NewControllerClient (conn )
255
301
c = csi .NewNodeClient (conn )
256
- controllerPublishSupported = isCapabilitySupported (
257
- s ,
258
- csi .ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME )
259
302
})
260
303
261
304
It ("should fail when no volume id is provided" , func () {
@@ -283,106 +326,6 @@ var _ = Describe("NodeUnpublishVolume [Node Server]", func() {
283
326
Expect (ok ).To (BeTrue ())
284
327
Expect (serverError .Code ()).To (Equal (codes .InvalidArgument ))
285
328
})
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
- })
386
329
})
387
330
388
331
// TODO: Tests for NodeStageVolume/NodeUnstageVolume
0 commit comments