-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathnode.go
755 lines (657 loc) · 23.2 KB
/
node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package sanity
import (
"context"
"fmt"
"github.com/container-storage-interface/spec/lib/go/csi"
"google.golang.org/grpc/codes"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func isNodeCapabilitySupported(c csi.NodeClient,
capType csi.NodeServiceCapability_RPC_Type,
) bool {
caps, err := c.NodeGetCapabilities(
context.Background(),
&csi.NodeGetCapabilitiesRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(caps).NotTo(BeNil())
for _, cap := range caps.GetCapabilities() {
Expect(cap.GetRpc()).NotTo(BeNil())
if cap.GetRpc().GetType() == capType {
return true
}
}
return false
}
func isPluginCapabilitySupported(c csi.IdentityClient,
capType csi.PluginCapability_Service_Type,
) bool {
caps, err := c.GetPluginCapabilities(
context.Background(),
&csi.GetPluginCapabilitiesRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(caps).NotTo(BeNil())
for _, cap := range caps.GetCapabilities() {
if cap.GetService() != nil && cap.GetService().GetType() == capType {
return true
}
}
return false
}
func runControllerTest(sc *TestContext, r *Resources, controllerPublishSupported bool, nodeStageSupported bool, nodeVolumeStatsSupported bool, count int) {
name := UniqueString(fmt.Sprintf("sanity-node-full-%d", count))
By("getting node information")
ni, err := r.NodeGetInfo(
context.Background(),
&csi.NodeGetInfoRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(ni).NotTo(BeNil())
Expect(ni.GetNodeId()).NotTo(BeEmpty())
var accReqs *csi.TopologyRequirement
if ni.AccessibleTopology != nil {
// Topology requirements are honored if provided by the driver
accReqs = &csi.TopologyRequirement{
Requisite: []*csi.Topology{ni.AccessibleTopology},
}
}
// Create Volume First
By("creating a single node writer volume")
req := MakeCreateVolumeReq(sc, name)
req.AccessibilityRequirements = accReqs
vol := r.MustCreateVolume(context.Background(), req)
var conpubvol *csi.ControllerPublishVolumeResponse
if controllerPublishSupported {
By("controller publishing volume")
conpubvol, err = r.ControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
NodeId: ni.GetNodeId(),
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
VolumeContext: vol.GetVolume().GetVolumeContext(),
Readonly: false,
Secrets: sc.Secrets.ControllerPublishVolumeSecret,
},
)
Expect(err).NotTo(HaveOccurred())
Expect(conpubvol).NotTo(BeNil())
}
// NodeStageVolume
if nodeStageSupported {
for i := 0; i < count; i++ {
By("node staging volume")
nodestagevol, err := r.NodeStageVolume(
context.Background(),
&csi.NodeStageVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
StagingTargetPath: sc.StagingPath,
VolumeContext: vol.GetVolume().GetVolumeContext(),
PublishContext: conpubvol.GetPublishContext(),
Secrets: sc.Secrets.NodeStageVolumeSecret,
},
)
Expect(err).NotTo(HaveOccurred())
Expect(nodestagevol).NotTo(BeNil())
}
}
// NodePublishVolume
var stagingPath string
if nodeStageSupported {
stagingPath = sc.StagingPath
}
for i := 0; i < count; i++ {
By("publishing the volume on a node")
nodepubvol, err := r.NodePublishVolume(
context.Background(),
&csi.NodePublishVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
TargetPath: sc.TargetPath + "/target",
StagingTargetPath: stagingPath,
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
VolumeContext: vol.GetVolume().GetVolumeContext(),
PublishContext: conpubvol.GetPublishContext(),
Secrets: sc.Secrets.NodePublishVolumeSecret,
},
)
Expect(err).NotTo(HaveOccurred())
Expect(nodepubvol).NotTo(BeNil())
}
// NodeGetVolumeStats
if nodeVolumeStatsSupported {
By("Get node volume stats")
statsResp, err := r.NodeGetVolumeStats(
context.Background(),
&csi.NodeGetVolumeStatsRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
VolumePath: sc.TargetPath + "/target",
},
)
Expect(err).ToNot(HaveOccurred())
Expect(statsResp.GetUsage()).ToNot(BeNil())
}
}
var _ = DescribeSanity("Node Service", func(sc *TestContext) {
var (
r *Resources
providesControllerService bool
controllerPublishSupported bool
nodeStageSupported bool
nodeVolumeStatsSupported bool
nodeExpansionSupported bool
controllerExpansionSupported bool
)
createVolume := func(volumeName string) *csi.CreateVolumeResponse {
By("creating a single node writer volume for expansion")
return r.MustCreateVolume(
context.Background(),
MakeCreateVolumeReq(sc, volumeName),
)
}
controllerPublishVolume := func(volumeName string, vol *csi.CreateVolumeResponse, nid *csi.NodeGetInfoResponse) *csi.ControllerPublishVolumeResponse {
var conpubvol *csi.ControllerPublishVolumeResponse
if controllerPublishSupported {
By("controller publishing volume")
conpubvol = r.MustControllerPublishVolume(
context.Background(),
&csi.ControllerPublishVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
NodeId: nid.GetNodeId(),
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
VolumeContext: vol.GetVolume().GetVolumeContext(),
Readonly: false,
Secrets: sc.Secrets.ControllerPublishVolumeSecret,
},
)
}
return conpubvol
}
nodeStageVolume := func(volumeName string, vol *csi.CreateVolumeResponse, conpubvol *csi.ControllerPublishVolumeResponse) *csi.NodeStageVolumeResponse {
// NodeStageVolume
if nodeStageSupported {
By("node staging volume")
nodeStageRequest := &csi.NodeStageVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
StagingTargetPath: sc.StagingPath,
VolumeContext: vol.GetVolume().GetVolumeContext(),
Secrets: sc.Secrets.NodeStageVolumeSecret,
}
if conpubvol != nil {
nodeStageRequest.PublishContext = conpubvol.GetPublishContext()
}
nodestagevol, err := r.NodeStageVolume(
context.Background(),
nodeStageRequest,
)
Expect(err).NotTo(HaveOccurred())
Expect(nodestagevol).NotTo(BeNil())
return nodestagevol
}
return nil
}
nodePublishVolume := func(volumeName string, vol *csi.CreateVolumeResponse, conpubvol *csi.ControllerPublishVolumeResponse) *csi.NodePublishVolumeResponse {
By("publishing the volume on a node")
var stagingPath string
if nodeStageSupported {
stagingPath = sc.StagingPath
}
nodePublishRequest := &csi.NodePublishVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
TargetPath: sc.TargetPath + "/target",
StagingTargetPath: stagingPath,
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
VolumeContext: vol.GetVolume().GetVolumeContext(),
Secrets: sc.Secrets.NodePublishVolumeSecret,
}
if conpubvol != nil {
nodePublishRequest.PublishContext = conpubvol.GetPublishContext()
}
nodepubvol, err := r.NodePublishVolume(
context.Background(),
nodePublishRequest,
)
Expect(err).NotTo(HaveOccurred())
Expect(nodepubvol).NotTo(BeNil())
return nodepubvol
}
BeforeEach(func() {
cl := csi.NewControllerClient(sc.ControllerConn)
n := csi.NewNodeClient(sc.Conn)
i := csi.NewIdentityClient(sc.Conn)
req := &csi.GetPluginCapabilitiesRequest{}
res, err := i.GetPluginCapabilities(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(res).NotTo(BeNil())
for _, cap := range res.GetCapabilities() {
switch cap.GetType().(type) {
case *csi.PluginCapability_Service_:
switch cap.GetService().GetType() {
case csi.PluginCapability_Service_CONTROLLER_SERVICE:
providesControllerService = true
}
}
}
if providesControllerService {
controllerPublishSupported = isControllerCapabilitySupported(
cl,
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME)
}
nodeStageSupported = isNodeCapabilitySupported(n, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME)
nodeVolumeStatsSupported = isNodeCapabilitySupported(n, csi.NodeServiceCapability_RPC_GET_VOLUME_STATS)
nodeExpansionSupported = isNodeCapabilitySupported(n, csi.NodeServiceCapability_RPC_EXPAND_VOLUME)
controllerExpansionSupported = isControllerCapabilitySupported(cl, csi.ControllerServiceCapability_RPC_EXPAND_VOLUME)
r = &Resources{
Context: sc,
ControllerClient: cl,
NodeClient: n,
}
})
AfterEach(func() {
r.Cleanup()
})
Describe("NodeGetCapabilities", func() {
It("should return appropriate capabilities", func() {
caps, err := r.NodeGetCapabilities(
context.Background(),
&csi.NodeGetCapabilitiesRequest{})
By("checking successful response")
Expect(err).NotTo(HaveOccurred())
Expect(caps).NotTo(BeNil())
for _, cap := range caps.GetCapabilities() {
Expect(cap.GetRpc()).NotTo(BeNil())
switch cap.GetRpc().GetType() {
case csi.NodeServiceCapability_RPC_UNKNOWN:
case csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME:
case csi.NodeServiceCapability_RPC_GET_VOLUME_STATS:
case csi.NodeServiceCapability_RPC_EXPAND_VOLUME:
case csi.NodeServiceCapability_RPC_VOLUME_CONDITION:
case csi.NodeServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER:
case csi.NodeServiceCapability_RPC_VOLUME_MOUNT_GROUP:
default:
Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetRpc().GetType()))
}
}
})
})
Describe("NodeGetInfo", func() {
var (
i csi.IdentityClient
accessibilityConstraintSupported bool
)
BeforeEach(func() {
i = csi.NewIdentityClient(sc.Conn)
accessibilityConstraintSupported = isPluginCapabilitySupported(i, csi.PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS)
})
It("should return appropriate values", func() {
ninfo, err := r.NodeGetInfo(
context.Background(),
&csi.NodeGetInfoRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(ninfo).NotTo(BeNil())
Expect(ninfo.GetNodeId()).NotTo(BeEmpty())
Expect(ninfo.GetMaxVolumesPerNode()).NotTo(BeNumerically("<", 0))
if accessibilityConstraintSupported {
Expect(ninfo.GetAccessibleTopology()).NotTo(BeNil())
}
})
})
Describe("NodePublishVolume", func() {
It("should fail when no volume id is provided", func() {
rsp, err := r.NodePublishVolume(
context.Background(),
&csi.NodePublishVolumeRequest{
Secrets: sc.Secrets.NodePublishVolumeSecret,
},
)
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
It("should fail when no target path is provided", func() {
rsp, err := r.NodePublishVolume(
context.Background(),
&csi.NodePublishVolumeRequest{
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
Secrets: sc.Secrets.NodePublishVolumeSecret,
},
)
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
It("should fail when no volume capability is provided", func() {
rsp, err := r.NodePublishVolume(
context.Background(),
&csi.NodePublishVolumeRequest{
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
VolumeCapability: nil,
TargetPath: sc.TargetPath + "/target",
Secrets: sc.Secrets.NodePublishVolumeSecret,
},
)
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
})
Describe("NodeUnpublishVolume", func() {
It("should fail when no volume id is provided", func() {
rsp, err := r.NodeUnpublishVolume(
context.Background(),
&csi.NodeUnpublishVolumeRequest{})
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
It("should fail when no target path is provided", func() {
rsp, err := r.NodeUnpublishVolume(
context.Background(),
&csi.NodeUnpublishVolumeRequest{
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
})
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
It("should remove target path", func() {
// This test may break for consumers that are using
// custom target path functions if they have not yet
// implemented similar functionality to check if the
// path exists. Skip this test if there is a custom
// command or function provided to create the path,
// but not yet provided to check the path.
if sc.Config.CreateTargetPathCmd != "" && sc.Config.CheckPathCmd == "" {
Skip("CreateTargetPathCmd was set, but CheckPathCmd was not. Please update your testing configuration to enable CheckPathCmd.")
}
if sc.Config.CreateTargetDir != nil && sc.Config.CheckPath == nil {
Skip("CreateTargetDir was set, but CheckPath was not. Please update your testing configuration to enable CheckPath.")
}
name := UniqueString("sanity-node-unpublish-volume")
vol := createVolume(name)
volid := vol.GetVolume().GetVolumeId()
volpath := sc.TargetPath + "/target"
By("Getting a node id")
nid, err := r.NodeGetInfo(
context.Background(),
&csi.NodeGetInfoRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(nid).NotTo(BeNil())
Expect(nid.GetNodeId()).NotTo(BeEmpty())
By("Staging and publishing a volume")
conpubvol := controllerPublishVolume(name, vol, nid)
_ = nodeStageVolume(name, vol, conpubvol)
_ = nodePublishVolume(name, vol, conpubvol)
// Verify that the path exists before calling
// NodeUnpublishVolume.
By("Checking the target path exists")
pa, err := CheckPath(volpath, sc.Config)
Expect(err).NotTo(HaveOccurred(), "checking path %q", volpath)
Expect(pa).NotTo(Equal(PathIsNotFound), "path %q should have been created by CSI driver and the test config should be enabling testing for that path", volpath)
By("Unpublishing the volume")
_, err = r.NodeUnpublishVolume(
context.Background(),
&csi.NodeUnpublishVolumeRequest{
VolumeId: volid,
TargetPath: volpath,
},
)
Expect(err).NotTo(HaveOccurred())
// The CSI spec states that the SP MUST delete
// the file or directory it created at this path
// as part of NodeUnpublishVolume.
By("Checking the target path was removed")
pa, err = CheckPath(volpath, sc.Config)
Expect(err).NotTo(HaveOccurred(), "checking path %q", volpath)
Expect(pa).To(Equal(PathIsNotFound), "path %q should have been removed by the CSI driver during NodeUnpublishVolume", volpath)
})
})
Describe("NodeStageVolume", func() {
var (
device string
)
BeforeEach(func() {
if !nodeStageSupported {
Skip("NodeStageVolume not supported")
}
device = "/dev/mock"
})
It("should fail when no volume id is provided", func() {
rsp, err := r.NodeStageVolume(
context.Background(),
&csi.NodeStageVolumeRequest{
StagingTargetPath: sc.StagingPath,
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
PublishContext: map[string]string{
"device": device,
},
Secrets: sc.Secrets.NodeStageVolumeSecret,
},
)
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
It("should fail when no staging target path is provided", func() {
rsp, err := r.NodeStageVolume(
context.Background(),
&csi.NodeStageVolumeRequest{
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
PublishContext: map[string]string{
"device": device,
},
Secrets: sc.Secrets.NodeStageVolumeSecret,
},
)
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
It("should fail when no volume capability is provided", func() {
// Create Volume First
By("creating a single node writer volume")
name := UniqueString("sanity-node-stage-nocaps")
vol := r.MustCreateVolume(
context.Background(),
MakeCreateVolumeReq(sc, name),
)
rsp, err := r.NodeStageVolume(
context.Background(),
&csi.NodeStageVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
StagingTargetPath: sc.StagingPath,
PublishContext: map[string]string{
"device": device,
},
Secrets: sc.Secrets.NodeStageVolumeSecret,
},
)
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
})
Describe("NodeUnstageVolume", func() {
BeforeEach(func() {
if !nodeStageSupported {
Skip("NodeUnstageVolume not supported")
}
})
It("should fail when no volume id is provided", func() {
rsp, err := r.NodeUnstageVolume(
context.Background(),
&csi.NodeUnstageVolumeRequest{
StagingTargetPath: sc.StagingPath,
})
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
It("should fail when no staging target path is provided", func() {
rsp, err := r.NodeUnstageVolume(
context.Background(),
&csi.NodeUnstageVolumeRequest{
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
})
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
})
Describe("NodeGetVolumeStats", func() {
BeforeEach(func() {
if !nodeVolumeStatsSupported {
Skip("NodeGetVolume not supported")
}
})
It("should fail when no volume id is provided", func() {
rsp, err := r.NodeGetVolumeStats(
context.Background(),
&csi.NodeGetVolumeStatsRequest{
VolumePath: "some/path",
},
)
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
It("should fail when no volume path is provided", func() {
rsp, err := r.NodeGetVolumeStats(
context.Background(),
&csi.NodeGetVolumeStatsRequest{
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
},
)
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
It("should fail when volume is not found", func() {
rsp, err := r.NodeGetVolumeStats(
context.Background(),
&csi.NodeGetVolumeStatsRequest{
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
VolumePath: "some/path",
},
)
ExpectErrorCode(rsp, err, codes.NotFound)
})
It("should fail when volume does not exist on the specified path", func() {
name := UniqueString("sanity-node-get-volume-stats")
vol := createVolume(name)
By("getting a node id")
nid, err := r.NodeGetInfo(
context.Background(),
&csi.NodeGetInfoRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(nid).NotTo(BeNil())
Expect(nid.GetNodeId()).NotTo(BeEmpty())
conpubvol := controllerPublishVolume(name, vol, nid)
// NodeStageVolume
_ = nodeStageVolume(name, vol, conpubvol)
// NodePublishVolume
_ = nodePublishVolume(name, vol, conpubvol)
// NodeGetVolumeStats
By("Get node volume stats")
rsp, err := r.NodeGetVolumeStats(
context.Background(),
&csi.NodeGetVolumeStatsRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
VolumePath: "some/path",
},
)
ExpectErrorCode(rsp, err, codes.NotFound)
})
})
Describe("NodeExpandVolume", func() {
BeforeEach(func() {
if !nodeExpansionSupported {
Skip("NodeExpandVolume not supported")
}
})
It("should fail when no volume id is provided", func() {
rsp, err := r.NodeExpandVolume(
context.Background(),
&csi.NodeExpandVolumeRequest{
VolumePath: sc.TargetPath,
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
)
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
It("should fail when no volume path is provided", func() {
name := UniqueString("sanity-node-expand-volume-valid-id")
vol := createVolume(name)
rsp, err := r.NodeExpandVolume(
context.Background(),
&csi.NodeExpandVolumeRequest{
VolumeId: vol.GetVolume().VolumeId,
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
},
)
ExpectErrorCode(rsp, err, codes.InvalidArgument)
})
It("should fail when volume is not found", func() {
rsp, err := r.NodeExpandVolume(
context.Background(),
&csi.NodeExpandVolumeRequest{
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
VolumePath: "some/path",
},
)
ExpectErrorCode(rsp, err, codes.NotFound)
})
It("should work if node-expand is called after node-publish", func() {
name := UniqueString("sanity-node-expand-volume")
// Created volumes are automatically cleaned up via cl.DeleteVolumes
vol := createVolume(name)
if controllerExpansionSupported {
By("controller expanding the volume")
expReq := &csi.ControllerExpandVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeExpandSize(sc),
},
Secrets: sc.Secrets.ControllerExpandVolumeSecret,
}
rsp, err := r.ControllerExpandVolume(context.Background(), expReq)
Expect(err).NotTo(HaveOccurred())
Expect(rsp).NotTo(BeNil())
Expect(rsp.GetCapacityBytes()).To(Equal(TestVolumeExpandSize(sc)))
}
By("getting a node id")
nid, err := r.NodeGetInfo(
context.Background(),
&csi.NodeGetInfoRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(nid).NotTo(BeNil())
Expect(nid.GetNodeId()).NotTo(BeEmpty())
conpubvol := controllerPublishVolume(name, vol, nid)
// NodeStageVolume
_ = nodeStageVolume(name, vol, conpubvol)
// NodePublishVolume
_ = nodePublishVolume(name, vol, conpubvol)
By("expanding the volume on a node")
_, err = r.NodeExpandVolume(
context.Background(),
&csi.NodeExpandVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
VolumePath: sc.TargetPath + "/target",
CapacityRange: &csi.CapacityRange{
RequiredBytes: TestVolumeExpandSize(sc),
},
},
)
Expect(err).ToNot(HaveOccurred(), "while expanding volume on node")
})
})
// CSI spec poses no specific requirements for the cluster/storage setups that a SP MUST support. To perform
// meaningful checks the following test assumes that topology-aware provisioning on a single node setup is supported
It("should work", func() {
if !providesControllerService {
Skip("Controller Service not provided: CreateVolume not supported")
}
By("runControllerTest")
runControllerTest(sc, r, controllerPublishSupported, nodeStageSupported, nodeVolumeStatsSupported, 1)
})
It("should be idempotent", func() {
if !providesControllerService {
Skip("Controller Service not provided: CreateVolume not supported")
}
if sc.Config.IdempotentCount <= 0 {
Skip("Config.IdempotentCount is zero or negative, skip tests")
}
count := sc.Config.IdempotentCount
By("runControllerTest with Idempotent count")
runControllerTest(sc, r, controllerPublishSupported, nodeStageSupported, nodeVolumeStatsSupported, count)
})
})