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 (
|
import (
|
||||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
)
|
)
|
||||||
|
|
||||||
type nfsDriver struct {
|
type nfsDriver struct {
|
||||||
@ -61,14 +62,15 @@ func NewNFSdriver(nodeID, endpoint string) *nfsDriver {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNodeServer(n *nfsDriver) *nodeServer {
|
func NewNodeServer(n *nfsDriver, mounter mount.Interface) *nodeServer {
|
||||||
return &nodeServer{
|
return &nodeServer{
|
||||||
Driver: n,
|
Driver: n,
|
||||||
|
mounter: mounter,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *nfsDriver) Run() {
|
func (n *nfsDriver) Run() {
|
||||||
n.ns = NewNodeServer(n)
|
n.ns = NewNodeServer(n, mount.New(""))
|
||||||
s := NewNonBlockingGRPCServer()
|
s := NewNonBlockingGRPCServer()
|
||||||
s.Start(n.endpoint,
|
s.Start(n.endpoint,
|
||||||
NewDefaultIdentityServer(n),
|
NewDefaultIdentityServer(n),
|
||||||
|
|||||||
@ -18,10 +18,11 @@ package nfs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang/glog"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
|
|
||||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
@ -31,11 +32,12 @@ import (
|
|||||||
|
|
||||||
type nodeServer struct {
|
type nodeServer struct {
|
||||||
Driver *nfsDriver
|
Driver *nfsDriver
|
||||||
|
mounter mount.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
|
func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
|
||||||
targetPath := req.GetTargetPath()
|
targetPath := req.GetTargetPath()
|
||||||
notMnt, err := mount.New("").IsLikelyNotMountPoint(targetPath)
|
notMnt, err := ns.mounter.IsLikelyNotMountPoint(targetPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
if err := os.MkdirAll(targetPath, 0750); err != nil {
|
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"]
|
ep := req.GetVolumeContext()["share"]
|
||||||
source := fmt.Sprintf("%s:%s", s, ep)
|
source := fmt.Sprintf("%s:%s", s, ep)
|
||||||
|
|
||||||
mounter := mount.New("")
|
err = ns.mounter.Mount(source, targetPath, "nfs", mo)
|
||||||
err = mounter.Mount(source, targetPath, "nfs", mo)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsPermission(err) {
|
if os.IsPermission(err) {
|
||||||
return nil, status.Error(codes.PermissionDenied, err.Error())
|
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) {
|
func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
|
||||||
targetPath := req.GetTargetPath()
|
targetPath := req.GetTargetPath()
|
||||||
notMnt, err := mount.New("").IsLikelyNotMountPoint(targetPath)
|
notMnt, err := ns.mounter.IsLikelyNotMountPoint(targetPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
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")
|
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 {
|
if err != nil {
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user