Commit 112aa327 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #41521 from spiffxp/osx-make-test

Automatic merge from submit-queue (batch tested with PRs 41401, 41195, 41664, 41521, 41651) Allow `make test` to pass on OSX **What this PR does / why we need it**: `make test` doesn't pass on my OSX setup (10.11.6, go1.7, docker 1.13.1) on `master`, `release-1.5`, nor `release-1.4`. Our [docs on unit tests](https://github.com/kubernetes/community/blob/master/contributors/devel/testing.md#unit-tests) say they should always pass on OS X. This PR allows them to pass. **Release note**: ```release-note NONE ``` ref: #24717 for the motivation behind dereferencing mount symlinks /cc @kubernetes/sig-testing-pr-reviews
parents a574c85e ddc8d8c4
...@@ -267,7 +267,7 @@ func TestGetKubetest(t *testing.T) { ...@@ -267,7 +267,7 @@ func TestGetKubetest(t *testing.T) {
stat: pk, stat: pk,
path: true, path: true,
age: 100, age: time.Second,
upgraded: true, upgraded: true,
touched: true, touched: true,
goPath: gp, goPath: gp,
...@@ -281,7 +281,7 @@ func TestGetKubetest(t *testing.T) { ...@@ -281,7 +281,7 @@ func TestGetKubetest(t *testing.T) {
stat: pk, stat: pk,
path: true, path: true,
age: 100, age: time.Second,
upgraded: false, upgraded: false,
touched: false, touched: false,
goPath: gpk, goPath: gpk,
...@@ -295,7 +295,7 @@ func TestGetKubetest(t *testing.T) { ...@@ -295,7 +295,7 @@ func TestGetKubetest(t *testing.T) {
stat: pk, stat: pk,
path: true, path: true,
age: 100, age: time.Second,
upgraded: true, upgraded: true,
touched: false, touched: false,
goPath: gpk, goPath: gpk,
...@@ -314,7 +314,7 @@ func TestGetKubetest(t *testing.T) { ...@@ -314,7 +314,7 @@ func TestGetKubetest(t *testing.T) {
if p != c.stat { if p != c.stat {
return nil, fmt.Errorf("Failed to find %s", p) return nil, fmt.Errorf("Failed to find %s", p)
} }
return FileInfo{time.Now().Add(c.age)}, nil return FileInfo{time.Now().Add(c.age * -1)}, nil
}, },
func(name string) (string, error) { func(name string) (string, error) {
if c.path { if c.path {
......
...@@ -17,6 +17,7 @@ limitations under the License. ...@@ -17,6 +17,7 @@ limitations under the License.
package mount package mount
import ( import (
"path/filepath"
"sync" "sync"
"github.com/golang/glog" "github.com/golang/glog"
...@@ -80,9 +81,15 @@ func (f *FakeMounter) Mount(source string, target string, fstype string, options ...@@ -80,9 +81,15 @@ func (f *FakeMounter) Mount(source string, target string, fstype string, options
} }
} }
f.MountPoints = append(f.MountPoints, MountPoint{Device: source, Path: target, Type: fstype}) // If target is a symlink, get its absolute path
glog.V(5).Infof("Fake mounter: mounted %s to %s", source, target) absTarget, err := filepath.EvalSymlinks(target)
f.Log = append(f.Log, FakeAction{Action: FakeActionMount, Target: target, Source: source, FSType: fstype}) if err != nil {
absTarget = target
}
f.MountPoints = append(f.MountPoints, MountPoint{Device: source, Path: absTarget, Type: fstype})
glog.V(5).Infof("Fake mounter: mounted %s to %s", source, absTarget)
f.Log = append(f.Log, FakeAction{Action: FakeActionMount, Target: absTarget, Source: source, FSType: fstype})
return nil return nil
} }
...@@ -90,17 +97,23 @@ func (f *FakeMounter) Unmount(target string) error { ...@@ -90,17 +97,23 @@ func (f *FakeMounter) Unmount(target string) error {
f.mutex.Lock() f.mutex.Lock()
defer f.mutex.Unlock() defer f.mutex.Unlock()
// If target is a symlink, get its absolute path
absTarget, err := filepath.EvalSymlinks(target)
if err != nil {
absTarget = target
}
newMountpoints := []MountPoint{} newMountpoints := []MountPoint{}
for _, mp := range f.MountPoints { for _, mp := range f.MountPoints {
if mp.Path == target { if mp.Path == absTarget {
glog.V(5).Infof("Fake mounter: unmounted %s from %s", mp.Device, target) glog.V(5).Infof("Fake mounter: unmounted %s from %s", mp.Device, absTarget)
// Don't copy it to newMountpoints // Don't copy it to newMountpoints
continue continue
} }
newMountpoints = append(newMountpoints, MountPoint{Device: mp.Device, Path: mp.Path, Type: mp.Type}) newMountpoints = append(newMountpoints, MountPoint{Device: mp.Device, Path: mp.Path, Type: mp.Type})
} }
f.MountPoints = newMountpoints f.MountPoints = newMountpoints
f.Log = append(f.Log, FakeAction{Action: FakeActionUnmount, Target: target}) f.Log = append(f.Log, FakeAction{Action: FakeActionUnmount, Target: absTarget})
return nil return nil
} }
...@@ -115,13 +128,19 @@ func (f *FakeMounter) IsLikelyNotMountPoint(file string) (bool, error) { ...@@ -115,13 +128,19 @@ func (f *FakeMounter) IsLikelyNotMountPoint(file string) (bool, error) {
f.mutex.Lock() f.mutex.Lock()
defer f.mutex.Unlock() defer f.mutex.Unlock()
// If file is a symlink, get its absolute path
absFile, err := filepath.EvalSymlinks(file)
if err != nil {
absFile = file
}
for _, mp := range f.MountPoints { for _, mp := range f.MountPoints {
if mp.Path == file { if mp.Path == absFile {
glog.V(5).Infof("isLikelyMountPoint for %s: mounted %s, false", file, mp.Path) glog.V(5).Infof("isLikelyNotMountPoint for %s: mounted %s, false", file, mp.Path)
return false, nil return false, nil
} }
} }
glog.V(5).Infof("isLikelyMountPoint for %s: true", file) glog.V(5).Infof("isLikelyNotMountPoint for %s: true", file)
return true, nil return true, nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment