1
0
mirror of https://github.com/moby/moby.git synced 2025-07-30 18:23:29 +03:00

Clean some runCommandWithOutput accross integration-cli code

There is still ways to go

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester
2017-01-05 12:38:34 +01:00
parent 766e53d8cb
commit 87e3fcfe1e
19 changed files with 433 additions and 578 deletions

View File

@ -16,6 +16,7 @@ import (
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/docker/go-units" "github.com/docker/go-units"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -100,12 +101,10 @@ func (s *DockerSuite) TestBuildAddChangeOwnership(c *check.C) {
} }
defer testFile.Close() defer testFile.Close()
chownCmd := exec.Command("chown", "daemon:daemon", "foo") icmd.RunCmd(icmd.Cmd{
chownCmd.Dir = tmpDir Command: []string{"chown", "daemon:daemon", "foo"},
out, _, err := runCommandWithOutput(chownCmd) Dir: tmpDir,
if err != nil { }).Assert(c, icmd.Success)
c.Fatal(err, out)
}
if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil { if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil {
c.Fatalf("failed to open destination dockerfile: %v", err) c.Fatalf("failed to open destination dockerfile: %v", err)

View File

@ -12,6 +12,7 @@ import (
"github.com/docker/docker/api" "github.com/docker/docker/api"
"github.com/docker/docker/dockerversion" "github.com/docker/docker/dockerversion"
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/docker/docker/pkg/homedir" "github.com/docker/docker/pkg/homedir"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -51,15 +52,15 @@ func (s *DockerSuite) TestConfigHTTPHeader(c *check.C) {
err = ioutil.WriteFile(tmpCfg, []byte(data), 0600) err = ioutil.WriteFile(tmpCfg, []byte(data), 0600)
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
cmd := exec.Command(dockerBinary, "-H="+server.URL[7:], "ps") result := icmd.RunCommand(dockerBinary, "-H="+server.URL[7:], "ps")
out, _, _ := runCommandWithOutput(cmd) result.Assert(c, icmd.Success)
c.Assert(headers["User-Agent"], checker.NotNil, check.Commentf("Missing User-Agent")) c.Assert(headers["User-Agent"], checker.NotNil, check.Commentf("Missing User-Agent"))
c.Assert(headers["User-Agent"][0], checker.Equals, "Docker-Client/"+dockerversion.Version+" ("+runtime.GOOS+")", check.Commentf("Badly formatted User-Agent,out:%v", out)) c.Assert(headers["User-Agent"][0], checker.Equals, "Docker-Client/"+dockerversion.Version+" ("+runtime.GOOS+")", check.Commentf("Badly formatted User-Agent,out:%v", result.Combined()))
c.Assert(headers["Myheader"], checker.NotNil) c.Assert(headers["Myheader"], checker.NotNil)
c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("Missing/bad header,out:%v", out)) c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("Missing/bad header,out:%v", result.Combined()))
} }
@ -72,11 +73,10 @@ func (s *DockerSuite) TestConfigDir(c *check.C) {
dockerCmd(c, "--config", cDir, "ps") dockerCmd(c, "--config", cDir, "ps")
// Test with env var too // Test with env var too
cmd := exec.Command(dockerBinary, "ps") icmd.RunCmd(icm.Cmd{
cmd.Env = appendBaseEnv(true, "DOCKER_CONFIG="+cDir) Command: []string{dockerBinary, "ps"},
out, _, err := runCommandWithOutput(cmd) Env: appendBaseEnv(true, "DOCKER_CONFIG="+cDir),
}).Assert(c, icmd.Success)
c.Assert(err, checker.IsNil, check.Commentf("ps2 didn't work,out:%v", out))
// Start a server so we can check to see if the config file was // Start a server so we can check to see if the config file was
// loaded properly // loaded properly
@ -99,42 +99,49 @@ func (s *DockerSuite) TestConfigDir(c *check.C) {
env := appendBaseEnv(false) env := appendBaseEnv(false)
cmd = exec.Command(dockerBinary, "--config", cDir, "-H="+server.URL[7:], "ps") icmd.RunCmd(icmd.Cmd{
cmd.Env = env Command: []string{dockerBinary, "--config", cDir, "-H="+server.URL[7:], "ps"},
out, _, err = runCommandWithOutput(cmd) Env: env,
}).Assert(c, icmd.Exepected{
c.Assert(err, checker.NotNil, check.Commentf("out:%v", out)) Error: "exit status 1",
})
c.Assert(headers["Myheader"], checker.NotNil) c.Assert(headers["Myheader"], checker.NotNil)
c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("ps3 - Missing header,out:%v", out)) c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("ps3 - Missing header,out:%v", out))
// Reset headers and try again using env var this time // Reset headers and try again using env var this time
headers = map[string][]string{} headers = map[string][]string{}
cmd = exec.Command(dockerBinary, "-H="+server.URL[7:], "ps") icmd.RunCmd(icmd.Cmd{
cmd.Env = append(env, "DOCKER_CONFIG="+cDir) Command: []string{dockerBinary, "--config", cDir, "-H="+server.URL[7:], "ps"},
out, _, err = runCommandWithOutput(cmd) Env: append(env, "DOCKER_CONFIG="+cDir),
}).Assert(c, icmd.Exepected{
c.Assert(err, checker.NotNil, check.Commentf("%v", out)) Error: "exit status 1",
})
c.Assert(headers["Myheader"], checker.NotNil) c.Assert(headers["Myheader"], checker.NotNil)
c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("ps4 - Missing header,out:%v", out)) c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("ps4 - Missing header,out:%v", out))
// FIXME(vdemeester) should be a unit test
// Reset headers and make sure flag overrides the env var // Reset headers and make sure flag overrides the env var
headers = map[string][]string{} headers = map[string][]string{}
cmd = exec.Command(dockerBinary, "--config", cDir, "-H="+server.URL[7:], "ps") icmd.RunCmd(icmd.Cmd{
cmd.Env = append(env, "DOCKER_CONFIG=MissingDir") Command: []string{dockerBinary, "--config", cDir, "-H="+server.URL[7:], "ps"},
out, _, err = runCommandWithOutput(cmd) Env: append(env, "DOCKER_CONFIG=MissingDir"),
}).Assert(c, icmd.Exepected{
c.Assert(err, checker.NotNil, check.Commentf("out:%v", out)) Error: "exit status 1",
})
c.Assert(headers["Myheader"], checker.NotNil) c.Assert(headers["Myheader"], checker.NotNil)
c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("ps5 - Missing header,out:%v", out)) c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("ps5 - Missing header,out:%v", out))
// FIXME(vdemeester) should be a unit test
// Reset headers and make sure flag overrides the env var. // Reset headers and make sure flag overrides the env var.
// Almost same as previous but make sure the "MissingDir" isn't // Almost same as previous but make sure the "MissingDir" isn't
// ignore - we don't want to default back to the env var. // ignore - we don't want to default back to the env var.
headers = map[string][]string{} headers = map[string][]string{}
cmd = exec.Command(dockerBinary, "--config", "MissingDir", "-H="+server.URL[7:], "ps") icmd.RunCmd(icmd.Cmd{
cmd.Env = append(env, "DOCKER_CONFIG="+cDir) Command: []string{dockerBinary, "--config", "MissingDir", "-H="+server.URL[7:], "ps"},
out, _, err = runCommandWithOutput(cmd) Env: append(env, "DOCKER_CONFIG="+cDir),
}).Assert(c, icmd.Exepected{
Error: "exit status 1",
})
c.Assert(err, checker.NotNil, check.Commentf("out:%v", out))
c.Assert(headers["Myheader"], checker.IsNil, check.Commentf("ps6 - Headers shouldn't be the expected value,out:%v", out)) c.Assert(headers["Myheader"], checker.IsNil, check.Commentf("ps6 - Headers shouldn't be the expected value,out:%v", out))
} }

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
"syscall" "syscall"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/mount"
"github.com/go-check/check" "github.com/go-check/check"
@ -92,10 +93,7 @@ func (s *DockerDaemonSuite) TestDaemonKillLiveRestoreWithPlugins(c *check.C) {
c.Fatalf("Could not kill daemon: %v", err) c.Fatalf("Could not kill daemon: %v", err)
} }
cmd := exec.Command("pgrep", "-f", pluginProcessName) icmd.RunCommand("pgrep", "-f", pluginProcessName).Assert(c, icmd.Success)
if out, ec, err := runCommandWithOutput(cmd); ec != 0 {
c.Fatalf("Expected exit code '0', got %d err: %v output: %s ", ec, err, out)
}
} }
// TestDaemonShutdownLiveRestoreWithPlugins SIGTERMs daemon started with --live-restore. // TestDaemonShutdownLiveRestoreWithPlugins SIGTERMs daemon started with --live-restore.
@ -121,10 +119,7 @@ func (s *DockerDaemonSuite) TestDaemonShutdownLiveRestoreWithPlugins(c *check.C)
c.Fatalf("Could not kill daemon: %v", err) c.Fatalf("Could not kill daemon: %v", err)
} }
cmd := exec.Command("pgrep", "-f", pluginProcessName) icmd.RunCommand("pgrep", "-f", pluginProcessName).Assert(c, icmd.Success)
if out, ec, err := runCommandWithOutput(cmd); ec != 0 {
c.Fatalf("Expected exit code '0', got %d err: %v output: %s ", ec, err, out)
}
} }
// TestDaemonShutdownWithPlugins shuts down running plugins. // TestDaemonShutdownWithPlugins shuts down running plugins.
@ -156,15 +151,13 @@ func (s *DockerDaemonSuite) TestDaemonShutdownWithPlugins(c *check.C) {
} }
} }
cmd := exec.Command("pgrep", "-f", pluginProcessName) icmd.RunCommand("pgrep", "-f", pluginProcessName).Assert(c, icmd.Expected{
if out, ec, err := runCommandWithOutput(cmd); ec != 1 { ExitCode: 1,
c.Fatalf("Expected exit code '1', got %d err: %v output: %s ", ec, err, out) Error: "exit status 1",
} })
s.d.Start(c, "--live-restore") s.d.Start(c, "--live-restore")
cmd = exec.Command("pgrep", "-f", pluginProcessName) icmd.RunCommand("pgrep", "-f", pluginProcessName).Assert(c, icmd.Success)
out, _, err := runCommandWithOutput(cmd)
c.Assert(err, checker.IsNil, check.Commentf(out))
} }
// TestVolumePlugin tests volume creation using a plugin. // TestVolumePlugin tests volume creation using a plugin.

View File

