@@ -63,6 +63,7 @@ func TestCreateVolume(t *testing.T) {
63
63
properties := map [string ]string {cinderCSIClusterIDKey : FakeCluster }
64
64
osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), FakeVolType , FakeAvailability , "" , "" , "" , properties ).Return (& FakeVol , nil )
65
65
osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
66
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
66
67
67
68
assert := assert .New (t )
68
69
@@ -110,6 +111,7 @@ func TestCreateVolumeQuotaError(t *testing.T) {
110
111
properties := map [string ]string {cinderCSIClusterIDKey : FakeCluster }
111
112
osmock .On ("CreateVolume" , errorVolume , mock .AnythingOfType ("int" ), FakeVolType , FakeAvailability , "" , "" , "" , properties ).Return (& volumes.Volume {}, cpoerrors .ErrQuotaExceeded )
112
113
osmock .On ("GetVolumesByName" , errorVolume ).Return (FakeVolListEmpty , nil )
114
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
113
115
114
116
assert := assert .New (t )
115
117
@@ -155,6 +157,7 @@ func TestCreateVolumeWithParam(t *testing.T) {
155
157
properties := map [string ]string {cinderCSIClusterIDKey : FakeCluster }
156
158
osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), "dummyVolType" , "cinder" , "" , "" , "" , properties ).Return (& FakeVol , nil )
157
159
osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
160
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
158
161
159
162
assert := assert .New (t )
160
163
@@ -197,6 +200,66 @@ func TestCreateVolumeWithParam(t *testing.T) {
197
200
assert .Equal (FakeAvailability , actualRes .Volume .AccessibleTopology [0 ].GetSegments ()[topologyKey ])
198
201
}
199
202
203
+ // Test CreateVolume with ignore-volume-az option
204
+ func TestCreateVolumeWithIgnoreVolumeAZ (t * testing.T ) {
205
+ fakeCs , osmock := fakeControllerServer ()
206
+
207
+ properties := map [string ]string {cinderCSIClusterIDKey : FakeCluster }
208
+ osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), FakeVolType , "cinder" , "" , "" , "" , properties ).Return (& FakeVol , nil )
209
+ osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
210
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {IgnoreVolumeAZ : true })
211
+
212
+ assert := assert .New (t )
213
+
214
+ // Fake request
215
+ fakeReq := & csi.CreateVolumeRequest {
216
+ Name : FakeVolName ,
217
+ VolumeCapabilities : []* csi.VolumeCapability {
218
+ {
219
+ AccessMode : & csi.VolumeCapability_AccessMode {
220
+ Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
221
+ },
222
+ },
223
+ },
224
+
225
+ Parameters : map [string ]string {
226
+ "availability" : "cinder" ,
227
+ },
228
+
229
+ AccessibilityRequirements : & csi.TopologyRequirement {
230
+ Requisite : []* csi.Topology {
231
+ {
232
+ Segments : map [string ]string {topologyKey : "bar" },
233
+ },
234
+ {
235
+ Segments : map [string ]string {topologyKey : "foo" },
236
+ },
237
+ },
238
+ Preferred : []* csi.Topology {
239
+ {
240
+ Segments : map [string ]string {topologyKey : "foo" },
241
+ },
242
+ {
243
+ Segments : map [string ]string {topologyKey : "bar" },
244
+ },
245
+ },
246
+ },
247
+ }
248
+
249
+ // Invoke CreateVolume
250
+ actualRes , err := fakeCs .CreateVolume (FakeCtx , fakeReq )
251
+ if err != nil {
252
+ t .Errorf ("failed to CreateVolume: %v" , err )
253
+ }
254
+
255
+ // Assert
256
+ assert .NotNil (actualRes .Volume )
257
+ assert .NotNil (actualRes .Volume .CapacityBytes )
258
+ assert .NotEqual (0 , len (actualRes .Volume .VolumeId ), "Volume Id is nil" )
259
+ assert .NotNil (actualRes .Volume .AccessibleTopology )
260
+ assert .Equal ("foo" , actualRes .Volume .AccessibleTopology [0 ].GetSegments ()[topologyKey ])
261
+ }
262
+
200
263
func TestCreateVolumeWithExtraMetadata (t * testing.T ) {
201
264
fakeCs , osmock := fakeControllerServer ()
202
265
@@ -209,6 +272,7 @@ func TestCreateVolumeWithExtraMetadata(t *testing.T) {
209
272
}
210
273
osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), FakeVolType , FakeAvailability , "" , "" , "" , properties ).Return (& FakeVol , nil )
211
274
osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
275
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
212
276
213
277
// Fake request
214
278
fakeReq := & csi.CreateVolumeRequest {
@@ -248,6 +312,7 @@ func TestCreateVolumeFromSnapshot(t *testing.T) {
248
312
properties := map [string ]string {cinderCSIClusterIDKey : FakeCluster }
249
313
osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), FakeVolType , "" , FakeSnapshotID , "" , "" , properties ).Return (& FakeVolFromSnapshot , nil )
250
314
osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
315
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
251
316
252
317
assert := assert .New (t )
253
318
@@ -294,6 +359,7 @@ func TestCreateVolumeFromSourceVolume(t *testing.T) {
294
359
properties := map [string ]string {cinderCSIClusterIDKey : FakeCluster }
295
360
osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), FakeVolType , "" , "" , FakeVolID , "" , properties ).Return (& FakeVolFromSourceVolume , nil )
296
361
osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
362
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
297
363
298
364
assert := assert .New (t )
299
365
0 commit comments