Skip to content

Commit 2cf46b0

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

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

pkg/csi/cinder/controllerserver_test.go

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

6465
assert := assert.New(t)
6566

@@ -106,6 +107,7 @@ func TestCreateVolumeWithParam(t *testing.T) {
106107
properties := map[string]string{cinderCSIClusterIDKey: FakeCluster}
107108
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), "dummyVolType", "cinder", "", "", "", properties).Return(&FakeVol, nil)
108109
osmock.On("GetVolumesByName", FakeVolName).Return(FakeVolListEmpty, nil)
110+
osmock.On("GetBlockStorageOpts").Return(openstack.BlockStorageOpts{})
109111

110112
assert := assert.New(t)
111113

@@ -149,6 +151,63 @@ func TestCreateVolumeWithParam(t *testing.T) {
149151

150152
}
151153

154+
// Test CreateVolume with ignore-volume-az option
155+
func TestCreateVolumeWithIgnoreVolumeAZ(t *testing.T) {
156+
fakeCs, osmock := fakeControllerServer()
157+
158+
properties := map[string]string{cinderCSIClusterIDKey: FakeCluster}
159+
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), FakeVolType, "cinder", "", "", "", properties).Return(&FakeVol, nil)
160+
osmock.On("GetVolumesByName", FakeVolName).Return(FakeVolListEmpty, nil)
161+
osmock.On("GetBlockStorageOpts").Return(openstack.BlockStorageOpts{IgnoreVolumeAZ: true})
162+
163+
assert := assert.New(t)
164+
165+
// Fake request
166+
fakeReq := &csi.CreateVolumeRequest{
167+
Name: FakeVolName,
168+
VolumeCapabilities: []*csi.VolumeCapability{
169+
{
170+
AccessMode: &csi.VolumeCapability_AccessMode{
171+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
172+
},
173+
},
174+
},
175+
176+
Parameters: map[string]string{
177+
"availability": "cinder",
178+
},
179+
180+
AccessibilityRequirements: &csi.TopologyRequirement{
181+
Requisite: []*csi.Topology{
182+
{
183+
Segments: map[string]string{topologyKey: "foo"},
184+
},
185+
{
186+
Segments: map[string]string{topologyKey: "bar"},
187+
},
188+
},
189+
Preferred: []*csi.Topology{
190+
{
191+
Segments: map[string]string{topologyKey: "foo"},
192+
},
193+
},
194+
},
195+
}
196+
197+
// Invoke CreateVolume
198+
actualRes, err := fakeCs.CreateVolume(FakeCtx, fakeReq)
199+
if err != nil {
200+
t.Errorf("failed to CreateVolume: %v", err)
201+
}
202+
203+
// Assert
204+
assert.NotNil(actualRes.Volume)
205+
assert.NotNil(actualRes.Volume.CapacityBytes)
206+
assert.NotEqual(0, len(actualRes.Volume.VolumeId), "Volume Id is nil")
207+
assert.NotNil(actualRes.Volume.AccessibleTopology)
208+
assert.Equal("foo", actualRes.Volume.AccessibleTopology[0].GetSegments()[topologyKey])
209+
}
210+
152211
func TestCreateVolumeWithExtraMetadata(t *testing.T) {
153212
fakeCs, osmock := fakeControllerServer()
154213

@@ -159,10 +218,9 @@ func TestCreateVolumeWithExtraMetadata(t *testing.T) {
159218
sharedcsi.PvcNameKey: FakePVCName,
160219
sharedcsi.PvcNamespaceKey: FakePVCNamespace,
161220
}
162-
// CreateVolume(name string, size int, vtype, availability string, snapshotID string, sourceVolID string, sourceBackupID string, tags map[string]string) (string, string, int, error)
163221
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), FakeVolType, FakeAvailability, "", "", "", properties).Return(&FakeVol, nil)
164-
165222
osmock.On("GetVolumesByName", FakeVolName).Return(FakeVolListEmpty, nil)
223+
osmock.On("GetBlockStorageOpts").Return(openstack.BlockStorageOpts{})
166224

167225
// Fake request
168226
fakeReq := &csi.CreateVolumeRequest{
@@ -203,6 +261,7 @@ func TestCreateVolumeFromSnapshot(t *testing.T) {
203261
properties := map[string]string{cinderCSIClusterIDKey: FakeCluster}
204262
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), FakeVolType, "", FakeSnapshotID, "", "", properties).Return(&FakeVolFromSnapshot, nil)
205263
osmock.On("GetVolumesByName", FakeVolName).Return(FakeVolListEmpty, nil)
264+
osmock.On("GetBlockStorageOpts").Return(openstack.BlockStorageOpts{})
206265

207266
assert := assert.New(t)
208267

@@ -250,6 +309,7 @@ func TestCreateVolumeFromSourceVolume(t *testing.T) {
250309
properties := map[string]string{cinderCSIClusterIDKey: FakeCluster}
251310
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), FakeVolType, "", "", FakeVolID, "", properties).Return(&FakeVolFromSourceVolume, nil)
252311
osmock.On("GetVolumesByName", FakeVolName).Return(FakeVolListEmpty, nil)
312+
osmock.On("GetBlockStorageOpts").Return(openstack.BlockStorageOpts{})
253313

254314
assert := assert.New(t)
255315

@@ -300,8 +360,6 @@ func TestCreateVolumeDuplicate(t *testing.T) {
300360

301361
assert := assert.New(t)
302362

303-
osmock.On("GetVolumesByName", "fake-duplicate").Return(FakeVolList, nil)
304-
305363
// Fake request
306364
fakeReq := &csi.CreateVolumeRequest{
307365
Name: "fake-duplicate",

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)