-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: John Howard <[email protected]>
- Loading branch information
John Howard
committed
Aug 14, 2015
1 parent
650feb2
commit f6ed590
Showing
15 changed files
with
300 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package main | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/docker/docker/runconfig" | ||
"github.com/go-check/check" | ||
) | ||
|
||
// GH14530. Validates combinations of --net= with other options | ||
|
||
// stringCheckPS is how the output of PS starts in order to validate that | ||
// the command executed in a container did really run PS correctly. | ||
const stringCheckPS = "PID USER" | ||
|
||
// checkContains is a helper function that validates a command output did | ||
// contain what was expected. | ||
func checkContains(expected string, out string, c *check.C) { | ||
if !strings.Contains(out, expected) { | ||
c.Fatalf("Expected '%s', got '%s'", expected, out) | ||
} | ||
} | ||
|
||
func (s *DockerSuite) TestNetHostname(c *check.C) { | ||
|
||
var ( | ||
out string | ||
err error | ||
runCmd *exec.Cmd | ||
) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "-h=name", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err != nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(stringCheckPS, out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err != nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(stringCheckPS, out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "-h=name", "--net=bridge", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err != nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(stringCheckPS, out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "-h=name", "--net=none", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err != nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(stringCheckPS, out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "-h=name", "--net=host", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(runconfig.ErrConflictNetworkHostname.Error(), out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "-h=name", "--net=container:other", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err, c) | ||
} | ||
checkContains(runconfig.ErrConflictNetworkHostname.Error(), out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=container", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err, c) | ||
} | ||
checkContains("--net: invalid net mode: invalid container format container:<name|id>", out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=weird", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains("invalid --net: weird", out, c) | ||
} | ||
|
||
func (s *DockerSuite) TestConflictContainerNetworkAndLinks(c *check.C) { | ||
var ( | ||
out string | ||
err error | ||
runCmd *exec.Cmd | ||
) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=container:other", "--link=zip:zap", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(runconfig.ErrConflictContainerNetworkAndLinks.Error(), out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=host", "--link=zip:zap", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(runconfig.ErrConflictHostNetworkAndLinks.Error(), out, c) | ||
} | ||
|
||
func (s *DockerSuite) TestConflictNetworkModeAndOptions(c *check.C) { | ||
var ( | ||
out string | ||
err error | ||
runCmd *exec.Cmd | ||
) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=host", "--dns=8.8.8.8", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(runconfig.ErrConflictNetworkAndDNS.Error(), out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=container:other", "--dns=8.8.8.8", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(runconfig.ErrConflictNetworkAndDNS.Error(), out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=host", "--add-host=name:8.8.8.8", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(runconfig.ErrConflictNetworkHosts.Error(), out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=container:other", "--add-host=name:8.8.8.8", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(runconfig.ErrConflictNetworkHosts.Error(), out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=host", "--mac-address=92:d0:c6:0a:29:33", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(runconfig.ErrConflictContainerNetworkAndMac.Error(), out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=container:other", "--mac-address=92:d0:c6:0a:29:33", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(runconfig.ErrConflictContainerNetworkAndMac.Error(), out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=container:other", "-P", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(runconfig.ErrConflictNetworkPublishPorts.Error(), out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=container:other", "-p", "8080", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(runconfig.ErrConflictNetworkPublishPorts.Error(), out, c) | ||
|
||
runCmd = exec.Command(dockerBinary, "run", "--net=container:other", "--expose", "8000-9000", "busybox", "ps") | ||
if out, _, err = runCommandWithOutput(runCmd); err == nil { | ||
c.Fatalf(out, err) | ||
} | ||
checkContains(runconfig.ErrConflictNetworkExposePorts.Error(), out, c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// +build !windows | ||
|
||
package runconfig | ||
|
||
// ContainerConfigWrapper is a Config wrapper that hold the container Config (portable) | ||
// and the corresponding HostConfig (non-portable). | ||
type ContainerConfigWrapper struct { | ||
*Config | ||
InnerHostConfig *HostConfig `json:"HostConfig,omitempty"` | ||
Cpuset string `json:",omitempty"` // Deprecated. Exported for backwards compatibility. | ||
*HostConfig // Deprecated. Exported to read attributes from json that are not in the inner host config structure. | ||
} | ||
|
||
// getHostConfig gets the HostConfig of the Config. | ||
// It's mostly there to handle Deprecated fields of the ContainerConfigWrapper | ||
func (w *ContainerConfigWrapper) getHostConfig() *HostConfig { | ||
hc := w.HostConfig | ||
|
||
if hc == nil && w.InnerHostConfig != nil { | ||
hc = w.InnerHostConfig | ||
} else if w.InnerHostConfig != nil { | ||
if hc.Memory != 0 && w.InnerHostConfig.Memory == 0 { | ||
w.InnerHostConfig.Memory = hc.Memory | ||
} | ||
if hc.MemorySwap != 0 && w.InnerHostConfig.MemorySwap == 0 { | ||
w.InnerHostConfig.MemorySwap = hc.MemorySwap | ||
} | ||
if hc.CPUShares != 0 && w.InnerHostConfig.CPUShares == 0 { | ||
w.InnerHostConfig.CPUShares = hc.CPUShares | ||
} | ||
if hc.CpusetCpus != "" && w.InnerHostConfig.CpusetCpus == "" { | ||
w.InnerHostConfig.CpusetCpus = hc.CpusetCpus | ||
} | ||
|
||
hc = w.InnerHostConfig | ||
} | ||
|
||
if hc != nil && w.Cpuset != "" && hc.CpusetCpus == "" { | ||
hc.CpusetCpus = w.Cpuset | ||
} | ||
|
||
// Make sure NetworkMode has an acceptable value. We do this to ensure | ||
// backwards compatible API behaviour. | ||
hc = SetDefaultNetModeIfBlank(hc) | ||
|
||
return hc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package runconfig | ||
|
||
// ContainerConfigWrapper is a Config wrapper that hold the container Config (portable) | ||
// and the corresponding HostConfig (non-portable). | ||
type ContainerConfigWrapper struct { | ||
*Config | ||
HostConfig *HostConfig `json:"HostConfig,omitempty"` | ||
} | ||
|
||
// getHostConfig gets the HostConfig of the Config. | ||
func (w *ContainerConfigWrapper) getHostConfig() *HostConfig { | ||
return w.HostConfig | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.