@ -262,30 +262,15 @@ func (s *DockerDaemonSuite) TestDaemonIptablesClean(c *check.C) {
c.Fatalf("Could not run top: %s, %v", out, err) c.Fatalf("Could not run top: %s, %v", out, err)
} }
// get output from iptables with container running
ipTablesSearchString := "tcp dpt:80" ipTablesSearchString := "tcp dpt:80"
ipTablesCmd := exec.Command("iptables", "-nvL")
out, _, err := runCommandWithOutput(ipTablesCmd)
if err != nil {
c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
}
if !strings.Contains(out, ipTablesSearchString) { // get output from iptables with container running
c.Fatalf("iptables output should have contained %q, but was %q", ipTablesSearchString, out) verifyIPTablesContains(c, ipTablesSearchString)
}
s.d.Stop(c) s.d.Stop(c)
// get output from iptables after restart // get output from iptables after restart
ipTablesCmd = exec.Command("iptables", "-nvL") verifyIPTablesDoesNotContains(c, ipTablesSearchString)
out, _, err = runCommandWithOutput(ipTablesCmd)
if err != nil {
c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
}
if strings.Contains(out, ipTablesSearchString) {
c.Fatalf("iptables output should not have contained %q, but was %q", ipTablesSearchString, out)
}
} }
func (s *DockerDaemonSuite) TestDaemonIptablesCreate(c *check.C) { func (s *DockerDaemonSuite) TestDaemonIptablesCreate(c *check.C) {
@ -297,36 +282,36 @@ func (s *DockerDaemonSuite) TestDaemonIptablesCreate(c *check.C) {
// get output from iptables with container running // get output from iptables with container running
ipTablesSearchString := "tcp dpt:80" ipTablesSearchString := "tcp dpt:80"
ipTablesCmd := exec.Command("iptables", "-nvL") verifyIPTablesContains(c, ipTablesSearchString)
out, _, err := runCommandWithOutput(ipTablesCmd)
if err != nil {
c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
}
if !strings.Contains(out, ipTablesSearchString) {
c.Fatalf("iptables output should have contained %q, but was %q", ipTablesSearchString, out)
}
s.d.Restart(c) s.d.Restart(c)
// make sure the container is not running // make sure the container is not running
runningOut, err := s.d.Cmd("inspect", "--format={{.State.Running}}", "top") runningOut, err := s.d.Cmd("inspect", "--format={{.State.Running}}", "top")
if err != nil { if err != nil {
c.Fatalf("Could not inspect on container: %s, %v", out, err) c.Fatalf("Could not inspect on container: %s, %v", runningOut, err)
} }
if strings.TrimSpace(runningOut) != "true" { if strings.TrimSpace(runningOut) != "true" {
c.Fatalf("Container should have been restarted after daemon restart. Status running should have been true but was: %q", strings.TrimSpace(runningOut)) c.Fatalf("Container should have been restarted after daemon restart. Status running should have been true but was: %q", strings.TrimSpace(runningOut))
} }
// get output from iptables after restart // get output from iptables after restart
ipTablesCmd = exec.Command("iptables", "-nvL") verifyIPTablesContains(c, ipTablesSearchString)
out, _, err = runCommandWithOutput(ipTablesCmd) }
if err != nil {
c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
}
if !strings.Contains(out, ipTablesSearchString) { func verifyIPTablesContains(c *check.C, ipTablesSearchString string) {
c.Fatalf("iptables output after restart should have contained %q, but was %q", ipTablesSearchString, out) result := icmd.RunCommand("iptables", "-nvL")
result.Assert(c, icmd.Success)
if !strings.Contains(result.Combined(), ipTablesSearchString) {
c.Fatalf("iptables output should have contained %q, but was %q", ipTablesSearchString, result.Combined())
}
}
func verifyIPTablesDoesNotContains(c *check.C, ipTablesSearchString string) {
result := icmd.RunCommand("iptables", "-nvL")
result.Assert(c, icmd.Success)
if strings.Contains(result.Combined(), ipTablesSearchString) {
c.Fatalf("iptables output should not have contained %q, but was %q", ipTablesSearchString, result.Combined())
} }
} }
@ -564,10 +549,7 @@ func (s *DockerDaemonSuite) TestDaemonExitOnFailure(c *check.C) {
c.Fatalf("Expected daemon not to start, got %v", err) c.Fatalf("Expected daemon not to start, got %v", err)
} }
// look in the log and make sure we got the message that daemon is shutting down // look in the log and make sure we got the message that daemon is shutting down
runCmd := exec.Command("grep", "Error starting daemon", s.d.LogFileName()) icmd.RunCommand("grep", "Error starting daemon", s.d.LogFileName()).Assert(c, icmd.Success)
if out, _, err := runCommandWithOutput(runCmd); err != nil {
c.Fatalf("Expected 'Error starting daemon' message; but doesn't exist in log: %q, err: %v", out, err)
}
} else { } else {
//if we didn't get an error and the daemon is running, this is a failure //if we didn't get an error and the daemon is running, this is a failure
c.Fatal("Conflicting options should cause the daemon to error out with a failure") c.Fatal("Conflicting options should cause the daemon to error out with a failure")
@ -584,20 +566,15 @@ func (s *DockerDaemonSuite) TestDaemonBridgeExternal(c *check.C) {
bridgeIP := "192.169.1.1/24" bridgeIP := "192.169.1.1/24"
_, bridgeIPNet, _ := net.ParseCIDR(bridgeIP) _, bridgeIPNet, _ := net.ParseCIDR(bridgeIP)
out, err := createInterface(c, "bridge", bridgeName, bridgeIP) createInterface(c, "bridge", bridgeName, bridgeIP)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, bridgeName) defer deleteInterface(c, bridgeName)
d.StartWithBusybox(c, "--bridge", bridgeName) d.StartWithBusybox(c, "--bridge", bridgeName)
ipTablesSearchString := bridgeIPNet.String() ipTablesSearchString := bridgeIPNet.String()
ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL") icmd.RunCommand("iptables", "-t", "nat", "-nvL").Assert(c, icmd.Expected{
out, _, err = runCommandWithOutput(ipTablesCmd) Out: ipTablesSearchString,
c.Assert(err, check.IsNil) })
c.Assert(strings.Contains(out, ipTablesSearchString), check.Equals, true,
check.Commentf("iptables output should have contained %q, but was %q",
ipTablesSearchString, out))
_, err = d.Cmd("run", "-d", "--name", "ExtContainer", "busybox", "top") _, err = d.Cmd("run", "-d", "--name", "ExtContainer", "busybox", "top")
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -617,41 +594,27 @@ func (s *DockerDaemonSuite) TestDaemonBridgeNone(c *check.C) {
defer d.Restart(c) defer d.Restart(c)
// verify docker0 iface is not there // verify docker0 iface is not there
out, _, err := runCommandWithOutput(exec.Command("ifconfig", "docker0")) icmd.RunCommand("ifconfig", "docker0").Assert(c, icmd.Expected{
c.Assert(err, check.NotNil, check.Commentf("docker0 should not be present if daemon started with --bridge=none")) ExitCode: 1,
c.Assert(strings.Contains(out, "Device not found"), check.Equals, true) Error: "exit status 1",
Err: "Device not found",
})
// verify default "bridge" network is not there // verify default "bridge" network is not there
out, err = d.Cmd("network", "inspect", "bridge") out, err := d.Cmd("network", "inspect", "bridge")
c.Assert(err, check.NotNil, check.Commentf("\"bridge\" network should not be present if daemon started with --bridge=none")) c.Assert(err, check.NotNil, check.Commentf("\"bridge\" network should not be present if daemon started with --bridge=none"))
c.Assert(strings.Contains(out, "No such network"), check.Equals, true) c.Assert(strings.Contains(out, "No such network"), check.Equals, true)
} }
func createInterface(c *check.C, ifType string, ifName string, ipNet string) (string, error) { func createInterface(c *check.C, ifType string, ifName string, ipNet string) {
args := []string{"link", "add", "name", ifName, "type", ifType} icmd.RunCommand("ip", "link", "add", "name", ifName, "type", ifType).Assert(c, icmd.Success)
ipLinkCmd := exec.Command("ip", args...) icmd.RunCommand("ifconfig", ifName, ipNet, "up").Assert(c, icmd.Success)
out, _, err := runCommandWithOutput(ipLinkCmd)
if err != nil {
return out, err
}
ifCfgCmd := exec.Command("ifconfig", ifName, ipNet, "up")
out, _, err = runCommandWithOutput(ifCfgCmd)
return out, err
} }
func deleteInterface(c *check.C, ifName string) { func deleteInterface(c *check.C, ifName string) {
ifCmd := exec.Command("ip", "link", "delete", ifName) icmd.RunCommand("ip", "link", "delete", ifName).Assert(c, icmd.Success)
out, _, err := runCommandWithOutput(ifCmd) icmd.RunCommand("iptables", "-t", "nat", "--flush").Assert(c, icmd.Success)
c.Assert(err, check.IsNil, check.Commentf(out)) icmd.RunCommand("iptables", "--flush").Assert(c, icmd.Success)
flushCmd := exec.Command("iptables", "-t", "nat", "--flush")
out, _, err = runCommandWithOutput(flushCmd)
c.Assert(err, check.IsNil, check.Commentf(out))
flushCmd = exec.Command("iptables", "--flush")
out, _, err = runCommandWithOutput(flushCmd)
c.Assert(err, check.IsNil, check.Commentf(out))
} }
func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) { func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) {
@ -723,8 +686,7 @@ func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr(c *check.C) {
bridgeName := "external-bridge" bridgeName := "external-bridge"
bridgeIP := "192.169.1.1/24" bridgeIP := "192.169.1.1/24"
out, err := createInterface(c, "bridge", bridgeName, bridgeIP) createInterface(c, "bridge", bridgeName, bridgeIP)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, bridgeName) defer deleteInterface(c, bridgeName)
args := []string{"--bridge", bridgeName, "--fixed-cidr", "192.169.1.0/30"} args := []string{"--bridge", bridgeName, "--fixed-cidr", "192.169.1.0/30"}
@ -747,14 +709,13 @@ func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr2(c *check.C) {
bridgeName := "external-bridge" bridgeName := "external-bridge"
bridgeIP := "10.2.2.1/16" bridgeIP := "10.2.2.1/16"
out, err := createInterface(c, "bridge", bridgeName, bridgeIP) createInterface(c, "bridge", bridgeName, bridgeIP)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, bridgeName) defer deleteInterface(c, bridgeName)
d.StartWithBusybox(c, "--bip", bridgeIP, "--fixed-cidr", "10.2.2.0/24") d.StartWithBusybox(c, "--bip", bridgeIP, "--fixed-cidr", "10.2.2.0/24")
defer s.d.Restart(c) defer s.d.Restart(c)
out, err = d.Cmd("run", "-d", "--name", "bb", "busybox", "top") out, err := d.Cmd("run", "-d", "--name", "bb", "busybox", "top")
c.Assert(err, checker.IsNil, check.Commentf(out)) c.Assert(err, checker.IsNil, check.Commentf(out))
defer d.Cmd("stop", "bb") defer d.Cmd("stop", "bb")
@ -772,14 +733,13 @@ func (s *DockerDaemonSuite) TestDaemonBridgeFixedCIDREqualBridgeNetwork(c *check
bridgeName := "external-bridge" bridgeName := "external-bridge"
bridgeIP := "172.27.42.1/16" bridgeIP := "172.27.42.1/16"
out, err := createInterface(c, "bridge", bridgeName, bridgeIP) createInterface(c, "bridge", bridgeName, bridgeIP)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, bridgeName) defer deleteInterface(c, bridgeName)
d.StartWithBusybox(c, "--bridge", bridgeName, "--fixed-cidr", bridgeIP) d.StartWithBusybox(c, "--bridge", bridgeName, "--fixed-cidr", bridgeIP)
defer s.d.Restart(c) defer s.d.Restart(c)
out, err = d.Cmd("run", "-d", "busybox", "top") out, err := d.Cmd("run", "-d", "busybox", "top")
c.Assert(err, check.IsNil, check.Commentf(out)) c.Assert(err, check.IsNil, check.Commentf(out))
cid1 := strings.TrimSpace(out) cid1 := strings.TrimSpace(out)
defer d.Cmd("stop", cid1) defer d.Cmd("stop", cid1)
@ -871,21 +831,18 @@ func (s *DockerDaemonSuite) TestDaemonIP(c *check.C) {
c.Assert(strings.Contains(out, "Error starting userland proxy"), check.Equals, true) c.Assert(strings.Contains(out, "Error starting userland proxy"), check.Equals, true)
ifName := "dummy" ifName := "dummy"
out, err = createInterface(c, "dummy", ifName, ipStr) createInterface(c, "dummy", ifName, ipStr)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, ifName) defer deleteInterface(c, ifName)
_, err = d.Cmd("run", "-d", "-p", "8000:8000", "busybox", "top") _, err = d.Cmd("run", "-d", "-p", "8000:8000", "busybox", "top")
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL") result := icmd.RunCommand("iptables", "-t", "nat", "-nvL")
out, _, err = runCommandWithOutput(ipTablesCmd) result.Assert(c, icmd.Success)
c.Assert(err, check.IsNil)
regex := fmt.Sprintf("DNAT.*%s.*dpt:8000", ip.String()) regex := fmt.Sprintf("DNAT.*%s.*dpt:8000", ip.String())
matched, _ := regexp.MatchString(regex, out) matched, _ := regexp.MatchString(regex, result.Combined())
c.Assert(matched, check.Equals, true, c.Assert(matched, check.Equals, true,
check.Commentf("iptables output should have contained %q, but was %q", regex, out)) check.Commentf("iptables output should have contained %q, but was %q", regex, result.Combined()))
} }
func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) { func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) {
@ -895,22 +852,18 @@ func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) {
bridgeName := "external-bridge" bridgeName := "external-bridge"
bridgeIP := "192.169.1.1/24" bridgeIP := "192.169.1.1/24"
out, err := createInterface(c, "bridge", bridgeName, bridgeIP) createInterface(c, "bridge", bridgeName, bridgeIP)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, bridgeName) defer deleteInterface(c, bridgeName)
args := []string{"--bridge", bridgeName, "--icc=false"} d.StartWithBusybox(c, "--bridge", bridgeName, "--icc=false")
d.StartWithBusybox(c, args...)
defer d.Restart(c) defer d.Restart(c)
ipTablesCmd := exec.Command("iptables", "-nvL", "FORWARD") result := icmd.RunCommand("iptables", "-nvL", "FORWARD")
out, _, err = runCommandWithOutput(ipTablesCmd) result.Assert(c, icmd.Success)
c.Assert(err, check.IsNil)
regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName) regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName)
matched, _ := regexp.MatchString(regex, out) matched, _ := regexp.MatchString(regex, result.Combined())
c.Assert(matched, check.Equals, true, c.Assert(matched, check.Equals, true,
check.Commentf("iptables output should have contained %q, but was %q", regex, out)) check.Commentf("iptables output should have contained %q, but was %q", regex, result.Combined()))
// Pinging another container must fail with --icc=false // Pinging another container must fail with --icc=false
pingContainers(c, d, true) pingContainers(c, d, true)
@ -924,7 +877,7 @@ func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) {
// But, Pinging external or a Host interface must succeed // But, Pinging external or a Host interface must succeed
pingCmd := fmt.Sprintf("ping -c 1 %s -W 1", ip.String()) pingCmd := fmt.Sprintf("ping -c 1 %s -W 1", ip.String())
runArgs := []string{"run", "--rm", "busybox", "sh", "-c", pingCmd} runArgs := []string{"run", "--rm", "busybox", "sh", "-c", pingCmd}
_, err = d.Cmd(runArgs...) _, err := d.Cmd(runArgs...)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
} }
@ -934,24 +887,20 @@ func (s *DockerDaemonSuite) TestDaemonICCLinkExpose(c *check.C) {
bridgeName := "external-bridge" bridgeName := "external-bridge"
bridgeIP := "192.169.1.1/24" bridgeIP := "192.169.1.1/24"
out, err := createInterface(c, "bridge", bridgeName, bridgeIP) createInterface(c, "bridge", bridgeName, bridgeIP)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, bridgeName) defer deleteInterface(c, bridgeName)
args := []string{"--bridge", bridgeName, "--icc=false"} d.StartWithBusybox(c, "--bridge", bridgeName, "--icc=false")
d.StartWithBusybox(c, args...)
defer d.Restart(c) defer d.Restart(c)
ipTablesCmd := exec.Command("iptables", "-nvL", "FORWARD") result := icmd.RunCommand("iptables", "-nvL", "FORWARD")
out, _, err = runCommandWithOutput(ipTablesCmd) result.Assert(c, icmd.Success)
c.Assert(err, check.IsNil)
regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName) regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName)
matched, _ := regexp.MatchString(regex, out) matched, _ := regexp.MatchString(regex, result.Combined())
c.Assert(matched, check.Equals, true, c.Assert(matched, check.Equals, true,
check.Commentf("iptables output should have contained %q, but was %q", regex, out)) check.Commentf("iptables output should have contained %q, but was %q", regex, result.Combined()))
out, err = d.Cmd("run", "-d", "--expose", "4567", "--name", "icc1", "busybox", "nc", "-l", "-p", "4567") out, err := d.Cmd("run", "-d", "--expose", "4567", "--name", "icc1", "busybox", "nc", "-l", "-p", "4567")
c.Assert(err, check.IsNil, check.Commentf(out)) c.Assert(err, check.IsNil, check.Commentf(out))
out, err = d.Cmd("run", "--link", "icc1:icc1", "busybox", "nc", "icc1", "4567") out, err = d.Cmd("run", "--link", "icc1:icc1", "busybox", "nc", "icc1", "4567")
@ -962,14 +911,13 @@ func (s *DockerDaemonSuite) TestDaemonLinksIpTablesRulesWhenLinkAndUnlink(c *che
bridgeName := "external-bridge" bridgeName := "external-bridge"
bridgeIP := "192.169.1.1/24" bridgeIP := "192.169.1.1/24"
out, err := createInterface(c, "bridge", bridgeName, bridgeIP) createInterface(c, "bridge", bridgeName, bridgeIP)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, bridgeName) defer deleteInterface(c, bridgeName)
s.d.StartWithBusybox(c, "--bridge", bridgeName, "--icc=false") s.d.StartWithBusybox(c, "--bridge", bridgeName, "--icc=false")
defer s.d.Restart(c) defer s.d.Restart(c)
_, err = s.d.Cmd("run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "top") _, err := s.d.Cmd("run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "top")
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
_, err = s.d.Cmd("run", "-d", "--name", "parent", "--link", "child:http", "busybox", "top") _, err = s.d.Cmd("run", "-d", "--name", "parent", "--link", "child:http", "busybox", "top")
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
@ -1464,10 +1412,7 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonAndContainerKill(c *chec
c.Assert(strings.Contains(string(mountOut), id), check.Equals, true, comment) c.Assert(strings.Contains(string(mountOut), id), check.Equals, true, comment)
// kill the container // kill the container
runCmd := exec.Command(ctrBinary, "--address", "unix:///var/run/docker/libcontainerd/docker-containerd.sock", "containers", "kill", id) icmd.RunCommand(ctrBinary, "--address", "unix:///var/run/docker/libcontainerd/docker-containerd.sock", "containers", "kill", id).Assert(c, icmd.Success)
if out, ec, err := runCommandWithOutput(runCmd); err != nil {
c.Fatalf("Failed to run ctr, ExitCode: %d, err: %v output: %s id: %s\n", ec, err, out, id)
}
// restart daemon. // restart daemon.
d.Restart(c) d.Restart(c)
@ -1564,10 +1509,9 @@ func (s *DockerDaemonSuite) TestDaemonRestartCleanupNetns(c *check.C) {
} }
// Test if the file still exists // Test if the file still exists
out, _, err = runCommandWithOutput(exec.Command("stat", "-c", "%n", fileName)) icmd.RunCommand("stat", "-c", "%n", fileName).Assert(c, icmd.Expected{
out = strings.TrimSpace(out) Out: fileName,
c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) })
c.Assert(out, check.Equals, fileName, check.Commentf("Output: %s", out))
// Remove the container and restart the daemon // Remove the container and restart the daemon
if out, err := s.d.Cmd("rm", "netns"); err != nil { if out, err := s.d.Cmd("rm", "netns"); err != nil {
@ -1577,32 +1521,34 @@ func (s *DockerDaemonSuite) TestDaemonRestartCleanupNetns(c *check.C) {
s.d.Restart(c) s.d.Restart(c)
// Test again and see now the netns file does not exist // Test again and see now the netns file does not exist
out, _, err = runCommandWithOutput(exec.Command("stat", "-c", "%n", fileName)) icmd.RunCommand("stat", "-c", "%n", fileName).Assert(c, icmd.Expected{
out = strings.TrimSpace(out) Err: "No such file or directory",
c.Assert(err, check.Not(check.IsNil), check.Commentf("Output: %s", out)) ExitCode: 1,
})
} }
// tests regression detailed in #13964 where DOCKER_TLS_VERIFY env is ignored // tests regression detailed in #13964 where DOCKER_TLS_VERIFY env is ignored
func (s *DockerDaemonSuite) TestDaemonTLSVerifyIssue13964(c *check.C) { func (s *DockerDaemonSuite) TestDaemonTLSVerifyIssue13964(c *check.C) {
host := "tcp://localhost:4271" host := "tcp://localhost:4271"
s.d.Start(c, "-H", host) s.d.Start(c, "-H", host)
cmd := exec.Command(dockerBinary, "-H", host, "info") icmd.RunCmd(icmd.Cmd{
cmd.Env = []string{"DOCKER_TLS_VERIFY=1", "DOCKER_CERT_PATH=fixtures/https"} Command: []string{dockerBinary, "-H", host, "info"},
out, _, err := runCommandWithOutput(cmd) Env: []string{"DOCKER_TLS_VERIFY=1", "DOCKER_CERT_PATH=fixtures/https"},
c.Assert(err, check.Not(check.IsNil), check.Commentf("%s", out)) }).Assert(c, icmd.Expected{
c.Assert(strings.Contains(out, "error during connect"), check.Equals, true) ExitCode: 1,
Err: "error during connect",
})
} }
func setupV6(c *check.C) { func setupV6(c *check.C) {
// Hack to get the right IPv6 address on docker0, which has already been created // Hack to get the right IPv6 address on docker0, which has already been created
result := icmd.RunCommand("ip", "addr", "add", "fe80::1/64", "dev", "docker0") result := icmd.RunCommand("ip", "addr", "add", "fe80::1/64", "dev", "docker0")
result.Assert(c, icmd.Expected{}) result.Assert(c, icmd.Success)
} }
func teardownV6(c *check.C) { func teardownV6(c *check.C) {
result := icmd.RunCommand("ip", "addr", "del", "fe80::1/64", "dev", "docker0") result := icmd.RunCommand("ip", "addr", "del", "fe80::1/64", "dev", "docker0")
result.Assert(c, icmd.Expected{}) result.Assert(c, icmd.Success)
} }
func (s *DockerDaemonSuite) TestDaemonRestartWithContainerWithRestartPolicyAlways(c *check.C) { func (s *DockerDaemonSuite) TestDaemonRestartWithContainerWithRestartPolicyAlways(c *check.C) {
@ -1708,10 +1654,7 @@ func (s *DockerDaemonSuite) TestDaemonCorruptedLogDriverAddress(c *check.C) {
}) })
c.Assert(d.StartWithError("--log-driver=syslog", "--log-opt", "syslog-address=corrupted:42"), check.NotNil) c.Assert(d.StartWithError("--log-driver=syslog", "--log-opt", "syslog-address=corrupted:42"), check.NotNil)
expected := "Failed to set log opts: syslog-address should be in form proto://address" expected := "Failed to set log opts: syslog-address should be in form proto://address"
runCmd := exec.Command("grep", expected, d.LogFileName()) icmd.RunCommand("grep", expected, d.LogFileName()).Assert(c, icmd.Success)
if out, _, err := runCommandWithOutput(runCmd); err != nil {
c.Fatalf("Expected %q message; but doesn't exist in log: %q, err: %v", expected, out, err)
}
} }
// FIXME(vdemeester) should be a unit test // FIXME(vdemeester) should be a unit test
@ -1721,10 +1664,7 @@ func (s *DockerDaemonSuite) TestDaemonCorruptedFluentdAddress(c *check.C) {
}) })
c.Assert(d.StartWithError("--log-driver=fluentd", "--log-opt", "fluentd-address=corrupted:c"), check.NotNil) c.Assert(d.StartWithError("--log-driver=fluentd", "--log-opt", "fluentd-address=corrupted:c"), check.NotNil)
expected := "Failed to set log opts: invalid fluentd-address corrupted:c: " expected := "Failed to set log opts: invalid fluentd-address corrupted:c: "
runCmd := exec.Command("grep", expected, d.LogFileName()) icmd.RunCommand("grep", expected, d.LogFileName()).Assert(c, icmd.Success)
if out, _, err := runCommandWithOutput(runCmd); err != nil {
c.Fatalf("Expected %q message; but doesn't exist in log: %q, err: %v", expected, out, err)
}
} }
// FIXME(vdemeester) Use a new daemon instance instead of the Suite one // FIXME(vdemeester) Use a new daemon instance instead of the Suite one
@ -1808,13 +1748,11 @@ func (s *DockerDaemonSuite) TestDaemonNoSpaceLeftOnDeviceError(c *check.C) {
// create a 2MiB image and mount it as graph root // create a 2MiB image and mount it as graph root
// Why in a container? Because `mount` sometimes behaves weirdly and often fails outright on this test in debian:jessie (which is what the test suite runs under if run from the Makefile) // Why in a container? Because `mount` sometimes behaves weirdly and often fails outright on this test in debian:jessie (which is what the test suite runs under if run from the Makefile)
dockerCmd(c, "run", "--rm", "-v", testDir+":/test", "busybox", "sh", "-c", "dd of=/test/testfs.img bs=1M seek=2 count=0") dockerCmd(c, "run", "--rm", "-v", testDir+":/test", "busybox", "sh", "-c", "dd of=/test/testfs.img bs=1M seek=2 count=0")
out, _, err := runCommandWithOutput(exec.Command("mkfs.ext4", "-F", filepath.Join(testDir, "testfs.img"))) // `mkfs.ext4` is not in busybox icmd.RunCommand("mkfs.ext4", "-F", filepath.Join(testDir, "testfs.img")).Assert(c, icmd.Success)
c.Assert(err, checker.IsNil, check.Commentf(out))
cmd := exec.Command("losetup", "-f", "--show", filepath.Join(testDir, "testfs.img")) result := icmd.RunCommand("losetup", "-f", "--show", filepath.Join(testDir, "testfs.img"))
loout, err := cmd.CombinedOutput() result.Assert(c, icmd.Success)
c.Assert(err, checker.IsNil) loopname := strings.TrimSpace(string(result.Combined()))
loopname := strings.TrimSpace(string(loout))
defer exec.Command("losetup", "-d", loopname).Run() defer exec.Command("losetup", "-d", loopname).Run()
dockerCmd(c, "run", "--privileged", "--rm", "-v", testDir+":/test:shared", "busybox", "sh", "-c", fmt.Sprintf("mkdir -p /test/test-mount && mount -t ext4 -no loop,rw %v /test/test-mount", loopname)) dockerCmd(c, "run", "--privileged", "--rm", "-v", testDir+":/test:shared", "busybox", "sh", "-c", fmt.Sprintf("mkdir -p /test/test-mount && mount -t ext4 -no loop,rw %v /test/test-mount", loopname))
@ -2007,10 +1945,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithKilledRunningContainer(t *check
} }
// kill the container // kill the container
runCmd := exec.Command(ctrBinary, "--address", "unix:///var/run/docker/libcontainerd/docker-containerd.sock", "containers", "kill", cid) icmd.RunCommand(ctrBinary, "--address", "unix:///var/run/docker/libcontainerd/docker-containerd.sock", "containers", "kill", cid).Assert(c, icmd.Success)
if out, ec, err := runCommandWithOutput(runCmd); err != nil {
t.Fatalf("Failed to run ctr, ExitCode: %d, err: '%v' output: '%s' cid: '%s'\n", ec, err, out, cid)
}
// Give time to containerd to process the command if we don't // Give time to containerd to process the command if we don't
// the exit event might be received after we do the inspect // the exit event might be received after we do the inspect

