Skip to content

Commit 017be70

Browse files
committed
test: use mock mount to fix sanit test failures
1 parent b973a88 commit 017be70

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

pkg/blob/blob.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ type Driver struct {
9595
csicommon.CSIDriver
9696
cloud *azure.Cloud
9797
blobfuseProxyEndpoint string
98+
enableBlobMockMount bool
9899
enableBlobfuseProxy bool
99100
blobfuseProxyConnTimout int
100101
mounter *mount.SafeFormatAndMount
@@ -106,7 +107,7 @@ type Driver struct {
106107

107108
// NewDriver Creates a NewCSIDriver object. Assumes vendor version is equal to driver version &
108109
// does not support optional driver plugin info manifest field. Refer to CSI spec for more details.
109-
func NewDriver(nodeID, blobfuseProxyEndpoint string, enableBlobfuseProxy bool, blobfuseProxyConnTimout int) *Driver {
110+
func NewDriver(nodeID, blobfuseProxyEndpoint string, enableBlobfuseProxy bool, blobfuseProxyConnTimout int, enableBlobMockMount bool) *Driver {
110111
driver := Driver{}
111112
driver.Name = DriverName
112113
driver.Version = driverVersion
@@ -116,6 +117,7 @@ func NewDriver(nodeID, blobfuseProxyEndpoint string, enableBlobfuseProxy bool, b
116117
driver.blobfuseProxyEndpoint = blobfuseProxyEndpoint
117118
driver.enableBlobfuseProxy = enableBlobfuseProxy
118119
driver.blobfuseProxyConnTimout = blobfuseProxyConnTimout
120+
driver.enableBlobMockMount = enableBlobMockMount
119121
return &driver
120122
}
121123

pkg/blob/blob_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ const (
4444
)
4545

4646
func NewFakeDriver() *Driver {
47-
driver := NewDriver(fakeNodeID, "", false, 5)
47+
driver := NewDriver(fakeNodeID, "", false, 5, false)
4848
driver.Name = fakeDriverName
4949
driver.Version = vendorVersion
5050
return driver
5151
}
5252

5353
func TestNewFakeDriver(t *testing.T) {
54-
d := NewDriver(fakeNodeID, "", false, 5)
54+
d := NewDriver(fakeNodeID, "", false, 5, false)
5555
assert.NotNil(t, d)
5656
}
5757

5858
func TestNewDriver(t *testing.T) {
59-
driver := NewDriver(fakeNodeID, "", false, 5)
59+
driver := NewDriver(fakeNodeID, "", false, 5, false)
6060
fakedriver := NewFakeDriver()
6161
fakedriver.Name = DriverName
6262
fakedriver.Version = driverVersion

pkg/blob/nodeserver.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
9292
}
9393

9494
klog.V(2).Infof("NodePublishVolume: volume %s mounting %s at %s with mountOptions: %v", volumeID, source, target, mountOptions)
95+
if d.enableBlobMockMount {
96+
if err := volumehelper.MakeDir(target); err != nil {
97+
klog.Errorf("MakeDir failed on target: %s (%v)", target, err)
98+
return nil, err
99+
}
100+
return &csi.NodePublishVolumeResponse{}, nil
101+
}
102+
95103
if err := d.mounter.Mount(source, target, "", mountOptions); err != nil {
96104
if removeErr := os.Remove(target); removeErr != nil {
97105
return nil, status.Errorf(codes.Internal, "Could not remove mount target %q: %v", target, removeErr)

pkg/blobplugin/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var (
4444
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
4545
enableBlobfuseProxy = flag.Bool("enable-blobfuse-proxy", false, "Whether supports using Blobfuse proxy for mounts")
4646
blobfuseProxyConnTimout = flag.Int("blobfuse-proxy-connect-timeout", 5, "blobfuse proxy connection timeout(seconds)")
47+
enableBlobMockMount = flag.Bool("enable-blob-mock-mount", false, "Whether enable mock mount")
4748
)
4849

4950
func main() {
@@ -64,7 +65,7 @@ func main() {
6465
}
6566

6667
func handle() {
67-
driver := blob.NewDriver(*nodeID, *blobfuseProxyEndpoint, *enableBlobfuseProxy, *blobfuseProxyConnTimout)
68+
driver := blob.NewDriver(*nodeID, *blobfuseProxyEndpoint, *enableBlobfuseProxy, *blobfuseProxyConnTimout, *enableBlobMockMount)
6869
if driver == nil {
6970
klog.Fatalln("Failed to initialize Azure Blob Storage CSI driver")
7071
}

test/e2e/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ var _ = ginkgo.BeforeSuite(func() {
110110
nodeid := os.Getenv("nodeid")
111111
kubeconfig := os.Getenv(kubeconfigEnvVar)
112112
_, useBlobfuseProxy := os.LookupEnv("ENABLE_BLOBFUSE_PROXY")
113-
blobDriver = blob.NewDriver(nodeid, "", useBlobfuseProxy, 5)
113+
blobDriver = blob.NewDriver(nodeid, "", useBlobfuseProxy, 5, false)
114114
go func() {
115115
os.Setenv("AZURE_CREDENTIAL_FILE", credentials.TempAzureCredentialFilePath)
116116
blobDriver.Run(fmt.Sprintf("unix:///tmp/csi-%s.sock", uuid.NewUUID().String()), kubeconfig, false)

test/sanity/run-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if [[ "$#" -gt 0 ]] && [[ -n "$1" ]]; then
3333
fi
3434

3535
_output/blobplugin --endpoint "$controllerendpoint" -v=5 &
36-
_output/blobplugin --endpoint "$nodeendpoint" --nodeid "$nodeid" -v=5 &
36+
_output/blobplugin --endpoint "$nodeendpoint" --nodeid "$nodeid" -v=5 --enable-blob-mock-mount &
3737

3838
echo "Begin to run sanity test..."
3939
readonly CSI_SANITY_BIN='csi-sanity'

0 commit comments

Comments
 (0)