Skip to content

Commit 0f8577d

Browse files
committed
test: use mock mount to fix sanit test failures
add comments
1 parent b973a88 commit 0f8577d

File tree

7 files changed

+23
-15
lines changed

7 files changed

+23
-15
lines changed

pkg/blob/blob.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ var (
9393
// Driver implements all interfaces of CSI drivers
9494
type Driver struct {
9595
csicommon.CSIDriver
96-
cloud *azure.Cloud
97-
blobfuseProxyEndpoint string
96+
cloud *azure.Cloud
97+
blobfuseProxyEndpoint string
98+
// enableBlobMockMount is only for testing, DO NOT set as true in non-testing scenario
99+
enableBlobMockMount bool
98100
enableBlobfuseProxy bool
99101
blobfuseProxyConnTimout int
100102
mounter *mount.SafeFormatAndMount
@@ -106,7 +108,7 @@ type Driver struct {
106108

107109
// NewDriver Creates a NewCSIDriver object. Assumes vendor version is equal to driver version &
108110
// 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 {
111+
func NewDriver(nodeID, blobfuseProxyEndpoint string, enableBlobfuseProxy bool, blobfuseProxyConnTimout int, enableBlobMockMount bool) *Driver {
110112
driver := Driver{}
111113
driver.Name = DriverName
112114
driver.Version = driverVersion
@@ -116,6 +118,7 @@ func NewDriver(nodeID, blobfuseProxyEndpoint string, enableBlobfuseProxy bool, b
116118
driver.blobfuseProxyEndpoint = blobfuseProxyEndpoint
117119
driver.enableBlobfuseProxy = enableBlobfuseProxy
118120
driver.blobfuseProxyConnTimout = blobfuseProxyConnTimout
121+
driver.enableBlobMockMount = enableBlobMockMount
119122
return &driver
120123
}
121124

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ var (
4242
version = flag.Bool("version", false, "Print the version and exit.")
4343
metricsAddress = flag.String("metrics-address", "0.0.0.0:29634", "export the metrics")
4444
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
45-
enableBlobfuseProxy = flag.Bool("enable-blobfuse-proxy", false, "Whether supports using Blobfuse proxy for mounts")
45+
enableBlobfuseProxy = flag.Bool("enable-blobfuse-proxy", false, "Whether 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(only for testing)")
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/integration/run-test.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ readonly cloud="$5"
3434
echo "Begin to run integration test on $cloud..."
3535

3636
# Run CSI driver as a background service
37-
_output/blobplugin --endpoint "$endpoint" --nodeid CSINode -v=5 &
37+
_output/blobplugin --endpoint "$endpoint" --nodeid CSINode --enable-blob-mock-mount -v=5 &
3838
trap cleanup EXIT
3939

4040
if [[ "$cloud" == "AzureChinaCloud" ]]; then
@@ -66,10 +66,6 @@ if [[ "$cloud" != "AzureChinaCloud" ]]; then
6666
csc node stats --endpoint "$endpoint" "$volumeid:$target_path:$staging_target_path"
6767
sleep 2
6868

69-
# FIXME: this is done has a workaround to fix failing blobfuse mounts in prow
70-
echo "unmounting manually"
71-
umount $target_path
72-
7369
echo 'expand volume test'
7470
csc controller expand-volume --endpoint "$endpoint" --req-bytes "$expanded_vol_size" "$volumeid"
7571

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" --enable-blob-mock-mount -v=5 &
3737

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

0 commit comments

Comments
 (0)