@@ -4,6 +4,7 @@ package driver
4
4
5
5
import (
6
6
"context"
7
+ "fmt"
7
8
"io/fs"
8
9
"os"
9
10
"os/exec"
@@ -16,6 +17,7 @@ import (
16
17
"github.com/stretchr/testify/mock"
17
18
"github.com/stretchr/testify/require"
18
19
nbs "github.com/ydb-platform/nbs/cloud/blockstore/public/api/protos"
20
+ nbsclient "github.com/ydb-platform/nbs/cloud/blockstore/public/sdk/go/client"
19
21
"github.com/ydb-platform/nbs/cloud/blockstore/tools/csi_driver/internal/driver/mocks"
20
22
csimounter "github.com/ydb-platform/nbs/cloud/blockstore/tools/csi_driver/internal/mounter"
21
23
nfs "github.com/ydb-platform/nbs/cloud/filestore/public/api/protos"
@@ -937,3 +939,171 @@ func TestPublishDeviceWithReadWriteManyModeIsNotSupportedWithNBS(t *testing.T) {
937
939
})
938
940
require .Error (t , err )
939
941
}
942
+
943
+ func TestGrpcTimeoutForIKubevirt (t * testing.T ) {
944
+ tempDir := t .TempDir ()
945
+
946
+ nbsClient := mocks .NewNbsClientMock ()
947
+ nfsClient := mocks .NewNfsEndpointClientMock ()
948
+ nfsLocalClient := mocks .NewNfsEndpointClientMock ()
949
+ mounter := csimounter .NewMock ()
950
+
951
+ ctx := context .Background ()
952
+ nodeId := "testNodeId"
953
+ clientId := "testClientId"
954
+ instanceId := "testInstanceId"
955
+ actualClientId := "testClientId-" + instanceId
956
+ diskId := "test-disk-id-42"
957
+ deviceName := diskId
958
+ volumeId := diskId + "#" + instanceId
959
+ backend := "nbs"
960
+
961
+ stagingTargetPath := filepath .Join (tempDir , "testStagingTargetPath" )
962
+ socketsDir := filepath .Join (tempDir , "sockets" )
963
+ sourcePath := filepath .Join (socketsDir , instanceId , diskId )
964
+ targetFsPathPattern := filepath .Join (tempDir , "pods/([a-z0-9-]+)/volumes/([a-z0-9-]+)/mount" )
965
+ nbsSocketPath := filepath .Join (sourcePath , "nbs.sock" )
966
+
967
+ nodeService := newNodeService (
968
+ nodeId ,
969
+ clientId ,
970
+ true ,
971
+ socketsDir ,
972
+ targetFsPathPattern ,
973
+ "" ,
974
+ make (LocalFilestoreOverrideMap ),
975
+ nbsClient ,
976
+ nfsClient ,
977
+ nfsLocalClient ,
978
+ mounter ,
979
+ )
980
+
981
+ accessMode := csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER
982
+
983
+ volumeCapability := csi.VolumeCapability {
984
+ AccessType : & csi.VolumeCapability_Mount {
985
+ Mount : & csi.VolumeCapability_MountVolume {},
986
+ },
987
+ AccessMode : & csi.VolumeCapability_AccessMode {
988
+ Mode : accessMode ,
989
+ },
990
+ }
991
+
992
+ volumeContext := map [string ]string {
993
+ backendVolumeContextKey : backend ,
994
+ instanceIdKey : instanceId ,
995
+ }
996
+
997
+ hostType := nbs .EHostType_HOST_TYPE_DEFAULT
998
+ grpcError := nbsclient.ClientError {Code : nbsclient .E_GRPC_DEADLINE_EXCEEDED }
999
+ startEndpointError := fmt .Errorf ("%w" , grpcError )
1000
+ nbsClient .On ("StartEndpoint" , ctx , & nbs.TStartEndpointRequest {
1001
+ UnixSocketPath : nbsSocketPath ,
1002
+ DiskId : diskId ,
1003
+ InstanceId : instanceId ,
1004
+ ClientId : actualClientId ,
1005
+ DeviceName : deviceName ,
1006
+ IpcType : nbs .EClientIpcType_IPC_VHOST ,
1007
+ VhostQueuesCount : 8 ,
1008
+ VolumeAccessMode : nbs .EVolumeAccessMode_VOLUME_ACCESS_READ_WRITE ,
1009
+ VolumeMountMode : nbs .EVolumeMountMode_VOLUME_MOUNT_LOCAL ,
1010
+ Persistent : true ,
1011
+ NbdDevice : & nbs.TStartEndpointRequest_UseFreeNbdDeviceFile {
1012
+ false ,
1013
+ },
1014
+ ClientProfile : & nbs.TClientProfile {
1015
+ HostType : & hostType ,
1016
+ },
1017
+ }).Once ().Return (& nbs.TStartEndpointResponse {}, startEndpointError )
1018
+
1019
+ nbsClient .On ("StopEndpoint" , ctx , & nbs.TStopEndpointRequest {
1020
+ UnixSocketPath : nbsSocketPath ,
1021
+ }).Once ().Return (& nbs.TStopEndpointResponse {}, nil )
1022
+
1023
+ _ , err := nodeService .NodeStageVolume (ctx , & csi.NodeStageVolumeRequest {
1024
+ VolumeId : volumeId ,
1025
+ StagingTargetPath : stagingTargetPath ,
1026
+ VolumeCapability : & volumeCapability ,
1027
+ VolumeContext : volumeContext ,
1028
+ })
1029
+ require .Error (t , err )
1030
+ }
1031
+
1032
+ func TestGrpcTimeoutForInfrakuber (t * testing.T ) {
1033
+ tempDir := t .TempDir ()
1034
+
1035
+ nbsClient := mocks .NewNbsClientMock ()
1036
+ mounter := csimounter .NewMock ()
1037
+
1038
+ ipcType := nbs .EClientIpcType_IPC_NBD
1039
+ nbdDeviceFile := filepath .Join (tempDir , "dev" , "nbd3" )
1040
+ err := os .MkdirAll (nbdDeviceFile , fs .FileMode (0755 ))
1041
+ require .NoError (t , err )
1042
+
1043
+ ctx := context .Background ()
1044
+ nodeId := "testNodeId"
1045
+ clientId := "testClientId"
1046
+ diskId := "test-disk-id-42"
1047
+ actualClientId := "testClientId-testNodeId"
1048
+ targetFsPathPattern := filepath .Join (tempDir , "pods/([a-z0-9-]+)/volumes/([a-z0-9-]+)/mount" )
1049
+ stagingTargetPath := "testStagingTargetPath"
1050
+ socketsDir := filepath .Join (tempDir , "sockets" )
1051
+ socketPath := filepath .Join (socketsDir , diskId , "nbs.sock" )
1052
+
1053
+ nodeService := newNodeService (
1054
+ nodeId ,
1055
+ clientId ,
1056
+ false ,
1057
+ socketsDir ,
1058
+ targetFsPathPattern ,
1059
+ "" ,
1060
+ make (LocalFilestoreOverrideMap ),
1061
+ nbsClient ,
1062
+ nil ,
1063
+ nil ,
1064
+ mounter ,
1065
+ )
1066
+
1067
+ volumeCapability := csi.VolumeCapability {
1068
+ AccessType : & csi.VolumeCapability_Mount {},
1069
+ AccessMode : & csi.VolumeCapability_AccessMode {
1070
+ Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
1071
+ },
1072
+ }
1073
+
1074
+ volumeContext := map [string ]string {}
1075
+
1076
+ hostType := nbs .EHostType_HOST_TYPE_DEFAULT
1077
+ grpcError := nbsclient.ClientError {Code : nbsclient .E_GRPC_DEADLINE_EXCEEDED }
1078
+ startEndpointError := fmt .Errorf ("%w" , grpcError )
1079
+ nbsClient .On ("StartEndpoint" , ctx , & nbs.TStartEndpointRequest {
1080
+ UnixSocketPath : socketPath ,
1081
+ DiskId : diskId ,
1082
+ InstanceId : nodeId ,
1083
+ ClientId : actualClientId ,
1084
+ DeviceName : diskId ,
1085
+ IpcType : ipcType ,
1086
+ VhostQueuesCount : 8 ,
1087
+ VolumeAccessMode : nbs .EVolumeAccessMode_VOLUME_ACCESS_READ_WRITE ,
1088
+ VolumeMountMode : nbs .EVolumeMountMode_VOLUME_MOUNT_LOCAL ,
1089
+ Persistent : true ,
1090
+ NbdDevice : & nbs.TStartEndpointRequest_UseFreeNbdDeviceFile {
1091
+ true ,
1092
+ },
1093
+ ClientProfile : & nbs.TClientProfile {
1094
+ HostType : & hostType ,
1095
+ },
1096
+ }).Return (& nbs.TStartEndpointResponse {}, startEndpointError )
1097
+
1098
+ nbsClient .On ("StopEndpoint" , ctx , & nbs.TStopEndpointRequest {
1099
+ UnixSocketPath : socketPath ,
1100
+ }).Return (& nbs.TStopEndpointResponse {}, nil )
1101
+
1102
+ _ , err = nodeService .NodeStageVolume (ctx , & csi.NodeStageVolumeRequest {
1103
+ VolumeId : diskId ,
1104
+ StagingTargetPath : stagingTargetPath ,
1105
+ VolumeCapability : & volumeCapability ,
1106
+ VolumeContext : volumeContext ,
1107
+ })
1108
+ require .Error (t , err )
1109
+ }
0 commit comments