Merge pull request #16 from msau42/fake-mounter

Add ability to use other mounters for unit testing
This commit is contained in:
Kubernetes Prow Robot 2019-08-16 11:10:11 -07:00 committed by GitHub
commit adb36fc9cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View File

@ -19,6 +19,7 @@ package nfs
import (
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/util/mount"
)
type nfsDriver struct {
@ -61,14 +62,15 @@ func NewNFSdriver(nodeID, endpoint string) *nfsDriver {
return n
}
func NewNodeServer(n *nfsDriver) *nodeServer {
func NewNodeServer(n *nfsDriver, mounter mount.Interface) *nodeServer {
return &nodeServer{
Driver: n,
Driver: n,
mounter: mounter,
}
}
func (n *nfsDriver) Run() {
n.ns = NewNodeServer(n)
n.ns = NewNodeServer(n, mount.New(""))
s := NewNonBlockingGRPCServer()
s.Start(n.endpoint,
NewDefaultIdentityServer(n),

View File

@ -18,10 +18,11 @@ package nfs
import (
"fmt"
"github.com/golang/glog"
"os"
"strings"
"github.com/golang/glog"
"github.com/container-storage-interface/spec/lib/go/csi"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
@ -30,12 +31,13 @@ import (
)
type nodeServer struct {
Driver *nfsDriver
Driver *nfsDriver
mounter mount.Interface
}
func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
targetPath := req.GetTargetPath()
notMnt, err := mount.New("").IsLikelyNotMountPoint(targetPath)
notMnt, err := ns.mounter.IsLikelyNotMountPoint(targetPath)
if err != nil {
if os.IsNotExist(err) {
if err := os.MkdirAll(targetPath, 0750); err != nil {
@ -60,8 +62,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
ep := req.GetVolumeContext()["share"]
source := fmt.Sprintf("%s:%s", s, ep)
mounter := mount.New("")
err = mounter.Mount(source, targetPath, "nfs", mo)
err = ns.mounter.Mount(source, targetPath, "nfs", mo)
if err != nil {
if os.IsPermission(err) {
return nil, status.Error(codes.PermissionDenied, err.Error())
@ -77,7 +78,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
targetPath := req.GetTargetPath()
notMnt, err := mount.New("").IsLikelyNotMountPoint(targetPath)
notMnt, err := ns.mounter.IsLikelyNotMountPoint(targetPath)
if err != nil {
if os.IsNotExist(err) {
@ -90,7 +91,7 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
return nil, status.Error(codes.NotFound, "Volume not mounted")
}
err = mount.CleanupMountPoint(req.GetTargetPath(), mount.New(""), false)
err = mount.CleanupMountPoint(req.GetTargetPath(), ns.mounter, false)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}