Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up fake mounters. #64426

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
110 changes: 8 additions & 102 deletions pkg/kubelet/cm/container_manager_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ limitations under the License.
package cm

import (
"errors"
"fmt"
"io/ioutil"
"os"
"path"
Expand All @@ -32,101 +30,9 @@ import (
"k8s.io/kubernetes/pkg/util/mount"
)

type fakeMountInterface struct {
mountPoints []mount.MountPoint
}

func (mi *fakeMountInterface) Mount(source string, target string, fstype string, options []string) error {
return fmt.Errorf("unsupported")
}

func (mi *fakeMountInterface) Unmount(target string) error {
return fmt.Errorf("unsupported")
}

func (mi *fakeMountInterface) List() ([]mount.MountPoint, error) {
return mi.mountPoints, nil
}

func (mi *fakeMountInterface) IsMountPointMatch(mp mount.MountPoint, dir string) bool {
return (mp.Path == dir)
}

func (mi *fakeMountInterface) IsNotMountPoint(dir string) (bool, error) {
return false, fmt.Errorf("unsupported")
}

func (mi *fakeMountInterface) IsLikelyNotMountPoint(file string) (bool, error) {
return false, fmt.Errorf("unsupported")
}
func (mi *fakeMountInterface) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) {
return "", nil
}

func (mi *fakeMountInterface) DeviceOpened(pathname string) (bool, error) {
for _, mp := range mi.mountPoints {
if mp.Device == pathname {
return true, nil
}
}
return false, nil
}

func (mi *fakeMountInterface) PathIsDevice(pathname string) (bool, error) {
return true, nil
}

func (mi *fakeMountInterface) MakeRShared(path string) error {
return nil
}

func (mi *fakeMountInterface) GetFileType(pathname string) (mount.FileType, error) {
return mount.FileType("fake"), nil
}

func (mi *fakeMountInterface) MakeDir(pathname string) error {
return nil
}

func (mi *fakeMountInterface) MakeFile(pathname string) error {
return nil
}

func (mi *fakeMountInterface) ExistsPath(pathname string) (bool, error) {
return true, errors.New("not implemented")
}

func (mi *fakeMountInterface) PrepareSafeSubpath(subPath mount.Subpath) (newHostPath string, cleanupAction func(), err error) {
return "", nil, nil
}

func (mi *fakeMountInterface) CleanSubPaths(_, _ string) error {
return nil
}

func (mi *fakeMountInterface) SafeMakeDir(_, _ string, _ os.FileMode) error {
return nil
}

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

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

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

func (mi *fakeMountInterface) GetMode(pathname string) (os.FileMode, error) {
return 0, errors.New("not implemented")
}

func fakeContainerMgrMountInt() mount.Interface {
return &fakeMountInterface{
[]mount.MountPoint{
return &mount.FakeMounter{
MountPoints: []mount.MountPoint{
{
Device: "cgroup",
Type: "cgroup",
Expand Down Expand Up @@ -158,8 +64,8 @@ func TestCgroupMountValidationSuccess(t *testing.T) {
}

func TestCgroupMountValidationMemoryMissing(t *testing.T) {
mountInt := &fakeMountInterface{
[]mount.MountPoint{
mountInt := &mount.FakeMounter{
MountPoints: []mount.MountPoint{
{
Device: "cgroup",
Type: "cgroup",
Expand All @@ -182,8 +88,8 @@ func TestCgroupMountValidationMemoryMissing(t *testing.T) {
}

func TestCgroupMountValidationMultipleSubsystem(t *testing.T) {
mountInt := &fakeMountInterface{
[]mount.MountPoint{
mountInt := &mount.FakeMounter{
MountPoints: []mount.MountPoint{
{
Device: "cgroup",
Type: "cgroup",
Expand Down Expand Up @@ -212,8 +118,8 @@ func TestSoftRequirementsValidationSuccess(t *testing.T) {
defer os.RemoveAll(tempDir)
req.NoError(ioutil.WriteFile(path.Join(tempDir, "cpu.cfs_period_us"), []byte("0"), os.ModePerm))
req.NoError(ioutil.WriteFile(path.Join(tempDir, "cpu.cfs_quota_us"), []byte("0"), os.ModePerm))
mountInt := &fakeMountInterface{
[]mount.MountPoint{
mountInt := &mount.FakeMounter{
MountPoints: []mount.MountPoint{
{
Device: "cgroup",
Type: "cgroup",
Expand Down
73 changes: 4 additions & 69 deletions pkg/util/mount/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 pkg/util/mount/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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type should be moved to a testing/ subdir so it doesn't get linked into non-test code. Won't block this PR on it.

Copy link
Member Author

@cofyc cofyc Jun 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. It'll change a lot of go imports and BUILD files, I'll create another PR for this.

// 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
87 changes: 4 additions & 83 deletions pkg/util/removeall/removeall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,87 +27,12 @@ import (
"k8s.io/kubernetes/pkg/util/mount"
)

type fakeMounter struct{}

var _ mount.Interface = &fakeMounter{}

func (mounter *fakeMounter) Mount(source string, target string, fstype string, options []string) error {
return errors.New("not implemented")
}

func (mounter *fakeMounter) Unmount(target string) error {
return errors.New("not implemented")
}

func (mounter *fakeMounter) List() ([]mount.MountPoint, error) {
return nil, errors.New("not implemented")
}

func (mounter fakeMounter) DeviceOpened(pathname string) (bool, error) {
return false, errors.New("not implemented")
}

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

func (mounter *fakeMounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) {
return "", errors.New("not implemented")
}

func (mounter *fakeMounter) IsMountPointMatch(mp mount.MountPoint, dir string) bool {
return mp.Path == dir
}

func (mounter *fakeMounter) IsNotMountPoint(dir string) (bool, error) {
return mount.IsNotMountPoint(mounter, dir)
}

func (mounter *fakeMounter) GetFileType(pathname string) (mount.FileType, error) {
return mount.FileType("fake"), errors.New("not implemented")
}

func (mounter *fakeMounter) MakeDir(pathname string) error {
return nil
type fakeMounter struct {
mount.FakeMounter
}

func (mounter *fakeMounter) MakeFile(pathname string) error {
return nil
}

func (mounter *fakeMounter) ExistsPath(pathname string) (bool, error) {
return true, errors.New("not implemented")
}

func (mounter *fakeMounter) PrepareSafeSubpath(subPath mount.Subpath) (newHostPath string, cleanupAction func(), err error) {
return "", nil, nil
}

func (mounter *fakeMounter) CleanSubPaths(_, _ string) error {
return nil
}

func (mounter *fakeMounter) SafeMakeDir(_, _ string, _ os.FileMode) error {
return nil
}

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

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

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

func (mounter *fakeMounter) GetMode(pathname string) (os.FileMode, error) {
return 0, errors.New("not implemented")
}

func (mounter *fakeMounter) IsLikelyNotMountPoint(file string) (bool, error) {
// IsLikelyNotMountPoint overrides mount.FakeMounter.IsLikelyNotMountPoint for our use.
func (f *fakeMounter) IsLikelyNotMountPoint(file string) (bool, error) {
name := path.Base(file)
if strings.HasPrefix(name, "mount") {
return false, nil
Expand All @@ -118,10 +43,6 @@ func (mounter *fakeMounter) IsLikelyNotMountPoint(file string) (bool, error) {
return true, nil
}

func (mounter *fakeMounter) MakeRShared(path string) error {
return nil
}

func TestRemoveAllOneFilesystem(t *testing.T) {
tests := []struct {
name string
Expand Down