View File

@ -2,10 +2,10 @@ package main
import ( import (
"os" "os"
"os/exec"
"strings" "strings"
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -18,12 +18,13 @@ func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
out, _ := dockerCmd(c, "export", containerID) out, _ := dockerCmd(c, "export", containerID)
importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1") result := icmd.RunCmd(icmd.Cmd{
importCmd.Stdin = strings.NewReader(out) Command: dockerBinary, "import", "-", "repo/testexp:v1",
out, _, err := runCommandWithOutput(importCmd) Stdin: strings.NewReader(out),
c.Assert(err, checker.IsNil, check.Commentf("failed to import image repo/testexp:v1: %s", out)) })
result.Assert(c, icmd.Success)
cleanedImageID := strings.TrimSpace(out) cleanedImageID := strings.TrimSpace(result.Combined())
c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id")) c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id"))
} }
@ -36,14 +37,15 @@ func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
dockerCmd(c, "export", "--output=testexp.tar", containerID) dockerCmd(c, "export", "--output=testexp.tar", containerID)
defer os.Remove("testexp.tar") defer os.Remove("testexp.tar")
out, _, err := runCommandWithOutput(exec.Command("cat", "testexp.tar")) resultCat := icmd.RunCommand("cat", "testexp.tar")
c.Assert(err, checker.IsNil, check.Commentf(out)) resultCat.Assert(c, icmd.Success)
importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1") result := icmd.RunCmd(icmd.Cmd{
importCmd.Stdin = strings.NewReader(out) Command: dockerBinary, "import", "-", "repo/testexp:v1",
out, _, err = runCommandWithOutput(importCmd) Stdin: strings.NewReader(resultCat.Combined()),
c.Assert(err, checker.IsNil, check.Commentf("failed to import image repo/testexp:v1: %s", out)) })
result.Assert(c, icmd.Success)
cleanedImageID := strings.TrimSpace(out) cleanedImageID := strings.TrimSpace(result.Combined())
c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id")) c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id"))
} }

View File

