@@ -30,8 +30,11 @@ import (
30
30
"google.golang.org/grpc"
31
31
"google.golang.org/grpc/codes"
32
32
"google.golang.org/grpc/status"
33
+ "sigs.k8s.io/cloud-provider-azure/pkg/provider"
33
34
35
+ "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-09-01/storage"
34
36
"github.com/container-storage-interface/spec/lib/go/csi"
37
+ "github.com/golang/mock/gomock"
35
38
"github.com/stretchr/testify/assert"
36
39
37
40
mount "k8s.io/mount-utils"
@@ -235,6 +238,7 @@ func TestNodePublishVolume(t *testing.T) {
235
238
_ = makeDir (sourceTest )
236
239
_ = makeDir (targetTest )
237
240
d := NewFakeDriver ()
241
+ d .cloud = provider .GetTestCloud (gomock .NewController (t ))
238
242
fakeMounter := & fakeMounter {}
239
243
fakeExec := & testingexec.FakeExec {ExactOrder : true }
240
244
d .mounter = & mount.SafeFormatAndMount {
@@ -243,6 +247,7 @@ func TestNodePublishVolume(t *testing.T) {
243
247
}
244
248
245
249
for _ , test := range tests {
250
+ d .cloud .ResourceGroup = "rg"
246
251
if test .setup != nil {
247
252
test .setup (d )
248
253
}
@@ -456,6 +461,102 @@ func TestNodeStageVolume(t *testing.T) {
456
461
}
457
462
},
458
463
},
464
+ {
465
+ name : "[Error] Could not mount to target" ,
466
+ testFunc : func (t * testing.T ) {
467
+ req := & csi.NodeStageVolumeRequest {
468
+ VolumeId : "unit-test" ,
469
+ StagingTargetPath : "error_is_likely" ,
470
+ VolumeCapability : & csi.VolumeCapability {AccessMode : & volumeCap },
471
+ VolumeContext : map [string ]string {
472
+ mountPermissionsField : "0755" ,
473
+ },
474
+ }
475
+ d := NewFakeDriver ()
476
+ fakeMounter := & fakeMounter {}
477
+ fakeExec := & testingexec.FakeExec {}
478
+ d .mounter = & mount.SafeFormatAndMount {
479
+ Interface : fakeMounter ,
480
+ Exec : fakeExec ,
481
+ }
482
+ _ , err := d .NodeStageVolume (context .TODO (), req )
483
+ expectedErr := status .Error (codes .Internal , fmt .Sprintf ("Could not mount target %q: %v" , req .StagingTargetPath , fmt .Errorf ("fake IsLikelyNotMountPoint: fake error" )))
484
+ if ! reflect .DeepEqual (err , expectedErr ) {
485
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , expectedErr )
486
+ }
487
+ },
488
+ },
489
+ {
490
+ name : "protocol = nfs" ,
491
+ testFunc : func (t * testing.T ) {
492
+ req := & csi.NodeStageVolumeRequest {
493
+ VolumeId : "rg#acc#cont#ns" ,
494
+ StagingTargetPath : targetTest ,
495
+ VolumeCapability : & csi.VolumeCapability {AccessMode : & volumeCap },
496
+ VolumeContext : map [string ]string {
497
+ mountPermissionsField : "0755" ,
498
+ protocolField : "nfs" ,
499
+ },
500
+ Secrets : map [string ]string {},
501
+ }
502
+ d := NewFakeDriver ()
503
+ d .cloud = provider .GetTestCloud (gomock .NewController (t ))
504
+ d .cloud .ResourceGroup = "rg"
505
+ d .enableBlobMockMount = true
506
+ fakeMounter := & fakeMounter {}
507
+ fakeExec := & testingexec.FakeExec {}
508
+ d .mounter = & mount.SafeFormatAndMount {
509
+ Interface : fakeMounter ,
510
+ Exec : fakeExec ,
511
+ }
512
+
513
+ _ , err := d .NodeStageVolume (context .TODO (), req )
514
+ //expectedErr := nil
515
+ if ! reflect .DeepEqual (err , nil ) {
516
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , nil )
517
+ }
518
+ },
519
+ },
520
+ {
521
+ name : "BlobMockMount Enabled" ,
522
+ testFunc : func (t * testing.T ) {
523
+ req := & csi.NodeStageVolumeRequest {
524
+ VolumeId : "rg#acc#cont#ns" ,
525
+ StagingTargetPath : targetTest ,
526
+ VolumeCapability : & csi.VolumeCapability {AccessMode : & volumeCap },
527
+ VolumeContext : map [string ]string {
528
+ mountPermissionsField : "0755" ,
529
+ protocolField : "protocol" ,
530
+ },
531
+ Secrets : map [string ]string {},
532
+ }
533
+ d := NewFakeDriver ()
534
+ d .cloud = provider .GetTestCloud (gomock .NewController (t ))
535
+ d .cloud .ResourceGroup = "rg"
536
+ d .enableBlobMockMount = true
537
+ fakeMounter := & fakeMounter {}
538
+ fakeExec := & testingexec.FakeExec {}
539
+ d .mounter = & mount.SafeFormatAndMount {
540
+ Interface : fakeMounter ,
541
+ Exec : fakeExec ,
542
+ }
543
+
544
+ keyList := make ([]storage.AccountKey , 1 )
545
+ fakeKey := "fakeKey"
546
+ fakeValue := "fakeValue"
547
+ keyList [0 ] = (storage.AccountKey {
548
+ KeyName : & fakeKey ,
549
+ Value : & fakeValue ,
550
+ })
551
+ d .cloud .StorageAccountClient = NewMockSAClient (context .Background (), gomock .NewController (t ), "subID" , "unit-test" , "unit-test" , & keyList )
552
+
553
+ _ , err := d .NodeStageVolume (context .TODO (), req )
554
+ //expectedErr := nil
555
+ if ! reflect .DeepEqual (err , nil ) {
556
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , nil )
557
+ }
558
+ },
559
+ },
459
560
}
460
561
for _ , tc := range testCases {
461
562
t .Run (tc .name , tc .testFunc )
@@ -520,6 +621,12 @@ func TestNodeUnstageVolume(t *testing.T) {
520
621
StagingTargetPath : "./unit-test" ,
521
622
}
522
623
d := NewFakeDriver ()
624
+ fakeMounter := & fakeMounter {}
625
+ fakeExec := & testingexec.FakeExec {}
626
+ d .mounter = & mount.SafeFormatAndMount {
627
+ Interface : fakeMounter ,
628
+ Exec : fakeExec ,
629
+ }
523
630
_ , err := d .NodeUnstageVolume (context .TODO (), req )
524
631
expectedErr := error (nil )
525
632
if ! reflect .DeepEqual (err , expectedErr ) {
0 commit comments