@@ -23,8 +23,9 @@ import (
23
23
"reflect"
24
24
"testing"
25
25
26
- "k8s.io/utils/exec/testing"
26
+ testingexec "k8s.io/utils/exec/testing"
27
27
28
+ "k8s.io/kubernetes/pkg/kubelet/config"
28
29
"k8s.io/kubernetes/pkg/volume"
29
30
volumetest "k8s.io/kubernetes/pkg/volume/testing"
30
31
)
@@ -350,55 +351,78 @@ func TestClonedIfaceUpdateError(t *testing.T) {
350
351
}
351
352
352
353
func TestGetVolCount (t * testing.T ) {
354
+ // This will create a dir structure like this:
355
+ // /tmp/refcounter555814673
356
+ // ├── iface-127.0.0.1:3260:pv1
357
+ // │ └── 127.0.0.1:3260-iqn.2003-01.io.k8s:e2e.volume-1-lun-3
358
+ // └── iface-127.0.0.1:3260:pv2
359
+ // │ ├── 127.0.0.1:3260-iqn.2003-01.io.k8s:e2e.volume-1-lun-2
360
+ // │ └── 192.168.0.1:3260-iqn.2003-01.io.k8s:e2e.volume-1-lun-1
361
+ // └── volumeDevices
362
+ // └── 192.168.0.2:3260-iqn.2003-01.io.k8s:e2e.volume-1-lun-4
363
+ // └── 192.168.0.3:3260-iqn.2003-01.io.k8s:e2e.volume-1-lun-5
364
+
365
+ baseDir , err := createFakePluginDirs ()
366
+ if err != nil {
367
+ t .Errorf ("error creating fake plugin dir: %v" , err )
368
+ }
369
+
370
+ defer os .RemoveAll (baseDir )
371
+
353
372
testCases := []struct {
354
- name string
355
- portal string
356
- iqn string
357
- count int
373
+ name string
374
+ baseDir string
375
+ portal string
376
+ iqn string
377
+ count int
358
378
}{
359
379
{
360
- name : "wrong portal, no volumes" ,
361
- portal : "192.168.0.2:3260" , // incorrect IP address
362
- iqn : "iqn.2003-01.io.k8s:e2e.volume-1" ,
363
- count : 0 ,
380
+ name : "wrong portal, no volumes" ,
381
+ baseDir : baseDir ,
382
+ portal : "192.168.0.2:3260" , // incorrect IP address
383
+ iqn : "iqn.2003-01.io.k8s:e2e.volume-1" ,
384
+ count : 0 ,
364
385
},
365
386
{
366
- name : "wrong iqn, no volumes" ,
367
- portal : "127.0.0.1:3260" ,
368
- iqn : "iqn.2003-01.io.k8s:e2e.volume-3" , // incorrect volume
369
- count : 0 ,
387
+ name : "wrong iqn, no volumes" ,
388
+ baseDir : baseDir ,
389
+ portal : "127.0.0.1:3260" ,
390
+ iqn : "iqn.2003-01.io.k8s:e2e.volume-3" , // incorrect volume
391
+ count : 0 ,
370
392
},
371
393
{
372
- name : "single volume" ,
373
- portal : "192.168.0.1:3260" ,
374
- iqn : "iqn.2003-01.io.k8s:e2e.volume-1" ,
375
- count : 1 ,
394
+ name : "single volume" ,
395
+ baseDir : baseDir ,
396
+ portal : "192.168.0.1:3260" ,
397
+ iqn : "iqn.2003-01.io.k8s:e2e.volume-1" ,
398
+ count : 1 ,
376
399
},
377
400
{
378
- name : "two volumes" ,
379
- portal : "127.0.0.1:3260" ,
380
- iqn : "iqn.2003-01.io.k8s:e2e.volume-1" ,
381
- count : 2 ,
401
+ name : "two volumes" ,
402
+ baseDir : baseDir ,
403
+ portal : "127.0.0.1:3260" ,
404
+ iqn : "iqn.2003-01.io.k8s:e2e.volume-1" ,
405
+ count : 2 ,
406
+ },
407
+ {
408
+ name : "volumeDevices (block) volume" ,
409
+ baseDir : filepath .Join (baseDir , config .DefaultKubeletVolumeDevicesDirName ),
410
+ portal : "192.168.0.2:3260" ,
411
+ iqn : "iqn.2003-01.io.k8s:e2e.volume-1-lun-4" ,
412
+ count : 1 ,
413
+ },
414
+ {
415
+ name : "nonexistent path" ,
416
+ baseDir : filepath .Join (baseDir , "this_path_should_not_exist" ),
417
+ portal : "127.0.0.1:3260" ,
418
+ iqn : "iqn.2003-01.io.k8s:e2e.unknown" ,
419
+ count : 0 ,
382
420
},
383
421
}
384
422
385
- // This will create a dir structure like this:
386
- // /tmp/refcounter555814673
387
- // ├── iface-127.0.0.1:3260:pv1
388
- // │ └── 127.0.0.1:3260-iqn.2003-01.io.k8s:e2e.volume-1-lun-3
389
- // └── iface-127.0.0.1:3260:pv2
390
- // ├── 127.0.0.1:3260-iqn.2003-01.io.k8s:e2e.volume-1-lun-2
391
- // └── 192.168.0.1:3260-iqn.2003-01.io.k8s:e2e.volume-1-lun-1
392
-
393
- baseDir , err := createFakePluginDir ()
394
- if err != nil {
395
- t .Errorf ("error creating fake plugin dir: %v" , err )
396
- }
397
- defer os .RemoveAll (baseDir )
398
-
399
423
for _ , tc := range testCases {
400
424
t .Run (tc .name , func (t * testing.T ) {
401
- count , err := getVolCount (baseDir , tc .portal , tc .iqn )
425
+ count , err := getVolCount (tc . baseDir , tc .portal , tc .iqn )
402
426
if err != nil {
403
427
t .Errorf ("expected no error, got %v" , err )
404
428
}
@@ -409,7 +433,7 @@ func TestGetVolCount(t *testing.T) {
409
433
}
410
434
}
411
435
412
- func createFakePluginDir () (string , error ) {
436
+ func createFakePluginDirs () (string , error ) {
413
437
dir , err := ioutil .TempDir ("" , "refcounter" )
414
438
if err != nil {
415
439
return "" , err
@@ -419,6 +443,8 @@ func createFakePluginDir() (string, error) {
419
443
"iface-127.0.0.1:3260:pv1/127.0.0.1:3260-iqn.2003-01.io.k8s:e2e.volume-1-lun-3" ,
420
444
"iface-127.0.0.1:3260:pv2/127.0.0.1:3260-iqn.2003-01.io.k8s:e2e.volume-1-lun-2" ,
421
445
"iface-127.0.0.1:3260:pv2/192.168.0.1:3260-iqn.2003-01.io.k8s:e2e.volume-1-lun-1" ,
446
+ filepath .Join (config .DefaultKubeletVolumeDevicesDirName , "iface-127.0.0.1:3260/192.168.0.2:3260-iqn.2003-01.io.k8s:e2e.volume-1-lun-4" ),
447
+ filepath .Join (config .DefaultKubeletVolumeDevicesDirName , "iface-127.0.0.1:3260/192.168.0.3:3260-iqn.2003-01.io.k8s:e2e.volume-1-lun-5" ),
422
448
}
423
449
424
450
for _ , d := range subdirs {
0 commit comments