From 14244b3645436c68faa195167031e9ef44c34643 Mon Sep 17 00:00:00 2001 From: Nicholas Goozeff Date: Wed, 31 Oct 2018 05:42:27 +0100 Subject: [PATCH 1/5] Test cases for issue #3044 - timestamps of mounted files incorrect with windows host. --- test/integration/flags.go | 2 ++ test/integration/mount_test.go | 20 ++++++++++- test/integration/util/util.go | 1 + third_party/go9p/ufs_windows_test.go | 53 ++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 third_party/go9p/ufs_windows_test.go diff --git a/test/integration/flags.go b/test/integration/flags.go index 89db1fda0b36..06d0911871d4 100644 --- a/test/integration/flags.go +++ b/test/integration/flags.go @@ -32,6 +32,7 @@ func TestMain(m *testing.M) { var binaryPath = flag.String("binary", "../../out/minikube", "path to minikube binary") var args = flag.String("minikube-args", "", "Arguments to pass to minikube") var startArgs = flag.String("minikube-start-args", "", "Arguments to pass to minikube start") +var mountArgs = flag.String("minikube-mount-args", "", "Arguments to pass to minikube mount") var testdataDir = flag.String("testdata-dir", "testdata", "the directory relative to test/integration where the testdata lives") func NewMinikubeRunner(t *testing.T) util.MinikubeRunner { @@ -39,6 +40,7 @@ func NewMinikubeRunner(t *testing.T) util.MinikubeRunner { Args: *args, BinaryPath: *binaryPath, StartArgs: *startArgs, + MountArgs: *mountArgs, T: t, } } diff --git a/test/integration/mount_test.go b/test/integration/mount_test.go index 596347d9d2ef..3081f9d3cc5c 100644 --- a/test/integration/mount_test.go +++ b/test/integration/mount_test.go @@ -49,7 +49,7 @@ func testMounting(t *testing.T) { } defer os.RemoveAll(tempDir) - mountCmd := fmt.Sprintf("mount %s:/mount-9p", tempDir) + mountCmd := fmt.Sprintf("mount %s %s:/mount-9p", minikubeRunner.MountArgs, tempDir) cmd, _ := minikubeRunner.RunDaemon(mountCmd) defer func() { err := cmd.Process.Kill() @@ -118,6 +118,24 @@ func testMounting(t *testing.T) { t.Fatalf("Expected file %s to contain text %s, was %s.", path, expected, out) } + // test file timestamps are correct + files := []string{"fromhost", "frompod"} + for _, file := range files { + statCmd := fmt.Sprintf("stat /mount-9p/%s", file) + statOutput, err := minikubeRunner.SSH(statCmd) + if err != nil { + t.Fatalf("%v", err) + } + + if strings.Contains(statOutput, "Access: 1970-01-01") { + t.Fatalf("Invalid access time\n%s", statOutput) + } + + if strings.Contains(statOutput, "Modify: 1970-01-01") { + t.Fatalf("Invalid modify time\n%s", statOutput) + } + } + // test that fromhostremove was deleted by the pod from the mount via rm /mount-9p/fromhostremove path = filepath.Join(tempDir, "fromhostremove") if _, err := os.Stat(path); err == nil { diff --git a/test/integration/util/util.go b/test/integration/util/util.go index 9b35f464e4bd..577601aa15ea 100644 --- a/test/integration/util/util.go +++ b/test/integration/util/util.go @@ -43,6 +43,7 @@ type MinikubeRunner struct { BinaryPath string Args string StartArgs string + MountArgs string } func (m *MinikubeRunner) Run(cmd string) error { diff --git a/third_party/go9p/ufs_windows_test.go b/third_party/go9p/ufs_windows_test.go new file mode 100644 index 000000000000..bb7fb260dbd7 --- /dev/null +++ b/third_party/go9p/ufs_windows_test.go @@ -0,0 +1,53 @@ +package go9p + +import ( + "fmt" + "os" + "testing" +) + +func assert_NotNil(t *testing.T, i interface {}) { + if (i == nil) { + t.Error("Value should not be nil") + } +} + +func assert_NotEqual(t *testing.T, lhs uint32, rhs uint32, message string) { + if (lhs == rhs) { + t.Errorf("Value %d should not be %d. %s", lhs, rhs, message) + } +} + +func TestDir2DirTimestamp(t *testing.T) { + fi, err := os.Stat(".") + if err != nil { + t.Error(err) + } + var st *Dir + st, _ = dir2Dir(".", fi, false, nil) + assert_NotNil(t, st) + + if testing.Verbose() { + fmt.Printf("%s %d %d\n", st.Name, st.Mtime, st.Atime) + } + + assert_NotEqual(t, st.Mtime, uint32(0), "Mtime should be set") + assert_NotEqual(t, st.Atime, uint32(0), "Atime should be set") +} + +func TestDir2DirTimestampDotu(t *testing.T) { + fi, err := os.Stat(".") + if err != nil { + t.Error(err) + } + var st *Dir + st, _ = dir2Dir(".", fi, true, nil) + assert_NotNil(t, st) + + if testing.Verbose() { + fmt.Printf("%s %d %d\n", st.Name, st.Mtime, st.Atime) + } + + assert_NotEqual(t, st.Mtime, uint32(0), "Mtime should be set") + assert_NotEqual(t, st.Atime, uint32(0), "Atime should be set") +} From 3ea3bb1c92b753f553b806d67069b10f9617289f Mon Sep 17 00:00:00 2001 From: Nicholas Goozeff Date: Wed, 31 Oct 2018 05:44:19 +0100 Subject: [PATCH 2/5] Issue #3044 - set timestamps of mounted files with windows host. --- third_party/go9p/ufs_windows.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/go9p/ufs_windows.go b/third_party/go9p/ufs_windows.go index a2ee9a1e025d..5bb501fd59f4 100644 --- a/third_party/go9p/ufs_windows.go +++ b/third_party/go9p/ufs_windows.go @@ -55,8 +55,8 @@ func dir2Dir(path string, d os.FileInfo, dotu bool, upool Users) (*Dir, error) { dir := new(ufsDir) dir.Qid = *dir2Qid(d) dir.Mode = dir2Npmode(d, dotu) - // dir.Atime = uint32(0 /*atime(sysMode).Unix()*/) - // dir.Mtime = uint32(d.ModTime().Unix()) + dir.Atime = uint32(atime(d).Unix()) + dir.Mtime = uint32(d.ModTime().Unix()) dir.Length = uint64(d.Size()) dir.Name = path[strings.LastIndex(path, "/")+1:] From e5da4db3a67efee25354b4a9a2a73d1e8efa8ec8 Mon Sep 17 00:00:00 2001 From: Nicholas Goozeff Date: Wed, 31 Oct 2018 11:18:03 +0100 Subject: [PATCH 3/5] go fmt --- third_party/go9p/ufs_windows_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/third_party/go9p/ufs_windows_test.go b/third_party/go9p/ufs_windows_test.go index bb7fb260dbd7..7acfc90798b8 100644 --- a/third_party/go9p/ufs_windows_test.go +++ b/third_party/go9p/ufs_windows_test.go @@ -6,16 +6,16 @@ import ( "testing" ) -func assert_NotNil(t *testing.T, i interface {}) { - if (i == nil) { - t.Error("Value should not be nil") - } +func assert_NotNil(t *testing.T, i interface{}) { + if i == nil { + t.Error("Value should not be nil") + } } func assert_NotEqual(t *testing.T, lhs uint32, rhs uint32, message string) { - if (lhs == rhs) { - t.Errorf("Value %d should not be %d. %s", lhs, rhs, message) - } + if lhs == rhs { + t.Errorf("Value %d should not be %d. %s", lhs, rhs, message) + } } func TestDir2DirTimestamp(t *testing.T) { From ff93c6e0674337af9d95d3d8e89eafefc6324db7 Mon Sep 17 00:00:00 2001 From: Nicholas Goozeff Date: Sat, 10 Nov 2018 18:32:41 +1100 Subject: [PATCH 4/5] Fix bug in construction of mount command for testing. Only check access time is set for windows OS. --- test/integration/mount_test.go | 24 ++++++++++++++++++++---- test/integration/util/util.go | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/test/integration/mount_test.go b/test/integration/mount_test.go index 3081f9d3cc5c..7ef9907ad7e1 100644 --- a/test/integration/mount_test.go +++ b/test/integration/mount_test.go @@ -20,6 +20,7 @@ package integration import ( "fmt" + "io" "io/ioutil" "os" "path/filepath" @@ -49,8 +50,16 @@ func testMounting(t *testing.T) { } defer os.RemoveAll(tempDir) - mountCmd := fmt.Sprintf("mount %s %s:/mount-9p", minikubeRunner.MountArgs, tempDir) - cmd, _ := minikubeRunner.RunDaemon(mountCmd) + var mountCmd string + if len(minikubeRunner.MountArgs) > 0 { + mountCmd = fmt.Sprintf("mount %s %s:/mount-9p", minikubeRunner.MountArgs, tempDir) + } else { + mountCmd = fmt.Sprintf("mount %s:/mount-9p", tempDir) + } + if testing.Verbose() { + fmt.Fprintf(os.Stderr, "runing mount cmd: %s\n", mountCmd) + } + cmd, out, serr := minikubeRunner.RunDaemon2(mountCmd) defer func() { err := cmd.Process.Kill() if err != nil { @@ -58,6 +67,11 @@ func testMounting(t *testing.T) { } }() + if testing.Verbose() { + go io.Copy(os.Stderr, out) + go io.Copy(os.Stderr, serr) + } + kubectlRunner := util.NewKubectlRunner(t) podName := "busybox-mount" podPath, _ := filepath.Abs("testdata/busybox-mount-test.yaml") @@ -127,8 +141,10 @@ func testMounting(t *testing.T) { t.Fatalf("%v", err) } - if strings.Contains(statOutput, "Access: 1970-01-01") { - t.Fatalf("Invalid access time\n%s", statOutput) + if runtime.GOOS == "windows" { + if strings.Contains(statOutput, "Access: 1970-01-01") { + t.Fatalf("Invalid access time\n%s", statOutput) + } } if strings.Contains(statOutput, "Modify: 1970-01-01") { diff --git a/test/integration/util/util.go b/test/integration/util/util.go index 577601aa15ea..922cfc97e90c 100644 --- a/test/integration/util/util.go +++ b/test/integration/util/util.go @@ -99,6 +99,26 @@ func (m *MinikubeRunner) RunDaemon(command string) (*exec.Cmd, *bufio.Reader) { } +func (m *MinikubeRunner) RunDaemon2(command string) (*exec.Cmd, *bufio.Reader, *bufio.Reader) { + commandArr := strings.Split(command, " ") + path, _ := filepath.Abs(m.BinaryPath) + cmd := exec.Command(path, commandArr...) + stdoutPipe, err := cmd.StdoutPipe() + if err != nil { + m.T.Fatalf("stdout pipe failed: %s %v", command, err) + } + stderrPipe, err := cmd.StderrPipe() + if err != nil { + m.T.Fatalf("stderr pipe failed: %s %v", command, err) + } + + err = cmd.Start() + if err != nil { + m.T.Fatalf("Error running command: %s %v", command, err) + } + return cmd, bufio.NewReader(stdoutPipe), bufio.NewReader(stderrPipe) +} + func (m *MinikubeRunner) SSH(command string) (string, error) { path, _ := filepath.Abs(m.BinaryPath) cmd := exec.Command(path, "ssh", command) From 919c9d9d36dd8addfcdbd8db36cf0067dc419228 Mon Sep 17 00:00:00 2001 From: Nicholas Goozeff Date: Wed, 28 Nov 2018 15:45:25 +1100 Subject: [PATCH 5/5] Remove extra debug logging for mount command. --- test/integration/mount_test.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/test/integration/mount_test.go b/test/integration/mount_test.go index 7ef9907ad7e1..9cb61d841fe3 100644 --- a/test/integration/mount_test.go +++ b/test/integration/mount_test.go @@ -20,7 +20,6 @@ package integration import ( "fmt" - "io" "io/ioutil" "os" "path/filepath" @@ -56,10 +55,7 @@ func testMounting(t *testing.T) { } else { mountCmd = fmt.Sprintf("mount %s:/mount-9p", tempDir) } - if testing.Verbose() { - fmt.Fprintf(os.Stderr, "runing mount cmd: %s\n", mountCmd) - } - cmd, out, serr := minikubeRunner.RunDaemon2(mountCmd) + cmd, _, _ := minikubeRunner.RunDaemon2(mountCmd) defer func() { err := cmd.Process.Kill() if err != nil { @@ -67,11 +63,6 @@ func testMounting(t *testing.T) { } }() - if testing.Verbose() { - go io.Copy(os.Stderr, out) - go io.Copy(os.Stderr, serr) - } - kubectlRunner := util.NewKubectlRunner(t) podName := "busybox-mount" podPath, _ := filepath.Abs("testdata/busybox-mount-test.yaml") @@ -138,7 +129,7 @@ func testMounting(t *testing.T) { statCmd := fmt.Sprintf("stat /mount-9p/%s", file) statOutput, err := minikubeRunner.SSH(statCmd) if err != nil { - t.Fatalf("%v", err) + t.Fatalf("Unable to stat %s via SSH. error %v, %s", file, err, statOutput) } if runtime.GOOS == "windows" {