Skip to content

Commit

Permalink
Merge pull request #64426 from cofyc/remove_unnecessary_fakemounters
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 64142, 64426, 62910, 63942, 64548). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Clean up fake mounters.

**What this PR does / why we need it**:

Fixes kubernetes/kubernetes#61502

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #

**Special notes for your reviewer**:

list of fake mounters:

- (keep) pkg/util/mount.FakeMounter
- (removed) pkg/kubelet/cm.fakeMountInterface:
- (inherit from mount.FakeMounter) pkg/util/mount.fakeMounter
- (inherit from mount.FakeMounter) pkg/util/removeall.fakeMounter
- (removed) pkg/volume/host_path.fakeFileTypeChecker

**Release note**:

```release-note
NONE
```
  • Loading branch information
Kubernetes Submit Queue committed Jun 20, 2018
2 parents f8a0ff7 + a7adb5c commit 8c73887
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 70 deletions.
73 changes: 4 additions & 69 deletions exec_mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ limitations under the License.
package mount

import (
"errors"
"fmt"
"os"
"reflect"
"strings"
"testing"
Expand All @@ -47,7 +45,7 @@ func TestMount(t *testing.T) {
return nil, nil
})

wrappedMounter := &fakeMounter{t}
wrappedMounter := &fakeMounter{FakeMounter: &FakeMounter{}, t: t}
mounter := NewExecMounter(exec, wrappedMounter)

mounter.Mount(sourcePath, destinationPath, fsType, mountOptions)
Expand Down Expand Up @@ -75,7 +73,7 @@ func TestBindMount(t *testing.T) {
return nil, nil
})

wrappedMounter := &fakeMounter{t}
wrappedMounter := &fakeMounter{FakeMounter: &FakeMounter{}, t: t}
mounter := NewExecMounter(exec, wrappedMounter)
bindOptions := append(mountOptions, "bind")
mounter.Mount(sourcePath, destinationPath, fsType, bindOptions)
Expand All @@ -94,14 +92,15 @@ func TestUnmount(t *testing.T) {
return nil, nil
})

wrappedMounter := &fakeMounter{t}
wrappedMounter := &fakeMounter{&FakeMounter{}, t}
mounter := NewExecMounter(exec, wrappedMounter)

mounter.Unmount(destinationPath)
}

/* Fake wrapped mounter */
type fakeMounter struct {
*FakeMounter
t *testing.T
}

Expand All @@ -116,67 +115,3 @@ func (fm *fakeMounter) Unmount(target string) error {
fm.t.Errorf("Unexpected wrapped mount call")
return fmt.Errorf("Unexpected wrapped mount call")
}

func (fm *fakeMounter) List() ([]MountPoint, error) {
return nil, nil
}
func (fm *fakeMounter) IsMountPointMatch(mp MountPoint, dir string) bool {
return false
}
func (fm *fakeMounter) IsNotMountPoint(file string) (bool, error) {
return false, nil
}
func (fm *fakeMounter) IsLikelyNotMountPoint(file string) (bool, error) {
return false, nil
}
func (fm *fakeMounter) DeviceOpened(pathname string) (bool, error) {
return false, nil
}
func (fm *fakeMounter) PathIsDevice(pathname string) (bool, error) {
return false, nil
}
func (fm *fakeMounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) {
return "", nil
}
func (fm *fakeMounter) MakeRShared(path string) error {
return nil
}
func (fm *fakeMounter) MakeFile(pathname string) error {
return nil
}
func (fm *fakeMounter) MakeDir(pathname string) error {
return nil
}
func (fm *fakeMounter) ExistsPath(pathname string) (bool, error) {
return false, errors.New("not implemented")
}
func (fm *fakeMounter) GetFileType(pathname string) (FileType, error) {
return FileTypeFile, nil
}
func (fm *fakeMounter) PrepareSafeSubpath(subPath Subpath) (newHostPath string, cleanupAction func(), err error) {
return subPath.Path, nil, nil
}

func (fm *fakeMounter) CleanSubPaths(podDir string, volumeName string) error {
return nil
}

func (fm *fakeMounter) SafeMakeDir(pathname string, base string, perm os.FileMode) error {
return nil
}

func (fm *fakeMounter) GetMountRefs(pathname string) ([]string, error) {
return nil, errors.New("not implemented")
}

func (fm *fakeMounter) GetFSGroup(pathname string) (int64, error) {
return -1, errors.New("not implemented")
}

func (fm *fakeMounter) GetSELinuxSupport(pathname string) (bool, error) {
return false, errors.New("not implemented")
}

func (fm *fakeMounter) GetMode(pathname string) (os.FileMode, error) {
return 0, errors.New("not implemented")
}
9 changes: 8 additions & 1 deletion fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
type FakeMounter struct {
MountPoints []MountPoint
Log []FakeAction
Filesystem map[string]FileType
// Some tests run things in parallel, make sure the mounter does not produce
// any golang's DATA RACE warnings.
mutex sync.Mutex
Expand Down Expand Up @@ -190,6 +191,9 @@ func (f *FakeMounter) MakeRShared(path string) error {
}

func (f *FakeMounter) GetFileType(pathname string) (FileType, error) {
if t, ok := f.Filesystem[pathname]; ok {
return t, nil
}
return FileType("fake"), nil
}

Expand All @@ -202,7 +206,10 @@ func (f *FakeMounter) MakeFile(pathname string) error {
}

func (f *FakeMounter) ExistsPath(pathname string) (bool, error) {
return false, errors.New("not implemented")
if _, ok := f.Filesystem[pathname]; ok {
return true, nil
}
return false, nil
}

func (f *FakeMounter) PrepareSafeSubpath(subPath Subpath) (newHostPath string, cleanupAction func(), err error) {
Expand Down

0 comments on commit 8c73887

Please sign in to comment.