@ -14,6 +14,7 @@ import (
) )
func (s *DockerSuite) TestHelpTextVerify(c *check.C) { func (s *DockerSuite) TestHelpTextVerify(c *check.C) {
// FIXME(vdemeester) should be a unit test, probably using golden files ?
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// Make sure main help text fits within 80 chars and that // Make sure main help text fits within 80 chars and that
@ -52,11 +53,12 @@ func (s *DockerSuite) TestHelpTextVerify(c *check.C) {
scanForHome := runtime.GOOS != "windows" && home != "/" scanForHome := runtime.GOOS != "windows" && home != "/"
// Check main help text to make sure its not over 80 chars // Check main help text to make sure its not over 80 chars
helpCmd := exec.Command(dockerBinary, "help") result := icmd.RunCmd(icmd.Cmd{
helpCmd.Env = newEnvs Command: []stirng{dockerBinary, "help"},
out, _, err := runCommandWithOutput(helpCmd) Env: newEnvs,
c.Assert(err, checker.IsNil, check.Commentf(out)) })
lines := strings.Split(out, "\n") result.Assert(c, icmd.Success)
lines := strings.Split(result.Combined(), "\n")
for _, line := range lines { for _, line := range lines {
// All lines should not end with a space // All lines should not end with a space
c.Assert(line, checker.Not(checker.HasSuffix), " ", check.Commentf("Line should not end with a space")) c.Assert(line, checker.Not(checker.HasSuffix), " ", check.Commentf("Line should not end with a space"))
@ -75,16 +77,17 @@ func (s *DockerSuite) TestHelpTextVerify(c *check.C) {
// Make sure each cmd's help text fits within 90 chars and that // Make sure each cmd's help text fits within 90 chars and that
// on non-windows system we use ~ when possible (to shorten things). // on non-windows system we use ~ when possible (to shorten things).
// Pull the list of commands from the "Commands:" section of docker help // Pull the list of commands from the "Commands:" section of docker help
helpCmd = exec.Command(dockerBinary, "help") // FIXME(vdemeester) Why re-run help ?
helpCmd.Env = newEnvs //helpCmd = exec.Command(dockerBinary, "help")
out, _, err = runCommandWithOutput(helpCmd) //helpCmd.Env = newEnvs
c.Assert(err, checker.IsNil, check.Commentf(out)) //out, _, err = runCommandWithOutput(helpCmd)
i := strings.Index(out, "Commands:") //c.Assert(err, checker.IsNil, check.Commentf(out))
c.Assert(i, checker.GreaterOrEqualThan, 0, check.Commentf("Missing 'Commands:' in:\n%s", out)) i := strings.Index(result.Combined(), "Commands:")
c.Assert(i, checker.GreaterOrEqualThan, 0, check.Commentf("Missing 'Commands:' in:\n%s", result.Combined()))
cmds := []string{} cmds := []string{}
// Grab all chars starting at "Commands:" // Grab all chars starting at "Commands:"
helpOut := strings.Split(out[i:], "\n") helpOut := strings.Split(result.Combined()[i:], "\n")
// Skip first line, it is just "Commands:" // Skip first line, it is just "Commands:"
helpOut = helpOut[1:] helpOut = helpOut[1:]

View File

@ -8,6 +8,7 @@ import (
"strings" "strings"
"time" "time"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/pkg/jsonlog" "github.com/docker/docker/pkg/jsonlog"
"github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil"
@ -188,14 +189,14 @@ func (s *DockerSuite) TestLogsSince(c *check.C) {
// Test with default value specified and parameter omitted // Test with default value specified and parameter omitted
expected := []string{"log1", "log2", "log3"} expected := []string{"log1", "log2", "log3"}
for _, cmd := range []*exec.Cmd{ for _, cmd := range [][]string{
exec.Command(dockerBinary, "logs", "-t", name), []string{dockerBinary, "logs", "-t", name},
exec.Command(dockerBinary, "logs", "-t", "--since=0", name), []string{dockerBinary, "logs", "-t", "--since=0", name},
} { } {
out, _, err = runCommandWithOutput(cmd) result := icmd.RunCommand(cmd...)
c.Assert(err, checker.IsNil, check.Commentf("failed to log container: %s", out)) result.Assert(c, icmd.Success)
for _, v := range expected { for _, v := range expected {
c.Assert(out, checker.Contains, v) c.Assert(result.Combined(), checker.Contains, v)
} }
} }
} }

View File

@ -803,15 +803,14 @@ func (s *DockerDaemonSuite) TestDockerNetworkNoDiscoveryDefaultBridgeNetwork(c *
hostsFile := "/etc/hosts" hostsFile := "/etc/hosts"
bridgeName := "external-bridge" bridgeName := "external-bridge"
bridgeIP := "192.169.255.254/24" bridgeIP := "192.169.255.254/24"
out, err := createInterface(c, "bridge", bridgeName, bridgeIP) createInterface(c, "bridge", bridgeName, bridgeIP)
c.Assert(err, check.IsNil, check.Commentf(out))
defer deleteInterface(c, bridgeName) defer deleteInterface(c, bridgeName)
s.d.StartWithBusybox(c, "--bridge", bridgeName) s.d.StartWithBusybox(c, "--bridge", bridgeName)
defer s.d.Restart(c) defer s.d.Restart(c)
// run two containers and store first container's etc/hosts content // run two containers and store first container's etc/hosts content
out, err = s.d.Cmd("run", "-d", "busybox", "top") out, err := s.d.Cmd("run", "-d", "busybox", "top")
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
cid1 := strings.TrimSpace(out) cid1 := strings.TrimSpace(out)
defer s.d.Cmd("stop", cid1) defer s.d.Cmd("stop", cid1)

View File

@ -5,20 +5,18 @@ import (
"os/exec" "os/exec"
"strings" "strings"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"github.com/go-check/check" "github.com/go-check/check"
) )
func (s *DockerSuite) TestCLIProxyDisableProxyUnixSock(c *check.C) { func (s *DockerSuite) TestCLIProxyDisableProxyUnixSock(c *check.C) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux, SameHostDaemon)
testRequires(c, SameHostDaemon) // test is valid when DOCKER_HOST=unix://..
cmd := exec.Command(dockerBinary, "info")
cmd.Env = appendBaseEnv(false, "HTTP_PROXY=http://127.0.0.1:9999")
out, _, err := runCommandWithOutput(cmd)
c.Assert(err, checker.IsNil, check.Commentf("%v", out))
icmd.RunCmd(icm.Cmd{
Command: []string{dockerBinary, "info"},
Env: appendBaseEnv(false, "HTTP_PROXY=http://127.0.0.1:9999"),
}).Assert(c, icmd.Success)
} }
// Can't use localhost here since go has a special case to not use proxy if connecting to localhost // Can't use localhost here since go has a special case to not use proxy if connecting to localhost
@ -41,12 +39,14 @@ func (s *DockerDaemonSuite) TestCLIProxyProxyTCPSock(c *check.C) {
c.Assert(ip, checker.Not(checker.Equals), "") c.Assert(ip, checker.Not(checker.Equals), "")
s.d.Start(c, "-H", "tcp://"+ip+":2375") s.d.Start(c, "-H", "tcp://"+ip+":2375")
cmd := exec.Command(dockerBinary, "info")
cmd.Env = []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"} icmd.RunCmd(icmd.Cmd{
out, _, err := runCommandWithOutput(cmd) Command: []string{dockerBinary, "info"},
c.Assert(err, checker.NotNil, check.Commentf("%v", out)) Env: []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"},
}).Assert(c, icmd.Expected{Error:"exit status 1", ExitCode: 1})
// Test with no_proxy // Test with no_proxy
cmd.Env = append(cmd.Env, "NO_PROXY="+ip) icmd.RunCommand(icmd.Cmd{
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "info")) Command: []string{dockerBinary, "info"},
c.Assert(err, checker.IsNil, check.Commentf("%v", out)) Env: []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999", "NO_PROXY="+ip},
}).Assert(c, icmd.Success)
} }

View File

@ -669,22 +669,19 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
originalImageName := "busybox:TestPsImageIDAfterUpdate-original" originalImageName := "busybox:TestPsImageIDAfterUpdate-original"
updatedImageName := "busybox:TestPsImageIDAfterUpdate-updated" updatedImageName := "busybox:TestPsImageIDAfterUpdate-updated"
runCmd := exec.Command(dockerBinary, "tag", "busybox:latest", originalImageName) icmd.RunCommand(dockerBinary, "tag", "busybox:latest", originalImageName).Assert(c, icmd.Success)
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, checker.IsNil)
originalImageID, err := getIDByName(originalImageName) originalImageID, err := getIDByName(originalImageName)
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
runCmd = exec.Command(dockerBinary, append([]string{"run", "-d", originalImageName}, sleepCommandForDaemonPlatform()...)...) result := icmd.RunCommand(dockerBinary, append([]string{"run", "-d", originalImageName}, sleepCommandForDaemonPlatform()...)...)
out, _, err = runCommandWithOutput(runCmd) result.Assert(c, icmd.Success)
c.Assert(err, checker.IsNil) containerID := strings.TrimSpace(result.Combined())
containerID := strings.TrimSpace(out)
linesOut, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput() result = icmd.RunCommand(dockerBinary, "ps", "--no-trunc")
c.Assert(err, checker.IsNil) result.Assert(c, icmd.Success)
lines := strings.Split(strings.TrimSpace(string(linesOut)), "\n") lines := strings.Split(strings.TrimSpace(string(result.Combined())), "\n")
// skip header // skip header
lines = lines[1:] lines = lines[1:]
c.Assert(len(lines), checker.Equals, 1) c.Assert(len(lines), checker.Equals, 1)
@ -694,18 +691,13 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
c.Assert(f[1], checker.Equals, originalImageName) c.Assert(f[1], checker.Equals, originalImageName)
} }
runCmd = exec.Command(dockerBinary, "commit", containerID, updatedImageName) icmd.RunCommand(dockerBinary, "commit", containerID, updatedImageName).Assert(c, icmd.Success)
out, _, err = runCommandWithOutput(runCmd) icmd.RunCommand(dockerBinary, "tag", updatedImageName, originalImageName).Assert(c, icmd.Success)
c.Assert(err, checker.IsNil)
runCmd = exec.Command(dockerBinary, "tag", updatedImageName, originalImageName) result = icmd.RunCommand(dockerBinary, "ps", "--no-trunc")
out, _, err = runCommandWithOutput(runCmd) result.Assert(c, icmd.Success)
c.Assert(err, checker.IsNil)
linesOut, err = exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput() lines = strings.Split(strings.TrimSpace(string(result.Combined())), "\n")
c.Assert(err, checker.IsNil)
lines = strings.Split(strings.TrimSpace(string(linesOut)), "\n")
// skip header // skip header
lines = lines[1:] lines = lines[1:]
c.Assert(len(lines), checker.Equals, 1) c.Assert(len(lines), checker.Equals, 1)

View File

