Skip to content

Commit

Permalink
Merge pull request #3285 from ngoozeff/bug3044
Browse files Browse the repository at this point in the history
Fix for issue #3044 - mounted timestamps incorrect with windows host
  • Loading branch information
tstromberg authored Jan 24, 2019
2 parents 308ce5a + d516caa commit 20c7325
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 4 deletions.
2 changes: 2 additions & 0 deletions test/integration/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ 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 {
return util.MinikubeRunner{
Args: *args,
BinaryPath: *binaryPath,
StartArgs: *startArgs,
MountArgs: *mountArgs,
T: t,
}
}
29 changes: 27 additions & 2 deletions test/integration/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ func testMounting(t *testing.T) {
}
defer os.RemoveAll(tempDir)

mountCmd := fmt.Sprintf("mount %s:/mount-9p", 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)
}
cmd, _, _ := minikubeRunner.RunDaemon2(mountCmd)
defer func() {
err := cmd.Process.Kill()
if err != nil {
Expand Down Expand Up @@ -119,6 +124,26 @@ 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("Unable to stat %s via SSH. error %v, %s", file, err, 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") {
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 {
Expand Down
21 changes: 21 additions & 0 deletions test/integration/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type MinikubeRunner struct {
BinaryPath string
Args string
StartArgs string
MountArgs string
Runtime string
}

Expand Down Expand Up @@ -164,6 +165,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)
}

// SetRuntime saves the runtime backend
func (m *MinikubeRunner) SetRuntime(runtime string) {
m.Runtime = runtime
Expand Down
4 changes: 2 additions & 2 deletions third_party/go9p/ufs_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]

Expand Down
53 changes: 53 additions & 0 deletions third_party/go9p/ufs_windows_test.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 20c7325

Please sign in to comment.