@@ -46,7 +46,9 @@ func TestCreateVolume(t *testing.T) {
46
46
47
47
stdVolSize := int64 (5 * 1024 * 1024 * 1024 )
48
48
stdCapRange := & csi.CapacityRange {RequiredBytes : stdVolSize }
49
- stdParams := map [string ]string {}
49
+ stdParams := map [string ]string {
50
+ "type" : cloud .DefaultVolumeType ,
51
+ }
50
52
51
53
testCases := []struct {
52
54
name string
@@ -60,14 +62,15 @@ func TestCreateVolume(t *testing.T) {
60
62
Name : "random-vol-name" ,
61
63
CapacityRange : stdCapRange ,
62
64
VolumeCapabilities : stdVolCap ,
63
- Parameters : nil ,
65
+ Parameters : stdParams ,
64
66
}
65
67
66
68
ctx := context .Background ()
67
69
68
70
mockDisk := & cloud.Disk {
69
71
VolumeID : req .Name ,
70
72
CapacityGiB : util .BytesToGiB (stdVolSize ),
73
+ DiskType : cloud .DefaultVolumeType ,
71
74
}
72
75
73
76
mockCtl := gomock .NewController (t )
@@ -109,7 +112,7 @@ func TestCreateVolume(t *testing.T) {
109
112
},
110
113
},
111
114
},
112
- Parameters : nil ,
115
+ Parameters : stdParams ,
113
116
}
114
117
115
118
ctx := context .Background ()
@@ -121,6 +124,7 @@ func TestCreateVolume(t *testing.T) {
121
124
mockDiskOpts := & cloud.DiskOptions {
122
125
Shareable : true ,
123
126
CapacityBytes : stdVolSize ,
127
+ VolumeType : cloud .DefaultVolumeType ,
124
128
}
125
129
126
130
mockCtl := gomock .NewController (t )
@@ -163,18 +167,20 @@ func TestCreateVolume(t *testing.T) {
163
167
},
164
168
},
165
169
},
166
- Parameters : nil ,
170
+ Parameters : stdParams ,
167
171
}
168
172
169
173
ctx := context .Background ()
170
174
mockDisk := & cloud.Disk {
171
175
VolumeID : req .Name ,
172
176
CapacityGiB : util .BytesToGiB (stdVolSize ),
173
177
Shareable : true ,
178
+ DiskType : cloud .DefaultVolumeType ,
174
179
}
175
180
mockDiskOpts := & cloud.DiskOptions {
176
181
Shareable : true ,
177
182
CapacityBytes : stdVolSize ,
183
+ VolumeType : cloud .DefaultVolumeType ,
178
184
}
179
185
180
186
mockCtl := gomock .NewController (t )
@@ -217,18 +223,20 @@ func TestCreateVolume(t *testing.T) {
217
223
},
218
224
},
219
225
},
220
- Parameters : nil ,
226
+ Parameters : stdParams ,
221
227
}
222
228
223
229
ctx := context .Background ()
224
230
mockDisk := & cloud.Disk {
225
231
VolumeID : req .Name ,
226
232
CapacityGiB : util .BytesToGiB (stdVolSize ),
227
233
Shareable : false ,
234
+ DiskType : cloud .DefaultVolumeType ,
228
235
}
229
236
mockDiskOpts := & cloud.DiskOptions {
230
237
Shareable : false ,
231
238
CapacityBytes : stdVolSize ,
239
+ VolumeType : cloud .DefaultVolumeType ,
232
240
}
233
241
234
242
mockCtl := gomock .NewController (t )
@@ -319,6 +327,7 @@ func TestCreateVolume(t *testing.T) {
319
327
mockDisk := & cloud.Disk {
320
328
VolumeID : req .Name ,
321
329
CapacityGiB : util .BytesToGiB (stdVolSize ),
330
+ DiskType : cloud .DefaultVolumeType ,
322
331
}
323
332
324
333
mockCtl := gomock .NewController (t )
@@ -401,6 +410,7 @@ func TestCreateVolume(t *testing.T) {
401
410
mockDisk := & cloud.Disk {
402
411
VolumeID : req .Name ,
403
412
CapacityGiB : util .BytesToGiB (cloud .DefaultVolumeSize ),
413
+ DiskType : cloud .DefaultVolumeType ,
404
414
}
405
415
406
416
mockCtl := gomock .NewController (t )
@@ -449,7 +459,7 @@ func TestCreateVolume(t *testing.T) {
449
459
Name : "vol-test" ,
450
460
CapacityRange : & csi.CapacityRange {RequiredBytes : 1073741825 },
451
461
VolumeCapabilities : stdVolCap ,
452
- Parameters : nil ,
462
+ Parameters : stdParams ,
453
463
}
454
464
expVol := & csi.Volume {
455
465
CapacityBytes : 2147483648 , // 1 GiB + 1 byte = 2 GiB
@@ -462,6 +472,7 @@ func TestCreateVolume(t *testing.T) {
462
472
mockDisk := & cloud.Disk {
463
473
VolumeID : req .Name ,
464
474
CapacityGiB : util .BytesToGiB (expVol .CapacityBytes ),
475
+ DiskType : cloud .DefaultVolumeType ,
465
476
}
466
477
467
478
mockCtl := gomock .NewController (t )
@@ -516,14 +527,19 @@ func TestCreateVolume(t *testing.T) {
516
527
mockDisk := & cloud.Disk {
517
528
VolumeID : req .Name ,
518
529
CapacityGiB : util .BytesToGiB (volSize ),
530
+ DiskType : cloud .VolumeTypeTier1 ,
519
531
}
520
532
533
+ mockDiskOpts := & cloud.DiskOptions {
534
+ CapacityBytes : volSize ,
535
+ VolumeType : cloud .VolumeTypeTier1 ,
536
+ }
521
537
mockCtl := gomock .NewController (t )
522
538
defer mockCtl .Finish ()
523
539
524
540
mockCloud := mocks .NewMockCloud (mockCtl )
525
541
mockCloud .EXPECT ().GetDiskByName (gomock .Eq (req .Name )).Return (nil , nil )
526
- mockCloud .EXPECT ().CreateDisk (gomock .Eq (req .Name ), gomock . Any () ).Return (mockDisk , nil )
542
+ mockCloud .EXPECT ().CreateDisk (gomock .Eq (req .Name ), mockDiskOpts ).Return (mockDisk , nil )
527
543
528
544
powervsDriver := controllerService {
529
545
cloud : mockCloud ,
@@ -560,14 +576,19 @@ func TestCreateVolume(t *testing.T) {
560
576
mockDisk := & cloud.Disk {
561
577
VolumeID : req .Name ,
562
578
CapacityGiB : util .BytesToGiB (volSize ),
579
+ DiskType : cloud .VolumeTypeTier3 ,
580
+ }
581
+ mockDiskOpts := & cloud.DiskOptions {
582
+ CapacityBytes : volSize ,
583
+ VolumeType : cloud .VolumeTypeTier3 ,
563
584
}
564
585
565
586
mockCtl := gomock .NewController (t )
566
587
defer mockCtl .Finish ()
567
588
568
589
mockCloud := mocks .NewMockCloud (mockCtl )
569
590
mockCloud .EXPECT ().GetDiskByName (gomock .Eq (req .Name )).Return (nil , nil )
570
- mockCloud .EXPECT ().CreateDisk (gomock .Eq (req .Name ), gomock . Any () ).Return (mockDisk , nil )
591
+ mockCloud .EXPECT ().CreateDisk (gomock .Eq (req .Name ), mockDiskOpts ).Return (mockDisk , nil )
571
592
572
593
powervsDriver := controllerService {
573
594
cloud : mockCloud ,
@@ -624,6 +645,54 @@ func TestCreateVolume(t *testing.T) {
624
645
}
625
646
},
626
647
},
648
+ {
649
+ name : "Pass with no volume type parameter" ,
650
+ testFunc : func (t * testing.T ) {
651
+ // iops 5000 requires at least 10GB
652
+ volSize := int64 (20 * 1024 * 1024 * 1024 )
653
+ capRange := & csi.CapacityRange {RequiredBytes : volSize }
654
+ req := & csi.CreateVolumeRequest {
655
+ Name : "vol-test" ,
656
+ CapacityRange : capRange ,
657
+ VolumeCapabilities : stdVolCap ,
658
+ Parameters : map [string ]string {},
659
+ }
660
+
661
+ ctx := context .Background ()
662
+
663
+ mockDisk := & cloud.Disk {
664
+ VolumeID : req .Name ,
665
+ CapacityGiB : util .BytesToGiB (volSize ),
666
+ DiskType : cloud .DefaultVolumeType ,
667
+ }
668
+
669
+ mockDiskOpts := & cloud.DiskOptions {
670
+ CapacityBytes : volSize ,
671
+ VolumeType : cloud .DefaultVolumeType ,
672
+ }
673
+
674
+ mockCtl := gomock .NewController (t )
675
+ defer mockCtl .Finish ()
676
+
677
+ mockCloud := mocks .NewMockCloud (mockCtl )
678
+ mockCloud .EXPECT ().GetDiskByName (gomock .Eq (req .Name )).Return (nil , nil )
679
+ mockCloud .EXPECT ().CreateDisk (gomock .Eq (req .Name ), mockDiskOpts ).Return (mockDisk , nil )
680
+
681
+ powervsDriver := controllerService {
682
+ cloud : mockCloud ,
683
+ driverOptions : & Options {},
684
+ volumeLocks : util .NewVolumeLocks (),
685
+ }
686
+
687
+ if _ , err := powervsDriver .CreateVolume (ctx , req ); err != nil {
688
+ srvErr , ok := status .FromError (err )
689
+ if ! ok {
690
+ t .Fatalf ("Could not get error status code from error: %v" , srvErr )
691
+ }
692
+ t .Fatalf ("Unexpected error: %v" , srvErr .Code ())
693
+ }
694
+ },
695
+ },
627
696
{
628
697
name : "fail locked volume request" ,
629
698
testFunc : func (t * testing.T ) {
0 commit comments