@@ -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,63 @@ 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 : "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
+
152
211
func TestCreateVolumeWithExtraMetadata (t * testing.T ) {
153
212
fakeCs , osmock := fakeControllerServer ()
154
213
@@ -159,10 +218,9 @@ func TestCreateVolumeWithExtraMetadata(t *testing.T) {
159
218
sharedcsi .PvcNameKey : FakePVCName ,
160
219
sharedcsi .PvcNamespaceKey : FakePVCNamespace ,
161
220
}
162
- // CreateVolume(name string, size int, vtype, availability string, snapshotID string, sourceVolID string, sourceBackupID string, tags map[string]string) (string, string, int, error)
163
221
osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), FakeVolType , FakeAvailability , "" , "" , "" , properties ).Return (& FakeVol , nil )
164
-
165
222
osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
223
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
166
224
167
225
// Fake request
168
226
fakeReq := & csi.CreateVolumeRequest {
@@ -203,6 +261,7 @@ func TestCreateVolumeFromSnapshot(t *testing.T) {
203
261
properties := map [string ]string {cinderCSIClusterIDKey : FakeCluster }
204
262
osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), FakeVolType , "" , FakeSnapshotID , "" , "" , properties ).Return (& FakeVolFromSnapshot , nil )
205
263
osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
264
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
206
265
207
266
assert := assert .New (t )
208
267
@@ -250,6 +309,7 @@ func TestCreateVolumeFromSourceVolume(t *testing.T) {
250
309
properties := map [string ]string {cinderCSIClusterIDKey : FakeCluster }
251
310
osmock .On ("CreateVolume" , FakeVolName , mock .AnythingOfType ("int" ), FakeVolType , "" , "" , FakeVolID , "" , properties ).Return (& FakeVolFromSourceVolume , nil )
252
311
osmock .On ("GetVolumesByName" , FakeVolName ).Return (FakeVolListEmpty , nil )
312
+ osmock .On ("GetBlockStorageOpts" ).Return (openstack.BlockStorageOpts {})
253
313
254
314
assert := assert .New (t )
255
315
@@ -300,8 +360,6 @@ func TestCreateVolumeDuplicate(t *testing.T) {
300
360
301
361
assert := assert .New (t )
302
362
303
- osmock .On ("GetVolumesByName" , "fake-duplicate" ).Return (FakeVolList , nil )
304
-
305
363
// Fake request
306
364
fakeReq := & csi.CreateVolumeRequest {
307
365
Name : "fake-duplicate" ,
0 commit comments