Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fake CSIProxyMounter to enable unit test #121

Closed
andyzhangx opened this issue Sep 23, 2020 · 3 comments
Closed

fake CSIProxyMounter to enable unit test #121

andyzhangx opened this issue Sep 23, 2020 · 3 comments
Assignees
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. test

Comments

@andyzhangx
Copy link
Member

andyzhangx commented Sep 23, 2020

Is your feature request related to a problem?/Why is this needed

Describe the solution you'd like in detail

Need to fake CSIProxyMounter, same as fakeMounter, and enable a few unit tests on Windows, current unit tests failed with return fmt.Errorf("could not cast to csi proxy class"

C:\Users\xiazhang\go\src\github.com\kubernetes-csi\csi-driver-smb\pkg\smb>git diff
diff --git a/pkg/smb/nodeserver_test.go b/pkg/smb/nodeserver_test.go
index ecaeab12..f9a9f386 100644
--- a/pkg/smb/nodeserver_test.go
+++ b/pkg/smb/nodeserver_test.go
@@ -22,9 +22,11 @@ import (
        "fmt"
        "os"
        "reflect"
+       "runtime"
        "syscall"
        "testing"

+       "github.com/kubernetes-csi/csi-driver-smb/pkg/mounter"
        "github.com/kubernetes-csi/csi-driver-smb/test/utils/testutil"

        "github.com/container-storage-interface/spec/lib/go/csi"
@@ -198,7 +200,7 @@ func TestNodeExpandVolume(t *testing.T) {
 }

 func TestNodePublishVolume(t *testing.T) {
-       skipIfTestingOnWindows(t)
+       //skipIfTestingOnWindows(t)
        volumeCap := csi.VolumeCapability_AccessMode{Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER}
        errorMountSource := "./error_mount_source"
        alreadyMountedTarget := "./false_is_likely_exist_target"
@@ -284,9 +286,15 @@ func TestNodePublishVolume(t *testing.T) {
        // Setup
        _ = makeDir(alreadyMountedTarget)
        d := NewFakeDriver()
-       fakeMounter := &fakeMounter{}
-       d.mounter = &mount.SafeFormatAndMount{
-               Interface: fakeMounter,
+       if runtime.GOOS == "windows" {
+               csiProxyMounter, _ := mounter.NewCSIProxyMounter()
+               d.mounter = &mount.SafeFormatAndMount{
+                       Interface: csiProxyMounter,
+               }
+       } else {
+               d.mounter = &mount.SafeFormatAndMount{
+                       Interface: &fakeMounter{},
+               }
        }

        for _, test := range tests {

Without fake, there would be panic:

C:\Users\xiazhang\go\src\github.com\kubernetes-csi\csi-driver-smb\pkg\smb>go test -run TestNodePublishVolume
--- FAIL: TestNodePublishVolume (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x10 pc=0x8ae83c]

goroutine 22 [running]:
testing.tRunner.func1(0xc000150100)
        c:/go/src/testing/testing.go:874 +0x3aa
panic(0x996b00, 0xeebb70)
        c:/go/src/runtime/panic.go:679 +0x1c0
github.com/kubernetes-csi/csi-driver-smb/pkg/mounter.(*CSIProxyMounter).ExistsPath(0xc000067e10, 0xa51ca5, 0x8, 0x0, 0x38, 0x8)
        C:/Users/xiazhang/go/src/github.com/kubernetes-csi/csi-driver-smb/pkg/mounter/safe_mounter_windows.go:210 +0x17c
github.com/kubernetes-csi/csi-driver-smb/pkg/mounter.(*CSIProxyMounter).IsLikelyNotMountPoint(0xc000067e10, 0xa51ca5, 0x8, 0xc000093420, 0x40cdf0, 0xc00006d640)
        C:/Users/xiazhang/go/src/github.com/kubernetes-csi/csi-driver-smb/pkg/mounter/safe_mounter_windows.go:148 +0xdf
github.com/kubernetes-csi/csi-driver-smb/pkg/smb.(*Driver).ensureMountPoint(0xc000093858, 0xa51ca5, 0x8, 0x1, 0x2, 0xc00006d640)
        C:/Users/xiazhang/go/src/github.com/kubernetes-csi/csi-driver-smb/pkg/smb/nodeserver.go:274 +0x70
github.com/kubernetes-csi/csi-driver-smb/pkg/smb.(*Driver).NodePublishVolume(0xc000093858, 0xb1fe80, 0xc0000720b0, 0xc0000938e8, 0x1, 0xb135c0, 0xc0000c2d70)
        C:/Users/xiazhang/go/src/github.com/kubernetes-csi/csi-driver-smb/pkg/smb/nodeserver.go:71 +0x1f4
github.com/kubernetes-csi/csi-driver-smb/pkg/smb.TestNodePublishVolume(0xc000150100)
        C:/Users/xiazhang/go/src/github.com/kubernetes-csi/csi-driver-smb/pkg/smb/nodeserver_test.go:301 +0x7f1
testing.tRunner(0xc000150100, 0xa7d240)
        c:/go/src/testing/testing.go:909 +0xd0
created by testing.(*T).Run
        c:/go/src/testing/testing.go:960 +0x357
exit status 2
FAIL    github.com/kubernetes-csi/csi-driver-smb/pkg/smb        1.950s

Another way is use real CSIProxyMounter, and run csi-proxy.exe on Windows before running unit tests.
follow guide here:

Or run as a service using nssm:

Describe alternatives you've considered

Additional context

@andyzhangx andyzhangx added help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. test labels Sep 23, 2020
@boddumanohar
Copy link
Contributor

/assign

@boddumanohar
Copy link
Contributor

Created a PR that runs CSI-Proxy as a background job. I also tried to run with NSSM but I am getting this error:

Run .\hack\start-csi-proxy.ps1
using the .exe .\nssm-2.24\win64\nssm.exe
Service "csi-proxy" installed successfully!
csi-proxy: Unexpected status SERVICE_STOPPED in response to START control.

I believe that windows runners in Github actions has some issues when running a process with Services.msc.

@boddumanohar
Copy link
Contributor

I believe this is fixed by #122

andyzhangx pushed a commit to andyzhangx/csi-driver-smb that referenced this issue May 1, 2022
Check namespace for snapshot-controller
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. test
Projects
None yet
Development

No branches or pull requests

2 participants