@@ -211,6 +211,80 @@ func TestCreateVolumeWithIgnoreVolumeAZ(t *testing.T) {
211
211
assert .Equal ("foo" , actualRes .Volume .AccessibleTopology [0 ].GetSegments ()[topologyKey ])
212
212
}
213
213
214
+ // Test CreateVolume with --with-topology=false flag
215
+ func TestCreateVolumeWithTopologyDisabled (t * testing.T ) {
216
+ assert := assert .New (t )
217
+
218
+ tests := []struct {
219
+ name string
220
+ volumeParams map [string ]string
221
+ expectedVolumeAZ string
222
+ expectedCSITopology string
223
+ }{
224
+ {
225
+ name : "empty paramters" ,
226
+ volumeParams : nil ,
227
+ expectedVolumeAZ : "" ,
228
+ // FIXME(stephenfin): This should be unset
229
+ expectedCSITopology : "nova" ,
230
+ },
231
+ {
232
+ name : "availability parameter" ,
233
+ volumeParams : map [string ]string {
234
+ "availability" : "cinder" ,
235
+ },
236
+ // FIXME(stephenfin): This should be "cinder" per the parameter
237
+ expectedVolumeAZ : "" ,
238
+ // ...and this should be unset
239
+ expectedCSITopology : "nova" ,
240
+ },
241
+ }
242
+ for _ , tt := range tests {
243
+ t .Run (tt .name , func (t * testing.T ) {
244
+ fakeCs , osmock := fakeControllerServer ()
245
+ fakeCs .Driver .withTopology = false
246
+
247
+ properties := map [string ]string {cinderCSIClusterIDKey : FakeCluster }
248
+ osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), FakeVolType , tt .expectedVolumeAZ , "" , "" , "" , properties ).Return (& FakeVol , nil )
249
+ osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
250
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
251
+
252
+ // Fake request
253
+ fakeReq := & csi.CreateVolumeRequest {
254
+ Name : FakeVolName ,
255
+ VolumeCapabilities : []* csi.VolumeCapability {
256
+ {
257
+ AccessMode : & csi.VolumeCapability_AccessMode {
258
+ Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
259
+ },
260
+ },
261
+ },
262
+
263
+ Parameters : tt .volumeParams ,
264
+
265
+ AccessibilityRequirements : nil ,
266
+ }
267
+
268
+ // Invoke CreateVolume
269
+ actualRes , err := fakeCs .CreateVolume (FakeCtx , fakeReq )
270
+ if err != nil {
271
+ t .Errorf ("failed to CreateVolume: %v" , err )
272
+ }
273
+
274
+ // Assert
275
+ assert .NotNil (actualRes .Volume )
276
+ assert .NotNil (actualRes .Volume .CapacityBytes )
277
+ assert .NotEqual (0 , len (actualRes .Volume .VolumeId ), "Volume Id is nil" )
278
+ if tt .expectedCSITopology == "" {
279
+ assert .Nil (actualRes .Volume .AccessibleTopology )
280
+ } else {
281
+ assert .GreaterOrEqual (len (actualRes .Volume .AccessibleTopology ), 1 )
282
+ assert .Equal (tt .expectedCSITopology , actualRes .Volume .AccessibleTopology [0 ].GetSegments ()[topologyKey ])
283
+ }
284
+ })
285
+ }
286
+ }
287
+
214
288
func TestCreateVolumeWithExtraMetadata (t * testing.T ) {
215
289
fakeCs , osmock := fakeControllerServer ()
216
290
0 commit comments