There is 5 calls left, that use StdinPipe that is not yet supported by
icmd.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
... | ... |
@@ -586,14 +586,14 @@ func (d *Daemon) GetBaseDeviceSize(c *check.C) int64 { |
586 | 586 |
// Cmd executes a docker CLI command against this daemon. |
587 | 587 |
// Example: d.Cmd("version") will run docker -H unix://path/to/unix.sock version |
588 | 588 |
func (d *Daemon) Cmd(args ...string) (string, error) { |
589 |
- b, err := d.Command(args...).CombinedOutput() |
|
590 |
- return string(b), err |
|
589 |
+ result := icmd.RunCmd(d.Command(args...)) |
|
590 |
+ return result.Combined(), result.Error |
|
591 | 591 |
} |
592 | 592 |
|
593 | 593 |
// Command creates a docker CLI command against this daemon, to be executed later. |
594 | 594 |
// Example: d.Command("version") creates a command to run "docker -H unix://path/to/unix.sock version" |
595 |
-func (d *Daemon) Command(args ...string) *exec.Cmd { |
|
596 |
- return exec.Command(d.dockerBinary, d.PrependHostArg(args)...) |
|
595 |
+func (d *Daemon) Command(args ...string) icmd.Cmd { |
|
596 |
+ return icmd.Command(d.dockerBinary, d.PrependHostArg(args)...) |
|
597 | 597 |
} |
598 | 598 |
|
599 | 599 |
// PrependHostArg prepend the specified arguments by the daemon host flags |
... | ... |
@@ -31,9 +31,7 @@ import ( |
31 | 31 |
) |
32 | 32 |
|
33 | 33 |
func (s *DockerSuite) TestContainerAPIGetAll(c *check.C) { |
34 |
- startCount, err := getContainerCount() |
|
35 |
- c.Assert(err, checker.IsNil, check.Commentf("Cannot query container count")) |
|
36 |
- |
|
34 |
+ startCount := getContainerCount(c) |
|
37 | 35 |
name := "getall" |
38 | 36 |
dockerCmd(c, "run", "--name", name, "busybox", "true") |
39 | 37 |
|
... | ... |
@@ -354,8 +352,7 @@ func (s *DockerSuite) TestContainerAPIPause(c *check.C) { |
354 | 354 |
c.Assert(err, checker.IsNil) |
355 | 355 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
356 | 356 |
|
357 |
- pausedContainers, err := getPausedContainers() |
|
358 |
- c.Assert(err, checker.IsNil, check.Commentf("error thrown while checking if containers were paused")) |
|
357 |
+ pausedContainers := getPausedContainers(c) |
|
359 | 358 |
|
360 | 359 |
if len(pausedContainers) != 1 || stringid.TruncateID(ContainerID) != pausedContainers[0] { |
361 | 360 |
c.Fatalf("there should be one paused container and not %d", len(pausedContainers)) |
... | ... |
@@ -365,8 +362,7 @@ func (s *DockerSuite) TestContainerAPIPause(c *check.C) { |
365 | 365 |
c.Assert(err, checker.IsNil) |
366 | 366 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
367 | 367 |
|
368 |
- pausedContainers, err = getPausedContainers() |
|
369 |
- c.Assert(err, checker.IsNil, check.Commentf("error thrown while checking if containers were paused")) |
|
368 |
+ pausedContainers = getPausedContainers(c) |
|
370 | 369 |
c.Assert(pausedContainers, checker.HasLen, 0, check.Commentf("There should be no paused container.")) |
371 | 370 |
} |
372 | 371 |
|
... | ... |
@@ -7,7 +7,6 @@ import ( |
7 | 7 |
"fmt" |
8 | 8 |
"io/ioutil" |
9 | 9 |
"os" |
10 |
- "os/exec" |
|
11 | 10 |
"path/filepath" |
12 | 11 |
"reflect" |
13 | 12 |
"regexp" |
... | ... |
@@ -1149,10 +1148,7 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) { |
1149 | 1149 |
} |
1150 | 1150 |
|
1151 | 1151 |
func (s *DockerSuite) TestBuildForceRm(c *check.C) { |
1152 |
- containerCountBefore, err := getContainerCount() |
|
1153 |
- if err != nil { |
|
1154 |
- c.Fatalf("failed to get the container count: %s", err) |
|
1155 |
- } |
|
1152 |
+ containerCountBefore := getContainerCount(c) |
|
1156 | 1153 |
name := "testbuildforcerm" |
1157 | 1154 |
|
1158 | 1155 |
buildImage(name, withBuildFlags("--force-rm"), withBuildContext(c, |
... | ... |
@@ -1162,11 +1158,7 @@ func (s *DockerSuite) TestBuildForceRm(c *check.C) { |
1162 | 1162 |
ExitCode: 1, |
1163 | 1163 |
}) |
1164 | 1164 |
|
1165 |
- containerCountAfter, err := getContainerCount() |
|
1166 |
- if err != nil { |
|
1167 |
- c.Fatalf("failed to get the container count: %s", err) |
|
1168 |
- } |
|
1169 |
- |
|
1165 |
+ containerCountAfter := getContainerCount(c) |
|
1170 | 1166 |
if containerCountBefore != containerCountAfter { |
1171 | 1167 |
c.Fatalf("--force-rm shouldn't have left containers behind") |
1172 | 1168 |
} |
... | ... |
@@ -1196,19 +1188,12 @@ func (s *DockerSuite) TestBuildRm(c *check.C) { |
1196 | 1196 |
} |
1197 | 1197 |
|
1198 | 1198 |
for _, tc := range testCases { |
1199 |
- containerCountBefore, err := getContainerCount() |
|
1200 |
- if err != nil { |
|
1201 |
- c.Fatalf("failed to get the container count: %s", err) |
|
1202 |
- } |
|
1199 |
+ containerCountBefore := getContainerCount(c) |
|
1203 | 1200 |
|
1204 | 1201 |
buildImageSuccessfully(c, name, withBuildFlags(tc.buildflags...), withDockerfile(`FROM busybox |
1205 | 1202 |
RUN echo hello world`)) |
1206 | 1203 |
|
1207 |
- containerCountAfter, err := getContainerCount() |
|
1208 |
- if err != nil { |
|
1209 |
- c.Fatalf("failed to get the container count: %s", err) |
|
1210 |
- } |
|
1211 |
- |
|
1204 |
+ containerCountAfter := getContainerCount(c) |
|
1212 | 1205 |
if tc.shouldLeftContainerBehind { |
1213 | 1206 |
if containerCountBefore == containerCountAfter { |
1214 | 1207 |
c.Fatalf("flags %v should have left containers behind", tc.buildflags) |
... | ... |
@@ -2863,13 +2848,10 @@ func (s *DockerSuite) TestBuildAddTarXz(c *check.C) { |
2863 | 2863 |
c.Fatalf("failed to close tar archive: %v", err) |
2864 | 2864 |
} |
2865 | 2865 |
|
2866 |
- xzCompressCmd := exec.Command("xz", "-k", "test.tar") |
|
2867 |
- xzCompressCmd.Dir = tmpDir |
|
2868 |
- out, _, err := runCommandWithOutput(xzCompressCmd) |
|
2869 |
- if err != nil { |
|
2870 |
- c.Fatal(err, out) |
|
2871 |
- } |
|
2872 |
- |
|
2866 |
+ icmd.RunCmd(icmd.Cmd{ |
|
2867 |
+ Command: []string{"xz", "-k", "test.tar"}, |
|
2868 |
+ Dir: tmpDir, |
|
2869 |
+ }).Assert(c, icmd.Success) |
|
2873 | 2870 |
if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil { |
2874 | 2871 |
c.Fatalf("failed to open destination dockerfile: %v", err) |
2875 | 2872 |
} |
... | ... |
@@ -2913,20 +2895,15 @@ func (s *DockerSuite) TestBuildAddTarXzGz(c *check.C) { |
2913 | 2913 |
c.Fatalf("failed to close tar archive: %v", err) |
2914 | 2914 |
} |
2915 | 2915 |
|
2916 |
- xzCompressCmd := exec.Command("xz", "-k", "test.tar") |
|
2917 |
- xzCompressCmd.Dir = tmpDir |
|
2918 |
- out, _, err := runCommandWithOutput(xzCompressCmd) |
|
2919 |
- if err != nil { |
|
2920 |
- c.Fatal(err, out) |
|
2921 |
- } |
|
2922 |
- |
|
2923 |
- gzipCompressCmd := exec.Command("gzip", "test.tar.xz") |
|
2924 |
- gzipCompressCmd.Dir = tmpDir |
|
2925 |
- out, _, err = runCommandWithOutput(gzipCompressCmd) |
|
2926 |
- if err != nil { |
|
2927 |
- c.Fatal(err, out) |
|
2928 |
- } |
|
2916 |
+ icmd.RunCmd(icmd.Cmd{ |
|
2917 |
+ Command: []string{"xz", "-k", "test.tar"}, |
|
2918 |
+ Dir: tmpDir, |
|
2919 |
+ }).Assert(c, icmd.Success) |
|
2929 | 2920 |
|
2921 |
+ icmd.RunCmd(icmd.Cmd{ |
|
2922 |
+ Command: []string{"gzip", "test.tar.xz"}, |
|
2923 |
+ Dir: tmpDir, |
|
2924 |
+ }) |
|
2930 | 2925 |
if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil { |
2931 | 2926 |
c.Fatalf("failed to open destination dockerfile: %v", err) |
2932 | 2927 |
} |
... | ... |
@@ -5591,8 +5568,7 @@ func (s *DockerSuite) TestBuildSquashParent(c *check.C) { |
5591 | 5591 |
dockerCmd(c, "run", "--rm", id, "/bin/sh", "-c", `[ "$(echo $HELLO)" == "world" ]`) |
5592 | 5592 |
|
5593 | 5593 |
// make sure the ID produced is the ID of the tag we specified |
5594 |
- inspectID, err := inspectImage("test", ".ID") |
|
5595 |
- c.Assert(err, checker.IsNil) |
|
5594 |
+ inspectID := inspectImage(c, "test", ".ID") |
|
5596 | 5595 |
c.Assert(inspectID, checker.Equals, id) |
5597 | 5596 |
|
5598 | 5597 |
origHistory, _ := dockerCmd(c, "history", origID) |
... | ... |
@@ -5602,8 +5578,7 @@ func (s *DockerSuite) TestBuildSquashParent(c *check.C) { |
5602 | 5602 |
splitTestHistory := strings.Split(strings.TrimSpace(testHistory), "\n") |
5603 | 5603 |
c.Assert(len(splitTestHistory), checker.Equals, len(splitOrigHistory)+1) |
5604 | 5604 |
|
5605 |
- out, err = inspectImage(id, "len .RootFS.Layers") |
|
5606 |
- c.Assert(err, checker.IsNil) |
|
5605 |
+ out = inspectImage(c, id, "len .RootFS.Layers") |
|
5607 | 5606 |
c.Assert(strings.TrimSpace(out), checker.Equals, "3") |
5608 | 5607 |
} |
5609 | 5608 |
|
... | ... |
@@ -422,7 +422,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) { |
422 | 422 |
// Copy actual /etc/resolv.conf |
423 | 423 |
dockerCmd(c, "cp", containerID+":/etc/resolv.conf", outDir) |
424 | 424 |
|
425 |
- expected, err := readContainerFile(containerID, "resolv.conf") |
|
425 |
+ expected := readContainerFile(c, containerID, "resolv.conf") |
|
426 | 426 |
actual, err := ioutil.ReadFile(outDir + "/resolv.conf") |
427 | 427 |
|
428 | 428 |
// Expected copied file to be duplicate of the container resolvconf |
... | ... |
@@ -431,7 +431,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) { |
431 | 431 |
// Copy actual /etc/hosts |
432 | 432 |
dockerCmd(c, "cp", containerID+":/etc/hosts", outDir) |
433 | 433 |
|
434 |
- expected, err = readContainerFile(containerID, "hosts") |
|
434 |
+ expected = readContainerFile(c, containerID, "hosts") |
|
435 | 435 |
actual, err = ioutil.ReadFile(outDir + "/hosts") |
436 | 436 |
|
437 | 437 |
// Expected copied file to be duplicate of the container hosts |
... | ... |
@@ -440,7 +440,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) { |
440 | 440 |
// Copy actual /etc/resolv.conf |
441 | 441 |
dockerCmd(c, "cp", containerID+":/etc/hostname", outDir) |
442 | 442 |
|
443 |
- expected, err = readContainerFile(containerID, "hostname") |
|
443 |
+ expected = readContainerFile(c, containerID, "hostname") |
|
444 | 444 |
actual, err = ioutil.ReadFile(outDir + "/hostname") |
445 | 445 |
c.Assert(err, checker.IsNil) |
446 | 446 |
|
... | ... |
@@ -1951,11 +1951,11 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithKilledRunningContainer(t *check |
1951 | 1951 |
|
1952 | 1952 |
// Give time to containerd to process the command if we don't |
1953 | 1953 |
// the exit event might be received after we do the inspect |
1954 |
- pidCmd := exec.Command("kill", "-0", pid) |
|
1955 |
- _, ec, _ := runCommandWithOutput(pidCmd) |
|
1956 |
- for ec == 0 { |
|
1954 |
+ result := icmd.RunCommand("kill", "-0", pid) |
|
1955 |
+ for result.ExitCode == 0 { |
|
1957 | 1956 |
time.Sleep(1 * time.Second) |
1958 |
- _, ec, _ = runCommandWithOutput(pidCmd) |
|
1957 |
+ // FIXME(vdemeester) should we check it doesn't error out ? |
|
1958 |
+ result = icmd.RunCommand("kill", "-0", pid) |
|
1959 | 1959 |
} |
1960 | 1960 |
|
1961 | 1961 |
// restart the daemon |
... | ... |
@@ -389,8 +389,7 @@ func (s *DockerSuite) TestRunMutableNetworkFiles(c *check.C) { |
389 | 389 |
for _, fn := range []string{"resolv.conf", "hosts"} { |
390 | 390 |
deleteAllContainers(c) |
391 | 391 |
|
392 |
- content, err := runCommandAndReadContainerFile(fn, exec.Command(dockerBinary, "run", "-d", "--name", "c1", "busybox", "sh", "-c", fmt.Sprintf("echo success >/etc/%s && top", fn))) |
|
393 |
- c.Assert(err, checker.IsNil) |
|
392 |
+ content := runCommandAndReadContainerFile(c, fn, dockerBinary, "run", "-d", "--name", "c1", "busybox", "sh", "-c", fmt.Sprintf("echo success >/etc/%s && top", fn)) |
|
394 | 393 |
|
395 | 394 |
c.Assert(strings.TrimSpace(string(content)), checker.Equals, "success", check.Commentf("Content was not what was modified in the container", string(content))) |
396 | 395 |
|
... | ... |
@@ -442,30 +441,27 @@ func (s *DockerSuite) TestExecWithPrivileged(c *check.C) { |
442 | 442 |
dockerCmd(c, "run", "-d", "--name", "parent", "--cap-drop=ALL", "busybox", "sh", "-c", `while (true); do if [ -e /exec_priv ]; then cat /exec_priv && mknod /tmp/sda b 8 0 && echo "Success"; else echo "Privileged exec has not run yet"; fi; usleep 10000; done`) |
443 | 443 |
|
444 | 444 |
// Check exec mknod doesn't work |
445 |
- cmd := exec.Command(dockerBinary, "exec", "parent", "sh", "-c", "mknod /tmp/sdb b 8 16") |
|
446 |
- out, _, err := runCommandWithOutput(cmd) |
|
447 |
- c.Assert(err, checker.NotNil, check.Commentf("exec mknod in --cap-drop=ALL container without --privileged should fail")) |
|
448 |
- c.Assert(out, checker.Contains, "Operation not permitted", check.Commentf("exec mknod in --cap-drop=ALL container without --privileged should fail")) |
|
445 |
+ icmd.RunCommand(dockerBinary, "exec", "parent", "sh", "-c", "mknod /tmp/sdb b 8 16").Assert(c, icmd.Expected{ |
|
446 |
+ ExitCode: 1, |
|
447 |
+ Err: "Operation not permitted", |
|
448 |
+ }) |
|
449 | 449 |
|
450 | 450 |
// Check exec mknod does work with --privileged |
451 |
- cmd = exec.Command(dockerBinary, "exec", "--privileged", "parent", "sh", "-c", `echo "Running exec --privileged" > /exec_priv && mknod /tmp/sdb b 8 16 && usleep 50000 && echo "Finished exec --privileged" > /exec_priv && echo ok`) |
|
452 |
- out, _, err = runCommandWithOutput(cmd) |
|
453 |
- c.Assert(err, checker.IsNil) |
|
451 |
+ result := icmd.RunCommand(dockerBinary, "exec", "--privileged", "parent", "sh", "-c", `echo "Running exec --privileged" > /exec_priv && mknod /tmp/sdb b 8 16 && usleep 50000 && echo "Finished exec --privileged" > /exec_priv && echo ok`) |
|
452 |
+ result.Assert(c, icmd.Success) |
|
454 | 453 |
|
455 |
- actual := strings.TrimSpace(out) |
|
456 |
- c.Assert(actual, checker.Equals, "ok", check.Commentf("exec mknod in --cap-drop=ALL container with --privileged failed, output: %q", out)) |
|
454 |
+ actual := strings.TrimSpace(result.Combined()) |
|
455 |
+ c.Assert(actual, checker.Equals, "ok", check.Commentf("exec mknod in --cap-drop=ALL container with --privileged failed, output: %q", result.Combined())) |
|
457 | 456 |
|
458 | 457 |
// Check subsequent unprivileged exec cannot mknod |
459 |
- cmd = exec.Command(dockerBinary, "exec", "parent", "sh", "-c", "mknod /tmp/sdc b 8 32") |
|
460 |
- out, _, err = runCommandWithOutput(cmd) |
|
461 |
- c.Assert(err, checker.NotNil, check.Commentf("repeating exec mknod in --cap-drop=ALL container after --privileged without --privileged should fail")) |
|
462 |
- c.Assert(out, checker.Contains, "Operation not permitted", check.Commentf("repeating exec mknod in --cap-drop=ALL container after --privileged without --privileged should fail")) |
|
463 |
- |
|
458 |
+ icmd.RunCommand(dockerBinary, "exec", "parent", "sh", "-c", "mknod /tmp/sdc b 8 32").Assert(c, icmd.Expected{ |
|
459 |
+ ExitCode: 1, |
|
460 |
+ Err: "Operation not permitted", |
|
461 |
+ }) |
|
464 | 462 |
// Confirm at no point was mknod allowed |
465 |
- logCmd := exec.Command(dockerBinary, "logs", "parent") |
|
466 |
- out, _, err = runCommandWithOutput(logCmd) |
|
467 |
- c.Assert(err, checker.IsNil) |
|
468 |
- c.Assert(out, checker.Not(checker.Contains), "Success") |
|
463 |
+ result = icmd.RunCommand(dockerBinary, "logs", "parent") |
|
464 |
+ result.Assert(c, icmd.Success) |
|
465 |
+ c.Assert(result.Combined(), checker.Not(checker.Contains), "Success") |
|
469 | 466 |
|
470 | 467 |
} |
471 | 468 |
|
... | ... |
@@ -146,11 +146,8 @@ func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) { |
146 | 146 |
|
147 | 147 |
c.Assert(waitRun(idTwo), checker.IsNil) |
148 | 148 |
|
149 |
- contentOne, err := readContainerFileWithExec(idOne, "/etc/hosts") |
|
150 |
- c.Assert(err, checker.IsNil, check.Commentf("contentOne: %s", string(contentOne))) |
|
151 |
- |
|
152 |
- contentTwo, err := readContainerFileWithExec(idTwo, "/etc/hosts") |
|
153 |
- c.Assert(err, checker.IsNil, check.Commentf("contentTwo: %s", string(contentTwo))) |
|
149 |
+ readContainerFileWithExec(c, idOne, "/etc/hosts") |
|
150 |
+ contentTwo := readContainerFileWithExec(c, idTwo, "/etc/hosts") |
|
154 | 151 |
// Host is not present in updated hosts file |
155 | 152 |
c.Assert(string(contentTwo), checker.Contains, "onetwo") |
156 | 153 |
} |
... | ... |
@@ -163,8 +160,7 @@ func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) { |
163 | 163 |
id := strings.TrimSpace(string(out)) |
164 | 164 |
|
165 | 165 |
realIP := inspectField(c, "one", "NetworkSettings.Networks.bridge.IPAddress") |
166 |
- content, err := readContainerFileWithExec(id, "/etc/hosts") |
|
167 |
- c.Assert(err, checker.IsNil) |
|
166 |
+ content := readContainerFileWithExec(c, id, "/etc/hosts") |
|
168 | 167 |
|
169 | 168 |
getIP := func(hosts []byte, hostname string) string { |
170 | 169 |
re := regexp.MustCompile(fmt.Sprintf(`(\S*)\t%s`, regexp.QuoteMeta(hostname))) |
... | ... |
@@ -181,8 +177,7 @@ func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) { |
181 | 181 |
dockerCmd(c, "restart", "one") |
182 | 182 |
realIP = inspectField(c, "one", "NetworkSettings.Networks.bridge.IPAddress") |
183 | 183 |
|
184 |
- content, err = readContainerFileWithExec(id, "/etc/hosts") |
|
185 |
- c.Assert(err, checker.IsNil, check.Commentf("content: %s", string(content))) |
|
184 |
+ content = readContainerFileWithExec(c, id, "/etc/hosts") |
|
186 | 185 |
ip = getIP(content, "one") |
187 | 186 |
c.Assert(ip, checker.Equals, realIP) |
188 | 187 |
|
... | ... |
@@ -869,18 +869,15 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) { |
869 | 869 |
out, _ := dockerCmd(c, "run", "-d", "--net", cstmBridgeNw, "busybox", "top") |
870 | 870 |
cid1 := strings.TrimSpace(out) |
871 | 871 |
|
872 |
- hosts1, err := readContainerFileWithExec(cid1, hostsFile) |
|
873 |
- c.Assert(err, checker.IsNil) |
|
872 |
+ hosts1 := readContainerFileWithExec(c, cid1, hostsFile) |
|
874 | 873 |
|
875 | 874 |
out, _ = dockerCmd(c, "run", "-d", "--net", cstmBridgeNw, "busybox", "top") |
876 | 875 |
cid2 := strings.TrimSpace(out) |
877 | 876 |
|
878 |
- hosts2, err := readContainerFileWithExec(cid2, hostsFile) |
|
879 |
- c.Assert(err, checker.IsNil) |
|
877 |
+ hosts2 := readContainerFileWithExec(c, cid2, hostsFile) |
|
880 | 878 |
|
881 | 879 |
// verify first container etc/hosts file has not changed |
882 |
- hosts1post, err := readContainerFileWithExec(cid1, hostsFile) |
|
883 |
- c.Assert(err, checker.IsNil) |
|
880 |
+ hosts1post := readContainerFileWithExec(c, cid1, hostsFile) |
|
884 | 881 |
c.Assert(string(hosts1), checker.Equals, string(hosts1post), |
885 | 882 |
check.Commentf("Unexpected %s change on anonymous container creation", hostsFile)) |
886 | 883 |
|
... | ... |
@@ -891,11 +888,8 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) { |
891 | 891 |
|
892 | 892 |
dockerCmd(c, "network", "connect", cstmBridgeNw1, cid2) |
893 | 893 |
|
894 |
- hosts2, err = readContainerFileWithExec(cid2, hostsFile) |
|
895 |
- c.Assert(err, checker.IsNil) |
|
896 |
- |
|
897 |
- hosts1post, err = readContainerFileWithExec(cid1, hostsFile) |
|
898 |
- c.Assert(err, checker.IsNil) |
|
894 |
+ hosts2 = readContainerFileWithExec(c, cid2, hostsFile) |
|
895 |
+ hosts1post = readContainerFileWithExec(c, cid1, hostsFile) |
|
899 | 896 |
c.Assert(string(hosts1), checker.Equals, string(hosts1post), |
900 | 897 |
check.Commentf("Unexpected %s change on container connect", hostsFile)) |
901 | 898 |
|
... | ... |
@@ -910,18 +904,16 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) { |
910 | 910 |
|
911 | 911 |
// Stop named container and verify first two containers' etc/hosts file hasn't changed |
912 | 912 |
dockerCmd(c, "stop", cid3) |
913 |
- hosts1post, err = readContainerFileWithExec(cid1, hostsFile) |
|
914 |
- c.Assert(err, checker.IsNil) |
|
913 |
+ hosts1post = readContainerFileWithExec(c, cid1, hostsFile) |
|
915 | 914 |
c.Assert(string(hosts1), checker.Equals, string(hosts1post), |
916 | 915 |
check.Commentf("Unexpected %s change on name container creation", hostsFile)) |
917 | 916 |
|
918 |
- hosts2post, err := readContainerFileWithExec(cid2, hostsFile) |
|
919 |
- c.Assert(err, checker.IsNil) |
|
917 |
+ hosts2post := readContainerFileWithExec(c, cid2, hostsFile) |
|
920 | 918 |
c.Assert(string(hosts2), checker.Equals, string(hosts2post), |
921 | 919 |
check.Commentf("Unexpected %s change on name container creation", hostsFile)) |
922 | 920 |
|
923 | 921 |
// verify that container 1 and 2 can't ping the named container now |
924 |
- _, _, err = dockerCmdWithError("exec", cid1, "ping", "-c", "1", cName) |
|
922 |
+ _, _, err := dockerCmdWithError("exec", cid1, "ping", "-c", "1", cName) |
|
925 | 923 |
c.Assert(err, check.NotNil) |
926 | 924 |
_, _, err = dockerCmdWithError("exec", cid2, "ping", "-c", "1", cName) |
927 | 925 |
c.Assert(err, check.NotNil) |
... | ... |
@@ -15,8 +15,7 @@ func (s *DockerSuite) TestPause(c *check.C) { |
15 | 15 |
runSleepingContainer(c, "-d", "--name", name) |
16 | 16 |
|
17 | 17 |
dockerCmd(c, "pause", name) |
18 |
- pausedContainers, err := getPausedContainers() |
|
19 |
- c.Assert(err, checker.IsNil) |
|
18 |
+ pausedContainers := getPausedContainers(c) |
|
20 | 19 |
c.Assert(len(pausedContainers), checker.Equals, 1) |
21 | 20 |
|
22 | 21 |
dockerCmd(c, "unpause", name) |
... | ... |
@@ -41,8 +40,7 @@ func (s *DockerSuite) TestPauseMultipleContainers(c *check.C) { |
41 | 41 |
runSleepingContainer(c, "-d", "--name", name) |
42 | 42 |
} |
43 | 43 |
dockerCmd(c, append([]string{"pause"}, containers...)...) |
44 |
- pausedContainers, err := getPausedContainers() |
|
45 |
- c.Assert(err, checker.IsNil) |
|
44 |
+ pausedContainers := getPausedContainers(c) |
|
46 | 45 |
c.Assert(len(pausedContainers), checker.Equals, len(containers)) |
47 | 46 |
|
48 | 47 |
dockerCmd(c, append([]string{"unpause"}, containers...)...) |
... | ... |
@@ -4,7 +4,6 @@ import ( |
4 | 4 |
"fmt" |
5 | 5 |
"io/ioutil" |
6 | 6 |
"os" |
7 |
- "os/exec" |
|
8 | 7 |
"path/filepath" |
9 | 8 |
"sort" |
10 | 9 |
"strconv" |
... | ... |
@@ -159,12 +158,11 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) { |
159 | 159 |
dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test") |
160 | 160 |
id := getIDByName(c, name) |
161 | 161 |
|
162 |
- runCmd := exec.Command(dockerBinary, "ps", "-s", "-n=1") |
|
163 |
- var out string |
|
162 |
+ var result *icmd.Result |
|
164 | 163 |
|
165 | 164 |
wait := make(chan struct{}) |
166 | 165 |
go func() { |
167 |
- out, _, err = runCommandWithOutput(runCmd) |
|
166 |
+ result = icmd.RunCommand(dockerBinary, "ps", "-s", "-n=1") |
|
168 | 167 |
close(wait) |
169 | 168 |
}() |
170 | 169 |
select { |
... | ... |
@@ -172,8 +170,8 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) { |
172 | 172 |
case <-time.After(3 * time.Second): |
173 | 173 |
c.Fatalf("Calling \"docker ps -s\" timed out!") |
174 | 174 |
} |
175 |
- c.Assert(err, checker.IsNil) |
|
176 |
- lines := strings.Split(strings.Trim(out, "\n "), "\n") |
|
175 |
+ result.Assert(c, icmd.Success) |
|
176 |
+ lines := strings.Split(strings.Trim(result.Combined(), "\n "), "\n") |
|
177 | 177 |
c.Assert(lines, checker.HasLen, 2, check.Commentf("Expected 2 lines for 'ps -s -n=1' output, got %d", len(lines))) |
178 | 178 |
sizeIndex := strings.Index(lines[0], "SIZE") |
179 | 179 |
idIndex := strings.Index(lines[0], "CONTAINER ID") |
... | ... |
@@ -1464,10 +1464,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) { |
1464 | 1464 |
dockerCmd(c, "start", "first") |
1465 | 1465 |
|
1466 | 1466 |
// check for update in container |
1467 |
- containerResolv, err := readContainerFile(containerID1, "resolv.conf") |
|
1468 |
- if err != nil { |
|
1469 |
- c.Fatal(err) |
|
1470 |
- } |
|
1467 |
+ containerResolv := readContainerFile(c, containerID1, "resolv.conf") |
|
1471 | 1468 |
if !bytes.Equal(containerResolv, bytesResolvConf) { |
1472 | 1469 |
c.Fatalf("Restarted container does not have updated resolv.conf; expected %q, got %q", tmpResolvConf, string(containerResolv)) |
1473 | 1470 |
} |
... | ... |
@@ -1490,11 +1487,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) { |
1490 | 1490 |
dockerCmd(c, "start", "second") |
1491 | 1491 |
|
1492 | 1492 |
// check for update in container |
1493 |
- containerResolv, err = readContainerFile(containerID2, "resolv.conf") |
|
1494 |
- if err != nil { |
|
1495 |
- c.Fatal(err) |
|
1496 |
- } |
|
1497 |
- |
|
1493 |
+ containerResolv = readContainerFile(c, containerID2, "resolv.conf") |
|
1498 | 1494 |
if bytes.Equal(containerResolv, resolvConfSystem) { |
1499 | 1495 |
c.Fatalf("Container's resolv.conf should not have been updated with host resolv.conf: %q", string(containerResolv)) |
1500 | 1496 |
} |
... | ... |
@@ -1509,11 +1502,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) { |
1509 | 1509 |
} |
1510 | 1510 |
|
1511 | 1511 |
// check for update in container |
1512 |
- containerResolv, err = readContainerFile(runningContainerID, "resolv.conf") |
|
1513 |
- if err != nil { |
|
1514 |
- c.Fatal(err) |
|
1515 |
- } |
|
1516 |
- |
|
1512 |
+ containerResolv = readContainerFile(c, runningContainerID, "resolv.conf") |
|
1517 | 1513 |
if bytes.Equal(containerResolv, bytesResolvConf) { |
1518 | 1514 |
c.Fatalf("Running container should not have updated resolv.conf; expected %q, got %q", string(resolvConfSystem), string(containerResolv)) |
1519 | 1515 |
} |
... | ... |
@@ -1523,10 +1512,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) { |
1523 | 1523 |
dockerCmd(c, "restart", runningContainerID) |
1524 | 1524 |
|
1525 | 1525 |
// check for update in container |
1526 |
- containerResolv, err = readContainerFile(runningContainerID, "resolv.conf") |
|
1527 |
- if err != nil { |
|
1528 |
- c.Fatal(err) |
|
1529 |
- } |
|
1526 |
+ containerResolv = readContainerFile(c, runningContainerID, "resolv.conf") |
|
1530 | 1527 |
if !bytes.Equal(containerResolv, bytesResolvConf) { |
1531 | 1528 |
c.Fatalf("Restarted container should have updated resolv.conf; expected %q, got %q", string(bytesResolvConf), string(containerResolv)) |
1532 | 1529 |
} |
... | ... |
@@ -1545,11 +1531,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) { |
1545 | 1545 |
|
1546 | 1546 |
// our first exited container ID should have been updated, but with default DNS |
1547 | 1547 |
// after the cleanup of resolv.conf found only a localhost nameserver: |
1548 |
- containerResolv, err = readContainerFile(containerID1, "resolv.conf") |
|
1549 |
- if err != nil { |
|
1550 |
- c.Fatal(err) |
|
1551 |
- } |
|
1552 |
- |
|
1548 |
+ containerResolv = readContainerFile(c, containerID1, "resolv.conf") |
|
1553 | 1549 |
expected := "\nnameserver 8.8.8.8\nnameserver 8.8.4.4\n" |
1554 | 1550 |
if !bytes.Equal(containerResolv, []byte(expected)) { |
1555 | 1551 |
c.Fatalf("Container does not have cleaned/replaced DNS in resolv.conf; expected %q, got %q", expected, string(containerResolv)) |
... | ... |
@@ -1582,10 +1564,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) { |
1582 | 1582 |
dockerCmd(c, "start", "third") |
1583 | 1583 |
|
1584 | 1584 |
// check for update in container |
1585 |
- containerResolv, err = readContainerFile(containerID3, "resolv.conf") |
|
1586 |
- if err != nil { |
|
1587 |
- c.Fatal(err) |
|
1588 |
- } |
|
1585 |
+ containerResolv = readContainerFile(c, containerID3, "resolv.conf") |
|
1589 | 1586 |
if !bytes.Equal(containerResolv, bytesResolvConf) { |
1590 | 1587 |
c.Fatalf("Stopped container does not have updated resolv.conf; expected\n%q\n got\n%q", tmpResolvConf, string(containerResolv)) |
1591 | 1588 |
} |
... | ... |
@@ -2840,11 +2819,7 @@ func (s *DockerSuite) TestRunContainerWithRmFlagExitCodeNotEqualToZero(c *check. |
2840 | 2840 |
c.Fatal("Expected docker run to fail", out, err) |
2841 | 2841 |
} |
2842 | 2842 |
|
2843 |
- out, err = getAllContainers() |
|
2844 |
- if err != nil { |
|
2845 |
- c.Fatal(out, err) |
|
2846 |
- } |
|
2847 |
- |
|
2843 |
+ out = getAllContainers(c) |
|
2848 | 2844 |
if out != "" { |
2849 | 2845 |
c.Fatal("Expected not to have containers", out) |
2850 | 2846 |
} |
... | ... |
@@ -2857,11 +2832,7 @@ func (s *DockerSuite) TestRunContainerWithRmFlagCannotStartContainer(c *check.C) |
2857 | 2857 |
c.Fatal("Expected docker run to fail", out, err) |
2858 | 2858 |
} |
2859 | 2859 |
|
2860 |
- out, err = getAllContainers() |
|
2861 |
- if err != nil { |
|
2862 |
- c.Fatal(out, err) |
|
2863 |
- } |
|
2864 |
- |
|
2860 |
+ out = getAllContainers(c) |
|
2865 | 2861 |
if out != "" { |
2866 | 2862 |
c.Fatal("Expected not to have containers", out) |
2867 | 2863 |
} |
... | ... |
@@ -15,6 +15,7 @@ import ( |
15 | 15 |
|
16 | 16 |
"github.com/docker/docker/integration-cli/checker" |
17 | 17 |
"github.com/docker/docker/pkg/testutil" |
18 |
+ icmd "github.com/docker/docker/pkg/testutil/cmd" |
|
18 | 19 |
"github.com/go-check/check" |
19 | 20 |
"github.com/opencontainers/go-digest" |
20 | 21 |
) |
... | ... |
@@ -37,10 +38,12 @@ func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *check.C) { |
37 | 37 |
c.Assert(err, checker.IsNil, check.Commentf("failed to save repo: %v %v", out, err)) |
38 | 38 |
deleteImages(repoName) |
39 | 39 |
|
40 |
- loadCmd := exec.Command(dockerBinary, "load") |
|
41 |
- loadCmd.Stdin = strings.NewReader(repoTarball) |
|
42 |
- out, _, err = runCommandWithOutput(loadCmd) |
|
43 |
- c.Assert(err, checker.NotNil, check.Commentf("expected error, but succeeded with no error and output: %v", out)) |
|
40 |
+ icmd.RunCmd(icmd.Cmd{ |
|
41 |
+ Command: []string{dockerBinary, "load"}, |
|
42 |
+ Stdin: strings.NewReader(repoTarball), |
|
43 |
+ }).Assert(c, icmd.Expected{ |
|
44 |
+ ExitCode: 1, |
|
45 |
+ }) |
|
44 | 46 |
|
45 | 47 |
after, _, err := dockerCmdWithError("inspect", repoName) |
46 | 48 |
c.Assert(err, checker.NotNil, check.Commentf("the repo should not exist: %v", after)) |
... | ... |
@@ -65,10 +68,12 @@ func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *check.C) { |
65 | 65 |
|
66 | 66 |
deleteImages(repoName) |
67 | 67 |
|
68 |
- loadCmd := exec.Command(dockerBinary, "load") |
|
69 |
- loadCmd.Stdin = strings.NewReader(out) |
|
70 |
- out, _, err = runCommandWithOutput(loadCmd) |
|
71 |
- c.Assert(err, checker.NotNil, check.Commentf("expected error, but succeeded with no error and output: %v", out)) |
|
68 |
+ icmd.RunCmd(icmd.Cmd{ |
|
69 |
+ Command: []string{dockerBinary, "load"}, |
|
70 |
+ Stdin: strings.NewReader(out), |
|
71 |
+ }).Assert(c, icmd.Expected{ |
|
72 |
+ ExitCode: 1, |
|
73 |
+ }) |
|
72 | 74 |
|
73 | 75 |
after, _, err := dockerCmdWithError("inspect", repoName) |
74 | 76 |
c.Assert(err, checker.NotNil, check.Commentf("the repo should not exist: %v", after)) |
... | ... |
@@ -41,11 +41,10 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) { |
41 | 41 |
|
42 | 42 |
deleteImages(repoName) |
43 | 43 |
|
44 |
- loadCmd := exec.Command(dockerBinary, "load") |
|
45 |
- loadCmd.Stdin = tmpFile |
|
46 |
- |
|
47 |
- out, _, err := runCommandWithOutput(loadCmd) |
|
48 |
- c.Assert(err, check.IsNil, check.Commentf(out)) |
|
44 |
+ icmd.RunCmd(icmd.Cmd{ |
|
45 |
+ Command: []string{dockerBinary, "load"}, |
|
46 |
+ Stdin: tmpFile, |
|
47 |
+ }).Assert(c, icmd.Success) |
|
49 | 48 |
|
50 | 49 |
after := inspectField(c, repoName, "Id") |
51 | 50 |
after = strings.TrimRight(after, "\n") |
... | ... |
@@ -67,7 +66,7 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) { |
67 | 67 |
|
68 | 68 |
n, err := pty.Read(buf) |
69 | 69 |
c.Assert(err, check.IsNil) //could not read tty output |
70 |
- c.Assert(string(buf[:n]), checker.Contains, "Cowardly refusing", check.Commentf("help output is not being yielded", out)) |
|
70 |
+ c.Assert(string(buf[:n]), checker.Contains, "Cowardly refusing", check.Commentf("help output is not being yielded")) |
|
71 | 71 |
} |
72 | 72 |
|
73 | 73 |
func (s *DockerSuite) TestSaveAndLoadWithProgressBar(c *check.C) { |
... | ... |
@@ -17,6 +17,7 @@ import ( |
17 | 17 |
"github.com/docker/docker/api/types/swarm" |
18 | 18 |
"github.com/docker/docker/integration-cli/checker" |
19 | 19 |
"github.com/docker/docker/integration-cli/daemon" |
20 |
+ icmd "github.com/docker/docker/pkg/testutil/cmd" |
|
20 | 21 |
"github.com/docker/libnetwork/driverapi" |
21 | 22 |
"github.com/docker/libnetwork/ipamapi" |
22 | 23 |
remoteipam "github.com/docker/libnetwork/ipams/remote/api" |
... | ... |
@@ -832,8 +833,7 @@ func checkSwarmLockedToUnlocked(c *check.C, d *daemon.Swarm, unlockKey string) { |
832 | 832 |
// it must not have updated to be unlocked in time - unlock, wait 3 seconds, and try again |
833 | 833 |
cmd := d.Command("swarm", "unlock") |
834 | 834 |
cmd.Stdin = bytes.NewBufferString(unlockKey) |
835 |
- out, err := cmd.CombinedOutput() |
|
836 |
- c.Assert(err, checker.IsNil, check.Commentf("out: %v", string(out))) |
|
835 |
+ icmd.RunCmd(cmd).Assert(c, icmd.Success) |
|
837 | 836 |
|
838 | 837 |
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive) |
839 | 838 |
|
... | ... |
@@ -860,22 +860,24 @@ func (s *DockerSwarmSuite) TestUnlockEngineAndUnlockedSwarm(c *check.C) { |
860 | 860 |
|
861 | 861 |
// unlocking a normal engine should return an error - it does not even ask for the key |
862 | 862 |
cmd := d.Command("swarm", "unlock") |
863 |
- outs, err := cmd.CombinedOutput() |
|
864 |
- |
|
865 |
- c.Assert(err, checker.NotNil, check.Commentf("out: %v", string(outs))) |
|
866 |
- c.Assert(string(outs), checker.Contains, "Error: This node is not part of a swarm") |
|
867 |
- c.Assert(string(outs), checker.Not(checker.Contains), "Please enter unlock key") |
|
863 |
+ result := icmd.RunCmd(cmd) |
|
864 |
+ result.Assert(c, icmd.Expected{ |
|
865 |
+ ExitCode: 1, |
|
866 |
+ }) |
|
867 |
+ c.Assert(result.Combined(), checker.Contains, "Error: This node is not part of a swarm") |
|
868 |
+ c.Assert(result.Combined(), checker.Not(checker.Contains), "Please enter unlock key") |
|
868 | 869 |
|
869 |
- _, err = d.Cmd("swarm", "init") |
|
870 |
+ _, err := d.Cmd("swarm", "init") |
|
870 | 871 |
c.Assert(err, checker.IsNil) |
871 | 872 |
|
872 | 873 |
// unlocking an unlocked swarm should return an error - it does not even ask for the key |
873 | 874 |
cmd = d.Command("swarm", "unlock") |
874 |
- outs, err = cmd.CombinedOutput() |
|
875 |
- |
|
876 |
- c.Assert(err, checker.NotNil, check.Commentf("out: %v", string(outs))) |
|
877 |
- c.Assert(string(outs), checker.Contains, "Error: swarm is not locked") |
|
878 |
- c.Assert(string(outs), checker.Not(checker.Contains), "Please enter unlock key") |
|
875 |
+ result = icmd.RunCmd(cmd) |
|
876 |
+ result.Assert(c, icmd.Expected{ |
|
877 |
+ ExitCode: 1, |
|
878 |
+ }) |
|
879 |
+ c.Assert(result.Combined(), checker.Contains, "Error: swarm is not locked") |
|
880 |
+ c.Assert(result.Combined(), checker.Not(checker.Contains), "Please enter unlock key") |
|
879 | 881 |
} |
880 | 882 |
|
881 | 883 |
func (s *DockerSwarmSuite) TestSwarmInitLocked(c *check.C) { |
... | ... |
@@ -907,16 +909,16 @@ func (s *DockerSwarmSuite) TestSwarmInitLocked(c *check.C) { |
907 | 907 |
|
908 | 908 |
cmd := d.Command("swarm", "unlock") |
909 | 909 |
cmd.Stdin = bytes.NewBufferString("wrong-secret-key") |
910 |
- out, err := cmd.CombinedOutput() |
|
911 |
- c.Assert(err, checker.NotNil, check.Commentf("out: %v", string(out))) |
|
912 |
- c.Assert(string(out), checker.Contains, "invalid key") |
|
910 |
+ icmd.RunCmd(cmd).Assert(c, icmd.Expected{ |
|
911 |
+ ExitCode: 1, |
|
912 |
+ Err: "invalid key", |
|
913 |
+ }) |
|
913 | 914 |
|
914 | 915 |
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateLocked) |
915 | 916 |
|
916 | 917 |
cmd = d.Command("swarm", "unlock") |
917 | 918 |
cmd.Stdin = bytes.NewBufferString(unlockKey) |
918 |
- out, err = cmd.CombinedOutput() |
|
919 |
- c.Assert(err, checker.IsNil, check.Commentf("out: %v", string(out))) |
|
919 |
+ icmd.RunCmd(cmd).Assert(c, icmd.Success) |
|
920 | 920 |
|
921 | 921 |
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive) |
922 | 922 |
|
... | ... |
@@ -1007,8 +1009,7 @@ func (s *DockerSwarmSuite) TestSwarmLockUnlockCluster(c *check.C) { |
1007 | 1007 |
|
1008 | 1008 |
cmd := d.Command("swarm", "unlock") |
1009 | 1009 |
cmd.Stdin = bytes.NewBufferString(unlockKey) |
1010 |
- out, err := cmd.CombinedOutput() |
|
1011 |
- c.Assert(err, checker.IsNil, check.Commentf("out: %v", string(out))) |
|
1010 |
+ icmd.RunCmd(cmd).Assert(c, icmd.Success) |
|
1012 | 1011 |
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive) |
1013 | 1012 |
} |
1014 | 1013 |
|
... | ... |
@@ -1034,8 +1035,7 @@ func (s *DockerSwarmSuite) TestSwarmLockUnlockCluster(c *check.C) { |
1034 | 1034 |
// unlock it |
1035 | 1035 |
cmd := d2.Command("swarm", "unlock") |
1036 | 1036 |
cmd.Stdin = bytes.NewBufferString(unlockKey) |
1037 |
- out, err := cmd.CombinedOutput() |
|
1038 |
- c.Assert(err, checker.IsNil, check.Commentf("out: %v", string(out))) |
|
1037 |
+ icmd.RunCmd(cmd).Assert(c, icmd.Success) |
|
1039 | 1038 |
c.Assert(getNodeStatus(c, d2), checker.Equals, swarm.LocalNodeStateActive) |
1040 | 1039 |
|
1041 | 1040 |
// once it's caught up, d2 is set to not be locked |
... | ... |
@@ -1088,8 +1088,7 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *check.C) { |
1088 | 1088 |
|
1089 | 1089 |
cmd := d.Command("swarm", "unlock") |
1090 | 1090 |
cmd.Stdin = bytes.NewBufferString(unlockKey) |
1091 |
- out, err := cmd.CombinedOutput() |
|
1092 |
- c.Assert(err, checker.IsNil, check.Commentf("out: %v", string(out))) |
|
1091 |
+ icmd.RunCmd(cmd).Assert(c, icmd.Success) |
|
1093 | 1092 |
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive) |
1094 | 1093 |
} |
1095 | 1094 |
|
... | ... |
@@ -1159,9 +1158,9 @@ func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *check.C) { |
1159 | 1159 |
|
1160 | 1160 |
cmd := d.Command("swarm", "unlock") |
1161 | 1161 |
cmd.Stdin = bytes.NewBufferString(unlockKey) |
1162 |
- out, err := cmd.CombinedOutput() |
|
1162 |
+ result := icmd.RunCmd(cmd) |
|
1163 | 1163 |
|
1164 |
- if err == nil { |
|
1164 |
+ if result.Error == nil { |
|
1165 | 1165 |
// On occasion, the daemon may not have finished |
1166 | 1166 |
// rotating the KEK before restarting. The test is |
1167 | 1167 |
// intentionally written to explore this behavior. |
... | ... |
@@ -1176,18 +1175,19 @@ func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *check.C) { |
1176 | 1176 |
|
1177 | 1177 |
cmd = d.Command("swarm", "unlock") |
1178 | 1178 |
cmd.Stdin = bytes.NewBufferString(unlockKey) |
1179 |
- out, err = cmd.CombinedOutput() |
|
1179 |
+ result = icmd.RunCmd(cmd) |
|
1180 | 1180 |
} |
1181 |
- c.Assert(err, checker.NotNil, check.Commentf("out: %v", string(out))) |
|
1182 |
- c.Assert(string(out), checker.Contains, "invalid key") |
|
1181 |
+ result.Assert(c, icmd.Expected{ |
|
1182 |
+ ExitCode: 1, |
|
1183 |
+ Err: "invalid key", |
|
1184 |
+ }) |
|
1183 | 1185 |
|
1184 | 1186 |
outs, _ = d.Cmd("node", "ls") |
1185 | 1187 |
c.Assert(outs, checker.Contains, "Swarm is encrypted and needs to be unlocked") |
1186 | 1188 |
|
1187 | 1189 |
cmd = d.Command("swarm", "unlock") |
1188 | 1190 |
cmd.Stdin = bytes.NewBufferString(newUnlockKey) |
1189 |
- out, err = cmd.CombinedOutput() |
|
1190 |
- c.Assert(err, checker.IsNil, check.Commentf("out: %v", string(out))) |
|
1191 |
+ icmd.RunCmd(cmd).Assert(c, icmd.Success) |
|
1191 | 1192 |
|
1192 | 1193 |
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive) |
1193 | 1194 |
|
... | ... |
@@ -1245,9 +1245,9 @@ func (s *DockerSwarmSuite) TestSwarmClusterRotateUnlockKey(c *check.C) { |
1245 | 1245 |
|
1246 | 1246 |
cmd := d.Command("swarm", "unlock") |
1247 | 1247 |
cmd.Stdin = bytes.NewBufferString(unlockKey) |
1248 |
- out, err := cmd.CombinedOutput() |
|
1248 |
+ result := icmd.RunCmd(cmd) |
|
1249 | 1249 |
|
1250 |
- if err == nil { |
|
1250 |
+ if result.Error == nil { |
|
1251 | 1251 |
// On occasion, the daemon may not have finished |
1252 | 1252 |
// rotating the KEK before restarting. The test is |
1253 | 1253 |
// intentionally written to explore this behavior. |
... | ... |
@@ -1262,18 +1262,19 @@ func (s *DockerSwarmSuite) TestSwarmClusterRotateUnlockKey(c *check.C) { |
1262 | 1262 |
|
1263 | 1263 |
cmd = d.Command("swarm", "unlock") |
1264 | 1264 |
cmd.Stdin = bytes.NewBufferString(unlockKey) |
1265 |
- out, err = cmd.CombinedOutput() |
|
1265 |
+ result = icmd.RunCmd(cmd) |
|
1266 | 1266 |
} |
1267 |
- c.Assert(err, checker.NotNil, check.Commentf("out: %v", string(out))) |
|
1268 |
- c.Assert(string(out), checker.Contains, "invalid key") |
|
1267 |
+ result.Assert(c, icmd.Expected{ |
|
1268 |
+ ExitCode: 1, |
|
1269 |
+ Err: "invalid key", |
|
1270 |
+ }) |
|
1269 | 1271 |
|
1270 | 1272 |
outs, _ = d.Cmd("node", "ls") |
1271 | 1273 |
c.Assert(outs, checker.Contains, "Swarm is encrypted and needs to be unlocked") |
1272 | 1274 |
|
1273 | 1275 |
cmd = d.Command("swarm", "unlock") |
1274 | 1276 |
cmd.Stdin = bytes.NewBufferString(newUnlockKey) |
1275 |
- out, err = cmd.CombinedOutput() |
|
1276 |
- c.Assert(err, checker.IsNil, check.Commentf("out: %v", string(out))) |
|
1277 |
+ icmd.RunCmd(cmd).Assert(c, icmd.Success) |
|
1277 | 1278 |
|
1278 | 1279 |
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive) |
1279 | 1280 |
|
... | ... |
@@ -1308,8 +1309,7 @@ func (s *DockerSwarmSuite) TestSwarmAlternateLockUnlock(c *check.C) { |
1308 | 1308 |
|
1309 | 1309 |
cmd := d.Command("swarm", "unlock") |
1310 | 1310 |
cmd.Stdin = bytes.NewBufferString(unlockKey) |
1311 |
- out, err := cmd.CombinedOutput() |
|
1312 |
- c.Assert(err, checker.IsNil, check.Commentf("out: %v", string(out))) |
|
1311 |
+ icmd.RunCmd(cmd).Assert(c, icmd.Success) |
|
1313 | 1312 |
|
1314 | 1313 |
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive) |
1315 | 1314 |
|
... | ... |
@@ -1410,12 +1410,11 @@ func (s *DockerTrustedSwarmSuite) TestTrustedServiceCreate(c *check.C) { |
1410 | 1410 |
|
1411 | 1411 |
name := "trusted" |
1412 | 1412 |
serviceCmd := d.Command("-D", "service", "create", "--name", name, repoName, "top") |
1413 |
- trustedExecCmd(serviceCmd) |
|
1414 |
- out, _, err := runCommandWithOutput(serviceCmd) |
|
1415 |
- c.Assert(err, checker.IsNil, check.Commentf(out)) |
|
1416 |
- c.Assert(out, checker.Contains, "resolved image tag to", check.Commentf(out)) |
|
1413 |
+ icmd.RunCmd(serviceCmd, trustedCmd).Assert(c, icmd.Expected{ |
|
1414 |
+ Err: "resolved image tag to", |
|
1415 |
+ }) |
|
1417 | 1416 |
|
1418 |
- out, err = d.Cmd("service", "inspect", "--pretty", name) |
|
1417 |
+ out, err := d.Cmd("service", "inspect", "--pretty", name) |
|
1419 | 1418 |
c.Assert(err, checker.IsNil, check.Commentf(out)) |
1420 | 1419 |
c.Assert(out, checker.Contains, repoName+"@", check.Commentf(out)) |
1421 | 1420 |
|
... | ... |
@@ -1429,11 +1428,10 @@ func (s *DockerTrustedSwarmSuite) TestTrustedServiceCreate(c *check.C) { |
1429 | 1429 |
|
1430 | 1430 |
name = "untrusted" |
1431 | 1431 |
serviceCmd = d.Command("service", "create", "--name", name, repoName, "top") |
1432 |
- trustedExecCmd(serviceCmd) |
|
1433 |
- out, _, err = runCommandWithOutput(serviceCmd) |
|
1434 |
- |
|
1435 |
- c.Assert(err, check.NotNil, check.Commentf(out)) |
|
1436 |
- c.Assert(string(out), checker.Contains, "Error: remote trust data does not exist", check.Commentf(out)) |
|
1432 |
+ icmd.RunCmd(serviceCmd, trustedCmd).Assert(c, icmd.Expected{ |
|
1433 |
+ ExitCode: 1, |
|
1434 |
+ Err: "Error: remote trust data does not exist", |
|
1435 |
+ }) |
|
1437 | 1436 |
|
1438 | 1437 |
out, err = d.Cmd("service", "inspect", "--pretty", name) |
1439 | 1438 |
c.Assert(err, checker.NotNil, check.Commentf(out)) |
... | ... |
@@ -1458,10 +1456,9 @@ func (s *DockerTrustedSwarmSuite) TestTrustedServiceUpdate(c *check.C) { |
1458 | 1458 |
c.Assert(out, check.Not(checker.Contains), repoName+"@", check.Commentf(out)) |
1459 | 1459 |
|
1460 | 1460 |
serviceCmd := d.Command("-D", "service", "update", "--image", repoName, name) |
1461 |
- trustedExecCmd(serviceCmd) |
|
1462 |
- out, _, err = runCommandWithOutput(serviceCmd) |
|
1463 |
- c.Assert(err, checker.IsNil, check.Commentf(out)) |
|
1464 |
- c.Assert(out, checker.Contains, "resolved image tag to", check.Commentf(out)) |
|
1461 |
+ icmd.RunCmd(serviceCmd, trustedCmd).Assert(c, icmd.Expected{ |
|
1462 |
+ Err: "resolved image tag to", |
|
1463 |
+ }) |
|
1465 | 1464 |
|
1466 | 1465 |
out, err = d.Cmd("service", "inspect", "--pretty", name) |
1467 | 1466 |
c.Assert(err, checker.IsNil, check.Commentf(out)) |
... | ... |
@@ -1476,11 +1473,10 @@ func (s *DockerTrustedSwarmSuite) TestTrustedServiceUpdate(c *check.C) { |
1476 | 1476 |
dockerCmd(c, "rmi", repoName) |
1477 | 1477 |
|
1478 | 1478 |
serviceCmd = d.Command("service", "update", "--image", repoName, name) |
1479 |
- trustedExecCmd(serviceCmd) |
|
1480 |
- out, _, err = runCommandWithOutput(serviceCmd) |
|
1481 |
- |
|
1482 |
- c.Assert(err, check.NotNil, check.Commentf(out)) |
|
1483 |
- c.Assert(string(out), checker.Contains, "Error: remote trust data does not exist", check.Commentf(out)) |
|
1479 |
+ icmd.RunCmd(serviceCmd, trustedCmd).Assert(c, icmd.Expected{ |
|
1480 |
+ ExitCode: 1, |
|
1481 |
+ Err: "Error: remote trust data does not exist", |
|
1482 |
+ }) |
|
1484 | 1483 |
} |
1485 | 1484 |
|
1486 | 1485 |
// Test case for issue #27866, which did not allow NW name that is the prefix of a swarm NW ID. |
... | ... |
@@ -52,22 +52,16 @@ func deleteContainer(ignoreNoSuchContainer bool, container ...string) error { |
52 | 52 |
return result.Compare(icmd.Success) |
53 | 53 |
} |
54 | 54 |
|
55 |
-func getAllContainers() (string, error) { |
|
56 |
- getContainersCmd := exec.Command(dockerBinary, "ps", "-q", "-a") |
|
57 |
- out, exitCode, err := runCommandWithOutput(getContainersCmd) |
|
58 |
- if exitCode != 0 && err == nil { |
|
59 |
- err = fmt.Errorf("failed to get a list of containers: %v\n", out) |
|
60 |
- } |
|
61 |
- |
|
62 |
- return out, err |
|
55 |
+func getAllContainers(c *check.C) string { |
|
56 |
+ result := icmd.RunCommand(dockerBinary, "ps", "-q", "-a") |
|
57 |
+ result.Assert(c, icmd.Success) |
|
58 |
+ return result.Combined() |
|
63 | 59 |
} |
64 | 60 |
|
65 | 61 |
func deleteAllContainers(c *check.C) { |
66 |
- containers, err := getAllContainers() |
|
67 |
- c.Assert(err, checker.IsNil, check.Commentf("containers: %v", containers)) |
|
68 |
- |
|
62 |
+ containers := getAllContainers(c) |
|
69 | 63 |
if containers != "" { |
70 |
- err = deleteContainer(true, strings.Split(strings.TrimSpace(containers), "\n")...) |
|
64 |
+ err := deleteContainer(true, strings.Split(strings.TrimSpace(containers), "\n")...) |
|
71 | 65 |
c.Assert(err, checker.IsNil) |
72 | 66 |
} |
73 | 67 |
} |
... | ... |
@@ -202,17 +196,10 @@ func deleteAllImages(c *check.C) { |
202 | 202 |
} |
203 | 203 |
} |
204 | 204 |
|
205 |
-func getPausedContainers() ([]string, error) { |
|
206 |
- getPausedContainersCmd := exec.Command(dockerBinary, "ps", "-f", "status=paused", "-q", "-a") |
|
207 |
- out, exitCode, err := runCommandWithOutput(getPausedContainersCmd) |
|
208 |
- if exitCode != 0 && err == nil { |
|
209 |
- err = fmt.Errorf("failed to get a list of paused containers: %v\n", out) |
|
210 |
- } |
|
211 |
- if err != nil { |
|
212 |
- return nil, err |
|
213 |
- } |
|
214 |
- |
|
215 |
- return strings.Fields(out), nil |
|
205 |
+func getPausedContainers(c *check.C) []string { |
|
206 |
+ result := icmd.RunCommand(dockerBinary, "ps", "-f", "status=paused", "-q", "-a") |
|
207 |
+ result.Assert(c, icmd.Success) |
|
208 |
+ return strings.Fields(result.Combined()) |
|
216 | 209 |
} |
217 | 210 |
|
218 | 211 |
func unpauseContainer(c *check.C, container string) { |
... | ... |
@@ -220,8 +207,7 @@ func unpauseContainer(c *check.C, container string) { |
220 | 220 |
} |
221 | 221 |
|
222 | 222 |
func unpauseAllContainers(c *check.C) { |
223 |
- containers, err := getPausedContainers() |
|
224 |
- c.Assert(err, checker.IsNil, check.Commentf("containers: %v", containers)) |
|
223 |
+ containers := getPausedContainers(c) |
|
225 | 224 |
for _, value := range containers { |
226 | 225 |
unpauseContainer(c, value) |
227 | 226 |
} |
... | ... |
@@ -310,29 +296,24 @@ func findContainerIP(c *check.C, id string, network string) string { |
310 | 310 |
return strings.Trim(out, " \r\n'") |
311 | 311 |
} |
312 | 312 |
|
313 |
-func getContainerCount() (int, error) { |
|
313 |
+func getContainerCount(c *check.C) int { |
|
314 | 314 |
const containers = "Containers:" |
315 | 315 |
|
316 |
- cmd := exec.Command(dockerBinary, "info") |
|
317 |
- out, _, err := runCommandWithOutput(cmd) |
|
318 |
- if err != nil { |
|
319 |
- return 0, err |
|
320 |
- } |
|
316 |
+ result := icmd.RunCommand(dockerBinary, "info") |
|
317 |
+ result.Assert(c, icmd.Success) |
|
321 | 318 |
|
322 |
- lines := strings.Split(out, "\n") |
|
319 |
+ lines := strings.Split(result.Combined(), "\n") |
|
323 | 320 |
for _, line := range lines { |
324 | 321 |
if strings.Contains(line, containers) { |
325 | 322 |
output := strings.TrimSpace(line) |
326 | 323 |
output = strings.TrimLeft(output, containers) |
327 | 324 |
output = strings.Trim(output, " ") |
328 | 325 |
containerCount, err := strconv.Atoi(output) |
329 |
- if err != nil { |
|
330 |
- return 0, err |
|
331 |
- } |
|
332 |
- return containerCount, nil |
|
326 |
+ c.Assert(err, checker.IsNil) |
|
327 |
+ return containerCount |
|
333 | 328 |
} |
334 | 329 |
} |
335 |
- return 0, fmt.Errorf("couldn't find the Container count in the output") |
|
330 |
+ return 0 |
|
336 | 331 |
} |
337 | 332 |
|
338 | 333 |
// FakeContext creates directories that can be used as a build context |
... | ... |
@@ -626,19 +607,16 @@ func inspectMountPointJSON(j, destination string) (types.MountPoint, error) { |
626 | 626 |
return *m, nil |
627 | 627 |
} |
628 | 628 |
|
629 |
-func inspectImage(name, filter string) (string, error) { |
|
629 |
+func inspectImage(c *check.C, name, filter string) string { |
|
630 | 630 |
args := []string{"inspect", "--type", "image"} |
631 | 631 |
if filter != "" { |
632 | 632 |
format := fmt.Sprintf("{{%s}}", filter) |
633 | 633 |
args = append(args, "-f", format) |
634 | 634 |
} |
635 | 635 |
args = append(args, name) |
636 |
- inspectCmd := exec.Command(dockerBinary, args...) |
|
637 |
- out, exitCode, err := runCommandWithOutput(inspectCmd) |
|
638 |
- if err != nil || exitCode != 0 { |
|
639 |
- return "", fmt.Errorf("failed to inspect %s: %s", name, out) |
|
640 |
- } |
|
641 |
- return strings.TrimSpace(out), nil |
|
636 |
+ result := icmd.RunCommand(dockerBinary, args...) |
|
637 |
+ result.Assert(c, icmd.Success) |
|
638 |
+ return strings.TrimSpace(result.Combined()) |
|
642 | 639 |
} |
643 | 640 |
|
644 | 641 |
func getIDByName(c *check.C, name string) string { |
... | ... |
@@ -864,39 +842,30 @@ func containerStorageFile(containerID, basename string) string { |
864 | 864 |
} |
865 | 865 |
|
866 | 866 |
// docker commands that use this function must be run with the '-d' switch. |
867 |
-func runCommandAndReadContainerFile(filename string, cmd *exec.Cmd) ([]byte, error) { |
|
868 |
- out, _, err := runCommandWithOutput(cmd) |
|
869 |
- if err != nil { |
|
870 |
- return nil, fmt.Errorf("%v: %q", err, out) |
|
871 |
- } |
|
872 |
- |
|
873 |
- contID := strings.TrimSpace(out) |
|
874 |
- |
|
867 |
+func runCommandAndReadContainerFile(c *check.C, filename string, command string, args ...string) []byte { |
|
868 |
+ result := icmd.RunCommand(command, args...) |
|
869 |
+ result.Assert(c, icmd.Success) |
|
870 |
+ contID := strings.TrimSpace(result.Combined()) |
|
875 | 871 |
if err := waitRun(contID); err != nil { |
876 |
- return nil, fmt.Errorf("%v: %q", contID, err) |
|
872 |
+ c.Fatalf("%v: %q", contID, err) |
|
877 | 873 |
} |
878 |
- |
|
879 |
- return readContainerFile(contID, filename) |
|
874 |
+ return readContainerFile(c, contID, filename) |
|
880 | 875 |
} |
881 | 876 |
|
882 |
-func readContainerFile(containerID, filename string) ([]byte, error) { |
|
877 |
+func readContainerFile(c *check.C, containerID, filename string) []byte { |
|
883 | 878 |
f, err := os.Open(containerStorageFile(containerID, filename)) |
884 |
- if err != nil { |
|
885 |
- return nil, err |
|
886 |
- } |
|
879 |
+ c.Assert(err, checker.IsNil) |
|
887 | 880 |
defer f.Close() |
888 | 881 |
|
889 | 882 |
content, err := ioutil.ReadAll(f) |
890 |
- if err != nil { |
|
891 |
- return nil, err |
|
892 |
- } |
|
893 |
- |
|
894 |
- return content, nil |
|
883 |
+ c.Assert(err, checker.IsNil) |
|
884 |
+ return content |
|
895 | 885 |
} |
896 | 886 |
|
897 |
-func readContainerFileWithExec(containerID, filename string) ([]byte, error) { |
|
898 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "exec", containerID, "cat", filename)) |
|
899 |
- return []byte(out), err |
|
887 |
+func readContainerFileWithExec(c *check.C, containerID, filename string) []byte { |
|
888 |
+ result := icmd.RunCommand(dockerBinary, "exec", containerID, "cat", filename) |
|
889 |
+ result.Assert(c, icmd.Success) |
|
890 |
+ return []byte(result.Combined()) |
|
900 | 891 |
} |
901 | 892 |
|
902 | 893 |
// daemonTime provides the current time on the daemon host |