@ -12,6 +12,7 @@ import (
"github.com/docker/distribution" "github.com/docker/distribution"
"github.com/docker/distribution/digest" "github.com/docker/distribution/digest"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/docker/distribution/manifest" "github.com/docker/distribution/manifest"
"github.com/docker/distribution/manifest/manifestlist" "github.com/docker/distribution/manifest/manifestlist"
"github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/manifest/schema2"
@ -87,8 +88,8 @@ func testConcurrentPullWholeRepo(c *check.C) {
for i := 0; i != numPulls; i++ { for i := 0; i != numPulls; i++ {
go func() { go func() {
_, _, err := runCommandWithOutput(exec.Command(dockerBinary, "pull", "-a", repoName)) result := icmd.RunCommand(dockerBinary, "pull", "-a", repoName)
results <- err results <- result.Error
}() }()
} }
@ -125,8 +126,8 @@ func testConcurrentFailingPull(c *check.C) {
for i := 0; i != numPulls; i++ { for i := 0; i != numPulls; i++ {
go func() { go func() {
_, _, err := runCommandWithOutput(exec.Command(dockerBinary, "pull", repoName+":asdfasdf")) result := icmd.RunCommand(dockerBinary, "pull", repoName+":asdfasdf")
results <- err results <- result.Error
}() }()
} }
@ -175,8 +176,8 @@ func testConcurrentPullMultipleTags(c *check.C) {
for _, repo := range repos { for _, repo := range repos {
go func(repo string) { go func(repo string) {
_, _, err := runCommandWithOutput(exec.Command(dockerBinary, "pull", repo)) result := icmd.RunCommand(dockerBinary, "pull", repo)
results <- err results <- result.Error
}(repo) }(repo)
} }

View File

@ -14,6 +14,7 @@ import (
"time" "time"
"github.com/docker/distribution/reference" "github.com/docker/distribution/reference"
icmd "github.com/docker/docker/pkg/testutil/cmd"
cliconfig "github.com/docker/docker/cli/config" cliconfig "github.com/docker/docker/cli/config"
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil"
@ -135,10 +136,10 @@ func testPushEmptyLayer(c *check.C) {
c.Assert(err, check.IsNil, check.Commentf("Could not open test tarball")) c.Assert(err, check.IsNil, check.Commentf("Could not open test tarball"))
defer freader.Close() defer freader.Close()
importCmd := exec.Command(dockerBinary, "import", "-", repoName) icmd.RunCmd(icmd.Cmd{
importCmd.Stdin = freader Command: []string{dockerBinary, "import", "-", repoName},
out, _, err := runCommandWithOutput(importCmd) Stdin: freader,
c.Assert(err, check.IsNil, check.Commentf("import failed: %q", out)) }).Assert(c, icmd.Success)
// Now verify we can push it // Now verify we can push it
out, _, err = dockerCmdWithError("push", repoName) out, _, err = dockerCmdWithError("push", repoName)
@ -177,8 +178,8 @@ func testConcurrentPush(c *check.C) {
for _, repo := range repos { for _, repo := range repos {
go func(repo string) { go func(repo string) {
_, _, err := runCommandWithOutput(exec.Command(dockerBinary, "push", repo)) result := icmd.RunCommand(dockerBinary, "push", repo)
results <- err results <- result.Error
}(repo) }(repo)
} }

View File

@ -6,6 +6,7 @@ import (
"strings" "strings"
"time" "time"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/go-check/check" "github.com/go-check/check"
@ -175,12 +176,11 @@ func (s *DockerSuite) TestRmiTagWithExistingContainers(c *check.C) {
func (s *DockerSuite) TestRmiForceWithExistingContainers(c *check.C) { func (s *DockerSuite) TestRmiForceWithExistingContainers(c *check.C) {
image := "busybox-clone" image := "busybox-clone"
cmd := exec.Command(dockerBinary, "build", "--no-cache", "-t", image, "-") icmd.RunCmd(icmd.Cmd{
cmd.Stdin = strings.NewReader(`FROM busybox Command: []string{dockerBinary, "build", "--no-cache", "-t", image, "-"},
Stdin: strings.NewReader(`FROM busybox
MAINTAINER foo`) MAINTAINER foo`)
}).Assert(c, icmd.Success)
out, _, err := runCommandWithOutput(cmd)
c.Assert(err, checker.IsNil, check.Commentf("Could not build %s: %s", image, out))
dockerCmd(c, "run", "--name", "test-force-rmi", image, "/bin/true") dockerCmd(c, "run", "--name", "test-force-rmi", image, "/bin/true")

View File

@ -819,21 +819,21 @@ func (s *DockerSuite) TestRunEnvironment(c *check.C) {
// TODO Windows: Environment handling is different between Linux and // TODO Windows: Environment handling is different between Linux and
// Windows and this test relies currently on unix functionality. // Windows and this test relies currently on unix functionality.
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
cmd := exec.Command(dockerBinary, "run", "-h", "testing", "-e=FALSE=true", "-e=TRUE", "-e=TRICKY", "-e=HOME=", "busybox", "env") result := icmd.RunCmd(icmd.Cmd{
cmd.Env = append(os.Environ(), Command: []string{dockerBinary, "run", "-h", "testing", "-e=FALSE=true", "-e=TRUE", "-e=TRICKY", "-e=HOME=", "busybox", "env"},
"TRUE=false", Env: append(os.Environ(),
"TRICKY=tri\ncky\n", "TRUE=false",
) "TRICKY=tri\ncky\n",
),
})
result.Assert(c, icmd.Success)
out, _, err := runCommandWithOutput(cmd) actualEnv := strings.Split(strings.TrimSpace(result.Combined()), "\n")
if err != nil {
c.Fatal(err, out)
}
actualEnv := strings.Split(strings.TrimSpace(out), "\n")
sort.Strings(actualEnv) sort.Strings(actualEnv)
goodEnv := []string{ goodEnv := []string{
// The first two should not be tested here, those are "inherent" environment variable. This test validates
// the -e behavior, not the default environment variable (that could be subject to change)
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"HOSTNAME=testing", "HOSTNAME=testing",
"FALSE=true", "FALSE=true",
@ -863,15 +863,13 @@ func (s *DockerSuite) TestRunEnvironmentErase(c *check.C) {
// not set in our local env that they're removed (if present) in // not set in our local env that they're removed (if present) in
// the container // the container
cmd := exec.Command(dockerBinary, "run", "-e", "FOO", "-e", "HOSTNAME", "busybox", "env") result := icmd.RunCmd(icmd.Cmd{
cmd.Env = appendBaseEnv(true) Command: []string{dockerBinary, "run", "-e", "FOO", "-e", "HOSTNAME", "busybox", "env"},
Env: appendBaseEnd(true),
})
result.Assert(c, icmd.Success)
out, _, err := runCommandWithOutput(cmd) actualEnv := strings.Split(strings.TrimSpace(result.Combined()), "\n")
if err != nil {
c.Fatal(err, out)
}
actualEnv := strings.Split(strings.TrimSpace(out), "\n")
sort.Strings(actualEnv) sort.Strings(actualEnv)
goodEnv := []string{ goodEnv := []string{
@ -897,15 +895,13 @@ func (s *DockerSuite) TestRunEnvironmentOverride(c *check.C) {
// Test to make sure that when we use -e on env vars that are // Test to make sure that when we use -e on env vars that are
// already in the env that we're overriding them // already in the env that we're overriding them
cmd := exec.Command(dockerBinary, "run", "-e", "HOSTNAME", "-e", "HOME=/root2", "busybox", "env") result := icmd.RunCmd(icmd.Cmd{
cmd.Env = appendBaseEnv(true, "HOSTNAME=bar") Command: []string{dockerBinary, "run", "-e", "HOSTNAME", "-e", "HOME=/root2", "busybox", "env"},
Env: appendBaseEnv(true, "HOSTNAME=bar"),
})
result.Assert(c, icmd.Success)
out, _, err := runCommandWithOutput(cmd) actualEnv := strings.Split(strings.TrimSpace(result.Combined()), "\n")
if err != nil {
c.Fatal(err, out)
}
actualEnv := strings.Split(strings.TrimSpace(out), "\n")
sort.Strings(actualEnv) sort.Strings(actualEnv)
goodEnv := []string{ goodEnv := []string{
@ -2111,12 +2107,9 @@ func (s *DockerSuite) TestRunDeallocatePortOnMissingIptablesRule(c *check.C) {
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
ip := inspectField(c, id, "NetworkSettings.Networks.bridge.IPAddress") ip := inspectField(c, id, "NetworkSettings.Networks.bridge.IPAddress")
iptCmd := exec.Command("iptables", "-D", "DOCKER", "-d", fmt.Sprintf("%s/32", ip), icmd.RunCommand("iptables", "-D", "DOCKER", "-d", fmt.Sprintf("%s/32", ip),
"!", "-i", "docker0", "-o", "docker0", "-p", "tcp", "-m", "tcp", "--dport", "23", "-j", "ACCEPT") "!", "-i", "docker0", "-o", "docker0", "-p", "tcp", "-m", "tcp", "--dport", "23", "-j", "ACCEPT").Assert(c, icmd.Success)
out, _, err := runCommandWithOutput(iptCmd)
if err != nil {
c.Fatal(err, out)
}
if err := deleteContainer(false, id); err != nil { if err := deleteContainer(false, id); err != nil {
c.Fatal(err) c.Fatal(err)
} }
@ -4012,23 +4005,19 @@ func (s *DockerSuite) TestRunWrongCpusetMemsFlagValue(c *check.C) {
// TestRunNonExecutableCmd checks that 'docker run busybox foo' exits with error code 127' // TestRunNonExecutableCmd checks that 'docker run busybox foo' exits with error code 127'
func (s *DockerSuite) TestRunNonExecutableCmd(c *check.C) { func (s *DockerSuite) TestRunNonExecutableCmd(c *check.C) {
name := "testNonExecutableCmd" name := "testNonExecutableCmd"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "foo") icmd.RunCommand(dockerBinary, "run", "--name", name, "busybox", "foo").Assert(c, icmd.Expected{
_, exit, _ := runCommandWithOutput(runCmd) ExitCode: 127,
stateExitCode := findContainerExitCode(c, name) Error: "exit status 127",
if !(exit == 127 && strings.Contains(stateExitCode, "127")) { })
c.Fatalf("Run non-executable command should have errored with exit code 127, but we got exit: %d, State.ExitCode: %s", exit, stateExitCode)
}
} }
// TestRunNonExistingCmd checks that 'docker run busybox /bin/foo' exits with code 127. // TestRunNonExistingCmd checks that 'docker run busybox /bin/foo' exits with code 127.
func (s *DockerSuite) TestRunNonExistingCmd(c *check.C) { func (s *DockerSuite) TestRunNonExistingCmd(c *check.C) {
name := "testNonExistingCmd" name := "testNonExistingCmd"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "/bin/foo") icmd.RunCommand(dockerBinary, "run", "--name", name, "busybox", "/bin/foo").Assert(c, icmd.Expected{
_, exit, _ := runCommandWithOutput(runCmd) ExitCode: 127,
stateExitCode := findContainerExitCode(c, name) Error: "exit status 127",
if !(exit == 127 && strings.Contains(stateExitCode, "127")) { })
c.Fatalf("Run non-existing command should have errored with exit code 127, but we got exit: %d, State.ExitCode: %s", exit, stateExitCode)
}
} }
// TestCmdCannotBeInvoked checks that 'docker run busybox /etc' exits with 126, or // TestCmdCannotBeInvoked checks that 'docker run busybox /etc' exits with 126, or
@ -4040,30 +4029,28 @@ func (s *DockerSuite) TestCmdCannotBeInvoked(c *check.C) {
expected = 127 expected = 127
} }
name := "testCmdCannotBeInvoked" name := "testCmdCannotBeInvoked"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "/etc") icmd.RunCommand(dockerBinary, "run", "--name", name, "busybox", "/etc").Assert(c, icmd.Expected{
_, exit, _ := runCommandWithOutput(runCmd) ExitCode: expected,
stateExitCode := findContainerExitCode(c, name) Error: fmt.Sprintf("exit status %d", expected),
if !(exit == expected && strings.Contains(stateExitCode, strconv.Itoa(expected))) { })
c.Fatalf("Run cmd that cannot be invoked should have errored with code %d, but we got exit: %d, State.ExitCode: %s", expected, exit, stateExitCode)
}
} }
// TestRunNonExistingImage checks that 'docker run foo' exits with error msg 125 and contains 'Unable to find image' // TestRunNonExistingImage checks that 'docker run foo' exits with error msg 125 and contains 'Unable to find image'
// FIXME(vdemeester) should be a unit test
func (s *DockerSuite) TestRunNonExistingImage(c *check.C) { func (s *DockerSuite) TestRunNonExistingImage(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "foo") icmd.RunCommand(dockerBinary, "run", "foo").Assert(c, icmd.Expected{
out, exit, err := runCommandWithOutput(runCmd) ExitCode: 125,
if !(err != nil && exit == 125 && strings.Contains(out, "Unable to find image")) { Err: "Unable to find image",
c.Fatalf("Run non-existing image should have errored with 'Unable to find image' code 125, but we got out: %s, exit: %d, err: %s", out, exit, err) })
}
} }
// TestDockerFails checks that 'docker run -foo busybox' exits with 125 to signal docker run failed // TestDockerFails checks that 'docker run -foo busybox' exits with 125 to signal docker run failed
// FIXME(vdemeester) should be a unit test
func (s *DockerSuite) TestDockerFails(c *check.C) { func (s *DockerSuite) TestDockerFails(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-foo", "busybox") icmd.RunCommand(dockerBinary, "run", "-foo", "busybox").Assert(c, icmd.Expected{
out, exit, err := runCommandWithOutput(runCmd) ExitCode: 125,
if !(err != nil && exit == 125) { Error: "exit status 125",
c.Fatalf("Docker run with flag not defined should exit with 125, but we got out: %s, exit: %d, err: %s", out, exit, err) })
}
} }
// TestRunInvalidReference invokes docker run with a bad reference. // TestRunInvalidReference invokes docker run with a bad reference.
@ -4490,9 +4477,9 @@ func (s *DockerSuite) TestRunServicingContainer(c *check.C) {
err := waitExited(containerID, 60*time.Second) err := waitExited(containerID, 60*time.Second)
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
cmd := exec.Command("powershell", "echo", `(Get-WinEvent -ProviderName "Microsoft-Windows-Hyper-V-Compute" -FilterXPath 'Event[System[EventID=2010]]' -MaxEvents 1).Message`) result := icmd.RunCommand("powershell", "echo", `(Get-WinEvent -ProviderName "Microsoft-Windows-Hyper-V-Compute" -FilterXPath 'Event[System[EventID=2010]]' -MaxEvents 1).Message`)
out2, _, err := runCommandWithOutput(cmd) result.Assert(c, icmd.Success)
c.Assert(err, checker.IsNil) out2 := result.Combined()
c.Assert(out2, checker.Contains, `"Servicing":true`, check.Commentf("Servicing container does not appear to have been started: %s", out2)) c.Assert(out2, checker.Contains, `"Servicing":true`, check.Commentf("Servicing container does not appear to have been started: %s", out2))
c.Assert(out2, checker.Contains, `Windows Container (Servicing)`, check.Commentf("Didn't find 'Windows Container (Servicing): %s", out2)) c.Assert(out2, checker.Contains, `Windows Container (Servicing)`, check.Commentf("Didn't find 'Windows Container (Servicing): %s", out2))
c.Assert(out2, checker.Contains, containerID+"_servicing", check.Commentf("Didn't find '%s_servicing': %s", containerID+"_servicing", out2)) c.Assert(out2, checker.Contains, containerID+"_servicing", check.Commentf("Didn't find '%s_servicing': %s", containerID+"_servicing", out2))

View File

@ -21,6 +21,7 @@ import (
"github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/mount"
"github.com/docker/docker/pkg/parsers" "github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/pkg/sysinfo" "github.com/docker/docker/pkg/sysinfo"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/go-check/check" "github.com/go-check/check"
"github.com/kr/pty" "github.com/kr/pty"
) )
@ -884,7 +885,6 @@ func (s *DockerSuite) TestRunTmpfsMountsWithOptions(c *check.C) {
} }
func (s *DockerSuite) TestRunSysctls(c *check.C) { func (s *DockerSuite) TestRunSysctls(c *check.C) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
var err error var err error
@ -907,11 +907,11 @@ func (s *DockerSuite) TestRunSysctls(c *check.C) {
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
c.Assert(sysctls["net.ipv4.ip_forward"], check.Equals, "0") c.Assert(sysctls["net.ipv4.ip_forward"], check.Equals, "0")
runCmd := exec.Command(dockerBinary, "run", "--sysctl", "kernel.foobar=1", "--name", "test2", "busybox", "cat", "/proc/sys/kernel/foobar") icmd.RunCommand(dockerBinary, "run", "--sysctl", "kernel.foobar=1", "--name", "test2",
out, _, _ = runCommandWithOutput(runCmd) "busybox", "cat", "/proc/sys/kernel/foobar").Assert(c, icmd.Expected{
if !strings.Contains(out, "invalid argument") { ExitCode: 1,
c.Fatalf("expected --sysctl to fail, got %s", out) Err: "invalid argument",
} })
} }
// TestRunSeccompProfileDenyUnshare checks that 'docker run --security-opt seccomp=/tmp/profile.json debian:jessie unshare' exits with operation not permitted. // TestRunSeccompProfileDenyUnshare checks that 'docker run --security-opt seccomp=/tmp/profile.json debian:jessie unshare' exits with operation not permitted.
@ -935,11 +935,12 @@ func (s *DockerSuite) TestRunSeccompProfileDenyUnshare(c *check.C) {
if _, err := tmpFile.Write([]byte(jsonData)); err != nil { if _, err := tmpFile.Write([]byte(jsonData)); err != nil {
c.Fatal(err) c.Fatal(err)
} }
runCmd := exec.Command(dockerBinary, "run", "--security-opt", "apparmor=unconfined", "--security-opt", "seccomp="+tmpFile.Name(), "debian:jessie", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc") icmd.RunCommand(dockerBinary, "run", "--security-opt", "apparmor=unconfined",
out, _, _ := runCommandWithOutput(runCmd) "--security-opt", "seccomp="+tmpFile.Name(),
if !strings.Contains(out, "Operation not permitted") { "debian:jessie", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc").Assert(c, icmd.Expected{
c.Fatalf("expected unshare with seccomp profile denied to fail, got %s", out) ExitCode: 1,
} Err: "Operation not permitted",
})
} }
// TestRunSeccompProfileDenyChmod checks that 'docker run --security-opt seccomp=/tmp/profile.json busybox chmod 400 /etc/hostname' exits with operation not permitted. // TestRunSeccompProfileDenyChmod checks that 'docker run --security-opt seccomp=/tmp/profile.json busybox chmod 400 /etc/hostname' exits with operation not permitted.
@ -969,11 +970,11 @@ func (s *DockerSuite) TestRunSeccompProfileDenyChmod(c *check.C) {
if _, err := tmpFile.Write([]byte(jsonData)); err != nil { if _, err := tmpFile.Write([]byte(jsonData)); err != nil {
c.Fatal(err) c.Fatal(err)
} }
runCmd := exec.Command(dockerBinary, "run", "--security-opt", "seccomp="+tmpFile.Name(), "busybox", "chmod", "400", "/etc/hostname") icmd.RunCommand(dockerBinary, "run", "--security-opt", "seccomp="+tmpFile.Name(),
out, _, _ := runCommandWithOutput(runCmd) "busybox", "chmod", "400", "/etc/hostname").Assert(c, icmd.Expected{
if !strings.Contains(out, "Operation not permitted") { ExitCode: 1,
c.Fatalf("expected chmod with seccomp profile denied to fail, got %s", out) Err: "Operation not permitted",
} })
} }
// TestRunSeccompProfileDenyUnshareUserns checks that 'docker run debian:jessie unshare --map-root-user --user sh -c whoami' with a specific profile to // TestRunSeccompProfileDenyUnshareUserns checks that 'docker run debian:jessie unshare --map-root-user --user sh -c whoami' with a specific profile to
@ -1006,11 +1007,12 @@ func (s *DockerSuite) TestRunSeccompProfileDenyUnshareUserns(c *check.C) {
if _, err := tmpFile.Write([]byte(jsonData)); err != nil { if _, err := tmpFile.Write([]byte(jsonData)); err != nil {
c.Fatal(err) c.Fatal(err)
} }
runCmd := exec.Command(dockerBinary, "run", "--security-opt", "apparmor=unconfined", "--security-opt", "seccomp="+tmpFile.Name(), "debian:jessie", "unshare", "--map-root-user", "--user", "sh", "-c", "whoami") icmd.RunCommand(dockerBinary, "run",
out, _, _ := runCommandWithOutput(runCmd) "--security-opt", "apparmor=unconfined", "--security-opt", "seccomp="+tmpFile.Name(),
if !strings.Contains(out, "Operation not permitted") { "debian:jessie", "unshare", "--map-root-user", "--user", "sh", "-c", "whoami").Assert(c, icmd.Expected{
c.Fatalf("expected unshare userns with seccomp profile denied to fail, got %s", out) ExitCode: 1,
} Err: "Operation not permitted",
})
} }
// TestRunSeccompProfileDenyCloneUserns checks that 'docker run syscall-test' // TestRunSeccompProfileDenyCloneUserns checks that 'docker run syscall-test'
@ -1019,11 +1021,10 @@ func (s *DockerSuite) TestRunSeccompProfileDenyCloneUserns(c *check.C) {
testRequires(c, SameHostDaemon, seccompEnabled) testRequires(c, SameHostDaemon, seccompEnabled)
ensureSyscallTest(c) ensureSyscallTest(c)
runCmd := exec.Command(dockerBinary, "run", "syscall-test", "userns-test", "id") icmd.RunCommand(dockerBinary, "run", "syscall-test", "userns-test", "id").Assert(c, icmd.Expected{
out, _, err := runCommandWithOutput(runCmd) ExitCode: 1,
if err == nil || !strings.Contains(out, "clone failed: Operation not permitted") { Err: "clone failed: Operation not permitted",
c.Fatalf("expected clone userns with default seccomp profile denied to fail, got %s: %v", out, err) })
}
} }
// TestRunSeccompUnconfinedCloneUserns checks that // TestRunSeccompUnconfinedCloneUserns checks that
@ -1033,10 +1034,10 @@ func (s *DockerSuite) TestRunSeccompUnconfinedCloneUserns(c *check.C) {
ensureSyscallTest(c) ensureSyscallTest(c)
// make sure running w privileged is ok // make sure running w privileged is ok
runCmd := exec.Command(dockerBinary, "run", "--security-opt", "seccomp=unconfined", "syscall-test", "userns-test", "id") icmd.RunCommand(dockerBinary, "run", "--security-opt", "seccomp=unconfined",
if out, _, err := runCommandWithOutput(runCmd); err != nil || !strings.Contains(out, "nobody") { "syscall-test", "userns-test", "id").Assert(c, icmd.Expected{
c.Fatalf("expected clone userns with --security-opt seccomp=unconfined to succeed, got %s: %v", out, err) Out: "nobody",
} })
} }
// TestRunSeccompAllowPrivCloneUserns checks that 'docker run --privileged syscall-test' // TestRunSeccompAllowPrivCloneUserns checks that 'docker run --privileged syscall-test'
@ -1046,10 +1047,9 @@ func (s *DockerSuite) TestRunSeccompAllowPrivCloneUserns(c *check.C) {
ensureSyscallTest(c) ensureSyscallTest(c)
// make sure running w privileged is ok // make sure running w privileged is ok
runCmd := exec.Command(dockerBinary, "run", "--privileged", "syscall-test", "userns-test", "id") icmd.RunCommand(dockerBinary, "run", "--privileged", "syscall-test", "userns-test", "id").Assert(c, icmd.Expected{
if out, _, err := runCommandWithOutput(runCmd); err != nil || !strings.Contains(out, "nobody") { Out: "nobody",
c.Fatalf("expected clone userns with --privileged to succeed, got %s: %v", out, err) })
}
} }
// TestRunSeccompProfileAllow32Bit checks that 32 bit code can run on x86_64 // TestRunSeccompProfileAllow32Bit checks that 32 bit code can run on x86_64
@ -1058,10 +1058,7 @@ func (s *DockerSuite) TestRunSeccompProfileAllow32Bit(c *check.C) {
testRequires(c, SameHostDaemon, seccompEnabled, IsAmd64) testRequires(c, SameHostDaemon, seccompEnabled, IsAmd64)
ensureSyscallTest(c) ensureSyscallTest(c)
runCmd := exec.Command(dockerBinary, "run", "syscall-test", "exit32-test", "id") icmd.RunCommand(dockerBinary, "run", "syscall-test", "exit32-test", "id").Assert(c, icmd.Success)
if out, _, err := runCommandWithOutput(runCmd); err != nil {
c.Fatalf("expected to be able to run 32 bit code, got %s: %v", out, err)
}
} }
// TestRunSeccompAllowSetrlimit checks that 'docker run debian:jessie ulimit -v 1048510' succeeds. // TestRunSeccompAllowSetrlimit checks that 'docker run debian:jessie ulimit -v 1048510' succeeds.
@ -1069,10 +1066,7 @@ func (s *DockerSuite) TestRunSeccompAllowSetrlimit(c *check.C) {
testRequires(c, SameHostDaemon, seccompEnabled) testRequires(c, SameHostDaemon, seccompEnabled)
// ulimit uses setrlimit, so we want to make sure we don't break it // ulimit uses setrlimit, so we want to make sure we don't break it
runCmd := exec.Command(dockerBinary, "run", "debian:jessie", "bash", "-c", "ulimit -v 1048510") icmd.RunCommand(dockerBinary, "run", "debian:jessie", "bash", "-c", "ulimit -v 1048510").Assert(c, icmd.Success)
if out, _, err := runCommandWithOutput(runCmd); err != nil {
c.Fatalf("expected ulimit with seccomp to succeed, got %s: %v", out, err)
}
} }
func (s *DockerSuite) TestRunSeccompDefaultProfileAcct(c *check.C) { func (s *DockerSuite) TestRunSeccompDefaultProfileAcct(c *check.C) {
@ -1147,10 +1141,10 @@ func (s *DockerSuite) TestRunNoNewPrivSetuid(c *check.C) {
ensureNNPTest(c) ensureNNPTest(c)
// test that running a setuid binary results in no effective uid transition // test that running a setuid binary results in no effective uid transition
runCmd := exec.Command(dockerBinary, "run", "--security-opt", "no-new-privileges", "--user", "1000", "nnp-test", "/usr/bin/nnp-test") icmd.RunCommand(dockerBinary, "run", "--security-opt", "no-new-privileges", "--user", "1000",
if out, _, err := runCommandWithOutput(runCmd); err != nil || !strings.Contains(out, "EUID=1000") { "nnp-test", "/usr/bin/nnp-test").Assert(c, icmd.Expected{
c.Fatalf("expected output to contain EUID=1000, got %s: %v", out, err) Out: "EUID=1000",
} })
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChown(c *check.C) { func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChown(c *check.C) {
@ -1158,19 +1152,17 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChown(c *check.C) {
ensureSyscallTest(c) ensureSyscallTest(c)
// test that a root user has default capability CAP_CHOWN // test that a root user has default capability CAP_CHOWN
runCmd := exec.Command(dockerBinary, "run", "busybox", "chown", "100", "/tmp") dockerCmd("run", "busybox", "chown", "100", "/tmp")
_, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
// test that non root user does not have default capability CAP_CHOWN // test that non root user does not have default capability CAP_CHOWN
runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "busybox", "chown", "100", "/tmp") icmd.RunCommand(dockerBinary, "run", "--user", "1000:1000", "busybox", "chown", "100", "/tmp").Assert(c, icmd.Expected{
out, _, err := runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Operation not permitted",
c.Assert(out, checker.Contains, "Operation not permitted") })
// test that root user can drop default capability CAP_CHOWN // test that root user can drop default capability CAP_CHOWN
runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "chown", "busybox", "chown", "100", "/tmp") icmd.RunCommand(dockerBinary, "run", "--cap-drop", "chown", "busybox", "chown", "100", "/tmp").Assert(c, icmd.Expected{
out, _, err = runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Operation not permitted",
c.Assert(out, checker.Contains, "Operation not permitted") })
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesDacOverride(c *check.C) { func (s *DockerSuite) TestUserNoEffectiveCapabilitiesDacOverride(c *check.C) {
@ -1178,15 +1170,12 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesDacOverride(c *check.C) {
ensureSyscallTest(c) ensureSyscallTest(c)
// test that a root user has default capability CAP_DAC_OVERRIDE // test that a root user has default capability CAP_DAC_OVERRIDE
runCmd := exec.Command(dockerBinary, "run", "busybox", "sh", "-c", "echo test > /etc/passwd") dockerCmd("run", "busybox", "sh", "-c", "echo test > /etc/passwd")
_, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
// test that non root user does not have default capability CAP_DAC_OVERRIDE // test that non root user does not have default capability CAP_DAC_OVERRIDE
runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "busybox", "sh", "-c", "echo test > /etc/passwd") icmd.RunCommand(dockerBinary, "run", "--user", "1000:1000", "busybox", "sh", "-c", "echo test > /etc/passwd").Assert(c, icmd.Expected{
out, _, err := runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Permission denied",
c.Assert(out, checker.Contains, "Permission denied") })
// TODO test that root user can drop default capability CAP_DAC_OVERRIDE
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesFowner(c *check.C) { func (s *DockerSuite) TestUserNoEffectiveCapabilitiesFowner(c *check.C) {
@ -1194,14 +1183,12 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesFowner(c *check.C) {
ensureSyscallTest(c) ensureSyscallTest(c)
// test that a root user has default capability CAP_FOWNER // test that a root user has default capability CAP_FOWNER
runCmd := exec.Command(dockerBinary, "run", "busybox", "chmod", "777", "/etc/passwd") dockerCmd("run", "busybox", "chmod", "777", "/etc/passwd")
_, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
// test that non root user does not have default capability CAP_FOWNER // test that non root user does not have default capability CAP_FOWNER
runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "busybox", "chmod", "777", "/etc/passwd") icmd.RunCommand(dockerBinary, "run", "--user", "1000:1000", "busybox", "chmod", "777", "/etc/passwd").Assert(c, icmd.Expected{
out, _, err := runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Operation not permitted",
c.Assert(out, checker.Contains, "Operation not permitted") })
// TODO test that root user can drop default capability CAP_FOWNER // TODO test that root user can drop default capability CAP_FOWNER
} }
@ -1212,19 +1199,17 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetuid(c *check.C) {
ensureSyscallTest(c) ensureSyscallTest(c)
// test that a root user has default capability CAP_SETUID // test that a root user has default capability CAP_SETUID
runCmd := exec.Command(dockerBinary, "run", "syscall-test", "setuid-test") dockerCmd("run", "syscall-test", "setuid-test")
_, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
// test that non root user does not have default capability CAP_SETUID // test that non root user does not have default capability CAP_SETUID
runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "syscall-test", "setuid-test") icmd.RunCommand(dockerBinary, "run", "--user", "1000:1000", "syscall-test", "setuid-test").Assert(c, icmd.Expected{
out, _, err := runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Operation not permitted",
c.Assert(out, checker.Contains, "Operation not permitted") })
// test that root user can drop default capability CAP_SETUID // test that root user can drop default capability CAP_SETUID
runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "setuid", "syscall-test", "setuid-test") icmd.RunCommand(dockerBinary, "run", "--cap-drop", "setuid", "syscall-test", "setuid-test").Assert(c, icmd.Expected{
out, _, err = runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Operation not permitted",
c.Assert(out, checker.Contains, "Operation not permitted") })
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetgid(c *check.C) { func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetgid(c *check.C) {
@ -1232,19 +1217,17 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetgid(c *check.C) {
ensureSyscallTest(c) ensureSyscallTest(c)
// test that a root user has default capability CAP_SETGID // test that a root user has default capability CAP_SETGID
runCmd := exec.Command(dockerBinary, "run", "syscall-test", "setgid-test") dockerCmd("run", "syscall-test", "setgid-test")
_, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
// test that non root user does not have default capability CAP_SETGID // test that non root user does not have default capability CAP_SETGID
runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "syscall-test", "setgid-test") icmd.RunCommand(dockerBinary, "run", "--user", "1000:1000", "syscall-test", "setgid-test").Assert(c, icmd.Expected{
out, _, err := runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Operation not permitted",
c.Assert(out, checker.Contains, "Operation not permitted") })
// test that root user can drop default capability CAP_SETGID // test that root user can drop default capability CAP_SETGID
runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "setgid", "syscall-test", "setgid-test") icmd.RunCommand(dockerBinary, "run", "--cap-drop", "setgid", "syscall-test", "setgid-test").Assert(c, icmd.Expected{
out, _, err = runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Operation not permitted",
c.Assert(out, checker.Contains, "Operation not permitted") })
} }
// TODO CAP_SETPCAP // TODO CAP_SETPCAP
@ -1254,19 +1237,17 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetBindService(c *check.C)
ensureSyscallTest(c) ensureSyscallTest(c)
// test that a root user has default capability CAP_NET_BIND_SERVICE // test that a root user has default capability CAP_NET_BIND_SERVICE
runCmd := exec.Command(dockerBinary, "run", "syscall-test", "socket-test") dockerCmd("run", "syscall-test", "socket-test")
_, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
// test that non root user does not have default capability CAP_NET_BIND_SERVICE // test that non root user does not have default capability CAP_NET_BIND_SERVICE
runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "syscall-test", "socket-test") icmd.RunCommand(dockerBinary, "run", "--user", "1000:1000", "syscall-test", "socket-test").Assert(c, icmd.Expected{
out, _, err := runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Permission denied",
c.Assert(out, checker.Contains, "Permission denied") })
// test that root user can drop default capability CAP_NET_BIND_SERVICE // test that root user can drop default capability CAP_NET_BIND_SERVICE
runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "net_bind_service", "syscall-test", "socket-test") icmd.RunCommand(dockerBinary, "run", "--cap-drop", "net_bind_service", "syscall-test", "socket-test").Assert(c, icmd.Expected{
out, _, err = runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Permission denied",
c.Assert(out, checker.Contains, "Permission denied") })
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetRaw(c *check.C) { func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetRaw(c *check.C) {
@ -1274,19 +1255,17 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetRaw(c *check.C) {
ensureSyscallTest(c) ensureSyscallTest(c)
// test that a root user has default capability CAP_NET_RAW // test that a root user has default capability CAP_NET_RAW
runCmd := exec.Command(dockerBinary, "run", "syscall-test", "raw-test") dockerCmd("run", "syscall-test", "raw-test")
_, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
// test that non root user does not have default capability CAP_NET_RAW // test that non root user does not have default capability CAP_NET_RAW
runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "syscall-test", "raw-test") icmd.RunCommand(dockerBinary, "run", "--user", "1000:1000", "syscall-test", "raw-test").Assert(c, icmd.Expected{
out, _, err := runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Operation not permitted",
c.Assert(out, checker.Contains, "Operation not permitted") })
// test that root user can drop default capability CAP_NET_RAW // test that root user can drop default capability CAP_NET_RAW
runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "net_raw", "syscall-test", "raw-test") icmd.RunCommand(dockerBinary, "run", "--cap-drop", "net_raw", "syscall-test", "raw-test").Assert(c, icmd.Expected{
out, _, err = runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Operation not permitted",
c.Assert(out, checker.Contains, "Operation not permitted") })
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChroot(c *check.C) { func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChroot(c *check.C) {
@ -1294,19 +1273,17 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChroot(c *check.C) {
ensureSyscallTest(c) ensureSyscallTest(c)
// test that a root user has default capability CAP_SYS_CHROOT // test that a root user has default capability CAP_SYS_CHROOT
runCmd := exec.Command(dockerBinary, "run", "busybox", "chroot", "/", "/bin/true") dockerCmd("run", "busybox", "chroot", "/", "/bin/true")
_, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
// test that non root user does not have default capability CAP_SYS_CHROOT // test that non root user does not have default capability CAP_SYS_CHROOT
runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "busybox", "chroot", "/", "/bin/true") icmd.RunCommand(dockerBinary, "run", "--user", "1000:1000", "busybox", "chroot", "/", "/bin/true").Assert(c, icmd.Expected{
out, _, err := runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Operation not permitted",
c.Assert(out, checker.Contains, "Operation not permitted") })
// test that root user can drop default capability CAP_SYS_CHROOT // test that root user can drop default capability CAP_SYS_CHROOT
runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "sys_chroot", "busybox", "chroot", "/", "/bin/true") icmd.RunCommand(dockerBinary, "run", "--cap-drop", "sys_chroot", "busybox", "chroot", "/", "/bin/true").Assert(c, icmd.Expected{
out, _, err = runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Operation not permitted",
c.Assert(out, checker.Contains, "Operation not permitted") })
} }
func (s *DockerSuite) TestUserNoEffectiveCapabilitiesMknod(c *check.C) { func (s *DockerSuite) TestUserNoEffectiveCapabilitiesMknod(c *check.C) {
@ -1314,19 +1291,18 @@ func (s *DockerSuite) TestUserNoEffectiveCapabilitiesMknod(c *check.C) {
ensureSyscallTest(c) ensureSyscallTest(c)
// test that a root user has default capability CAP_MKNOD // test that a root user has default capability CAP_MKNOD
runCmd := exec.Command(dockerBinary, "run", "busybox", "mknod", "/tmp/node", "b", "1", "2") dockerCmd("run", "busybox", "mknod", "/tmp/node", "b", "1", "2")
_, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
// test that non root user does not have default capability CAP_MKNOD // test that non root user does not have default capability CAP_MKNOD
runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "busybox", "mknod", "/tmp/node", "b", "1", "2") // test that root user can drop default capability CAP_SYS_CHROOT
out, _, err := runCommandWithOutput(runCmd) icmd.RunCommand(dockerBinary, "run", "--user", "1000:1000", "busybox", "mknod", "/tmp/node", "b", "1", "2").Assert(c, icmd.Expected{
c.Assert(err, checker.NotNil, check.Commentf(out)) ExitCode: 1,
c.Assert(out, checker.Contains, "Operation not permitted") Err: "Operation not permitted",
})
// test that root user can drop default capability CAP_MKNOD // test that root user can drop default capability CAP_MKNOD
runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "mknod", "busybox", "mknod", "/tmp/node", "b", "1", "2") icmd.RunCommand(dockerBinary, "run", "--cap-drop", "mknod", "busybox", "mknod", "/tmp/node", "b", "1", "2").Assert(c, icmd.Expected{
out, _, err = runCommandWithOutput(runCmd) ExitCode: 1,
c.Assert(err, checker.NotNil, check.Commentf(out)) Err: "Operation not permitted",
c.Assert(out, checker.Contains, "Operation not permitted") })
} }
// TODO CAP_AUDIT_WRITE // TODO CAP_AUDIT_WRITE
@ -1336,14 +1312,16 @@ func (s *DockerSuite) TestRunApparmorProcDirectory(c *check.C) {
testRequires(c, SameHostDaemon, Apparmor) testRequires(c, SameHostDaemon, Apparmor)
// running w seccomp unconfined tests the apparmor profile // running w seccomp unconfined tests the apparmor profile
runCmd := exec.Command(dockerBinary, "run", "--security-opt", "seccomp=unconfined", "busybox", "chmod", "777", "/proc/1/cgroup") result := icmd.RunCommand(dockerBinary, "run", "--security-opt", "seccomp=unconfined", "busybox", "chmod", "777", "/proc/1/cgroup")
if out, _, err := runCommandWithOutput(runCmd); err == nil || !(strings.Contains(out, "Permission denied") || strings.Contains(out, "Operation not permitted")) { result.Assert(c, icmd.Expected{ExitCode: 1})
c.Fatalf("expected chmod 777 /proc/1/cgroup to fail, got %s: %v", out, err) if !(strings.Contains(result.Combined(), "Permission denied") || strings.Contains(result.Combined(), "Operation not permitted")) {
c.Fatalf("expected chmod 777 /proc/1/cgroup to fail, got %s: %v", result.Combined(), err)
} }
runCmd = exec.Command(dockerBinary, "run", "--security-opt", "seccomp=unconfined", "busybox", "chmod", "777", "/proc/1/attr/current") result = icmd.RunCommand(dockerBinary, "run", "--security-opt", "seccomp=unconfined", "busybox", "chmod", "777", "/proc/1/attr/current")
if out, _, err := runCommandWithOutput(runCmd); err == nil || !(strings.Contains(out, "Permission denied") || strings.Contains(out, "Operation not permitted")) { result.Assert(c, icmd.Expected{ExitCode: 1})
c.Fatalf("expected chmod 777 /proc/1/attr/current to fail, got %s: %v", out, err) if !(strings.Contains(result.Combined(), "Permission denied") || strings.Contains(result.Combined(), "Operation not permitted")) {
c.Fatalf("expected chmod 777 /proc/1/attr/current to fail, got %s: %v", result.Combined(), err)
} }
} }

View File

@ -226,11 +226,11 @@ func (s *DockerSuite) TestVolumeCLIRm(c *check.C) {
volumeID := "testing" volumeID := "testing"
dockerCmd(c, "run", "-v", volumeID+":"+prefix+"/foo", "--name=test", "busybox", "sh", "-c", "echo hello > /foo/bar") dockerCmd(c, "run", "-v", volumeID+":"+prefix+"/foo", "--name=test", "busybox", "sh", "-c", "echo hello > /foo/bar")
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "volume", "rm", "testing"))
c.Assert( icmd.RunCommand(dockerBinary, "volume", "rm", "testing").Assert(c, icmd.Expected{
err, ExitCode: 1,
check.Not(check.IsNil), Error: "exit status 1",
check.Commentf("Should not be able to remove volume that is in use by a container\n%s", out)) })
out, _ = dockerCmd(c, "run", "--volumes-from=test", "--name=test2", "busybox", "sh", "-c", "cat /foo/bar") out, _ = dockerCmd(c, "run", "--volumes-from=test", "--name=test2", "busybox", "sh", "-c", "cat /foo/bar")
c.Assert(strings.TrimSpace(out), check.Equals, "hello") c.Assert(strings.TrimSpace(out), check.Equals, "hello")
@ -401,8 +401,7 @@ func (s *DockerSuite) TestVolumeCLIRmForce(c *check.C) {
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
// Mountpoint is in the form of "/var/lib/docker/volumes/.../_data", removing `/_data` // Mountpoint is in the form of "/var/lib/docker/volumes/.../_data", removing `/_data`
path := strings.TrimSuffix(strings.TrimSpace(out), "/_data") path := strings.TrimSuffix(strings.TrimSpace(out), "/_data")
out, _, err := runCommandWithOutput(exec.Command("rm", "-rf", path)) icmd.RunCommand("rm", "-rf", path).Assert(c, icmd.Success)
c.Assert(err, check.IsNil)
dockerCmd(c, "volume", "rm", "-f", "test") dockerCmd(c, "volume", "rm", "-f", "test")
out, _ = dockerCmd(c, "volume", "ls") out, _ = dockerCmd(c, "volume", "ls")

View File

@ -6,6 +6,7 @@ import (
"strings" "strings"
"time" "time"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/checker"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -36,7 +37,7 @@ func (s *DockerSuite) TestWaitBlockedExitZero(c *check.C) {
chWait := make(chan string) chWait := make(chan string)
go func() { go func() {
chWait <- "" chWait <- ""
out, _, _ := runCommandWithOutput(exec.Command(dockerBinary, "wait", containerID)) out := icmd.RunCommand(dockerBinary, "wait", containerID).Combined()
chWait <- out chWait <- out
}() }()

View File

@ -3,7 +3,6 @@
package main package main
import ( import (
"os/exec"
"strings" "strings"
"time" "time"
@ -48,8 +47,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkMacvlanPersistance(c *check.C) {
// master dummy interface 'dm' abbreviation represents 'docker macvlan' // master dummy interface 'dm' abbreviation represents 'docker macvlan'
master := "dm-dummy0" master := "dm-dummy0"
// simulate the master link the vlan tagged subinterface parent link will use // simulate the master link the vlan tagged subinterface parent link will use
out, err := createMasterDummy(c, master) createMasterDummy(c, master)
c.Assert(err, check.IsNil, check.Commentf(out))
// create a network specifying the desired sub-interface name // create a network specifying the desired sub-interface name
dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.60", "dm-persist") dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.60", "dm-persist")
assertNwIsAvailable(c, "dm-persist") assertNwIsAvailable(c, "dm-persist")
@ -67,8 +65,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkIpvlanPersistance(c *check.C) {
// master dummy interface 'di' notation represent 'docker ipvlan' // master dummy interface 'di' notation represent 'docker ipvlan'
master := "di-dummy0" master := "di-dummy0"
// simulate the master link the vlan tagged subinterface parent link will use // simulate the master link the vlan tagged subinterface parent link will use
out, err := createMasterDummy(c, master) createMasterDummy(c, master)
c.Assert(err, check.IsNil, check.Commentf(out))
// create a network specifying the desired sub-interface name // create a network specifying the desired sub-interface name
dockerCmd(c, "network", "create", "--driver=ipvlan", "-o", "parent=di-dummy0.70", "di-persist") dockerCmd(c, "network", "create", "--driver=ipvlan", "-o", "parent=di-dummy0.70", "di-persist")
assertNwIsAvailable(c, "di-persist") assertNwIsAvailable(c, "di-persist")
@ -86,8 +83,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkMacvlanSubIntCreate(c *check.C) {
// master dummy interface 'dm' abbreviation represents 'docker macvlan' // master dummy interface 'dm' abbreviation represents 'docker macvlan'
master := "dm-dummy0" master := "dm-dummy0"
// simulate the master link the vlan tagged subinterface parent link will use // simulate the master link the vlan tagged subinterface parent link will use
out, err := createMasterDummy(c, master) createMasterDummy(c, master)
c.Assert(err, check.IsNil, check.Commentf(out))
// create a network specifying the desired sub-interface name // create a network specifying the desired sub-interface name
dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.50", "dm-subinterface") dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.50", "dm-subinterface")
assertNwIsAvailable(c, "dm-subinterface") assertNwIsAvailable(c, "dm-subinterface")
@ -101,8 +97,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkIpvlanSubIntCreate(c *check.C) {
// master dummy interface 'dm' abbreviation represents 'docker ipvlan' // master dummy interface 'dm' abbreviation represents 'docker ipvlan'
master := "di-dummy0" master := "di-dummy0"
// simulate the master link the vlan tagged subinterface parent link will use // simulate the master link the vlan tagged subinterface parent link will use
out, err := createMasterDummy(c, master) createMasterDummy(c, master)
c.Assert(err, check.IsNil, check.Commentf(out))
// create a network specifying the desired sub-interface name // create a network specifying the desired sub-interface name
dockerCmd(c, "network", "create", "--driver=ipvlan", "-o", "parent=di-dummy0.60", "di-subinterface") dockerCmd(c, "network", "create", "--driver=ipvlan", "-o", "parent=di-dummy0.60", "di-subinterface")
assertNwIsAvailable(c, "di-subinterface") assertNwIsAvailable(c, "di-subinterface")
@ -115,17 +110,15 @@ func (s *DockerNetworkSuite) TestDockerNetworkMacvlanOverlapParent(c *check.C) {
testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
// master dummy interface 'dm' abbreviation represents 'docker macvlan' // master dummy interface 'dm' abbreviation represents 'docker macvlan'
master := "dm-dummy0" master := "dm-dummy0"
out, err := createMasterDummy(c, master) createMasterDummy(c, master)
c.Assert(err, check.IsNil, check.Commentf(out)) createVlanInterface(c, master, "dm-dummy0.40", "40")
out, err = createVlanInterface(c, master, "dm-dummy0.40", "40")
c.Assert(err, check.IsNil, check.Commentf(out))
// create a network using an existing parent interface // create a network using an existing parent interface
dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.40", "dm-subinterface") dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.40", "dm-subinterface")
assertNwIsAvailable(c, "dm-subinterface") assertNwIsAvailable(c, "dm-subinterface")
// attempt to create another network using the same parent iface that should fail // attempt to create another network using the same parent iface that should fail
out, _, err = dockerCmdWithError("network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.40", "dm-parent-net-overlap") out, _, err := dockerCmdWithError("network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.40", "dm-parent-net-overlap")
// verify that the overlap returns an error // verify that the overlap returns an error
c.Assert(err, check.NotNil) c.Assert(err, check.NotNil, check.Commentf(out))
// cleanup the master interface which also collects the slave dev // cleanup the master interface which also collects the slave dev
deleteInterface(c, "dm-dummy0") deleteInterface(c, "dm-dummy0")
} }
@ -135,17 +128,15 @@ func (s *DockerNetworkSuite) TestDockerNetworkIpvlanOverlapParent(c *check.C) {
testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
// master dummy interface 'dm' abbreviation represents 'docker ipvlan' // master dummy interface 'dm' abbreviation represents 'docker ipvlan'
master := "di-dummy0" master := "di-dummy0"
out, err := createMasterDummy(c, master) createMasterDummy(c, master)
c.Assert(err, check.IsNil, check.Commentf(out)) createVlanInterface(c, master, "di-dummy0.30", "30")
out, err = createVlanInterface(c, master, "di-dummy0.30", "30")
c.Assert(err, check.IsNil, check.Commentf(out))
// create a network using an existing parent interface // create a network using an existing parent interface
dockerCmd(c, "network", "create", "--driver=ipvlan", "-o", "parent=di-dummy0.30", "di-subinterface") dockerCmd(c, "network", "create", "--driver=ipvlan", "-o", "parent=di-dummy0.30", "di-subinterface")
assertNwIsAvailable(c, "di-subinterface") assertNwIsAvailable(c, "di-subinterface")
// attempt to create another network using the same parent iface that should fail // attempt to create another network using the same parent iface that should fail
out, _, err = dockerCmdWithError("network", "create", "--driver=ipvlan", "-o", "parent=di-dummy0.30", "di-parent-net-overlap") out, _, err := dockerCmdWithError("network", "create", "--driver=ipvlan", "-o", "parent=di-dummy0.30", "di-parent-net-overlap")
// verify that the overlap returns an error // verify that the overlap returns an error
c.Assert(err, check.NotNil) c.Assert(err, check.NotNil, check.Commentf(out))
// cleanup the master interface which also collects the slave dev // cleanup the master interface which also collects the slave dev
deleteInterface(c, "di-dummy0") deleteInterface(c, "di-dummy0")
} }
@ -488,9 +479,8 @@ func (s *DockerSuite) TestDockerNetworkMacVlanExistingParent(c *check.C) {
// macvlan bridge mode - empty parent interface containers can reach each other internally but not externally // macvlan bridge mode - empty parent interface containers can reach each other internally but not externally
testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
netName := "dm-parent-exists" netName := "dm-parent-exists"
out, err := createMasterDummy(c, "dm-dummy0") createMasterDummy(c, "dm-dummy0")
//out, err := createVlanInterface(c, "dm-parent", "dm-slave", "macvlan", "bridge") //out, err := createVlanInterface(c, "dm-parent", "dm-slave", "macvlan", "bridge")
c.Assert(err, check.IsNil, check.Commentf(out))
// create a network using an existing parent interface // create a network using an existing parent interface
dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0", netName) dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0", netName)
assertNwIsAvailable(c, netName) assertNwIsAvailable(c, netName)
@ -498,20 +488,16 @@ func (s *DockerSuite) TestDockerNetworkMacVlanExistingParent(c *check.C) {
dockerCmd(c, "network", "rm", netName) dockerCmd(c, "network", "rm", netName)
assertNwNotAvailable(c, netName) assertNwNotAvailable(c, netName)
// verify the network delete did not delete the predefined link // verify the network delete did not delete the predefined link
out, err = linkExists(c, "dm-dummy0") linkExists(c, "dm-dummy0")
c.Assert(err, check.IsNil, check.Commentf(out))
deleteInterface(c, "dm-dummy0") deleteInterface(c, "dm-dummy0")
c.Assert(err, check.IsNil, check.Commentf(out))
} }
func (s *DockerSuite) TestDockerNetworkMacVlanSubinterface(c *check.C) { func (s *DockerSuite) TestDockerNetworkMacVlanSubinterface(c *check.C) {
// macvlan bridge mode - empty parent interface containers can reach each other internally but not externally // macvlan bridge mode - empty parent interface containers can reach each other internally but not externally
testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon)
netName := "dm-subinterface" netName := "dm-subinterface"
out, err := createMasterDummy(c, "dm-dummy0") createMasterDummy(c, "dm-dummy0")
c.Assert(err, check.IsNil, check.Commentf(out)) createVlanInterface(c, "dm-dummy0", "dm-dummy0.20", "20")
out, err = createVlanInterface(c, "dm-dummy0", "dm-dummy0.20", "20")
c.Assert(err, check.IsNil, check.Commentf(out))
// create a network using an existing parent interface // create a network using an existing parent interface
dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.20", netName) dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.20", netName)
assertNwIsAvailable(c, netName) assertNwIsAvailable(c, netName)
@ -522,7 +508,7 @@ func (s *DockerSuite) TestDockerNetworkMacVlanSubinterface(c *check.C) {
dockerCmd(c, "run", "-d", "--net=dm-subinterface", "--name=second", "busybox", "top") dockerCmd(c, "run", "-d", "--net=dm-subinterface", "--name=second", "busybox", "top")
c.Assert(waitRun("second"), check.IsNil) c.Assert(waitRun("second"), check.IsNil)
// verify containers can communicate // verify containers can communicate
_, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
// remove the containers // remove the containers
@ -532,56 +518,25 @@ func (s *DockerSuite) TestDockerNetworkMacVlanSubinterface(c *check.C) {
dockerCmd(c, "network", "rm", netName) dockerCmd(c, "network", "rm", netName)
assertNwNotAvailable(c, netName) assertNwNotAvailable(c, netName)
// verify the network delete did not delete the predefined sub-interface // verify the network delete did not delete the predefined sub-interface
out, err = linkExists(c, "dm-dummy0.20") linkExists(c, "dm-dummy0.20")
c.Assert(err, check.IsNil, check.Commentf(out))
// delete the parent interface which also collects the slave // delete the parent interface which also collects the slave
deleteInterface(c, "dm-dummy0") deleteInterface(c, "dm-dummy0")
c.Assert(err, check.IsNil, check.Commentf(out))
} }
func createMasterDummy(c *check.C, master string) (string, error) { func createMasterDummy(c *check.C, master string) {
// ip link add <dummy_name> type dummy // ip link add <dummy_name> type dummy
args := []string{"link", "add", master, "type", "dummy"} icmd.RunCommand("ip", "link", "add", master, "type", "dummy").Assert(c, icmd.Success)
ipLinkCmd := exec.Command("ip", args...) icmd.RunCommand("ip", "link", "set", master, "up").Assert(c, icmd.Success)
out, _, err := runCommandWithOutput(ipLinkCmd)
if err != nil {
return out, err
}
// ip link set dummy_name up
args = []string{"link", "set", master, "up"}
ipLinkCmd = exec.Command("ip", args...)
out, _, err = runCommandWithOutput(ipLinkCmd)
if err != nil {
return out, err
}
return out, err
} }
func createVlanInterface(c *check.C, master, slave, id string) (string, error) { func createVlanInterface(c *check.C, master, slave, id string) {
// ip link add link <master> name <master>.<VID> type vlan id <VID> // ip link add link <master> name <master>.<VID> type vlan id <VID>
args := []string{"link", "add", "link", master, "name", slave, "type", "vlan", "id", id} icmd.RunCommand("ip", "link", "add", "link", master, "name", slave, "type", "vlan", "id", id).Assert(c, icmd.Success)
ipLinkCmd := exec.Command("ip", args...)
out, _, err := runCommandWithOutput(ipLinkCmd)
if err != nil {
return out, err
}
// ip link set <sub_interface_name> up // ip link set <sub_interface_name> up
args = []string{"link", "set", slave, "up"} icmd.RunCommand("ip", "link", "set", slave, "up").Assert(c, icmd.Success)
ipLinkCmd = exec.Command("ip", args...)
out, _, err = runCommandWithOutput(ipLinkCmd)
if err != nil {
return out, err
}
return out, err
} }
func linkExists(c *check.C, master string) (string, error) { func linkExists(c *check.C, master string) {
// verify the specified link exists, ip link show <link_name> // verify the specified link exists, ip link show <link_name>
args := []string{"link", "show", master} icmd.RunCommand("ip", "link", "show", master).Assert(c, icmd.Success)
ipLinkCmd := exec.Command("ip", args...)
out, _, err := runCommandWithOutput(ipLinkCmd)
if err != nil {
return out, err
}
return out, err
} }

View File

@ -818,10 +818,12 @@ func buildImageFromContextWithOut(name string, ctx *FakeContext, useCache bool,
} }
args = append(args, buildFlags...) args = append(args, buildFlags...)
args = append(args, ".") args = append(args, ".")
buildCmd := exec.Command(dockerBinary, args...) result := icmd.RunCmd(icmd.Cmd{
buildCmd.Dir = ctx.Dir Command: append([]string{dockerBinary}, args...),
out, exitCode, err := runCommandWithOutput(buildCmd) Dir: ctx.Dir,
if err != nil || exitCode != 0 { })
out := result.Combined()
if result.Error != nil || result.ExitCode != 0 {
return "", "", fmt.Errorf("failed to build the image: %s", out) return "", "", fmt.Errorf("failed to build the image: %s", out)
} }
id, err := getIDByName(name) id, err := getIDByName(name)