Skip to content

test: use mock mount to fix sanity test failures #393

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

Merged
merged 1 commit into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ var (
// Driver implements all interfaces of CSI drivers
type Driver struct {
csicommon.CSIDriver
cloud *azure.Cloud
blobfuseProxyEndpoint string
cloud *azure.Cloud
blobfuseProxyEndpoint string
// enableBlobMockMount is only for testing, DO NOT set as true in non-testing scenario
enableBlobMockMount bool
enableBlobfuseProxy bool
blobfuseProxyConnTimout int
mounter *mount.SafeFormatAndMount
Expand All @@ -106,7 +108,7 @@ type Driver struct {

// NewDriver Creates a NewCSIDriver object. Assumes vendor version is equal to driver version &
// does not support optional driver plugin info manifest field. Refer to CSI spec for more details.
func NewDriver(nodeID, blobfuseProxyEndpoint string, enableBlobfuseProxy bool, blobfuseProxyConnTimout int) *Driver {
func NewDriver(nodeID, blobfuseProxyEndpoint string, enableBlobfuseProxy bool, blobfuseProxyConnTimout int, enableBlobMockMount bool) *Driver {
driver := Driver{}
driver.Name = DriverName
driver.Version = driverVersion
Expand All @@ -116,6 +118,7 @@ func NewDriver(nodeID, blobfuseProxyEndpoint string, enableBlobfuseProxy bool, b
driver.blobfuseProxyEndpoint = blobfuseProxyEndpoint
driver.enableBlobfuseProxy = enableBlobfuseProxy
driver.blobfuseProxyConnTimout = blobfuseProxyConnTimout
driver.enableBlobMockMount = enableBlobMockMount
return &driver
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ const (
)

func NewFakeDriver() *Driver {
driver := NewDriver(fakeNodeID, "", false, 5)
driver := NewDriver(fakeNodeID, "", false, 5, false)
driver.Name = fakeDriverName
driver.Version = vendorVersion
return driver
}

func TestNewFakeDriver(t *testing.T) {
d := NewDriver(fakeNodeID, "", false, 5)
d := NewDriver(fakeNodeID, "", false, 5, false)
assert.NotNil(t, d)
}

func TestNewDriver(t *testing.T) {
driver := NewDriver(fakeNodeID, "", false, 5)
driver := NewDriver(fakeNodeID, "", false, 5, false)
fakedriver := NewFakeDriver()
fakedriver.Name = DriverName
fakedriver.Version = driverVersion
Expand Down
8 changes: 8 additions & 0 deletions pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
}

klog.V(2).Infof("NodePublishVolume: volume %s mounting %s at %s with mountOptions: %v", volumeID, source, target, mountOptions)
if d.enableBlobMockMount {
if err := volumehelper.MakeDir(target); err != nil {
klog.Errorf("MakeDir failed on target: %s (%v)", target, err)
return nil, err
}
return &csi.NodePublishVolumeResponse{}, nil
}

if err := d.mounter.Mount(source, target, "", mountOptions); err != nil {
if removeErr := os.Remove(target); removeErr != nil {
return nil, status.Errorf(codes.Internal, "Could not remove mount target %q: %v", target, removeErr)
Expand Down
5 changes: 3 additions & 2 deletions pkg/blobplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ var (
version = flag.Bool("version", false, "Print the version and exit.")
metricsAddress = flag.String("metrics-address", "0.0.0.0:29634", "export the metrics")
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
enableBlobfuseProxy = flag.Bool("enable-blobfuse-proxy", false, "Whether supports using Blobfuse proxy for mounts")
enableBlobfuseProxy = flag.Bool("enable-blobfuse-proxy", false, "Whether using blobfuse proxy for mounts")
blobfuseProxyConnTimout = flag.Int("blobfuse-proxy-connect-timeout", 5, "blobfuse proxy connection timeout(seconds)")
enableBlobMockMount = flag.Bool("enable-blob-mock-mount", false, "Whether enable mock mount(only for testing)")
)

func main() {
Expand All @@ -64,7 +65,7 @@ func main() {
}

func handle() {
driver := blob.NewDriver(*nodeID, *blobfuseProxyEndpoint, *enableBlobfuseProxy, *blobfuseProxyConnTimout)
driver := blob.NewDriver(*nodeID, *blobfuseProxyEndpoint, *enableBlobfuseProxy, *blobfuseProxyConnTimout, *enableBlobMockMount)
if driver == nil {
klog.Fatalln("Failed to initialize Azure Blob Storage CSI driver")
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var _ = ginkgo.BeforeSuite(func() {
nodeid := os.Getenv("nodeid")
kubeconfig := os.Getenv(kubeconfigEnvVar)
_, useBlobfuseProxy := os.LookupEnv("ENABLE_BLOBFUSE_PROXY")
blobDriver = blob.NewDriver(nodeid, "", useBlobfuseProxy, 5)
blobDriver = blob.NewDriver(nodeid, "", useBlobfuseProxy, 5, false)
go func() {
os.Setenv("AZURE_CREDENTIAL_FILE", credentials.TempAzureCredentialFilePath)
blobDriver.Run(fmt.Sprintf("unix:///tmp/csi-%s.sock", uuid.NewUUID().String()), kubeconfig, false)
Expand Down
6 changes: 1 addition & 5 deletions test/integration/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ readonly cloud="$5"
echo "Begin to run integration test on $cloud..."

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

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

# FIXME: this is done has a workaround to fix failing blobfuse mounts in prow
echo "unmounting manually"
umount $target_path

echo 'expand volume test'
csc controller expand-volume --endpoint "$endpoint" --req-bytes "$expanded_vol_size" "$volumeid"

Expand Down
2 changes: 1 addition & 1 deletion test/sanity/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if [[ "$#" -gt 0 ]] && [[ -n "$1" ]]; then
fi

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

echo "Begin to run sanity test..."
readonly CSI_SANITY_BIN='csi-sanity'
Expand Down