@@ -216,7 +216,6 @@ var _ = Describe("CreateVolume [Controller Server]", func() {
216
216
Expect (err ).NotTo (HaveOccurred ())
217
217
})
218
218
219
- // Pending fix in mock file
220
219
It ("should return appropriate values SingleNodeWriter WithCapacity 1Gi Type:Mount" , func () {
221
220
222
221
By ("creating a volume" )
@@ -240,12 +239,20 @@ var _ = Describe("CreateVolume [Controller Server]", func() {
240
239
RequiredBytes : size ,
241
240
},
242
241
})
243
- Expect (err ).NotTo (HaveOccurred ())
244
- Expect (vol ).NotTo (BeNil ())
245
- Expect (vol .GetVolume ()).NotTo (BeNil ())
246
- Expect (vol .GetVolume ().GetId ()).NotTo (BeEmpty ())
247
- Expect (vol .GetVolume ().GetCapacityBytes ()).To (Equal (size ))
242
+ if serverError , ok := status .FromError (err ); ok {
243
+ if serverError .Code () == codes .OutOfRange || serverError .Code () == codes .Unimplemented {
244
+ Skip ("Required bytes not supported" )
245
+ } else {
246
+ Expect (err ).NotTo (HaveOccurred ())
247
+ }
248
+ } else {
248
249
250
+ Expect (err ).NotTo (HaveOccurred ())
251
+ Expect (vol ).NotTo (BeNil ())
252
+ Expect (vol .GetVolume ()).NotTo (BeNil ())
253
+ Expect (vol .GetVolume ().GetId ()).NotTo (BeEmpty ())
254
+ Expect (vol .GetVolume ().GetCapacityBytes ()).To (Equal (size ))
255
+ }
249
256
By ("cleaning up deleting the volume" )
250
257
_ , err = c .DeleteVolume (
251
258
context .Background (),
@@ -254,6 +261,154 @@ var _ = Describe("CreateVolume [Controller Server]", func() {
254
261
})
255
262
Expect (err ).NotTo (HaveOccurred ())
256
263
})
264
+ It ("should not fail when requesting to create a volume with already exisiting name and same capacity." , func () {
265
+
266
+ By ("creating a volume" )
267
+ name := "sanity"
268
+ size := int64 (1 * 1024 * 1024 * 1024 )
269
+ vol1 , err := c .CreateVolume (
270
+ context .Background (),
271
+ & csi.CreateVolumeRequest {
272
+ Name : name ,
273
+ VolumeCapabilities : []* csi.VolumeCapability {
274
+ {
275
+ AccessType : & csi.VolumeCapability_Mount {
276
+ Mount : & csi.VolumeCapability_MountVolume {},
277
+ },
278
+ AccessMode : & csi.VolumeCapability_AccessMode {
279
+ Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
280
+ },
281
+ },
282
+ },
283
+ CapacityRange : & csi.CapacityRange {
284
+ RequiredBytes : size ,
285
+ },
286
+ })
287
+ Expect (err ).NotTo (HaveOccurred ())
288
+ Expect (vol1 ).NotTo (BeNil ())
289
+ Expect (vol1 .GetVolume ()).NotTo (BeNil ())
290
+ Expect (vol1 .GetVolume ().GetId ()).NotTo (BeEmpty ())
291
+ Expect (vol1 .GetVolume ().GetCapacityBytes ()).To (Equal (size ))
292
+ vol2 , err := c .CreateVolume (
293
+ context .Background (),
294
+ & csi.CreateVolumeRequest {
295
+ Name : name ,
296
+ VolumeCapabilities : []* csi.VolumeCapability {
297
+ {
298
+ AccessType : & csi.VolumeCapability_Mount {
299
+ Mount : & csi.VolumeCapability_MountVolume {},
300
+ },
301
+ AccessMode : & csi.VolumeCapability_AccessMode {
302
+ Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
303
+ },
304
+ },
305
+ },
306
+ CapacityRange : & csi.CapacityRange {
307
+ RequiredBytes : size ,
308
+ },
309
+ })
310
+ Expect (err ).NotTo (HaveOccurred ())
311
+ Expect (vol2 ).NotTo (BeNil ())
312
+ Expect (vol2 .GetVolume ()).NotTo (BeNil ())
313
+ Expect (vol2 .GetVolume ().GetId ()).NotTo (BeEmpty ())
314
+ Expect (vol2 .GetVolume ().GetCapacityBytes ()).To (Equal (size ))
315
+ Expect (vol1 .GetVolume ().GetId ()).To (Equal (vol2 .GetVolume ().GetId ()))
316
+
317
+ By ("cleaning up deleting the volume" )
318
+ _ , err = c .DeleteVolume (
319
+ context .Background (),
320
+ & csi.DeleteVolumeRequest {
321
+ VolumeId : vol1 .GetVolume ().GetId (),
322
+ })
323
+ Expect (err ).NotTo (HaveOccurred ())
324
+ })
325
+ It ("should fail when requesting to create a volume with already exisiting name and different capacity." , func () {
326
+
327
+ By ("creating a volume" )
328
+ name := "sanity"
329
+ size1 := int64 (1 * 1024 * 1024 * 1024 )
330
+ vol1 , err := c .CreateVolume (
331
+ context .Background (),
332
+ & csi.CreateVolumeRequest {
333
+ Name : name ,
334
+ VolumeCapabilities : []* csi.VolumeCapability {
335
+ {
336
+ AccessType : & csi.VolumeCapability_Mount {
337
+ Mount : & csi.VolumeCapability_MountVolume {},
338
+ },
339
+ AccessMode : & csi.VolumeCapability_AccessMode {
340
+ Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
341
+ },
342
+ },
343
+ },
344
+ CapacityRange : & csi.CapacityRange {
345
+ RequiredBytes : size1 ,
346
+ },
347
+ })
348
+ Expect (err ).ToNot (HaveOccurred ())
349
+ Expect (vol1 ).NotTo (BeNil ())
350
+ Expect (vol1 .GetVolume ()).NotTo (BeNil ())
351
+ Expect (vol1 .GetVolume ().GetId ()).NotTo (BeEmpty ())
352
+ size2 := int64 (2 * 1024 * 1024 * 1024 )
353
+ _ , err = c .CreateVolume (
354
+ context .Background (),
355
+ & csi.CreateVolumeRequest {
356
+ Name : name ,
357
+ VolumeCapabilities : []* csi.VolumeCapability {
358
+ {
359
+ AccessType : & csi.VolumeCapability_Mount {
360
+ Mount : & csi.VolumeCapability_MountVolume {},
361
+ },
362
+ AccessMode : & csi.VolumeCapability_AccessMode {
363
+ Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
364
+ },
365
+ },
366
+ },
367
+ CapacityRange : & csi.CapacityRange {
368
+ RequiredBytes : size2 ,
369
+ },
370
+ })
371
+ Expect (err ).To (HaveOccurred ())
372
+ serverError , ok := status .FromError (err )
373
+ Expect (ok ).To (BeTrue ())
374
+ Expect (serverError .Code ()).To (Equal (codes .AlreadyExists ))
375
+
376
+ By ("cleaning up deleting the volume" )
377
+ _ , err = c .DeleteVolume (
378
+ context .Background (),
379
+ & csi.DeleteVolumeRequest {
380
+ VolumeId : vol1 .GetVolume ().GetId (),
381
+ })
382
+ Expect (err ).NotTo (HaveOccurred ())
383
+ })
384
+ It ("should fail when requesting to create a volume exceeding Maximum Capacity" , func () {
385
+
386
+ By ("creating a volume" )
387
+ name := "sanity"
388
+ size := int64 (10 * 1024 * 1024 * 1024 * 1024 )
389
+ _ , err := c .CreateVolume (
390
+ context .Background (),
391
+ & csi.CreateVolumeRequest {
392
+ Name : name ,
393
+ VolumeCapabilities : []* csi.VolumeCapability {
394
+ {
395
+ AccessType : & csi.VolumeCapability_Mount {
396
+ Mount : & csi.VolumeCapability_MountVolume {},
397
+ },
398
+ AccessMode : & csi.VolumeCapability_AccessMode {
399
+ Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
400
+ },
401
+ },
402
+ },
403
+ CapacityRange : & csi.CapacityRange {
404
+ RequiredBytes : size ,
405
+ },
406
+ })
407
+ Expect (err ).To (HaveOccurred ())
408
+ serverError , ok := status .FromError (err )
409
+ Expect (ok ).To (BeTrue ())
410
+ Expect (serverError .Code ()).To (Equal (codes .OutOfRange ))
411
+ })
257
412
})
258
413
259
414
var _ = Describe ("DeleteVolume [Controller Server]" , func () {
0 commit comments