Signed-off-by: Hu Keping <hukeping@huawei.com>
| ... | ... |
@@ -1,7 +1,6 @@ |
| 1 | 1 |
package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "os/exec" |
|
| 5 | 4 |
"strings" |
| 6 | 5 |
|
| 7 | 6 |
"github.com/docker/docker/pkg/stringid" |
| ... | ... |
@@ -9,28 +8,14 @@ import ( |
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 | 11 |
func (s *DockerSuite) TestRenameStoppedContainer(c *check.C) {
|
| 12 |
- runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh") |
|
| 13 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 14 |
- if err != nil {
|
|
| 15 |
- c.Fatalf(out, err) |
|
| 16 |
- } |
|
| 12 |
+ out, _ := dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", "sh") |
|
| 17 | 13 |
|
| 18 | 14 |
cleanedContainerID := strings.TrimSpace(out) |
| 19 |
- |
|
| 20 |
- runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID) |
|
| 21 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 22 |
- if err != nil {
|
|
| 23 |
- c.Fatalf(out, err) |
|
| 24 |
- } |
|
| 15 |
+ dockerCmd(c, "wait", cleanedContainerID) |
|
| 25 | 16 |
|
| 26 | 17 |
name, err := inspectField(cleanedContainerID, "Name") |
| 27 |
- |
|
| 28 | 18 |
newName := "new_name" + stringid.GenerateRandomID() |
| 29 |
- runCmd = exec.Command(dockerBinary, "rename", "first_name", newName) |
|
| 30 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 31 |
- if err != nil {
|
|
| 32 |
- c.Fatalf(out, err) |
|
| 33 |
- } |
|
| 19 |
+ dockerCmd(c, "rename", "first_name", newName) |
|
| 34 | 20 |
|
| 35 | 21 |
name, err = inspectField(cleanedContainerID, "Name") |
| 36 | 22 |
if err != nil {
|
| ... | ... |
@@ -43,19 +28,11 @@ func (s *DockerSuite) TestRenameStoppedContainer(c *check.C) {
|
| 43 | 43 |
} |
| 44 | 44 |
|
| 45 | 45 |
func (s *DockerSuite) TestRenameRunningContainer(c *check.C) {
|
| 46 |
- runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh") |
|
| 47 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 48 |
- if err != nil {
|
|
| 49 |
- c.Fatalf(out, err) |
|
| 50 |
- } |
|
| 46 |
+ out, _ := dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", "sh") |
|
| 51 | 47 |
|
| 52 | 48 |
newName := "new_name" + stringid.GenerateRandomID() |
| 53 | 49 |
cleanedContainerID := strings.TrimSpace(out) |
| 54 |
- runCmd = exec.Command(dockerBinary, "rename", "first_name", newName) |
|
| 55 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 56 |
- if err != nil {
|
|
| 57 |
- c.Fatalf(out, err) |
|
| 58 |
- } |
|
| 50 |
+ dockerCmd(c, "rename", "first_name", newName) |
|
| 59 | 51 |
|
| 60 | 52 |
name, err := inspectField(cleanedContainerID, "Name") |
| 61 | 53 |
if err != nil {
|
| ... | ... |
@@ -67,18 +44,10 @@ func (s *DockerSuite) TestRenameRunningContainer(c *check.C) {
|
| 67 | 67 |
} |
| 68 | 68 |
|
| 69 | 69 |
func (s *DockerSuite) TestRenameCheckNames(c *check.C) {
|
| 70 |
- runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh") |
|
| 71 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 72 |
- if err != nil {
|
|
| 73 |
- c.Fatalf(out, err) |
|
| 74 |
- } |
|
| 70 |
+ dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", "sh") |
|
| 75 | 71 |
|
| 76 | 72 |
newName := "new_name" + stringid.GenerateRandomID() |
| 77 |
- runCmd = exec.Command(dockerBinary, "rename", "first_name", newName) |
|
| 78 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 79 |
- if err != nil {
|
|
| 80 |
- c.Fatalf(out, err) |
|
| 81 |
- } |
|
| 73 |
+ dockerCmd(c, "rename", "first_name", newName) |
|
| 82 | 74 |
|
| 83 | 75 |
name, err := inspectField(newName, "Name") |
| 84 | 76 |
if err != nil {
|
| ... | ... |
@@ -95,18 +64,13 @@ func (s *DockerSuite) TestRenameCheckNames(c *check.C) {
|
| 95 | 95 |
} |
| 96 | 96 |
|
| 97 | 97 |
func (s *DockerSuite) TestRenameInvalidName(c *check.C) {
|
| 98 |
- runCmd := exec.Command(dockerBinary, "run", "--name", "myname", "-d", "busybox", "top") |
|
| 99 |
- if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
|
| 100 |
- c.Fatalf(out, err) |
|
| 101 |
- } |
|
| 98 |
+ dockerCmd(c, "run", "--name", "myname", "-d", "busybox", "top") |
|
| 102 | 99 |
|
| 103 |
- runCmd = exec.Command(dockerBinary, "rename", "myname", "new:invalid") |
|
| 104 |
- if out, _, err := runCommandWithOutput(runCmd); err == nil || !strings.Contains(out, "Invalid container name") {
|
|
| 100 |
+ if out, _, err := dockerCmdWithError(c, "rename", "myname", "new:invalid"); err == nil || !strings.Contains(out, "Invalid container name") {
|
|
| 105 | 101 |
c.Fatalf("Renaming container to invalid name should have failed: %s\n%v", out, err)
|
| 106 | 102 |
} |
| 107 | 103 |
|
| 108 |
- runCmd = exec.Command(dockerBinary, "ps", "-a") |
|
| 109 |
- if out, _, err := runCommandWithOutput(runCmd); err != nil || !strings.Contains(out, "myname") {
|
|
| 104 |
+ if out, _, err := dockerCmdWithError(c, "ps", "-a"); err != nil || !strings.Contains(out, "myname") {
|
|
| 110 | 105 |
c.Fatalf("Output of docker ps should have included 'myname': %s\n%v", out, err)
|
| 111 | 106 |
} |
| 112 | 107 |
} |
| ... | ... |
@@ -1,7 +1,6 @@ |
| 1 | 1 |
package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "os/exec" |
|
| 5 | 4 |
"strings" |
| 6 | 5 |
"time" |
| 7 | 6 |
|
| ... | ... |
@@ -9,104 +8,53 @@ import ( |
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 | 11 |
func (s *DockerSuite) TestRestartStoppedContainer(c *check.C) {
|
| 12 |
- |
|
| 13 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "foobar") |
|
| 14 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 15 |
- if err != nil {
|
|
| 16 |
- c.Fatal(out, err) |
|
| 17 |
- } |
|
| 12 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", "foobar") |
|
| 18 | 13 |
|
| 19 | 14 |
cleanedContainerID := strings.TrimSpace(out) |
| 15 |
+ dockerCmd(c, "wait", cleanedContainerID) |
|
| 20 | 16 |
|
| 21 |
- runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID) |
|
| 22 |
- if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 23 |
- c.Fatal(out, err) |
|
| 24 |
- } |
|
| 25 |
- |
|
| 26 |
- runCmd = exec.Command(dockerBinary, "logs", cleanedContainerID) |
|
| 27 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 28 |
- if err != nil {
|
|
| 29 |
- c.Fatal(out, err) |
|
| 30 |
- } |
|
| 31 |
- |
|
| 17 |
+ out, _ = dockerCmd(c, "logs", cleanedContainerID) |
|
| 32 | 18 |
if out != "foobar\n" {
|
| 33 | 19 |
c.Errorf("container should've printed 'foobar'")
|
| 34 | 20 |
} |
| 35 | 21 |
|
| 36 |
- runCmd = exec.Command(dockerBinary, "restart", cleanedContainerID) |
|
| 37 |
- if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 38 |
- c.Fatal(out, err) |
|
| 39 |
- } |
|
| 40 |
- |
|
| 41 |
- runCmd = exec.Command(dockerBinary, "logs", cleanedContainerID) |
|
| 42 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 43 |
- if err != nil {
|
|
| 44 |
- c.Fatal(out, err) |
|
| 45 |
- } |
|
| 22 |
+ dockerCmd(c, "restart", cleanedContainerID) |
|
| 46 | 23 |
|
| 24 |
+ out, _ = dockerCmd(c, "logs", cleanedContainerID) |
|
| 47 | 25 |
if out != "foobar\nfoobar\n" {
|
| 48 | 26 |
c.Errorf("container should've printed 'foobar' twice")
|
| 49 | 27 |
} |
| 50 |
- |
|
| 51 | 28 |
} |
| 52 | 29 |
|
| 53 | 30 |
func (s *DockerSuite) TestRestartRunningContainer(c *check.C) {
|
| 54 |
- |
|
| 55 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "echo foobar && sleep 30 && echo 'should not print this'") |
|
| 56 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 57 |
- if err != nil {
|
|
| 58 |
- c.Fatal(out, err) |
|
| 59 |
- } |
|
| 31 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "echo foobar && sleep 30 && echo 'should not print this'") |
|
| 60 | 32 |
|
| 61 | 33 |
cleanedContainerID := strings.TrimSpace(out) |
| 62 | 34 |
|
| 63 | 35 |
time.Sleep(1 * time.Second) |
| 64 | 36 |
|
| 65 |
- runCmd = exec.Command(dockerBinary, "logs", cleanedContainerID) |
|
| 66 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 67 |
- if err != nil {
|
|
| 68 |
- c.Fatal(out, err) |
|
| 69 |
- } |
|
| 70 |
- |
|
| 37 |
+ out, _ = dockerCmd(c, "logs", cleanedContainerID) |
|
| 71 | 38 |
if out != "foobar\n" {
|
| 72 | 39 |
c.Errorf("container should've printed 'foobar'")
|
| 73 | 40 |
} |
| 74 | 41 |
|
| 75 |
- runCmd = exec.Command(dockerBinary, "restart", "-t", "1", cleanedContainerID) |
|
| 76 |
- if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 77 |
- c.Fatal(out, err) |
|
| 78 |
- } |
|
| 42 |
+ dockerCmd(c, "restart", "-t", "1", cleanedContainerID) |
|
| 79 | 43 |
|
| 80 |
- runCmd = exec.Command(dockerBinary, "logs", cleanedContainerID) |
|
| 81 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 82 |
- if err != nil {
|
|
| 83 |
- c.Fatal(out, err) |
|
| 84 |
- } |
|
| 44 |
+ out, _ = dockerCmd(c, "logs", cleanedContainerID) |
|
| 85 | 45 |
|
| 86 | 46 |
time.Sleep(1 * time.Second) |
| 87 | 47 |
|
| 88 | 48 |
if out != "foobar\nfoobar\n" {
|
| 89 | 49 |
c.Errorf("container should've printed 'foobar' twice")
|
| 90 | 50 |
} |
| 91 |
- |
|
| 92 | 51 |
} |
| 93 | 52 |
|
| 94 | 53 |
// Test that restarting a container with a volume does not create a new volume on restart. Regression test for #819. |
| 95 | 54 |
func (s *DockerSuite) TestRestartWithVolumes(c *check.C) {
|
| 96 |
- |
|
| 97 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "-v", "/test", "busybox", "top") |
|
| 98 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 99 |
- if err != nil {
|
|
| 100 |
- c.Fatal(out, err) |
|
| 101 |
- } |
|
| 55 |
+ out, _ := dockerCmd(c, "run", "-d", "-v", "/test", "busybox", "top") |
|
| 102 | 56 |
|
| 103 | 57 |
cleanedContainerID := strings.TrimSpace(out) |
| 104 |
- |
|
| 105 |
- runCmd = exec.Command(dockerBinary, "inspect", "--format", "{{ len .Volumes }}", cleanedContainerID)
|
|
| 106 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 107 |
- if err != nil {
|
|
| 108 |
- c.Fatal(out, err) |
|
| 109 |
- } |
|
| 58 |
+ out, _ = dockerCmd(c, "inspect", "--format", "{{ len .Volumes }}", cleanedContainerID)
|
|
| 110 | 59 |
|
| 111 | 60 |
if out = strings.Trim(out, " \n\r"); out != "1" {
|
| 112 | 61 |
c.Errorf("expect 1 volume received %s", out)
|
| ... | ... |
@@ -115,17 +63,9 @@ func (s *DockerSuite) TestRestartWithVolumes(c *check.C) {
|
| 115 | 115 |
volumes, err := inspectField(cleanedContainerID, "Volumes") |
| 116 | 116 |
c.Assert(err, check.IsNil) |
| 117 | 117 |
|
| 118 |
- runCmd = exec.Command(dockerBinary, "restart", cleanedContainerID) |
|
| 119 |
- if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 120 |
- c.Fatal(out, err) |
|
| 121 |
- } |
|
| 122 |
- |
|
| 123 |
- runCmd = exec.Command(dockerBinary, "inspect", "--format", "{{ len .Volumes }}", cleanedContainerID)
|
|
| 124 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 125 |
- if err != nil {
|
|
| 126 |
- c.Fatal(out, err) |
|
| 127 |
- } |
|
| 118 |
+ dockerCmd(c, "restart", cleanedContainerID) |
|
| 128 | 119 |
|
| 120 |
+ out, _ = dockerCmd(c, "inspect", "--format", "{{ len .Volumes }}", cleanedContainerID)
|
|
| 129 | 121 |
if out = strings.Trim(out, " \n\r"); out != "1" {
|
| 130 | 122 |
c.Errorf("expect 1 volume after restart received %s", out)
|
| 131 | 123 |
} |
| ... | ... |
@@ -136,16 +76,10 @@ func (s *DockerSuite) TestRestartWithVolumes(c *check.C) {
|
| 136 | 136 |
if volumes != volumesAfterRestart {
|
| 137 | 137 |
c.Errorf("expected volume path: %s Actual path: %s", volumes, volumesAfterRestart)
|
| 138 | 138 |
} |
| 139 |
- |
|
| 140 | 139 |
} |
| 141 | 140 |
|
| 142 | 141 |
func (s *DockerSuite) TestRestartPolicyNO(c *check.C) {
|
| 143 |
- |
|
| 144 |
- cmd := exec.Command(dockerBinary, "run", "-d", "--restart=no", "busybox", "false") |
|
| 145 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 146 |
- if err != nil {
|
|
| 147 |
- c.Fatal(err, out) |
|
| 148 |
- } |
|
| 142 |
+ out, _ := dockerCmd(c, "run", "-d", "--restart=no", "busybox", "false") |
|
| 149 | 143 |
|
| 150 | 144 |
id := strings.TrimSpace(string(out)) |
| 151 | 145 |
name, err := inspectField(id, "HostConfig.RestartPolicy.Name") |
| ... | ... |
@@ -153,16 +87,10 @@ func (s *DockerSuite) TestRestartPolicyNO(c *check.C) {
|
| 153 | 153 |
if name != "no" {
|
| 154 | 154 |
c.Fatalf("Container restart policy name is %s, expected %s", name, "no")
|
| 155 | 155 |
} |
| 156 |
- |
|
| 157 | 156 |
} |
| 158 | 157 |
|
| 159 | 158 |
func (s *DockerSuite) TestRestartPolicyAlways(c *check.C) {
|
| 160 |
- |
|
| 161 |
- cmd := exec.Command(dockerBinary, "run", "-d", "--restart=always", "busybox", "false") |
|
| 162 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 163 |
- if err != nil {
|
|
| 164 |
- c.Fatal(err, out) |
|
| 165 |
- } |
|
| 159 |
+ out, _ := dockerCmd(c, "run", "-d", "--restart=always", "busybox", "false") |
|
| 166 | 160 |
|
| 167 | 161 |
id := strings.TrimSpace(string(out)) |
| 168 | 162 |
name, err := inspectField(id, "HostConfig.RestartPolicy.Name") |
| ... | ... |
@@ -178,16 +106,10 @@ func (s *DockerSuite) TestRestartPolicyAlways(c *check.C) {
|
| 178 | 178 |
if MaximumRetryCount != "0" {
|
| 179 | 179 |
c.Fatalf("Container Maximum Retry Count is %s, expected %s", MaximumRetryCount, "0")
|
| 180 | 180 |
} |
| 181 |
- |
|
| 182 | 181 |
} |
| 183 | 182 |
|
| 184 | 183 |
func (s *DockerSuite) TestRestartPolicyOnFailure(c *check.C) {
|
| 185 |
- |
|
| 186 |
- cmd := exec.Command(dockerBinary, "run", "-d", "--restart=on-failure:1", "busybox", "false") |
|
| 187 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 188 |
- if err != nil {
|
|
| 189 |
- c.Fatal(err, out) |
|
| 190 |
- } |
|
| 184 |
+ out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:1", "busybox", "false") |
|
| 191 | 185 |
|
| 192 | 186 |
id := strings.TrimSpace(string(out)) |
| 193 | 187 |
name, err := inspectField(id, "HostConfig.RestartPolicy.Name") |
| ... | ... |
@@ -201,10 +123,8 @@ func (s *DockerSuite) TestRestartPolicyOnFailure(c *check.C) {
|
| 201 | 201 |
// a good container with --restart=on-failure:3 |
| 202 | 202 |
// MaximumRetryCount!=0; RestartCount=0 |
| 203 | 203 |
func (s *DockerSuite) TestContainerRestartwithGoodContainer(c *check.C) {
|
| 204 |
- out, err := exec.Command(dockerBinary, "run", "-d", "--restart=on-failure:3", "busybox", "true").CombinedOutput() |
|
| 205 |
- if err != nil {
|
|
| 206 |
- c.Fatal(string(out), err) |
|
| 207 |
- } |
|
| 204 |
+ out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "true") |
|
| 205 |
+ |
|
| 208 | 206 |
id := strings.TrimSpace(string(out)) |
| 209 | 207 |
if err := waitInspect(id, "{{ .State.Restarting }} {{ .State.Running }}", "false false", 5); err != nil {
|
| 210 | 208 |
c.Fatal(err) |
| ... | ... |
@@ -2,7 +2,6 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"os" |
| 5 |
- "os/exec" |
|
| 6 | 5 |
"strings" |
| 7 | 6 |
|
| 8 | 7 |
"github.com/go-check/check" |
| ... | ... |
@@ -11,58 +10,34 @@ import ( |
| 11 | 11 |
func (s *DockerSuite) TestRmContainerWithRemovedVolume(c *check.C) {
|
| 12 | 12 |
testRequires(c, SameHostDaemon) |
| 13 | 13 |
|
| 14 |
- cmd := exec.Command(dockerBinary, "run", "--name", "losemyvolumes", "-v", "/tmp/testing:/test", "busybox", "true") |
|
| 15 |
- if _, err := runCommand(cmd); err != nil {
|
|
| 16 |
- c.Fatal(err) |
|
| 17 |
- } |
|
| 14 |
+ dockerCmd(c, "run", "--name", "losemyvolumes", "-v", "/tmp/testing:/test", "busybox", "true") |
|
| 18 | 15 |
|
| 19 | 16 |
if err := os.Remove("/tmp/testing"); err != nil {
|
| 20 | 17 |
c.Fatal(err) |
| 21 | 18 |
} |
| 22 | 19 |
|
| 23 |
- cmd = exec.Command(dockerBinary, "rm", "-v", "losemyvolumes") |
|
| 24 |
- if out, _, err := runCommandWithOutput(cmd); err != nil {
|
|
| 25 |
- c.Fatal(out, err) |
|
| 26 |
- } |
|
| 27 |
- |
|
| 20 |
+ dockerCmd(c, "rm", "-v", "losemyvolumes") |
|
| 28 | 21 |
} |
| 29 | 22 |
|
| 30 | 23 |
func (s *DockerSuite) TestRmContainerWithVolume(c *check.C) {
|
| 24 |
+ dockerCmd(c, "run", "--name", "foo", "-v", "/srv", "busybox", "true") |
|
| 31 | 25 |
|
| 32 |
- cmd := exec.Command(dockerBinary, "run", "--name", "foo", "-v", "/srv", "busybox", "true") |
|
| 33 |
- if _, err := runCommand(cmd); err != nil {
|
|
| 34 |
- c.Fatal(err) |
|
| 35 |
- } |
|
| 36 |
- |
|
| 37 |
- cmd = exec.Command(dockerBinary, "rm", "-v", "foo") |
|
| 38 |
- if _, err := runCommand(cmd); err != nil {
|
|
| 39 |
- c.Fatal(err) |
|
| 40 |
- } |
|
| 41 |
- |
|
| 26 |
+ dockerCmd(c, "rm", "-v", "foo") |
|
| 42 | 27 |
} |
| 43 | 28 |
|
| 44 | 29 |
func (s *DockerSuite) TestRmRunningContainer(c *check.C) {
|
| 45 |
- |
|
| 46 | 30 |
createRunningContainer(c, "foo") |
| 47 | 31 |
|
| 48 |
- // Test cannot remove running container |
|
| 49 |
- cmd := exec.Command(dockerBinary, "rm", "foo") |
|
| 50 |
- if _, err := runCommand(cmd); err == nil {
|
|
| 32 |
+ if _, _, err := dockerCmdWithError(c, "rm", "foo"); err == nil {
|
|
| 51 | 33 |
c.Fatalf("Expected error, can't rm a running container")
|
| 52 | 34 |
} |
| 53 |
- |
|
| 54 | 35 |
} |
| 55 | 36 |
|
| 56 | 37 |
func (s *DockerSuite) TestRmForceRemoveRunningContainer(c *check.C) {
|
| 57 |
- |
|
| 58 | 38 |
createRunningContainer(c, "foo") |
| 59 | 39 |
|
| 60 | 40 |
// Stop then remove with -s |
| 61 |
- cmd := exec.Command(dockerBinary, "rm", "-f", "foo") |
|
| 62 |
- if _, err := runCommand(cmd); err != nil {
|
|
| 63 |
- c.Fatal(err) |
|
| 64 |
- } |
|
| 65 |
- |
|
| 41 |
+ dockerCmd(c, "rm", "-f", "foo") |
|
| 66 | 42 |
} |
| 67 | 43 |
|
| 68 | 44 |
func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {
|
| ... | ... |
@@ -80,40 +55,37 @@ func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {
|
| 80 | 80 |
c.Fatalf("Could not build image %s: %v", img, err)
|
| 81 | 81 |
} |
| 82 | 82 |
// run container on first image |
| 83 |
- if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", img)); err != nil {
|
|
| 83 |
+ if out, _, err := dockerCmdWithError(c, "run", img); err != nil {
|
|
| 84 | 84 |
c.Fatalf("Could not run image %s: %v: %s", img, err, out)
|
| 85 | 85 |
} |
| 86 |
+ |
|
| 86 | 87 |
// rebuild dockerfile with a small addition at the end |
| 87 | 88 |
if _, err := buildImage(img, dockerfile2, true); err != nil {
|
| 88 | 89 |
c.Fatalf("Could not rebuild image %s: %v", img, err)
|
| 89 | 90 |
} |
| 90 | 91 |
// try to remove the image, should error out. |
| 91 |
- if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "rmi", img)); err == nil {
|
|
| 92 |
+ if out, _, err := dockerCmdWithError(c, "rmi", img); err == nil {
|
|
| 92 | 93 |
c.Fatalf("Expected to error out removing the image, but succeeded: %s", out)
|
| 93 | 94 |
} |
| 95 |
+ |
|
| 94 | 96 |
// check if we deleted the first image |
| 95 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "images", "-q", "--no-trunc")) |
|
| 97 |
+ out, _, err := dockerCmdWithError(c, "images", "-q", "--no-trunc") |
|
| 96 | 98 |
if err != nil {
|
| 97 | 99 |
c.Fatalf("%v: %s", err, out)
|
| 98 | 100 |
} |
| 99 | 101 |
if !strings.Contains(out, img1) {
|
| 100 | 102 |
c.Fatalf("Orphaned container (could not find %q in docker images): %s", img1, out)
|
| 101 | 103 |
} |
| 102 |
- |
|
| 103 | 104 |
} |
| 104 | 105 |
|
| 105 | 106 |
func (s *DockerSuite) TestRmInvalidContainer(c *check.C) {
|
| 106 |
- if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "rm", "unknown")); err == nil {
|
|
| 107 |
+ if out, _, err := dockerCmdWithError(c, "rm", "unknown"); err == nil {
|
|
| 107 | 108 |
c.Fatal("Expected error on rm unknown container, got none")
|
| 108 | 109 |
} else if !strings.Contains(out, "failed to remove containers") {
|
| 109 | 110 |
c.Fatalf("Expected output to contain 'failed to remove containers', got %q", out)
|
| 110 | 111 |
} |
| 111 |
- |
|
| 112 | 112 |
} |
| 113 | 113 |
|
| 114 | 114 |
func createRunningContainer(c *check.C, name string) {
|
| 115 |
- cmd := exec.Command(dockerBinary, "run", "-dt", "--name", name, "busybox", "top") |
|
| 116 |
- if _, err := runCommand(cmd); err != nil {
|
|
| 117 |
- c.Fatal(err) |
|
| 118 |
- } |
|
| 115 |
+ dockerCmd(c, "run", "-dt", "--name", name, "busybox", "top") |
|
| 119 | 116 |
} |
| ... | ... |
@@ -12,8 +12,7 @@ func (s *DockerSuite) TestRmiWithContainerFails(c *check.C) {
|
| 12 | 12 |
errSubstr := "is using it" |
| 13 | 13 |
|
| 14 | 14 |
// create a container |
| 15 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true") |
|
| 16 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 15 |
+ out, _, err := dockerCmdWithError(c, "run", "-d", "busybox", "true") |
|
| 17 | 16 |
if err != nil {
|
| 18 | 17 |
c.Fatalf("failed to create a container: %s, %v", out, err)
|
| 19 | 18 |
} |
| ... | ... |
@@ -21,8 +20,7 @@ func (s *DockerSuite) TestRmiWithContainerFails(c *check.C) {
|
| 21 | 21 |
cleanedContainerID := strings.TrimSpace(out) |
| 22 | 22 |
|
| 23 | 23 |
// try to delete the image |
| 24 |
- runCmd = exec.Command(dockerBinary, "rmi", "busybox") |
|
| 25 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 24 |
+ out, _, err = dockerCmdWithError(c, "rmi", "busybox") |
|
| 26 | 25 |
if err == nil {
|
| 27 | 26 |
c.Fatalf("Container %q is using image, should not be able to rmi: %q", cleanedContainerID, out)
|
| 28 | 27 |
} |
| ... | ... |
@@ -75,14 +73,13 @@ func (s *DockerSuite) TestRmiTag(c *check.C) {
|
| 75 | 75 |
} |
| 76 | 76 |
|
| 77 | 77 |
func (s *DockerSuite) TestRmiImgIDMultipleTag(c *check.C) {
|
| 78 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-one'") |
|
| 79 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 78 |
+ out, _, err := dockerCmdWithError(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-one'") |
|
| 80 | 79 |
if err != nil {
|
| 81 | 80 |
c.Fatalf("failed to create a container:%s, %v", out, err)
|
| 82 | 81 |
} |
| 82 |
+ |
|
| 83 | 83 |
containerID := strings.TrimSpace(out) |
| 84 |
- runCmd = exec.Command(dockerBinary, "commit", containerID, "busybox-one") |
|
| 85 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 84 |
+ out, _, err = dockerCmdWithError(c, "commit", containerID, "busybox-one") |
|
| 86 | 85 |
if err != nil {
|
| 87 | 86 |
c.Fatalf("failed to commit a new busybox-one:%s, %v", out, err)
|
| 88 | 87 |
} |
| ... | ... |
@@ -100,14 +97,15 @@ func (s *DockerSuite) TestRmiImgIDMultipleTag(c *check.C) {
|
| 100 | 100 |
c.Assert(err, check.IsNil) |
| 101 | 101 |
|
| 102 | 102 |
// run a container with the image |
| 103 |
- out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "busybox-one", "top")) |
|
| 103 |
+ out, _, err = dockerCmdWithError(c, "run", "-d", "busybox-one", "top") |
|
| 104 | 104 |
if err != nil {
|
| 105 | 105 |
c.Fatalf("failed to create a container:%s, %v", out, err)
|
| 106 | 106 |
} |
| 107 |
+ |
|
| 107 | 108 |
containerID = strings.TrimSpace(out) |
| 108 | 109 |
|
| 109 | 110 |
// first checkout without force it fails |
| 110 |
- out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "rmi", imgID)) |
|
| 111 |
+ out, _, err = dockerCmdWithError(c, "rmi", imgID) |
|
| 111 | 112 |
expected := fmt.Sprintf("Conflict, cannot delete %s because the running container %s is using it, stop it and use -f to force", imgID[:12], containerID[:12])
|
| 112 | 113 |
if err == nil || !strings.Contains(out, expected) {
|
| 113 | 114 |
c.Fatalf("rmi tagged in multiple repos should have failed without force: %s, %v, expected: %s", out, err, expected)
|
| ... | ... |
@@ -120,18 +118,16 @@ func (s *DockerSuite) TestRmiImgIDMultipleTag(c *check.C) {
|
| 120 | 120 |
if strings.Contains(imagesAfter, imgID[:12]) {
|
| 121 | 121 |
c.Fatalf("rmi -f %s failed, image still exists: %q\n\n", imgID, imagesAfter)
|
| 122 | 122 |
} |
| 123 |
- |
|
| 124 | 123 |
} |
| 125 | 124 |
|
| 126 | 125 |
func (s *DockerSuite) TestRmiImgIDForce(c *check.C) {
|
| 127 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-test'") |
|
| 128 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 126 |
+ out, _, err := dockerCmdWithError(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-test'") |
|
| 129 | 127 |
if err != nil {
|
| 130 | 128 |
c.Fatalf("failed to create a container:%s, %v", out, err)
|
| 131 | 129 |
} |
| 130 |
+ |
|
| 132 | 131 |
containerID := strings.TrimSpace(out) |
| 133 |
- runCmd = exec.Command(dockerBinary, "commit", containerID, "busybox-test") |
|
| 134 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 132 |
+ out, _, err = dockerCmdWithError(c, "commit", containerID, "busybox-test") |
|
| 135 | 133 |
if err != nil {
|
| 136 | 134 |
c.Fatalf("failed to commit a new busybox-test:%s, %v", out, err)
|
| 137 | 135 |
} |
| ... | ... |
@@ -151,8 +147,7 @@ func (s *DockerSuite) TestRmiImgIDForce(c *check.C) {
|
| 151 | 151 |
c.Assert(err, check.IsNil) |
| 152 | 152 |
|
| 153 | 153 |
// first checkout without force it fails |
| 154 |
- runCmd = exec.Command(dockerBinary, "rmi", imgID) |
|
| 155 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 154 |
+ out, _, err = dockerCmdWithError(c, "rmi", imgID) |
|
| 156 | 155 |
if err == nil || !strings.Contains(out, fmt.Sprintf("Conflict, cannot delete image %s because it is tagged in multiple repositories, use -f to force", imgID)) {
|
| 157 | 156 |
c.Fatalf("rmi tagged in multiple repos should have failed without force:%s, %v", out, err)
|
| 158 | 157 |
} |
| ... | ... |
@@ -163,7 +158,6 @@ func (s *DockerSuite) TestRmiImgIDForce(c *check.C) {
|
| 163 | 163 |
if strings.Contains(imagesAfter, imgID[:12]) {
|
| 164 | 164 |
c.Fatalf("rmi -f %s failed, image still exists: %q\n\n", imgID, imagesAfter)
|
| 165 | 165 |
} |
| 166 |
- |
|
| 167 | 166 |
} |
| 168 | 167 |
} |
| 169 | 168 |
|
| ... | ... |
@@ -171,24 +165,22 @@ func (s *DockerSuite) TestRmiTagWithExistingContainers(c *check.C) {
|
| 171 | 171 |
container := "test-delete-tag" |
| 172 | 172 |
newtag := "busybox:newtag" |
| 173 | 173 |
bb := "busybox:latest" |
| 174 |
- if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", bb, newtag)); err != nil {
|
|
| 174 |
+ if out, _, err := dockerCmdWithError(c, "tag", bb, newtag); err != nil {
|
|
| 175 | 175 |
c.Fatalf("Could not tag busybox: %v: %s", err, out)
|
| 176 | 176 |
} |
| 177 |
- if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", container, bb, "/bin/true")); err != nil {
|
|
| 177 |
+ if out, _, err := dockerCmdWithError(c, "run", "--name", container, bb, "/bin/true"); err != nil {
|
|
| 178 | 178 |
c.Fatalf("Could not run busybox: %v: %s", err, out)
|
| 179 | 179 |
} |
| 180 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "rmi", newtag)) |
|
| 180 |
+ out, _, err := dockerCmdWithError(c, "rmi", newtag) |
|
| 181 | 181 |
if err != nil {
|
| 182 | 182 |
c.Fatalf("Could not remove tag %s: %v: %s", newtag, err, out)
|
| 183 | 183 |
} |
| 184 | 184 |
if d := strings.Count(out, "Untagged: "); d != 1 {
|
| 185 | 185 |
c.Fatalf("Expected 1 untagged entry got %d: %q", d, out)
|
| 186 | 186 |
} |
| 187 |
- |
|
| 188 | 187 |
} |
| 189 | 188 |
|
| 190 | 189 |
func (s *DockerSuite) TestRmiForceWithExistingContainers(c *check.C) {
|
| 191 |
- |
|
| 192 | 190 |
image := "busybox-clone" |
| 193 | 191 |
|
| 194 | 192 |
cmd := exec.Command(dockerBinary, "build", "--no-cache", "-t", image, "-") |
| ... | ... |
@@ -199,71 +191,60 @@ MAINTAINER foo`) |
| 199 | 199 |
c.Fatalf("Could not build %s: %s, %v", image, out, err)
|
| 200 | 200 |
} |
| 201 | 201 |
|
| 202 |
- if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "test-force-rmi", image, "/bin/true")); err != nil {
|
|
| 202 |
+ if out, _, err := dockerCmdWithError(c, "run", "--name", "test-force-rmi", image, "/bin/true"); err != nil {
|
|
| 203 | 203 |
c.Fatalf("Could not run container: %s, %v", out, err)
|
| 204 | 204 |
} |
| 205 | 205 |
|
| 206 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "rmi", "-f", image)) |
|
| 207 |
- if err != nil {
|
|
| 206 |
+ if out, _, err := dockerCmdWithError(c, "rmi", "-f", image); err != nil {
|
|
| 208 | 207 |
c.Fatalf("Could not remove image %s: %s, %v", image, out, err)
|
| 209 | 208 |
} |
| 210 |
- |
|
| 211 | 209 |
} |
| 212 | 210 |
|
| 213 | 211 |
func (s *DockerSuite) TestRmiWithMultipleRepositories(c *check.C) {
|
| 214 | 212 |
newRepo := "127.0.0.1:5000/busybox" |
| 215 | 213 |
oldRepo := "busybox" |
| 216 | 214 |
newTag := "busybox:test" |
| 217 |
- cmd := exec.Command(dockerBinary, "tag", oldRepo, newRepo) |
|
| 218 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 215 |
+ out, _, err := dockerCmdWithError(c, "tag", oldRepo, newRepo) |
|
| 219 | 216 |
if err != nil {
|
| 220 | 217 |
c.Fatalf("Could not tag busybox: %v: %s", err, out)
|
| 221 | 218 |
} |
| 222 |
- cmd = exec.Command(dockerBinary, "run", "--name", "test", oldRepo, "touch", "/home/abcd") |
|
| 223 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 219 |
+ |
|
| 220 |
+ out, _, err = dockerCmdWithError(c, "run", "--name", "test", oldRepo, "touch", "/home/abcd") |
|
| 224 | 221 |
if err != nil {
|
| 225 | 222 |
c.Fatalf("failed to run container: %v, output: %s", err, out)
|
| 226 | 223 |
} |
| 227 |
- cmd = exec.Command(dockerBinary, "commit", "test", newTag) |
|
| 228 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 224 |
+ |
|
| 225 |
+ out, _, err = dockerCmdWithError(c, "commit", "test", newTag) |
|
| 229 | 226 |
if err != nil {
|
| 230 | 227 |
c.Fatalf("failed to commit container: %v, output: %s", err, out)
|
| 231 | 228 |
} |
| 232 |
- cmd = exec.Command(dockerBinary, "rmi", newTag) |
|
| 233 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 229 |
+ |
|
| 230 |
+ out, _, err = dockerCmdWithError(c, "rmi", newTag) |
|
| 234 | 231 |
if err != nil {
|
| 235 | 232 |
c.Fatalf("failed to remove image: %v, output: %s", err, out)
|
| 236 | 233 |
} |
| 237 | 234 |
if !strings.Contains(out, "Untagged: "+newTag) {
|
| 238 | 235 |
c.Fatalf("Could not remove image %s: %s, %v", newTag, out, err)
|
| 239 | 236 |
} |
| 240 |
- |
|
| 241 | 237 |
} |
| 242 | 238 |
|
| 243 | 239 |
func (s *DockerSuite) TestRmiBlank(c *check.C) {
|
| 244 | 240 |
// try to delete a blank image name |
| 245 |
- runCmd := exec.Command(dockerBinary, "rmi", "") |
|
| 246 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 247 |
- |
|
| 241 |
+ out, _, err := dockerCmdWithError(c, "rmi", "") |
|
| 248 | 242 |
if err == nil {
|
| 249 | 243 |
c.Fatal("Should have failed to delete '' image")
|
| 250 | 244 |
} |
| 251 |
- |
|
| 252 | 245 |
if strings.Contains(out, "No such image") {
|
| 253 | 246 |
c.Fatalf("Wrong error message generated: %s", out)
|
| 254 | 247 |
} |
| 255 |
- |
|
| 256 | 248 |
if !strings.Contains(out, "Image name can not be blank") {
|
| 257 | 249 |
c.Fatalf("Expected error message not generated: %s", out)
|
| 258 | 250 |
} |
| 259 | 251 |
|
| 260 |
- runCmd = exec.Command(dockerBinary, "rmi", " ") |
|
| 261 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 262 |
- |
|
| 252 |
+ out, _, err = dockerCmdWithError(c, "rmi", " ") |
|
| 263 | 253 |
if err == nil {
|
| 264 | 254 |
c.Fatal("Should have failed to delete '' image")
|
| 265 | 255 |
} |
| 266 |
- |
|
| 267 | 256 |
if !strings.Contains(out, "No such image") {
|
| 268 | 257 |
c.Fatalf("Expected error message not generated: %s", out)
|
| 269 | 258 |
} |
| ... | ... |
@@ -88,11 +88,8 @@ func (s *DockerSuite) TestRunWithVolumesIsRecursive(c *check.C) {
|
| 88 | 88 |
|
| 89 | 89 |
func (s *DockerSuite) TestRunWithUlimits(c *check.C) {
|
| 90 | 90 |
testRequires(c, NativeExecDriver) |
| 91 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name=testulimits", "--ulimit", "nofile=42", "busybox", "/bin/sh", "-c", "ulimit -n")) |
|
| 92 |
- if err != nil {
|
|
| 93 |
- c.Fatal(err, out) |
|
| 94 |
- } |
|
| 95 | 91 |
|
| 92 |
+ out, _ := dockerCmd(c, "run", "--name=testulimits", "--ulimit", "nofile=42", "busybox", "/bin/sh", "-c", "ulimit -n") |
|
| 96 | 93 |
ul := strings.TrimSpace(out) |
| 97 | 94 |
if ul != "42" {
|
| 98 | 95 |
c.Fatalf("expected `ulimit -n` to be 42, got %s", ul)
|
| ... | ... |
@@ -113,7 +110,7 @@ func (s *DockerSuite) TestRunContainerWithCgroupParent(c *check.C) {
|
| 113 | 113 |
c.Fatalf("unable to find self cpu cgroup path. CgroupsPath: %v", selfCgroupPaths)
|
| 114 | 114 |
} |
| 115 | 115 |
|
| 116 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--cgroup-parent", cgroupParent, "--rm", "busybox", "cat", "/proc/self/cgroup")) |
|
| 116 |
+ out, _, err := dockerCmdWithError(c, "run", "--cgroup-parent", cgroupParent, "--rm", "busybox", "cat", "/proc/self/cgroup") |
|
| 117 | 117 |
if err != nil {
|
| 118 | 118 |
c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err)
|
| 119 | 119 |
} |
| ... | ... |
@@ -138,8 +135,7 @@ func (s *DockerSuite) TestRunContainerWithCgroupParentAbsPath(c *check.C) {
|
| 138 | 138 |
testRequires(c, NativeExecDriver) |
| 139 | 139 |
|
| 140 | 140 |
cgroupParent := "/cgroup-parent/test" |
| 141 |
- |
|
| 142 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--cgroup-parent", cgroupParent, "--rm", "busybox", "cat", "/proc/self/cgroup")) |
|
| 141 |
+ out, _, err := dockerCmdWithError(c, "run", "--cgroup-parent", cgroupParent, "--rm", "busybox", "cat", "/proc/self/cgroup") |
|
| 143 | 142 |
if err != nil {
|
| 144 | 143 |
c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err)
|
| 145 | 144 |
} |
| ... | ... |
@@ -163,8 +159,7 @@ func (s *DockerSuite) TestRunContainerWithCgroupMountRO(c *check.C) {
|
| 163 | 163 |
testRequires(c, NativeExecDriver) |
| 164 | 164 |
|
| 165 | 165 |
filename := "/sys/fs/cgroup/devices/test123" |
| 166 |
- cmd := exec.Command(dockerBinary, "run", "busybox", "touch", filename) |
|
| 167 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 166 |
+ out, _, err := dockerCmdWithError(c, "run", "busybox", "touch", filename) |
|
| 168 | 167 |
if err == nil {
|
| 169 | 168 |
c.Fatal("expected cgroup mount point to be read-only, touch file should fail")
|
| 170 | 169 |
} |
| ... | ... |
@@ -176,24 +171,13 @@ func (s *DockerSuite) TestRunContainerWithCgroupMountRO(c *check.C) {
|
| 176 | 176 |
|
| 177 | 177 |
func (s *DockerSuite) TestRunDeviceDirectory(c *check.C) {
|
| 178 | 178 |
testRequires(c, NativeExecDriver) |
| 179 |
- cmd := exec.Command(dockerBinary, "run", "--device", "/dev/snd:/dev/snd", "busybox", "sh", "-c", "ls /dev/snd/") |
|
| 180 |
- |
|
| 181 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 182 |
- if err != nil {
|
|
| 183 |
- c.Fatal(err, out) |
|
| 184 |
- } |
|
| 185 | 179 |
|
| 180 |
+ out, _ := dockerCmd(c, "run", "--device", "/dev/snd:/dev/snd", "busybox", "sh", "-c", "ls /dev/snd/") |
|
| 186 | 181 |
if actual := strings.Trim(out, "\r\n"); !strings.Contains(out, "timer") {
|
| 187 | 182 |
c.Fatalf("expected output /dev/snd/timer, received %s", actual)
|
| 188 | 183 |
} |
| 189 | 184 |
|
| 190 |
- cmd = exec.Command(dockerBinary, "run", "--device", "/dev/snd:/dev/othersnd", "busybox", "sh", "-c", "ls /dev/othersnd/") |
|
| 191 |
- |
|
| 192 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 193 |
- if err != nil {
|
|
| 194 |
- c.Fatal(err, out) |
|
| 195 |
- } |
|
| 196 |
- |
|
| 185 |
+ out, _ = dockerCmd(c, "run", "--device", "/dev/snd:/dev/othersnd", "busybox", "sh", "-c", "ls /dev/othersnd/") |
|
| 197 | 186 |
if actual := strings.Trim(out, "\r\n"); !strings.Contains(out, "seq") {
|
| 198 | 187 |
c.Fatalf("expected output /dev/othersnd/seq, received %s", actual)
|
| 199 | 188 |
} |
| ... | ... |
@@ -269,8 +253,8 @@ func (s *DockerSuite) TestRunAttachDetach(c *check.C) {
|
| 269 | 269 |
// "test" should be printed |
| 270 | 270 |
func (s *DockerSuite) TestRunEchoStdoutWithCPUQuota(c *check.C) {
|
| 271 | 271 |
testRequires(c, CpuCfsQuota) |
| 272 |
- runCmd := exec.Command(dockerBinary, "run", "--cpu-quota", "8000", "--name", "test", "busybox", "echo", "test") |
|
| 273 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
| 272 |
+ |
|
| 273 |
+ out, _, err := dockerCmdWithError(c, "run", "--cpu-quota", "8000", "--name", "test", "busybox", "echo", "test") |
|
| 274 | 274 |
if err != nil {
|
| 275 | 275 |
c.Fatalf("failed to run container: %v, output: %q", err, out)
|
| 276 | 276 |
} |
| ... | ... |
@@ -289,8 +273,8 @@ func (s *DockerSuite) TestRunEchoStdoutWithCPUQuota(c *check.C) {
|
| 289 | 289 |
|
| 290 | 290 |
func (s *DockerSuite) TestRunWithCpuPeriod(c *check.C) {
|
| 291 | 291 |
testRequires(c, CpuCfsPeriod) |
| 292 |
- runCmd := exec.Command(dockerBinary, "run", "--cpu-period", "50000", "--name", "test", "busybox", "true") |
|
| 293 |
- if _, err := runCommand(runCmd); err != nil {
|
|
| 292 |
+ |
|
| 293 |
+ if _, _, err := dockerCmdWithError(c, "run", "--cpu-period", "50000", "--name", "test", "busybox", "true"); err != nil {
|
|
| 294 | 294 |
c.Fatalf("failed to run container: %v", err)
|
| 295 | 295 |
} |
| 296 | 296 |
|
| ... | ... |
@@ -306,8 +290,7 @@ func (s *DockerSuite) TestRunOOMExitCode(c *check.C) {
|
| 306 | 306 |
errChan := make(chan error) |
| 307 | 307 |
go func() {
|
| 308 | 308 |
defer close(errChan) |
| 309 |
- runCmd := exec.Command(dockerBinary, "run", "-m", "4MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done") |
|
| 310 |
- out, exitCode, _ := runCommandWithOutput(runCmd) |
|
| 309 |
+ out, exitCode, _ := dockerCmdWithError(c, "run", "-m", "4MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done") |
|
| 311 | 310 |
if expected := 137; exitCode != expected {
|
| 312 | 311 |
errChan <- fmt.Errorf("wrong exit code for OOM container: expected %d, got %d (output: %q)", expected, exitCode, out)
|
| 313 | 312 |
} |
| ... | ... |
@@ -322,102 +305,63 @@ func (s *DockerSuite) TestRunOOMExitCode(c *check.C) {
|
| 322 | 322 |
} |
| 323 | 323 |
|
| 324 | 324 |
func (s *DockerSuite) TestContainerNetworkModeToSelf(c *check.C) {
|
| 325 |
- cmd := exec.Command(dockerBinary, "run", "--name=me", "--net=container:me", "busybox", "true") |
|
| 326 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 325 |
+ out, _, err := dockerCmdWithError(c, "run", "--name=me", "--net=container:me", "busybox", "true") |
|
| 327 | 326 |
if err == nil || !strings.Contains(out, "cannot join own network") {
|
| 328 | 327 |
c.Fatalf("using container net mode to self should result in an error")
|
| 329 | 328 |
} |
| 330 | 329 |
} |
| 331 | 330 |
|
| 332 | 331 |
func (s *DockerSuite) TestRunContainerNetModeWithDnsMacHosts(c *check.C) {
|
| 333 |
- cmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top") |
|
| 334 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 332 |
+ out, _, err := dockerCmdWithError(c, "run", "-d", "--name", "parent", "busybox", "top") |
|
| 335 | 333 |
if err != nil {
|
| 336 | 334 |
c.Fatalf("failed to run container: %v, output: %q", err, out)
|
| 337 | 335 |
} |
| 338 | 336 |
|
| 339 |
- cmd = exec.Command(dockerBinary, "run", "--dns", "1.2.3.4", "--net=container:parent", "busybox") |
|
| 340 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 337 |
+ out, _, err = dockerCmdWithError(c, "run", "--dns", "1.2.3.4", "--net=container:parent", "busybox") |
|
| 341 | 338 |
if err == nil || !strings.Contains(out, "Conflicting options: --dns and the network mode") {
|
| 342 | 339 |
c.Fatalf("run --net=container with --dns should error out")
|
| 343 | 340 |
} |
| 344 | 341 |
|
| 345 |
- cmd = exec.Command(dockerBinary, "run", "--mac-address", "92:d0:c6:0a:29:33", "--net=container:parent", "busybox") |
|
| 346 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 342 |
+ out, _, err = dockerCmdWithError(c, "run", "--mac-address", "92:d0:c6:0a:29:33", "--net=container:parent", "busybox") |
|
| 347 | 343 |
if err == nil || !strings.Contains(out, "--mac-address and the network mode") {
|
| 348 | 344 |
c.Fatalf("run --net=container with --mac-address should error out")
|
| 349 | 345 |
} |
| 350 | 346 |
|
| 351 |
- cmd = exec.Command(dockerBinary, "run", "--add-host", "test:192.168.2.109", "--net=container:parent", "busybox") |
|
| 352 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 347 |
+ out, _, err = dockerCmdWithError(c, "run", "--add-host", "test:192.168.2.109", "--net=container:parent", "busybox") |
|
| 353 | 348 |
if err == nil || !strings.Contains(out, "--add-host and the network mode") {
|
| 354 | 349 |
c.Fatalf("run --net=container with --add-host should error out")
|
| 355 | 350 |
} |
| 356 |
- |
|
| 357 | 351 |
} |
| 358 | 352 |
|
| 359 | 353 |
func (s *DockerSuite) TestRunContainerNetModeWithExposePort(c *check.C) {
|
| 360 |
- cmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top") |
|
| 361 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 362 |
- if err != nil {
|
|
| 363 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 364 |
- } |
|
| 354 |
+ dockerCmd(c, "run", "-d", "--name", "parent", "busybox", "top") |
|
| 365 | 355 |
|
| 366 |
- cmd = exec.Command(dockerBinary, "run", "-p", "5000:5000", "--net=container:parent", "busybox") |
|
| 367 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 356 |
+ out, _, err := dockerCmdWithError(c, "run", "-p", "5000:5000", "--net=container:parent", "busybox") |
|
| 368 | 357 |
if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
|
| 369 | 358 |
c.Fatalf("run --net=container with -p should error out")
|
| 370 | 359 |
} |
| 371 | 360 |
|
| 372 |
- cmd = exec.Command(dockerBinary, "run", "-P", "--net=container:parent", "busybox") |
|
| 373 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 361 |
+ out, _, err = dockerCmdWithError(c, "run", "-P", "--net=container:parent", "busybox") |
|
| 374 | 362 |
if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
|
| 375 | 363 |
c.Fatalf("run --net=container with -P should error out")
|
| 376 | 364 |
} |
| 377 | 365 |
|
| 378 |
- cmd = exec.Command(dockerBinary, "run", "--expose", "5000", "--net=container:parent", "busybox") |
|
| 379 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 366 |
+ out, _, err = dockerCmdWithError(c, "run", "--expose", "5000", "--net=container:parent", "busybox") |
|
| 380 | 367 |
if err == nil || !strings.Contains(out, "Conflicting options: --expose and the network mode (--expose)") {
|
| 381 | 368 |
c.Fatalf("run --net=container with --expose should error out")
|
| 382 | 369 |
} |
| 383 |
- |
|
| 384 | 370 |
} |
| 385 | 371 |
|
| 386 | 372 |
func (s *DockerSuite) TestRunLinkToContainerNetMode(c *check.C) {
|
| 387 |
- cmd := exec.Command(dockerBinary, "run", "--name", "test", "-d", "busybox", "top") |
|
| 388 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 389 |
- if err != nil {
|
|
| 390 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 391 |
- } |
|
| 392 |
- cmd = exec.Command(dockerBinary, "run", "--name", "parent", "-d", "--net=container:test", "busybox", "top") |
|
| 393 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 394 |
- if err != nil {
|
|
| 395 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 396 |
- } |
|
| 397 |
- cmd = exec.Command(dockerBinary, "run", "-d", "--link=parent:parent", "busybox", "top") |
|
| 398 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 399 |
- if err != nil {
|
|
| 400 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 401 |
- } |
|
| 402 |
- |
|
| 403 |
- cmd = exec.Command(dockerBinary, "run", "--name", "child", "-d", "--net=container:parent", "busybox", "top") |
|
| 404 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 405 |
- if err != nil {
|
|
| 406 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 407 |
- } |
|
| 408 |
- cmd = exec.Command(dockerBinary, "run", "-d", "--link=child:child", "busybox", "top") |
|
| 409 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 410 |
- if err != nil {
|
|
| 411 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 412 |
- } |
|
| 373 |
+ dockerCmd(c, "run", "--name", "test", "-d", "busybox", "top") |
|
| 374 |
+ dockerCmd(c, "run", "--name", "parent", "-d", "--net=container:test", "busybox", "top") |
|
| 375 |
+ dockerCmd(c, "run", "-d", "--link=parent:parent", "busybox", "top") |
|
| 376 |
+ dockerCmd(c, "run", "--name", "child", "-d", "--net=container:parent", "busybox", "top") |
|
| 377 |
+ dockerCmd(c, "run", "-d", "--link=child:child", "busybox", "top") |
|
| 413 | 378 |
} |
| 414 | 379 |
|
| 415 | 380 |
func (s *DockerSuite) TestRunLoopbackOnlyExistsWhenNetworkingDisabled(c *check.C) {
|
| 416 |
- cmd := exec.Command(dockerBinary, "run", "--net=none", "busybox", "ip", "-o", "-4", "a", "show", "up") |
|
| 417 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 418 |
- if err != nil {
|
|
| 419 |
- c.Fatal(err, out) |
|
| 420 |
- } |
|
| 381 |
+ out, _ := dockerCmd(c, "run", "--net=none", "busybox", "ip", "-o", "-4", "a", "show", "up") |
|
| 421 | 382 |
|
| 422 | 383 |
var ( |
| 423 | 384 |
count = 0 |
| ... | ... |
@@ -441,41 +385,23 @@ func (s *DockerSuite) TestRunLoopbackOnlyExistsWhenNetworkingDisabled(c *check.C |
| 441 | 441 |
|
| 442 | 442 |
// Issue #4681 |
| 443 | 443 |
func (s *DockerSuite) TestRunLoopbackWhenNetworkDisabled(c *check.C) {
|
| 444 |
- cmd := exec.Command(dockerBinary, "run", "--net=none", "busybox", "ping", "-c", "1", "127.0.0.1") |
|
| 445 |
- if _, err := runCommand(cmd); err != nil {
|
|
| 446 |
- c.Fatal(err) |
|
| 447 |
- } |
|
| 444 |
+ dockerCmd(c, "run", "--net=none", "busybox", "ping", "-c", "1", "127.0.0.1") |
|
| 448 | 445 |
} |
| 449 | 446 |
|
| 450 | 447 |
func (s *DockerSuite) TestRunModeNetContainerHostname(c *check.C) {
|
| 451 | 448 |
testRequires(c, ExecSupport) |
| 452 |
- cmd := exec.Command(dockerBinary, "run", "-i", "-d", "--name", "parent", "busybox", "top") |
|
| 453 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 454 |
- if err != nil {
|
|
| 455 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 456 |
- } |
|
| 457 |
- cmd = exec.Command(dockerBinary, "exec", "parent", "cat", "/etc/hostname") |
|
| 458 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 459 |
- if err != nil {
|
|
| 460 |
- c.Fatalf("failed to exec command: %v, output: %q", err, out)
|
|
| 461 |
- } |
|
| 462 | 449 |
|
| 463 |
- cmd = exec.Command(dockerBinary, "run", "--net=container:parent", "busybox", "cat", "/etc/hostname") |
|
| 464 |
- out1, _, err := runCommandWithOutput(cmd) |
|
| 465 |
- if err != nil {
|
|
| 466 |
- c.Fatalf("failed to run container: %v, output: %q", err, out1)
|
|
| 467 |
- } |
|
| 450 |
+ dockerCmd(c, "run", "-i", "-d", "--name", "parent", "busybox", "top") |
|
| 451 |
+ out, _ := dockerCmd(c, "exec", "parent", "cat", "/etc/hostname") |
|
| 452 |
+ out1, _ := dockerCmd(c, "run", "--net=container:parent", "busybox", "cat", "/etc/hostname") |
|
| 453 |
+ |
|
| 468 | 454 |
if out1 != out {
|
| 469 | 455 |
c.Fatal("containers with shared net namespace should have same hostname")
|
| 470 | 456 |
} |
| 471 | 457 |
} |
| 472 | 458 |
|
| 473 | 459 |
func (s *DockerSuite) TestRunNetworkNotInitializedNoneMode(c *check.C) {
|
| 474 |
- cmd := exec.Command(dockerBinary, "run", "-d", "--net=none", "busybox", "top") |
|
| 475 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 476 |
- if err != nil {
|
|
| 477 |
- c.Fatal(err) |
|
| 478 |
- } |
|
| 460 |
+ out, _, err := dockerCmdWithError(c, "run", "-d", "--net=none", "busybox", "top") |
|
| 479 | 461 |
id := strings.TrimSpace(out) |
| 480 | 462 |
res, err := inspectField(id, "NetworkSettings.IPAddress") |
| 481 | 463 |
c.Assert(err, check.IsNil) |