Skip to content

Commit 0bf6293

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 2cf46b0 commit 0bf6293

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
@@ -208,6 +208,80 @@ func TestCreateVolumeWithIgnoreVolumeAZ(t *testing.T) {
208208
assert.Equal("foo", actualRes.Volume.AccessibleTopology[0].GetSegments()[topologyKey])
209209
}
210210

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+
211285
func TestCreateVolumeWithExtraMetadata(t *testing.T) {
212286
fakeCs, osmock := fakeControllerServer()
213287

0 commit comments

Comments
 (0)