Skip to content

Commit 558663f

Browse files
committed
cinder-csi-plugin: Add tests for --with-topology=false
This highlights an issue (IMO) is how we handle parameter generation. Signed-off-by: Stephen Finucane <[email protected]>
1 parent 1bc5b09 commit 558663f

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

pkg/csi/cinder/controllerserver_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,80 @@ func TestCreateVolumeWithIgnoreVolumeAZ(t *testing.T) {
260260
assert.Equal("foo", actualRes.Volume.AccessibleTopology[0].GetSegments()[topologyKey])
261261
}
262262

263+
// Test CreateVolume with --with-topology=false flag
264+
func TestCreateVolumeWithTopologyDisabled(t *testing.T) {
265+
assert := assert.New(t)
266+
267+
tests := []struct {
268+
name string
269+
volumeParams map[string]string
270+
expectedVolumeAZ string
271+
expectedCSITopology string
272+
}{
273+
{
274+
name: "empty paramters",
275+
volumeParams: nil,
276+
expectedVolumeAZ: "",
277+
// FIXME(stephenfin): This should be unset
278+
expectedCSITopology: "nova",
279+
},
280+
{
281+
name: "availability parameter",
282+
volumeParams: map[string]string{
283+
"availability": "cinder",
284+
},
285+
// FIXME(stephenfin): This should be "cinder" per the parameter
286+
expectedVolumeAZ: "",
287+
// ...and this should be unset
288+
expectedCSITopology: "nova",
289+
},
290+
}
291+
for _, tt := range tests {
292+
t.Run(tt.name, func(t *testing.T) {
293+
fakeCs, osmock := fakeControllerServer()
294+
fakeCs.Driver.withTopology = false
295+
296+
properties := map[string]string{cinderCSIClusterIDKey: FakeCluster}
297+
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), FakeVolType, tt.expectedVolumeAZ, "", "", "", properties).Return(&FakeVol, nil)
298+
osmock.On("GetVolumesByName", FakeVolName).Return(FakeVolListEmpty, nil)
299+
osmock.On("GetBlockStorageOpts").Return(openstack.BlockStorageOpts{})
300+
301+
// Fake request
302+
fakeReq := &csi.CreateVolumeRequest{
303+
Name: FakeVolName,
304+
VolumeCapabilities: []*csi.VolumeCapability{
305+
{
306+
AccessMode: &csi.VolumeCapability_AccessMode{
307+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
308+
},
309+
},
310+
},
311+
312+
Parameters: tt.volumeParams,
313+
314+
AccessibilityRequirements: nil,
315+
}
316+
317+
// Invoke CreateVolume
318+
actualRes, err := fakeCs.CreateVolume(FakeCtx, fakeReq)
319+
if err != nil {
320+
t.Errorf("failed to CreateVolume: %v", err)
321+
}
322+
323+
// Assert
324+
assert.NotNil(actualRes.Volume)
325+
assert.NotNil(actualRes.Volume.CapacityBytes)
326+
assert.NotEqual(0, len(actualRes.Volume.VolumeId), "Volume Id is nil")
327+
if tt.expectedCSITopology == "" {
328+
assert.Nil(actualRes.Volume.AccessibleTopology)
329+
} else {
330+
assert.GreaterOrEqual(len(actualRes.Volume.AccessibleTopology), 1)
331+
assert.Equal(tt.expectedCSITopology, actualRes.Volume.AccessibleTopology[0].GetSegments()[topologyKey])
332+
}
333+
})
334+
}
335+
}
336+
263337
func TestCreateVolumeWithExtraMetadata(t *testing.T) {
264338
fakeCs, osmock := fakeControllerServer()
265339

0 commit comments

Comments
 (0)