From 403cc82fb3e1a528d7db143f5a5d9975b3bcfc9e Mon Sep 17 00:00:00 2001 From: John Starks Date: Mon, 28 Mar 2016 17:26:34 -0700 Subject: [PATCH 1/2] Windows: fix tests depending on entrypoint split behavior Existing tests assume that the entrypoint in a docker run command will be split into multiple arguments, which is inconsistent with Linux. Fix the tests depending on this behavior. Signed-off-by: John Starks Upstream-commit: 86ab343c3e98ded1ee1b12f04396ae011a0e6de6 Component: engine --- .../integration-cli/docker_cli_run_test.go | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/components/engine/integration-cli/docker_cli_run_test.go b/components/engine/integration-cli/docker_cli_run_test.go index c19603d964..620d029935 100644 --- a/components/engine/integration-cli/docker_cli_run_test.go +++ b/components/engine/integration-cli/docker_cli_run_test.go @@ -331,7 +331,7 @@ func (s *DockerSuite) TestRunWithVolumesFromExited(c *check.C) { // Create a file in a volume if daemonPlatform == "windows" { - out, exitCode = dockerCmd(c, "run", "--name", "test-data", "--volume", `c:\some\dir`, WindowsBaseImage, `cmd /c echo hello > c:\some\dir\file`) + out, exitCode = dockerCmd(c, "run", "--name", "test-data", "--volume", `c:\some\dir`, WindowsBaseImage, "cmd", "/c", `echo hello > c:\some\dir\file`) } else { out, exitCode = dockerCmd(c, "run", "--name", "test-data", "--volume", "/some/dir", "busybox", "touch", "/some/dir/file") } @@ -341,7 +341,7 @@ func (s *DockerSuite) TestRunWithVolumesFromExited(c *check.C) { // Read the file from another container using --volumes-from to access the volume in the second container if daemonPlatform == "windows" { - out, exitCode = dockerCmd(c, "run", "--volumes-from", "test-data", WindowsBaseImage, `cmd /c type c:\some\dir\file`) + out, exitCode = dockerCmd(c, "run", "--volumes-from", "test-data", WindowsBaseImage, "cmd", "/c", `type c:\some\dir\file`) } else { out, exitCode = dockerCmd(c, "run", "--volumes-from", "test-data", "busybox", "cat", "/some/dir/file") } @@ -1901,15 +1901,8 @@ func (s *DockerSuite) TestRunWithBadDevice(c *check.C) { func (s *DockerSuite) TestRunEntrypoint(c *check.C) { name := "entrypoint" - // Note Windows does not have an echo.exe built in. - var out, expected string - if daemonPlatform == "windows" { - out, _ = dockerCmd(c, "run", "--name", name, "--entrypoint", "cmd /s /c echo", "busybox", "foobar") - expected = "foobar\r\n" - } else { - out, _ = dockerCmd(c, "run", "--name", name, "--entrypoint", "/bin/echo", "busybox", "-n", "foobar") - expected = "foobar" - } + out, _ := dockerCmd(c, "run", "--name", name, "--entrypoint", "echo", "busybox", "-n", "foobar") + expected := "foobar" if out != expected { c.Fatalf("Output should be %q, actual out: %q", expected, out) @@ -2623,18 +2616,17 @@ func (s *DockerSuite) TestRunTTYWithPipe(c *check.C) { func (s *DockerSuite) TestRunNonLocalMacAddress(c *check.C) { addr := "00:16:3E:08:00:50" - cmd := "ifconfig" - image := "busybox" + args := []string{"run", "--mac-address", addr} expected := addr - if daemonPlatform == "windows" { - cmd = "ipconfig /all" - image = WindowsBaseImage + if daemonPlatform != "windows" { + args = append(args, "busybox", "ifconfig") + } else { + args = append(args, WindowsBaseImage, "ipconfig", "/all") expected = strings.Replace(strings.ToUpper(addr), ":", "-", -1) - } - if out, _ := dockerCmd(c, "run", "--mac-address", addr, image, cmd); !strings.Contains(out, expected) { + if out, _ := dockerCmd(c, args...); !strings.Contains(out, expected) { c.Fatalf("Output should have contained %q: %s", expected, out) } } From 6a83b0bb5c3e858ba205565e80b19abc44cd99b1 Mon Sep 17 00:00:00 2001 From: John Starks Date: Mon, 28 Mar 2016 17:35:56 -0700 Subject: [PATCH 2/2] Windows: escape entrypoint before passing to libcontainerd This makes Windows behavior consistent with Linux -- the entry point must be an executable, not an executable and set of arguments. Signed-off-by: John Starks Upstream-commit: 6fa0239772e672eefb98cef91ca8d806b86182b0 Component: engine --- components/engine/daemon/exec_windows.go | 3 +-- components/engine/daemon/oci_windows.go | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/components/engine/daemon/exec_windows.go b/components/engine/daemon/exec_windows.go index be25d20007..a6ac1db42d 100644 --- a/components/engine/daemon/exec_windows.go +++ b/components/engine/daemon/exec_windows.go @@ -8,7 +8,6 @@ import ( func execSetPlatformOpt(c *container.Container, ec *exec.Config, p *libcontainerd.Process) error { // Process arguments need to be escaped before sending to OCI. - // TODO (jstarks): escape the entrypoint too once the tests are fixed to not rely on this behavior - p.Args = append([]string{p.Args[0]}, escapeArgs(p.Args[1:])...) + p.Args = escapeArgs(p.Args) return nil } diff --git a/components/engine/daemon/oci_windows.go b/components/engine/daemon/oci_windows.go index 5bf3f82418..06eb7f5b4d 100644 --- a/components/engine/daemon/oci_windows.go +++ b/components/engine/daemon/oci_windows.go @@ -63,11 +63,9 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e } // In s.Process - if c.Config.ArgsEscaped { - s.Process.Args = append([]string{c.Path}, c.Args...) - } else { - // TODO (jstarks): escape the entrypoint too once the tests are fixed to not rely on this behavior - s.Process.Args = append([]string{c.Path}, escapeArgs(c.Args)...) + s.Process.Args = append([]string{c.Path}, c.Args...) + if !c.Config.ArgsEscaped { + s.Process.Args = escapeArgs(s.Process.Args) } s.Process.Cwd = c.Config.WorkingDir s.Process.Env = c.CreateDaemonEnvironment(linkedEnv)