Skip to content

Commit 1bc5b09

Browse files
committed
cinder-csi-plugin: Add tests for ignore-volume-az
Signed-off-by: Stephen Finucane <[email protected]>
1 parent 1bc40b5 commit 1bc5b09

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

pkg/csi/cinder/controllerserver_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func TestCreateVolume(t *testing.T) {
6363
properties := map[string]string{cinderCSIClusterIDKey: FakeCluster}
6464
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), FakeVolType, FakeAvailability, "", "", "", properties).Return(&FakeVol, nil)
6565
osmock.On("GetVolumesByName", FakeVolName).Return(FakeVolListEmpty, nil)
66+
osmock.On("GetBlockStorageOpts").Return(openstack.BlockStorageOpts{})
6667

6768
assert := assert.New(t)
6869

@@ -110,6 +111,7 @@ func TestCreateVolumeQuotaError(t *testing.T) {
110111
properties := map[string]string{cinderCSIClusterIDKey: FakeCluster}
111112
osmock.On("CreateVolume", errorVolume, mock.AnythingOfType("int"), FakeVolType, FakeAvailability, "", "", "", properties).Return(&volumes.Volume{}, cpoerrors.ErrQuotaExceeded)
112113
osmock.On("GetVolumesByName", errorVolume).Return(FakeVolListEmpty, nil)
114+
osmock.On("GetBlockStorageOpts").Return(openstack.BlockStorageOpts{})
113115

114116
assert := assert.New(t)
115117

@@ -155,6 +157,7 @@ func TestCreateVolumeWithParam(t *testing.T) {
155157
properties := map[string]string{cinderCSIClusterIDKey: FakeCluster}
156158
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), "dummyVolType", "cinder", "", "", "", properties).Return(&FakeVol, nil)
157159
osmock.On("GetVolumesByName", FakeVolName).Return(FakeVolListEmpty, nil)
160+
osmock.On("GetBlockStorageOpts").Return(openstack.BlockStorageOpts{})
158161

159162
assert := assert.New(t)
160163

@@ -197,6 +200,66 @@ func TestCreateVolumeWithParam(t *testing.T) {
197200
assert.Equal(FakeAvailability, actualRes.Volume.AccessibleTopology[0].GetSegments()[topologyKey])
198201
}
199202

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

@@ -209,6 +272,7 @@ func TestCreateVolumeWithExtraMetadata(t *testing.T) {
209272
}
210273
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), FakeVolType, FakeAvailability, "", "", "", properties).Return(&FakeVol, nil)
211274
osmock.On("GetVolumesByName", FakeVolName).Return(FakeVolListEmpty, nil)
275+
osmock.On("GetBlockStorageOpts").Return(openstack.BlockStorageOpts{})
212276

213277
// Fake request
214278
fakeReq := &csi.CreateVolumeRequest{
@@ -248,6 +312,7 @@ func TestCreateVolumeFromSnapshot(t *testing.T) {
248312
properties := map[string]string{cinderCSIClusterIDKey: FakeCluster}
249313
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), FakeVolType, "", FakeSnapshotID, "", "", properties).Return(&FakeVolFromSnapshot, nil)
250314
osmock.On("GetVolumesByName", FakeVolName).Return(FakeVolListEmpty, nil)
315+
osmock.On("GetBlockStorageOpts").Return(openstack.BlockStorageOpts{})
251316

252317
assert := assert.New(t)
253318

@@ -294,6 +359,7 @@ func TestCreateVolumeFromSourceVolume(t *testing.T) {
294359
properties := map[string]string{cinderCSIClusterIDKey: FakeCluster}
295360
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), FakeVolType, "", "", FakeVolID, "", properties).Return(&FakeVolFromSourceVolume, nil)
296361
osmock.On("GetVolumesByName", FakeVolName).Return(FakeVolListEmpty, nil)
362+
osmock.On("GetBlockStorageOpts").Return(openstack.BlockStorageOpts{})
297363

298364
assert := assert.New(t)
299365

pkg/csi/cinder/openstack/openstack_mock.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@ func (_m *OpenStackMock) GetMetadataOpts() metadata.Opts {
521521

522522
// GetBlockStorageOpts provides a mock function to return BlockStorageOpts
523523
func (_m *OpenStackMock) GetBlockStorageOpts() BlockStorageOpts {
524-
return BlockStorageOpts{}
524+
args := _m.Called()
525+
return args.Get(0).(BlockStorageOpts)
525526
}
526527

527528
// ResolveVolumeListToUUIDs provides a mock function to return volume UUIDs

0 commit comments

Comments
 (0)