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