Merge pull request #16 from msau42/fake-mounter
Add ability to use other mounters for unit testing
This commit is contained in:
commit
adb36fc9cd
@ -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,
|
||||
mounter: mounter,
|
||||
}
|
||||
}
|
||||
|
||||
func (n *nfsDriver) Run() {
|
||||
n.ns = NewNodeServer(n)
|
||||
n.ns = NewNodeServer(n, mount.New(""))
|
||||
s := NewNonBlockingGRPCServer()
|
||||
s.Start(n.endpoint,
|
||||
NewDefaultIdentityServer(n),
|
||||
|
||||
@ -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"
|
||||
@ -31,11 +32,12 @@ import (
|
||||
|
||||
type nodeServer struct {
|
||||
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())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user