mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
Merge pull request #117896 from kolyshkin/mount-utils-spring-cleaning
Mount utils spring cleaning and optimization
This commit is contained in:
commit
c984d53b31
@ -7,6 +7,7 @@ go 1.20
|
|||||||
require (
|
require (
|
||||||
github.com/moby/sys/mountinfo v0.6.2
|
github.com/moby/sys/mountinfo v0.6.2
|
||||||
github.com/stretchr/testify v1.8.2
|
github.com/stretchr/testify v1.8.2
|
||||||
|
golang.org/x/sys v0.8.0
|
||||||
k8s.io/klog/v2 v2.100.1
|
k8s.io/klog/v2 v2.100.1
|
||||||
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
|
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
|
||||||
)
|
)
|
||||||
@ -16,7 +17,6 @@ require (
|
|||||||
github.com/go-logr/logr v1.2.4 // indirect
|
github.com/go-logr/logr v1.2.4 // indirect
|
||||||
github.com/kr/pretty v0.3.0 // indirect
|
github.com/kr/pretty v0.3.0 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
golang.org/x/sys v0.8.0 // indirect
|
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
@ -18,7 +18,6 @@ package mount
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -27,13 +26,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestDoCleanupMountPoint(t *testing.T) {
|
func TestDoCleanupMountPoint(t *testing.T) {
|
||||||
|
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
t.Skipf("not supported on GOOS=%s", runtime.GOOS)
|
t.Skipf("not supported on GOOS=%s", runtime.GOOS)
|
||||||
}
|
}
|
||||||
|
|
||||||
const testMount = "test-mount"
|
const testMount = "test-mount"
|
||||||
const defaultPerm = 0750
|
const defaultPerm = 0o750
|
||||||
|
|
||||||
tests := map[string]struct {
|
tests := map[string]struct {
|
||||||
corruptedMnt bool
|
corruptedMnt bool
|
||||||
@ -43,8 +41,7 @@ func TestDoCleanupMountPoint(t *testing.T) {
|
|||||||
// and error if the prepare function encountered a fatal error.
|
// and error if the prepare function encountered a fatal error.
|
||||||
prepareMnt func(base string) (MountPoint, error, error)
|
prepareMnt func(base string) (MountPoint, error, error)
|
||||||
// Function that prepares the FakeMounter for the test.
|
// Function that prepares the FakeMounter for the test.
|
||||||
// Returns error if prepareMntr function encountered a fatal error.
|
prepareMntr func(mntr *FakeMounter)
|
||||||
prepareMntr func(mntr *FakeMounter) error
|
|
||||||
expectErr bool
|
expectErr bool
|
||||||
}{
|
}{
|
||||||
"mount-ok": {
|
"mount-ok": {
|
||||||
@ -96,9 +93,8 @@ func TestDoCleanupMountPoint(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return MountPoint{Device: "/dev/sdb", Path: path}, nil, nil
|
return MountPoint{Device: "/dev/sdb", Path: path}, nil, nil
|
||||||
},
|
},
|
||||||
prepareMntr: func(mntr *FakeMounter) error {
|
prepareMntr: func(mntr *FakeMounter) {
|
||||||
mntr.WithSkipMountPointCheck()
|
mntr.WithSkipMountPointCheck()
|
||||||
return nil
|
|
||||||
},
|
},
|
||||||
expectErr: false,
|
expectErr: false,
|
||||||
},
|
},
|
||||||
@ -106,12 +102,7 @@ func TestDoCleanupMountPoint(t *testing.T) {
|
|||||||
|
|
||||||
for name, tt := range tests {
|
for name, tt := range tests {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
|
tmpDir := t.TempDir()
|
||||||
tmpDir, err := ioutil.TempDir("", "unmount-mount-point-test")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to create tmpdir: %v", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpDir)
|
|
||||||
|
|
||||||
if tt.prepareMnt == nil {
|
if tt.prepareMnt == nil {
|
||||||
t.Fatalf("prepareMnt function required")
|
t.Fatalf("prepareMnt function required")
|
||||||
@ -152,15 +143,12 @@ func TestDoCleanupMountPoint(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateDirExists(dir string) error {
|
func validateDirExists(dir string) error {
|
||||||
_, err := ioutil.ReadDir(dir)
|
_, err := os.ReadDir(dir)
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateDirNotExists(dir string) error {
|
func validateDirNotExists(dir string) error {
|
||||||
_, err := ioutil.ReadDir(dir)
|
_, err := os.ReadDir(dir)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,17 @@ limitations under the License.
|
|||||||
package mount
|
package mount
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
utilio "k8s.io/utils/io"
|
utilio "k8s.io/utils/io"
|
||||||
)
|
)
|
||||||
@ -91,7 +94,7 @@ type MountInfo struct { // nolint: golint
|
|||||||
|
|
||||||
// ParseMountInfo parses /proc/xxx/mountinfo.
|
// ParseMountInfo parses /proc/xxx/mountinfo.
|
||||||
func ParseMountInfo(filename string) ([]MountInfo, error) {
|
func ParseMountInfo(filename string) ([]MountInfo, error) {
|
||||||
content, err := utilio.ConsistentRead(filename, maxListTries)
|
content, err := readMountInfo(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []MountInfo{}, err
|
return []MountInfo{}, err
|
||||||
}
|
}
|
||||||
@ -173,8 +176,7 @@ func splitMountOptions(s string) []string {
|
|||||||
// isMountPointMatch returns true if the path in mp is the same as dir.
|
// isMountPointMatch returns true if the path in mp is the same as dir.
|
||||||
// Handles case where mountpoint dir has been renamed due to stale NFS mount.
|
// Handles case where mountpoint dir has been renamed due to stale NFS mount.
|
||||||
func isMountPointMatch(mp MountPoint, dir string) bool {
|
func isMountPointMatch(mp MountPoint, dir string) bool {
|
||||||
deletedDir := fmt.Sprintf("%s\\040(deleted)", dir)
|
return strings.TrimSuffix(mp.Path, "\\040(deleted)") == dir
|
||||||
return ((mp.Path == dir) || (mp.Path == deletedDir))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathExists returns true if the specified path exists.
|
// PathExists returns true if the specified path exists.
|
||||||
@ -199,3 +201,50 @@ func PathExists(path string) (bool, error) {
|
|||||||
}
|
}
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These variables are used solely by kernelHasMountinfoBug.
|
||||||
|
var (
|
||||||
|
hasMountinfoBug bool
|
||||||
|
checkMountinfoBugOnce sync.Once
|
||||||
|
)
|
||||||
|
|
||||||
|
// kernelHasMountinfoBug checks if the kernel bug that can lead to incomplete
|
||||||
|
// mountinfo being read is fixed. It does so by checking the kernel version.
|
||||||
|
//
|
||||||
|
// The bug was fixed by the kernel commit 9f6c61f96f2d97 (since Linux 5.8).
|
||||||
|
// Alas, there is no better way to check if the bug is fixed other than to
|
||||||
|
// rely on the kernel version returned by uname.
|
||||||
|
func kernelHasMountinfoBug() bool {
|
||||||
|
checkMountinfoBugOnce.Do(func() {
|
||||||
|
// Assume old kernel.
|
||||||
|
hasMountinfoBug = true
|
||||||
|
|
||||||
|
uname := unix.Utsname{}
|
||||||
|
err := unix.Uname(&uname)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
end := bytes.IndexByte(uname.Release[:], 0)
|
||||||
|
v := bytes.SplitN(uname.Release[:end], []byte{'.'}, 3)
|
||||||
|
if len(v) != 3 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
major, _ := strconv.Atoi(string(v[0]))
|
||||||
|
minor, _ := strconv.Atoi(string(v[1]))
|
||||||
|
|
||||||
|
if major > 5 || (major == 5 && minor >= 8) {
|
||||||
|
hasMountinfoBug = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return hasMountinfoBug
|
||||||
|
}
|
||||||
|
|
||||||
|
func readMountInfo(path string) ([]byte, error) {
|
||||||
|
if kernelHasMountinfoBug() {
|
||||||
|
return utilio.ConsistentRead(path, maxListTries)
|
||||||
|
}
|
||||||
|
|
||||||
|
return os.ReadFile(path)
|
||||||
|
}
|
||||||
|
@ -20,30 +20,23 @@ limitations under the License.
|
|||||||
package mount
|
package mount
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeFile(content string) (string, string, error) {
|
func writeFile(t *testing.T, content string) string {
|
||||||
tempDir, err := ioutil.TempDir("", "mounter_shared_test")
|
filename := filepath.Join(t.TempDir(), "mountinfo")
|
||||||
|
err := os.WriteFile(filename, []byte(content), 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
filename := filepath.Join(tempDir, "mountinfo")
|
return filename
|
||||||
err = ioutil.WriteFile(filename, []byte(content), 0600)
|
|
||||||
if err != nil {
|
|
||||||
os.RemoveAll(tempDir)
|
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
return tempDir, filename, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMountInfo(t *testing.T) {
|
func TestParseMountInfo(t *testing.T) {
|
||||||
info :=
|
info := `62 0 253:0 / / rw,relatime shared:1 - ext4 /dev/mapper/ssd-root rw,seclabel,data=ordered
|
||||||
`62 0 253:0 / / rw,relatime shared:1 - ext4 /dev/mapper/ssd-root rw,seclabel,data=ordered
|
|
||||||
78 62 0:41 / /tmp rw,nosuid,nodev shared:30 - tmpfs tmpfs rw,seclabel
|
78 62 0:41 / /tmp rw,nosuid,nodev shared:30 - tmpfs tmpfs rw,seclabel
|
||||||
80 62 0:42 / /var/lib/nfs/rpc_pipefs rw,relatime shared:31 - rpc_pipefs sunrpc rw
|
80 62 0:42 / /var/lib/nfs/rpc_pipefs rw,relatime shared:31 - rpc_pipefs sunrpc rw
|
||||||
82 62 0:43 / /var/lib/foo rw,relatime shared:32 - tmpfs tmpfs rw
|
82 62 0:43 / /var/lib/foo rw,relatime shared:32 - tmpfs tmpfs rw
|
||||||
@ -85,11 +78,7 @@ func TestParseMountInfo(t *testing.T) {
|
|||||||
40 28 0:36 / /sys/fs/cgroup/perf_event rw,nosuid,nodev,noexec,relatime shared:22 - cgroup cgroup rw,perf_event
|
40 28 0:36 / /sys/fs/cgroup/perf_event rw,nosuid,nodev,noexec,relatime shared:22 - cgroup cgroup rw,perf_event
|
||||||
761 60 8:0 / /var/lib/kubelet/plugins/kubernetes.io/iscsi/iface-default/127.0.0.1:3260-iqn.2003-01.org.linux-iscsi.f21.x8664:sn.4b0aae584f7c-lun-0 rw,relatime shared:421 - ext4 /dev/sda rw,context="system_u:object_r:container_file_t:s0:c314,c894",data=ordered
|
761 60 8:0 / /var/lib/kubelet/plugins/kubernetes.io/iscsi/iface-default/127.0.0.1:3260-iqn.2003-01.org.linux-iscsi.f21.x8664:sn.4b0aae584f7c-lun-0 rw,relatime shared:421 - ext4 /dev/sda rw,context="system_u:object_r:container_file_t:s0:c314,c894",data=ordered
|
||||||
`
|
`
|
||||||
tempDir, filename, err := writeFile(info)
|
filename := writeFile(t, info)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("cannot create temporary file: %v", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tempDir)
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -304,11 +293,7 @@ func TestBadParseMountInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
tempDir, filename, err := writeFile(test.info)
|
filename := writeFile(t, test.info)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("cannot create temporary file: %v", err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tempDir)
|
|
||||||
|
|
||||||
infos, err := ParseMountInfo(filename)
|
infos, err := ParseMountInfo(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -333,3 +318,35 @@ func TestBadParseMountInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testIsMountPointMatch(t testing.TB) {
|
||||||
|
mpCases := []struct {
|
||||||
|
mp, dir string
|
||||||
|
res bool
|
||||||
|
}{
|
||||||
|
{"", "", true},
|
||||||
|
{"/", "/", true},
|
||||||
|
{"/some/path", "/some/path", true},
|
||||||
|
{"/a/different/kind/of/path\\040(deleted)", "/a/different/kind/of/path", true},
|
||||||
|
{"one", "two", false},
|
||||||
|
{"a somewhat long path that ends with A", "a somewhat long path that ends with B", false},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range mpCases {
|
||||||
|
mp := MountPoint{Path: tc.mp}
|
||||||
|
res := isMountPointMatch(mp, tc.dir)
|
||||||
|
if res != tc.res {
|
||||||
|
t.Errorf("mp: %q, dir: %q, expected %v, got %v", tc.mp, tc.dir, tc.res, res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIsMountPointMatch(t *testing.T) {
|
||||||
|
testIsMountPointMatch(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkIsMountPointMatch(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
testIsMountPointMatch(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -37,7 +36,6 @@ import (
|
|||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
utilexec "k8s.io/utils/exec"
|
utilexec "k8s.io/utils/exec"
|
||||||
utilio "k8s.io/utils/io"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -271,7 +269,7 @@ func detectSafeNotMountedBehavior() bool {
|
|||||||
// detectSafeNotMountedBehaviorWithExec is for testing with FakeExec.
|
// detectSafeNotMountedBehaviorWithExec is for testing with FakeExec.
|
||||||
func detectSafeNotMountedBehaviorWithExec(exec utilexec.Interface) bool {
|
func detectSafeNotMountedBehaviorWithExec(exec utilexec.Interface) bool {
|
||||||
// create a temp dir and try to umount it
|
// create a temp dir and try to umount it
|
||||||
path, err := ioutil.TempDir("", "kubelet-detect-safe-umount")
|
path, err := os.MkdirTemp("", "kubelet-detect-safe-umount")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.V(4).Infof("Cannot create temp dir to detect safe 'not mounted' behavior: %v", err)
|
klog.V(4).Infof("Cannot create temp dir to detect safe 'not mounted' behavior: %v", err)
|
||||||
return false
|
return false
|
||||||
@ -633,7 +631,7 @@ func (mounter *SafeFormatAndMount) GetDiskFormat(disk string) (string, error) {
|
|||||||
|
|
||||||
// ListProcMounts is shared with NsEnterMounter
|
// ListProcMounts is shared with NsEnterMounter
|
||||||
func ListProcMounts(mountFilePath string) ([]MountPoint, error) {
|
func ListProcMounts(mountFilePath string) ([]MountPoint, error) {
|
||||||
content, err := utilio.ConsistentRead(mountFilePath, maxListTries)
|
content, err := readMountInfo(mountFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -766,7 +764,7 @@ func (mounter *Mounter) IsMountPoint(file string) (bool, error) {
|
|||||||
// Resolve any symlinks in file, kernel would do the same and use the resolved path in /proc/mounts.
|
// Resolve any symlinks in file, kernel would do the same and use the resolved path in /proc/mounts.
|
||||||
resolvedFile, err := filepath.EvalSymlinks(file)
|
resolvedFile, err := filepath.EvalSymlinks(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(isMntErr, fs.ErrNotExist) {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
return false, fs.ErrNotExist
|
return false, fs.ErrNotExist
|
||||||
}
|
}
|
||||||
return false, err
|
return false, err
|
||||||
@ -810,7 +808,6 @@ func tryUnmount(target string, withSafeNotMountedBehavior bool, unmountTimeout t
|
|||||||
func forceUmount(target string, withSafeNotMountedBehavior bool) error {
|
func forceUmount(target string, withSafeNotMountedBehavior bool) error {
|
||||||
command := exec.Command("umount", "-f", target)
|
command := exec.Command("umount", "-f", target)
|
||||||
output, err := command.CombinedOutput()
|
output, err := command.CombinedOutput()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return checkUmountError(target, command, output, err, withSafeNotMountedBehavior)
|
return checkUmountError(target, command, output, err, withSafeNotMountedBehavior)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ package mount
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -31,13 +30,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
utilexec "k8s.io/utils/exec"
|
utilexec "k8s.io/utils/exec"
|
||||||
testexec "k8s.io/utils/exec/testing"
|
testexec "k8s.io/utils/exec/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReadProcMountsFrom(t *testing.T) {
|
func TestReadProcMountsFrom(t *testing.T) {
|
||||||
successCase :=
|
successCase := `/dev/0 /path/to/0 type0 flags 0 0
|
||||||
`/dev/0 /path/to/0 type0 flags 0 0
|
|
||||||
/dev/1 /path/to/1 type1 flags 1 1
|
/dev/1 /path/to/1 type1 flags 1 1
|
||||||
/dev/2 /path/to/2 type2 flags,1,2=3 2 2
|
/dev/2 /path/to/2 type2 flags,1,2=3 2 2
|
||||||
`
|
`
|
||||||
@ -148,10 +147,14 @@ func setEquivalent(set1, set2 []string) bool {
|
|||||||
func TestGetDeviceNameFromMount(t *testing.T) {
|
func TestGetDeviceNameFromMount(t *testing.T) {
|
||||||
fm := NewFakeMounter(
|
fm := NewFakeMounter(
|
||||||
[]MountPoint{
|
[]MountPoint{
|
||||||
{Device: "/dev/disk/by-path/prefix-lun-1",
|
{
|
||||||
Path: "/mnt/111"},
|
Device: "/dev/disk/by-path/prefix-lun-1",
|
||||||
{Device: "/dev/disk/by-path/prefix-lun-1",
|
Path: "/mnt/111",
|
||||||
Path: "/mnt/222"},
|
},
|
||||||
|
{
|
||||||
|
Device: "/dev/disk/by-path/prefix-lun-1",
|
||||||
|
Path: "/mnt/222",
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -203,7 +206,6 @@ func TestGetMountRefsByDev(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
|
|
||||||
if refs, err := getMountRefsByDev(fm, test.mountPath); err != nil || !setEquivalent(test.expectedRefs, refs) {
|
if refs, err := getMountRefsByDev(fm, test.mountPath); err != nil || !setEquivalent(test.expectedRefs, refs) {
|
||||||
t.Errorf("%d. getMountRefsByDev(%q) = %v, %v; expected %v, nil", i, test.mountPath, refs, err, test.expectedRefs)
|
t.Errorf("%d. getMountRefsByDev(%q) = %v, %v; expected %v, nil", i, test.mountPath, refs, err, test.expectedRefs)
|
||||||
}
|
}
|
||||||
@ -294,7 +296,6 @@ func TestPathWithinBase(t *testing.T) {
|
|||||||
if PathWithinBase(test.fullPath, test.basePath) != test.expected {
|
if PathWithinBase(test.fullPath, test.basePath) != test.expected {
|
||||||
t.Errorf("test %q failed: expected %v", test.name, test.expected)
|
t.Errorf("test %q failed: expected %v", test.name, test.expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,27 +423,31 @@ func TestSearchMountPoints(t *testing.T) {
|
|||||||
62 25 7:1 / /var/lib/kubelet/pods/f19fe4e2-5a63-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test rw,relatime shared:38 - ext4 /dev/loop1 rw,data=ordered
|
62 25 7:1 / /var/lib/kubelet/pods/f19fe4e2-5a63-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test rw,relatime shared:38 - ext4 /dev/loop1 rw,data=ordered
|
||||||
95 25 7:1 / /var/lib/kubelet/pods/4854a48b-5a64-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test rw,relatime shared:38 - ext4 /dev/loop1 rw,data=ordered
|
95 25 7:1 / /var/lib/kubelet/pods/4854a48b-5a64-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test rw,relatime shared:38 - ext4 /dev/loop1 rw,data=ordered
|
||||||
`,
|
`,
|
||||||
[]string{"/var/lib/kubelet/pods/f19fe4e2-5a63-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test",
|
[]string{
|
||||||
"/var/lib/kubelet/pods/4854a48b-5a64-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test"},
|
"/var/lib/kubelet/pods/f19fe4e2-5a63-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test",
|
||||||
|
"/var/lib/kubelet/pods/4854a48b-5a64-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test",
|
||||||
|
},
|
||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tmpFile, err := ioutil.TempFile("", "test-get-filetype")
|
tmpFile, err := os.CreateTemp("", "test-get-filetype")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer os.Remove(tmpFile.Name())
|
defer os.Remove(tmpFile.Name())
|
||||||
defer tmpFile.Close()
|
defer tmpFile.Close()
|
||||||
for _, v := range testcases {
|
for _, v := range testcases {
|
||||||
tmpFile.Truncate(0)
|
assert.NoError(t, tmpFile.Truncate(0))
|
||||||
tmpFile.Seek(0, 0)
|
_, err := tmpFile.Seek(0, 0)
|
||||||
tmpFile.WriteString(v.mountInfos)
|
assert.NoError(t, err)
|
||||||
tmpFile.Sync()
|
_, err = tmpFile.WriteString(v.mountInfos)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NoError(t, tmpFile.Sync())
|
||||||
refs, err := SearchMountPoints(v.source, tmpFile.Name())
|
refs, err := SearchMountPoints(v.source, tmpFile.Name())
|
||||||
if !reflect.DeepEqual(refs, v.expectedRefs) {
|
if !reflect.DeepEqual(refs, v.expectedRefs) {
|
||||||
t.Errorf("test %q: expected Refs: %#v, got %#v", v.name, v.expectedRefs, refs)
|
t.Errorf("test %q: expected Refs: %#v, got %#v", v.name, v.expectedRefs, refs)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(err, v.expectedErr) {
|
if err != v.expectedErr {
|
||||||
t.Errorf("test %q: expected err: %v, got %v", v.name, v.expectedErr, err)
|
t.Errorf("test %q: expected err: %v, got %v", v.name, v.expectedErr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,7 +464,6 @@ func TestSensitiveMountOptions(t *testing.T) {
|
|||||||
mountFlags []string
|
mountFlags []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
|
||||||
source: "mySrc",
|
source: "mySrc",
|
||||||
target: "myTarget",
|
target: "myTarget",
|
||||||
fstype: "myFS",
|
fstype: "myFS",
|
||||||
@ -468,7 +472,6 @@ func TestSensitiveMountOptions(t *testing.T) {
|
|||||||
mountFlags: []string{},
|
mountFlags: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
source: "mySrc",
|
source: "mySrc",
|
||||||
target: "myTarget",
|
target: "myTarget",
|
||||||
fstype: "myFS",
|
fstype: "myFS",
|
||||||
@ -477,7 +480,6 @@ func TestSensitiveMountOptions(t *testing.T) {
|
|||||||
mountFlags: []string{},
|
mountFlags: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
source: "mySrc",
|
source: "mySrc",
|
||||||
target: "myTarget",
|
target: "myTarget",
|
||||||
fstype: "myFS",
|
fstype: "myFS",
|
||||||
@ -486,7 +488,6 @@ func TestSensitiveMountOptions(t *testing.T) {
|
|||||||
mountFlags: []string{},
|
mountFlags: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
source: "mySrc",
|
source: "mySrc",
|
||||||
target: "myTarget",
|
target: "myTarget",
|
||||||
fstype: "myFS",
|
fstype: "myFS",
|
||||||
@ -705,7 +706,10 @@ func TestFormatConcurrency(t *testing.T) {
|
|||||||
// for one to be released
|
// for one to be released
|
||||||
for i := 0; i < tc.max+1; i++ {
|
for i := 0; i < tc.max+1; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
mounter.format(fstype, nil)
|
_, err := mounter.format(fstype, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("format(%q): %v", fstype, err)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -780,7 +784,10 @@ func TestFormatTimeout(t *testing.T) {
|
|||||||
|
|
||||||
for i := 0; i < maxConcurrency+1; i++ {
|
for i := 0; i < maxConcurrency+1; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
mounter.format(fstype, nil)
|
_, err := mounter.format(fstype, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("format(%q): %v", fstype, err)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ func TestMakeBindOpts(t *testing.T) {
|
|||||||
[]string{},
|
[]string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
[]string{"bind", "vers=2", "ro", "_netdev"},
|
[]string{"bind", "vers=2", "ro", "_netdev"},
|
||||||
true,
|
true,
|
||||||
[]string{"bind", "_netdev"},
|
[]string{"bind", "_netdev"},
|
||||||
@ -80,7 +79,6 @@ func TestMakeBindOptsSensitive(t *testing.T) {
|
|||||||
expectedSensitiveRemountOpts: []string{"user=foo", "pass=bar"},
|
expectedSensitiveRemountOpts: []string{"user=foo", "pass=bar"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
mountOptions: []string{"vers=2", "ro", "_netdev"},
|
mountOptions: []string{"vers=2", "ro", "_netdev"},
|
||||||
sensitiveMountOptions: []string{"user=foo", "pass=bar", "bind"},
|
sensitiveMountOptions: []string{"user=foo", "pass=bar", "bind"},
|
||||||
isBind: true,
|
isBind: true,
|
||||||
@ -105,7 +103,6 @@ func TestMakeBindOptsSensitive(t *testing.T) {
|
|||||||
expectedSensitiveRemountOpts: []string{"user=foo", "pass=bar"},
|
expectedSensitiveRemountOpts: []string{"user=foo", "pass=bar"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
mountOptions: []string{"vers=2", "bind", "ro", "_netdev"},
|
mountOptions: []string{"vers=2", "bind", "ro", "_netdev"},
|
||||||
sensitiveMountOptions: []string{"user=foo", "remount", "pass=bar"},
|
sensitiveMountOptions: []string{"user=foo", "remount", "pass=bar"},
|
||||||
isBind: true,
|
isBind: true,
|
||||||
@ -114,7 +111,6 @@ func TestMakeBindOptsSensitive(t *testing.T) {
|
|||||||
expectedSensitiveRemountOpts: []string{"user=foo", "pass=bar"},
|
expectedSensitiveRemountOpts: []string{"user=foo", "pass=bar"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
mountOptions: []string{"vers=2", "bind", "ro", "_netdev"},
|
mountOptions: []string{"vers=2", "bind", "ro", "_netdev"},
|
||||||
sensitiveMountOptions: []string{"user=foo", "remount", "pass=bar"},
|
sensitiveMountOptions: []string{"user=foo", "remount", "pass=bar"},
|
||||||
isBind: true,
|
isBind: true,
|
||||||
|
@ -82,11 +82,11 @@ func (mounter *Mounter) MountSensitive(source string, target string, fstype stri
|
|||||||
|
|
||||||
if source == "tmpfs" {
|
if source == "tmpfs" {
|
||||||
klog.V(3).Infof("mounting source (%q), target (%q), with options (%q)", source, target, sanitizedOptionsForLogging)
|
klog.V(3).Infof("mounting source (%q), target (%q), with options (%q)", source, target, sanitizedOptionsForLogging)
|
||||||
return os.MkdirAll(target, 0755)
|
return os.MkdirAll(target, 0o755)
|
||||||
}
|
}
|
||||||
|
|
||||||
parentDir := filepath.Dir(target)
|
parentDir := filepath.Dir(target)
|
||||||
if err := os.MkdirAll(parentDir, 0755); err != nil {
|
if err := os.MkdirAll(parentDir, 0o755); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ package mount
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -147,7 +146,7 @@ func TestIsLikelyNotMountPoint(t *testing.T) {
|
|||||||
"Dir",
|
"Dir",
|
||||||
"",
|
"",
|
||||||
func(base, fileName, targetLinkName string) error {
|
func(base, fileName, targetLinkName string) error {
|
||||||
return os.Mkdir(filepath.Join(base, fileName), 0750)
|
return os.Mkdir(filepath.Join(base, fileName), 0o750)
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
@ -166,7 +165,7 @@ func TestIsLikelyNotMountPoint(t *testing.T) {
|
|||||||
"targetSymLink",
|
"targetSymLink",
|
||||||
func(base, fileName, targetLinkName string) error {
|
func(base, fileName, targetLinkName string) error {
|
||||||
targeLinkPath := filepath.Join(base, targetLinkName)
|
targeLinkPath := filepath.Join(base, targetLinkName)
|
||||||
if err := os.Mkdir(targeLinkPath, 0750); err != nil {
|
if err := os.Mkdir(targeLinkPath, 0o750); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +183,7 @@ func TestIsLikelyNotMountPoint(t *testing.T) {
|
|||||||
"targetSymLink2",
|
"targetSymLink2",
|
||||||
func(base, fileName, targetLinkName string) error {
|
func(base, fileName, targetLinkName string) error {
|
||||||
targeLinkPath := filepath.Join(base, targetLinkName)
|
targeLinkPath := filepath.Join(base, targetLinkName)
|
||||||
if err := os.Mkdir(targeLinkPath, 0750); err != nil {
|
if err := os.Mkdir(targeLinkPath, 0o750); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,12 +199,7 @@ func TestIsLikelyNotMountPoint(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
base, err := ioutil.TempDir("", test.fileName)
|
base := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(base)
|
|
||||||
|
|
||||||
if err := test.setUp(base, test.fileName, test.targetLinkName); err != nil {
|
if err := test.setUp(base, test.fileName, test.targetLinkName); err != nil {
|
||||||
t.Fatalf("unexpected error in setUp(%s, %s): %v", test.fileName, test.targetLinkName, err)
|
t.Fatalf("unexpected error in setUp(%s, %s): %v", test.fileName, test.targetLinkName, err)
|
||||||
@ -280,13 +274,7 @@ func TestFormatAndMount(t *testing.T) {
|
|||||||
Interface: &fakeMounter,
|
Interface: &fakeMounter,
|
||||||
Exec: fakeExec,
|
Exec: fakeExec,
|
||||||
}
|
}
|
||||||
base, err := ioutil.TempDir("", test.device)
|
target := filepath.Join(t.TempDir(), test.target)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf(err.Error())
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(base)
|
|
||||||
|
|
||||||
target := filepath.Join(base, test.target)
|
|
||||||
err = mounter.FormatAndMount(test.device, target, test.fstype, test.mountOptions)
|
err = mounter.FormatAndMount(test.device, target, test.fstype, test.mountOptions)
|
||||||
if test.expectError {
|
if test.expectError {
|
||||||
assert.NotNil(t, err, "Expect error during FormatAndMount(%s, %s, %s, %v)", test.device, test.target, test.fstype, test.mountOptions)
|
assert.NotNil(t, err, "Expect error during FormatAndMount(%s, %s, %s, %v)", test.device, test.target, test.fstype, test.mountOptions)
|
||||||
|
@ -45,7 +45,6 @@ func NewResizeFs(exec utilexec.Interface) *ResizeFs {
|
|||||||
// Resize perform resize of file system
|
// Resize perform resize of file system
|
||||||
func (resizefs *ResizeFs) Resize(devicePath string, deviceMountPath string) (bool, error) {
|
func (resizefs *ResizeFs) Resize(devicePath string, deviceMountPath string) (bool, error) {
|
||||||
format, err := getDiskFormat(resizefs.exec, devicePath)
|
format, err := getDiskFormat(resizefs.exec, devicePath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
formatErr := fmt.Errorf("ResizeFS.Resize - error checking format for device %s: %v", devicePath, err)
|
formatErr := fmt.Errorf("ResizeFS.Resize - error checking format for device %s: %v", devicePath, err)
|
||||||
return false, formatErr
|
return false, formatErr
|
||||||
@ -78,7 +77,6 @@ func (resizefs *ResizeFs) extResize(devicePath string) (bool, error) {
|
|||||||
|
|
||||||
resizeError := fmt.Errorf("resize of device %s failed: %v. resize2fs output: %s", devicePath, err, string(output))
|
resizeError := fmt.Errorf("resize of device %s failed: %v. resize2fs output: %s", devicePath, err, string(output))
|
||||||
return false, resizeError
|
return false, resizeError
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (resizefs *ResizeFs) xfsResize(deviceMountPath string) (bool, error) {
|
func (resizefs *ResizeFs) xfsResize(deviceMountPath string) (bool, error) {
|
||||||
@ -161,6 +159,7 @@ func (resizefs *ResizeFs) NeedResize(devicePath string, deviceMountPath string)
|
|||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (resizefs *ResizeFs) getDeviceSize(devicePath string) (uint64, error) {
|
func (resizefs *ResizeFs) getDeviceSize(devicePath string) (uint64, error) {
|
||||||
output, err := resizefs.exec.Command(blockDev, "--getsize64", devicePath).CombinedOutput()
|
output, err := resizefs.exec.Command(blockDev, "--getsize64", devicePath).CombinedOutput()
|
||||||
outStr := strings.TrimSpace(string(output))
|
outStr := strings.TrimSpace(string(output))
|
||||||
|
@ -28,8 +28,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestGetFileSystemSize(t *testing.T) {
|
func TestGetFileSystemSize(t *testing.T) {
|
||||||
cmdOutputSuccessXfs :=
|
cmdOutputSuccessXfs := `
|
||||||
`
|
|
||||||
statfs.f_bsize = 4096
|
statfs.f_bsize = 4096
|
||||||
statfs.f_blocks = 1832448
|
statfs.f_blocks = 1832448
|
||||||
statfs.f_bavail = 1822366
|
statfs.f_bavail = 1822366
|
||||||
@ -50,8 +49,7 @@ func TestGetFileSystemSize(t *testing.T) {
|
|||||||
counts.freeino = 61
|
counts.freeino = 61
|
||||||
counts.allocino = 64
|
counts.allocino = 64
|
||||||
`
|
`
|
||||||
cmdOutputNoDataXfs :=
|
cmdOutputNoDataXfs := `
|
||||||
`
|
|
||||||
statfs.f_bsize = 4096
|
statfs.f_bsize = 4096
|
||||||
statfs.f_blocks = 1832448
|
statfs.f_blocks = 1832448
|
||||||
statfs.f_bavail = 1822366
|
statfs.f_bavail = 1822366
|
||||||
@ -70,8 +68,7 @@ func TestGetFileSystemSize(t *testing.T) {
|
|||||||
counts.freeino = 61
|
counts.freeino = 61
|
||||||
counts.allocino = 64
|
counts.allocino = 64
|
||||||
`
|
`
|
||||||
cmdOutputSuccessExt4 :=
|
cmdOutputSuccessExt4 := `
|
||||||
`
|
|
||||||
Filesystem volume name: cloudimg-rootfs
|
Filesystem volume name: cloudimg-rootfs
|
||||||
Last mounted on: /
|
Last mounted on: /
|
||||||
Filesystem UUID: testUUID
|
Filesystem UUID: testUUID
|
||||||
@ -121,8 +118,7 @@ Journal start: 1
|
|||||||
Journal checksum type: crc32c
|
Journal checksum type: crc32c
|
||||||
Journal checksum: 0xb7df3c6e
|
Journal checksum: 0xb7df3c6e
|
||||||
`
|
`
|
||||||
cmdOutputNoDataExt4 :=
|
cmdOutputNoDataExt4 := `Filesystem volume name: cloudimg-rootfs
|
||||||
`Filesystem volume name: cloudimg-rootfs
|
|
||||||
Last mounted on: /
|
Last mounted on: /
|
||||||
Filesystem UUID: testUUID
|
Filesystem UUID: testUUID
|
||||||
Filesystem magic number: 0xEF53
|
Filesystem magic number: 0xEF53
|
||||||
@ -169,8 +165,7 @@ Journal start: 1
|
|||||||
Journal checksum type: crc32c
|
Journal checksum type: crc32c
|
||||||
Journal checksum: 0xb7df3c6e
|
Journal checksum: 0xb7df3c6e
|
||||||
`
|
`
|
||||||
cmdOutputSuccessBtrfs :=
|
cmdOutputSuccessBtrfs := `superblock: bytenr=65536, device=/dev/loop0
|
||||||
`superblock: bytenr=65536, device=/dev/loop0
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
csum_type 0 (crc32c)
|
csum_type 0 (crc32c)
|
||||||
csum_size 4
|
csum_size 4
|
||||||
@ -279,8 +274,7 @@ backup_roots[4]:
|
|||||||
backup_num_devices: 1
|
backup_num_devices: 1
|
||||||
|
|
||||||
`
|
`
|
||||||
cmdOutputNoDataBtrfs :=
|
cmdOutputNoDataBtrfs := `superblock: bytenr=65536, device=/dev/loop0
|
||||||
`superblock: bytenr=65536, device=/dev/loop0
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
csum_type 0 (crc32c)
|
csum_type 0 (crc32c)
|
||||||
csum_size 4
|
csum_size 4
|
||||||
|
@ -18,8 +18,6 @@ package mount
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -58,11 +56,6 @@ 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
|
||||||
@ -241,7 +234,7 @@ func TestSafeFormatAndMount(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
device := "/dev/foo"
|
device := "/dev/foo"
|
||||||
dest := mntDir
|
dest := t.TempDir()
|
||||||
var err error
|
var err error
|
||||||
if len(test.formatOptions) > 0 {
|
if len(test.formatOptions) > 0 {
|
||||||
err = mounter.FormatAndMountSensitiveWithFormatOptions(device, dest, test.fstype, test.mountOptions, test.sensitiveMountOptions, test.formatOptions)
|
err = mounter.FormatAndMountSensitiveWithFormatOptions(device, dest, test.fstype, test.mountOptions, test.sensitiveMountOptions, test.formatOptions)
|
||||||
@ -261,7 +254,7 @@ func TestSafeFormatAndMount(t *testing.T) {
|
|||||||
t.Errorf("test \"%s\" the directory was not mounted", test.description)
|
t.Errorf("test \"%s\" the directory was not mounted", test.description)
|
||||||
}
|
}
|
||||||
|
|
||||||
//check that the correct device was mounted
|
// check that the correct device was mounted
|
||||||
mountedDevice, _, err := GetDeviceNameFromMount(fakeMounter.FakeMounter, dest)
|
mountedDevice, _, err := GetDeviceNameFromMount(fakeMounter.FakeMounter, dest)
|
||||||
if err != nil || mountedDevice != device {
|
if err != nil || mountedDevice != device {
|
||||||
t.Errorf("test \"%s\" the correct device was not mounted", test.description)
|
t.Errorf("test \"%s\" the correct device was not mounted", test.description)
|
||||||
|
Loading…
Reference in New Issue
Block a user