@@ -60,6 +60,7 @@ func TestCreateVolume(t *testing.T) {
60
60
properties := map [string ]string {cinderCSIClusterIDKey : FakeCluster }
61
61
osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), FakeVolType , FakeAvailability , "" , "" , "" , properties ).Return (& FakeVol , nil )
62
62
osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
63
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
63
64
64
65
assert := assert .New (t )
65
66
@@ -106,6 +107,7 @@ func TestCreateVolumeWithParam(t *testing.T) {
106
107
properties := map [string ]string {cinderCSIClusterIDKey : FakeCluster }
107
108
osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), "dummyVolType" , "cinder" , "" , "" , "" , properties ).Return (& FakeVol , nil )
108
109
osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
110
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
109
111
110
112
assert := assert .New (t )
111
113
@@ -149,6 +151,66 @@ func TestCreateVolumeWithParam(t *testing.T) {
149
151
150
152
}
151
153
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 : "bar" },
184
+ },
185
+ {
186
+ Segments : map [string ]string {topologyKey : "foo" },
187
+ },
188
+ },
189
+ Preferred : []* csi.Topology {
190
+ {
191
+ Segments : map [string ]string {topologyKey : "foo" },
192
+ },
193
+ {
194
+ Segments : map [string ]string {topologyKey : "bar" },
195
+ },
196
+ },
197
+ },
198
+ }
199
+
200
+ // Invoke CreateVolume
201
+ actualRes , err := fakeCs .CreateVolume (FakeCtx , fakeReq )
202
+ if err != nil {
203
+ t .Errorf ("failed to CreateVolume: %v" , err )
204
+ }
205
+
206
+ // Assert
207
+ assert .NotNil (actualRes .Volume )
208
+ assert .NotNil (actualRes .Volume .CapacityBytes )
209
+ assert .NotEqual (0 , len (actualRes .Volume .VolumeId ), "Volume Id is nil" )
210
+ assert .NotNil (actualRes .Volume .AccessibleTopology )
211
+ assert .Equal ("foo" , actualRes .Volume .AccessibleTopology [0 ].GetSegments ()[topologyKey ])
212
+ }
213
+
152
214
func TestCreateVolumeWithExtraMetadata (t * testing.T ) {
153
215
fakeCs , osmock := fakeControllerServer ()
154
216
@@ -159,10 +221,9 @@ func TestCreateVolumeWithExtraMetadata(t *testing.T) {
159
221
sharedcsi .PvcNameKey : FakePVCName ,
160
222
sharedcsi .PvcNamespaceKey : FakePVCNamespace ,
161
223
}
162
- // CreateVolume(name string, size int, vtype, availability string, snapshotID string, sourceVolID string, sourceBackupID string, tags map[string]string) (string, string, int, error)
163
224
osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), FakeVolType , FakeAvailability , "" , "" , "" , properties ).Return (& FakeVol , nil )
164
-
165
225
osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
226
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
166
227
167
228
// Fake request
168
229
fakeReq := & csi.CreateVolumeRequest {
@@ -203,6 +264,7 @@ func TestCreateVolumeFromSnapshot(t *testing.T) {
203
264
properties := map [string ]string {cinderCSIClusterIDKey : FakeCluster }
204
265
osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), FakeVolType , "" , FakeSnapshotID , "" , "" , properties ).Return (& FakeVolFromSnapshot , nil )
205
266
osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
267
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
206
268
207
269
assert := assert .New (t )
208
270
@@ -250,6 +312,7 @@ func TestCreateVolumeFromSourceVolume(t *testing.T) {
250
312
properties := map [string ]string {cinderCSIClusterIDKey : FakeCluster }
251
313
osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), FakeVolType , "" , "" , FakeVolID , "" , properties ).Return (& FakeVolFromSourceVolume , nil )
252
314
osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
315
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
253
316
254
317
assert := assert .New (t )
255
318
@@ -300,8 +363,6 @@ func TestCreateVolumeDuplicate(t *testing.T) {
300
363
301
364
assert := assert .New (t )
302
365
303
- osmock .On ("GetVolumesByName" , "fake-duplicate" ).Return (FakeVolList , nil )
304
-
305
366
// Fake request
306
367
fakeReq := & csi.CreateVolumeRequest {
307
368
Name : "fake-duplicate" ,
0 commit comments