RBD Plugin: Prepare to implement Attacher/Detacher interfaces.

1) Fix FakeMounter.IsLikelyNotMountPoint to return ErrNotExist if the
   directory does not exist. Mounter.IsLikelyNotMountPoint interface
   requires this, and RBD plugin depends on it.
pull/6/head
Yecheng Fu 2017-09-01 05:33:47 +00:00
parent c0a519be1f
commit a768092f9a
2 changed files with 14 additions and 1 deletions

View File

@ -17,6 +17,7 @@ limitations under the License.
package mount package mount
import ( import (
"os"
"path/filepath" "path/filepath"
"sync" "sync"
@ -136,6 +137,11 @@ func (f *FakeMounter) IsLikelyNotMountPoint(file string) (bool, error) {
f.mutex.Lock() f.mutex.Lock()
defer f.mutex.Unlock() defer f.mutex.Unlock()
_, err := os.Stat(file)
if err != nil {
return true, err
}
// If file is a symlink, get its absolute path // If file is a symlink, get its absolute path
absFile, err := filepath.EvalSymlinks(file) absFile, err := filepath.EvalSymlinks(file)
if err != nil { if err != nil {

View File

@ -18,6 +18,8 @@ package mount
import ( import (
"fmt" "fmt"
"io/ioutil"
"os"
"runtime" "runtime"
"testing" "testing"
@ -50,6 +52,11 @@ func TestSafeFormatAndMount(t *testing.T) {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" { if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
t.Skipf("not supported on GOOS=%s", runtime.GOOS) t.Skipf("not supported on GOOS=%s", runtime.GOOS)
} }
mntDir, err := ioutil.TempDir(os.TempDir(), "mount")
if err != nil {
t.Fatalf("failed to create tmp dir: %v", err)
}
defer os.RemoveAll(mntDir)
tests := []struct { tests := []struct {
description string description string
fstype string fstype string
@ -207,7 +214,7 @@ func TestSafeFormatAndMount(t *testing.T) {
} }
device := "/dev/foo" device := "/dev/foo"
dest := "/mnt/bar" dest := mntDir
err := mounter.FormatAndMount(device, dest, test.fstype, test.mountOptions) err := mounter.FormatAndMount(device, dest, test.fstype, test.mountOptions)
if test.expectedError == nil { if test.expectedError == nil {
if err != nil { if err != nil {