[test/integration-cli] small cleanups of FIXME(s)
| ... | ... |
@@ -350,14 +350,7 @@ func (s *DockerSwarmSuite) TearDownTest(c *check.C) {
|
| 350 | 350 |
for _, d := range s.daemons {
|
| 351 | 351 |
if d != nil {
|
| 352 | 352 |
d.Stop(c) |
| 353 |
- // FIXME(vdemeester) should be handled by SwarmDaemon ? |
|
| 354 |
- // raft state file is quite big (64MB) so remove it after every test |
|
| 355 |
- walDir := filepath.Join(d.Root, "swarm/raft/wal") |
|
| 356 |
- if err := os.RemoveAll(walDir); err != nil {
|
|
| 357 |
- c.Logf("error removing %v: %v", walDir, err)
|
|
| 358 |
- } |
|
| 359 |
- |
|
| 360 |
- d.CleanupExecRoot(c) |
|
| 353 |
+ d.Cleanup(c) |
|
| 361 | 354 |
} |
| 362 | 355 |
} |
| 363 | 356 |
s.daemons = nil |
| ... | ... |
@@ -2,7 +2,6 @@ package daemon // import "github.com/docker/docker/integration-cli/daemon" |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 |
- "os/exec" |
|
| 6 | 5 |
"strings" |
| 7 | 6 |
"time" |
| 8 | 7 |
|
| ... | ... |
@@ -88,19 +87,6 @@ func (d *Daemon) inspectFieldWithError(name, field string) (string, error) {
|
| 88 | 88 |
return d.inspectFilter(name, fmt.Sprintf(".%s", field))
|
| 89 | 89 |
} |
| 90 | 90 |
|
| 91 |
-// BuildImageWithOut builds an image with the specified dockerfile and options and returns the output |
|
| 92 |
-func (d *Daemon) BuildImageWithOut(name, dockerfile string, useCache bool, buildFlags ...string) (string, int, error) {
|
|
| 93 |
- buildCmd := BuildImageCmdWithHost(d.dockerBinary, name, dockerfile, d.Sock(), useCache, buildFlags...) |
|
| 94 |
- result := icmd.RunCmd(icmd.Cmd{
|
|
| 95 |
- Command: buildCmd.Args, |
|
| 96 |
- Env: buildCmd.Env, |
|
| 97 |
- Dir: buildCmd.Dir, |
|
| 98 |
- Stdin: buildCmd.Stdin, |
|
| 99 |
- Stdout: buildCmd.Stdout, |
|
| 100 |
- }) |
|
| 101 |
- return result.Combined(), result.ExitCode, result.Error |
|
| 102 |
-} |
|
| 103 |
- |
|
| 104 | 91 |
// CheckActiveContainerCount returns the number of active containers |
| 105 | 92 |
// FIXME(vdemeester) should re-use ActivateContainers in some way |
| 106 | 93 |
func (d *Daemon) CheckActiveContainerCount(c *check.C) (interface{}, check.CommentInterface) {
|
| ... | ... |
@@ -155,22 +141,3 @@ func WaitInspectWithArgs(dockerBinary, name, expr, expected string, timeout time |
| 155 | 155 |
} |
| 156 | 156 |
return nil |
| 157 | 157 |
} |
| 158 |
- |
|
| 159 |
-// BuildImageCmdWithHost create a build command with the specified arguments. |
|
| 160 |
-// Deprecated |
|
| 161 |
-// FIXME(vdemeester) move this away |
|
| 162 |
-func BuildImageCmdWithHost(dockerBinary, name, dockerfile, host string, useCache bool, buildFlags ...string) *exec.Cmd {
|
|
| 163 |
- args := []string{}
|
|
| 164 |
- if host != "" {
|
|
| 165 |
- args = append(args, "--host", host) |
|
| 166 |
- } |
|
| 167 |
- args = append(args, "build", "-t", name) |
|
| 168 |
- if !useCache {
|
|
| 169 |
- args = append(args, "--no-cache") |
|
| 170 |
- } |
|
| 171 |
- args = append(args, buildFlags...) |
|
| 172 |
- args = append(args, "-") |
|
| 173 |
- buildCmd := exec.Command(dockerBinary, args...) |
|
| 174 |
- buildCmd.Stdin = strings.NewReader(dockerfile) |
|
| 175 |
- return buildCmd |
|
| 176 |
-} |
| ... | ... |
@@ -11,9 +11,12 @@ import ( |
| 11 | 11 |
"github.com/docker/docker/api/types" |
| 12 | 12 |
"github.com/docker/docker/api/types/swarm" |
| 13 | 13 |
"github.com/docker/docker/integration-cli/checker" |
| 14 |
+ "github.com/docker/docker/integration-cli/cli" |
|
| 15 |
+ "github.com/docker/docker/integration-cli/cli/build" |
|
| 14 | 16 |
"github.com/docker/docker/integration-cli/daemon" |
| 15 | 17 |
testdaemon "github.com/docker/docker/internal/test/daemon" |
| 16 | 18 |
"github.com/go-check/check" |
| 19 |
+ "github.com/gotestyourself/gotestyourself/icmd" |
|
| 17 | 20 |
"golang.org/x/net/context" |
| 18 | 21 |
"golang.org/x/sys/unix" |
| 19 | 22 |
) |
| ... | ... |
@@ -205,12 +208,12 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *check.C) {
|
| 205 | 205 |
image2 := "testhealth:latest" |
| 206 | 206 |
|
| 207 | 207 |
// service started from this image won't pass health check |
| 208 |
- _, _, err := d.BuildImageWithOut(image2, |
|
| 209 |
- `FROM busybox |
|
| 208 |
+ result := cli.BuildCmd(c, image2, cli.Daemon(d), |
|
| 209 |
+ build.WithDockerfile(`FROM busybox |
|
| 210 | 210 |
HEALTHCHECK --interval=1s --timeout=30s --retries=1024 \ |
| 211 |
- CMD cat /status`, |
|
| 212 |
- true) |
|
| 213 |
- c.Check(err, check.IsNil) |
|
| 211 |
+ CMD cat /status`), |
|
| 212 |
+ ) |
|
| 213 |
+ result.Assert(c, icmd.Success) |
|
| 214 | 214 |
|
| 215 | 215 |
// create service |
| 216 | 216 |
instances := 5 |
| ... | ... |
@@ -7,7 +7,6 @@ import ( |
| 7 | 7 |
"io/ioutil" |
| 8 | 8 |
"net" |
| 9 | 9 |
"net/http" |
| 10 |
- "os" |
|
| 11 | 10 |
"path/filepath" |
| 12 | 11 |
"strings" |
| 13 | 12 |
"sync" |
| ... | ... |
@@ -810,10 +809,6 @@ func (s *DockerSwarmSuite) TestAPISwarmRestartCluster(c *check.C) {
|
| 810 | 810 |
if err := daemon.StopWithError(); err != nil {
|
| 811 | 811 |
errs <- err |
| 812 | 812 |
} |
| 813 |
- // FIXME(vdemeester) This is duplicated… |
|
| 814 |
- if root := os.Getenv("DOCKER_REMAP_ROOT"); root != "" {
|
|
| 815 |
- daemon.Root = filepath.Dir(daemon.Root) |
|
| 816 |
- } |
|
| 817 | 813 |
}(d) |
| 818 | 814 |
} |
| 819 | 815 |
wg.Wait() |
| ... | ... |
@@ -31,6 +31,7 @@ import ( |
| 31 | 31 |
moby_daemon "github.com/docker/docker/daemon" |
| 32 | 32 |
"github.com/docker/docker/integration-cli/checker" |
| 33 | 33 |
"github.com/docker/docker/integration-cli/cli" |
| 34 |
+ "github.com/docker/docker/integration-cli/cli/build" |
|
| 34 | 35 |
"github.com/docker/docker/integration-cli/daemon" |
| 35 | 36 |
testdaemon "github.com/docker/docker/internal/test/daemon" |
| 36 | 37 |
"github.com/docker/docker/opts" |
| ... | ... |
@@ -1155,14 +1156,16 @@ func (s *DockerDaemonSuite) TestDaemonLoggingDriverNoneLogsError(c *check.C) {
|
| 1155 | 1155 |
func (s *DockerDaemonSuite) TestDaemonLoggingDriverShouldBeIgnoredForBuild(c *check.C) {
|
| 1156 | 1156 |
s.d.StartWithBusybox(c, "--log-driver=splunk") |
| 1157 | 1157 |
|
| 1158 |
- out, err := s.d.Cmd("build")
|
|
| 1159 |
- out, code, err := s.d.BuildImageWithOut("busyboxs", `
|
|
| 1158 |
+ result := cli.BuildCmd(c, "busyboxs", cli.Daemon(s.d), |
|
| 1159 |
+ build.WithDockerfile(` |
|
| 1160 | 1160 |
FROM busybox |
| 1161 |
- RUN echo foo`, false) |
|
| 1162 |
- comment := check.Commentf("Failed to build image. output %s, exitCode %d, err %v", out, code, err)
|
|
| 1163 |
- c.Assert(err, check.IsNil, comment) |
|
| 1164 |
- c.Assert(code, check.Equals, 0, comment) |
|
| 1165 |
- c.Assert(out, checker.Contains, "foo", comment) |
|
| 1161 |
+ RUN echo foo`), |
|
| 1162 |
+ build.WithoutCache, |
|
| 1163 |
+ ) |
|
| 1164 |
+ comment := check.Commentf("Failed to build image. output %s, exitCode %d, err %v", result.Combined(), result.ExitCode, result.Error)
|
|
| 1165 |
+ c.Assert(result.Error, check.IsNil, comment) |
|
| 1166 |
+ c.Assert(result.ExitCode, check.Equals, 0, comment) |
|
| 1167 |
+ c.Assert(result.Combined(), checker.Contains, "foo", comment) |
|
| 1166 | 1168 |
} |
| 1167 | 1169 |
|
| 1168 | 1170 |
func (s *DockerDaemonSuite) TestDaemonUnixSockCleanedUp(c *check.C) {
|
| ... | ... |
@@ -2403,12 +2406,16 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFileReload(c *chec |
| 2403 | 2403 |
|
| 2404 | 2404 |
func (s *DockerDaemonSuite) TestBuildOnDisabledBridgeNetworkDaemon(c *check.C) {
|
| 2405 | 2405 |
s.d.StartWithBusybox(c, "-b=none", "--iptables=false") |
| 2406 |
- out, code, err := s.d.BuildImageWithOut("busyboxs",
|
|
| 2407 |
- `FROM busybox |
|
| 2408 |
- RUN cat /etc/hosts`, false) |
|
| 2409 |
- comment := check.Commentf("Failed to build image. output %s, exitCode %d, err %v", out, code, err)
|
|
| 2410 |
- c.Assert(err, check.IsNil, comment) |
|
| 2411 |
- c.Assert(code, check.Equals, 0, comment) |
|
| 2406 |
+ |
|
| 2407 |
+ result := cli.BuildCmd(c, "busyboxs", cli.Daemon(s.d), |
|
| 2408 |
+ build.WithDockerfile(` |
|
| 2409 |
+ FROM busybox |
|
| 2410 |
+ RUN cat /etc/hosts`), |
|
| 2411 |
+ build.WithoutCache, |
|
| 2412 |
+ ) |
|
| 2413 |
+ comment := check.Commentf("Failed to build image. output %s, exitCode %d, err %v", result.Combined(), result.ExitCode, result.Error)
|
|
| 2414 |
+ c.Assert(result.Error, check.IsNil, comment) |
|
| 2415 |
+ c.Assert(result.ExitCode, check.Equals, 0, comment) |
|
| 2412 | 2416 |
} |
| 2413 | 2417 |
|
| 2414 | 2418 |
// Test case for #21976 |
| ... | ... |
@@ -12,8 +12,10 @@ import ( |
| 12 | 12 |
|
| 13 | 13 |
"github.com/docker/docker/integration-cli/checker" |
| 14 | 14 |
"github.com/docker/docker/integration-cli/cli" |
| 15 |
+ "github.com/docker/docker/integration-cli/cli/build" |
|
| 15 | 16 |
"github.com/docker/docker/integration-cli/daemon" |
| 16 | 17 |
"github.com/go-check/check" |
| 18 |
+ "github.com/gotestyourself/gotestyourself/icmd" |
|
| 17 | 19 |
) |
| 18 | 20 |
|
| 19 | 21 |
func pruneNetworkAndVerify(c *check.C, d *daemon.Daemon, kept, pruned []string) {
|
| ... | ... |
@@ -79,13 +81,15 @@ func (s *DockerSwarmSuite) TestPruneNetwork(c *check.C) {
|
| 79 | 79 |
func (s *DockerDaemonSuite) TestPruneImageDangling(c *check.C) {
|
| 80 | 80 |
s.d.StartWithBusybox(c) |
| 81 | 81 |
|
| 82 |
- out, _, err := s.d.BuildImageWithOut("test",
|
|
| 83 |
- `FROM busybox |
|
| 84 |
- LABEL foo=bar`, true, "-q") |
|
| 85 |
- c.Assert(err, checker.IsNil) |
|
| 86 |
- id := strings.TrimSpace(out) |
|
| 82 |
+ result := cli.BuildCmd(c, "test", cli.Daemon(s.d), |
|
| 83 |
+ build.WithDockerfile(`FROM busybox |
|
| 84 |
+ LABEL foo=bar`), |
|
| 85 |
+ cli.WithFlags("-q"),
|
|
| 86 |
+ ) |
|
| 87 |
+ result.Assert(c, icmd.Success) |
|
| 88 |
+ id := strings.TrimSpace(result.Combined()) |
|
| 87 | 89 |
|
| 88 |
- out, err = s.d.Cmd("images", "-q", "--no-trunc")
|
|
| 90 |
+ out, err := s.d.Cmd("images", "-q", "--no-trunc")
|
|
| 89 | 91 |
c.Assert(err, checker.IsNil) |
| 90 | 92 |
c.Assert(strings.TrimSpace(out), checker.Contains, id) |
| 91 | 93 |
|
| ... | ... |
@@ -266,20 +270,24 @@ func (s *DockerSuite) TestPruneNetworkLabel(c *check.C) {
|
| 266 | 266 |
func (s *DockerDaemonSuite) TestPruneImageLabel(c *check.C) {
|
| 267 | 267 |
s.d.StartWithBusybox(c) |
| 268 | 268 |
|
| 269 |
- out, _, err := s.d.BuildImageWithOut("test1",
|
|
| 270 |
- `FROM busybox |
|
| 271 |
- LABEL foo=bar`, true, "-q") |
|
| 272 |
- c.Assert(err, checker.IsNil) |
|
| 273 |
- id1 := strings.TrimSpace(out) |
|
| 274 |
- out, err = s.d.Cmd("images", "-q", "--no-trunc")
|
|
| 269 |
+ result := cli.BuildCmd(c, "test1", cli.Daemon(s.d), |
|
| 270 |
+ build.WithDockerfile(`FROM busybox |
|
| 271 |
+ LABEL foo=bar`), |
|
| 272 |
+ cli.WithFlags("-q"),
|
|
| 273 |
+ ) |
|
| 274 |
+ result.Assert(c, icmd.Success) |
|
| 275 |
+ id1 := strings.TrimSpace(result.Combined()) |
|
| 276 |
+ out, err := s.d.Cmd("images", "-q", "--no-trunc")
|
|
| 275 | 277 |
c.Assert(err, checker.IsNil) |
| 276 | 278 |
c.Assert(strings.TrimSpace(out), checker.Contains, id1) |
| 277 | 279 |
|
| 278 |
- out, _, err = s.d.BuildImageWithOut("test2",
|
|
| 279 |
- `FROM busybox |
|
| 280 |
- LABEL bar=foo`, true, "-q") |
|
| 281 |
- c.Assert(err, checker.IsNil) |
|
| 282 |
- id2 := strings.TrimSpace(out) |
|
| 280 |
+ result = cli.BuildCmd(c, "test2", cli.Daemon(s.d), |
|
| 281 |
+ build.WithDockerfile(`FROM busybox |
|
| 282 |
+ LABEL bar=foo`), |
|
| 283 |
+ cli.WithFlags("-q"),
|
|
| 284 |
+ ) |
|
| 285 |
+ result.Assert(c, icmd.Success) |
|
| 286 |
+ id2 := strings.TrimSpace(result.Combined()) |
|
| 283 | 287 |
out, err = s.d.Cmd("images", "-q", "--no-trunc")
|
| 284 | 288 |
c.Assert(err, checker.IsNil) |
| 285 | 289 |
c.Assert(strings.TrimSpace(out), checker.Contains, id2) |
| ... | ... |
@@ -9,7 +9,10 @@ import ( |
| 9 | 9 |
"github.com/docker/docker/api/types/swarm" |
| 10 | 10 |
"github.com/docker/docker/daemon/cluster/executor/container" |
| 11 | 11 |
"github.com/docker/docker/integration-cli/checker" |
| 12 |
+ "github.com/docker/docker/integration-cli/cli" |
|
| 13 |
+ "github.com/docker/docker/integration-cli/cli/build" |
|
| 12 | 14 |
"github.com/go-check/check" |
| 15 |
+ "github.com/gotestyourself/gotestyourself/icmd" |
|
| 13 | 16 |
) |
| 14 | 17 |
|
| 15 | 18 |
// start a service, and then make its task unhealthy during running |
| ... | ... |
@@ -20,15 +23,14 @@ func (s *DockerSwarmSuite) TestServiceHealthRun(c *check.C) {
|
| 20 | 20 |
d := s.AddDaemon(c, true, true) |
| 21 | 21 |
|
| 22 | 22 |
// build image with health-check |
| 23 |
- // note: use `daemon.buildImageWithOut` to build, do not use `buildImage` to build |
|
| 24 | 23 |
imageName := "testhealth" |
| 25 |
- _, _, err := d.BuildImageWithOut(imageName, |
|
| 26 |
- `FROM busybox |
|
| 24 |
+ result := cli.BuildCmd(c, imageName, cli.Daemon(d), |
|
| 25 |
+ build.WithDockerfile(`FROM busybox |
|
| 27 | 26 |
RUN touch /status |
| 28 | 27 |
HEALTHCHECK --interval=1s --timeout=1s --retries=1\ |
| 29 |
- CMD cat /status`, |
|
| 30 |
- true) |
|
| 31 |
- c.Check(err, check.IsNil) |
|
| 28 |
+ CMD cat /status`), |
|
| 29 |
+ ) |
|
| 30 |
+ result.Assert(c, icmd.Success) |
|
| 32 | 31 |
|
| 33 | 32 |
serviceName := "healthServiceRun" |
| 34 | 33 |
out, err := d.Cmd("service", "create", "--no-resolve-image", "--detach=true", "--name", serviceName, imageName, "top")
|
| ... | ... |
@@ -84,12 +86,12 @@ func (s *DockerSwarmSuite) TestServiceHealthStart(c *check.C) {
|
| 84 | 84 |
|
| 85 | 85 |
// service started from this image won't pass health check |
| 86 | 86 |
imageName := "testhealth" |
| 87 |
- _, _, err := d.BuildImageWithOut(imageName, |
|
| 88 |
- `FROM busybox |
|
| 87 |
+ result := cli.BuildCmd(c, imageName, cli.Daemon(d), |
|
| 88 |
+ build.WithDockerfile(`FROM busybox |
|
| 89 | 89 |
HEALTHCHECK --interval=1s --timeout=1s --retries=1024\ |
| 90 |
- CMD cat /status`, |
|
| 91 |
- true) |
|
| 92 |
- c.Check(err, check.IsNil) |
|
| 90 |
+ CMD cat /status`), |
|
| 91 |
+ ) |
|
| 92 |
+ result.Assert(c, icmd.Success) |
|
| 93 | 93 |
|
| 94 | 94 |
serviceName := "healthServiceStart" |
| 95 | 95 |
out, err := d.Cmd("service", "create", "--no-resolve-image", "--detach=true", "--name", serviceName, imageName, "top")
|
| ... | ... |
@@ -176,9 +176,11 @@ func (d *Daemon) NewClientT(t assert.TestingT) *client.Client {
|
| 176 | 176 |
return c |
| 177 | 177 |
} |
| 178 | 178 |
|
| 179 |
-// CleanupExecRoot cleans the daemon exec root (network namespaces, ...) |
|
| 180 |
-func (d *Daemon) CleanupExecRoot(t testingT) {
|
|
| 181 |
- cleanupExecRoot(t, d.execRoot) |
|
| 179 |
+// Cleanup cleans the daemon files : exec root (network namespaces, ...), swarmkit files |
|
| 180 |
+func (d *Daemon) Cleanup(t testingT) {
|
|
| 181 |
+ // Cleanup swarmkit wal files if present |
|
| 182 |
+ cleanupRaftDir(t, d.Root) |
|
| 183 |
+ cleanupNetworkNamespace(t, d.execRoot) |
|
| 182 | 184 |
} |
| 183 | 185 |
|
| 184 | 186 |
// Start starts the daemon and return once it is ready to receive requests. |
| ... | ... |
@@ -201,6 +203,7 @@ func (d *Daemon) StartWithError(args ...string) error {
|
| 201 | 201 |
|
| 202 | 202 |
// StartWithLogFile will start the daemon and attach its streams to a given file. |
| 203 | 203 |
func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
|
| 204 |
+ d.handleUserns() |
|
| 204 | 205 |
dockerdBinary, err := exec.LookPath(d.dockerdBinary) |
| 205 | 206 |
if err != nil {
|
| 206 | 207 |
return errors.Wrapf(err, "[%s] could not find docker binary in $PATH", d.id) |
| ... | ... |
@@ -446,7 +449,6 @@ out2: |
| 446 | 446 |
// If an error occurs while starting the daemon, the test will fail. |
| 447 | 447 |
func (d *Daemon) Restart(t testingT, args ...string) {
|
| 448 | 448 |
d.Stop(t) |
| 449 |
- d.handleUserns() |
|
| 450 | 449 |
d.Start(t, args...) |
| 451 | 450 |
} |
| 452 | 451 |
|
| ... | ... |
@@ -455,7 +457,6 @@ func (d *Daemon) RestartWithError(arg ...string) error {
|
| 455 | 455 |
if err := d.StopWithError(); err != nil {
|
| 456 | 456 |
return err |
| 457 | 457 |
} |
| 458 |
- d.handleUserns() |
|
| 459 | 458 |
return d.StartWithError(arg...) |
| 460 | 459 |
} |
| 461 | 460 |
|
| ... | ... |
@@ -636,3 +637,10 @@ func (d *Daemon) Info(t assert.TestingT) types.Info {
|
| 636 | 636 |
assert.NilError(t, err) |
| 637 | 637 |
return info |
| 638 | 638 |
} |
| 639 |
+ |
|
| 640 |
+func cleanupRaftDir(t testingT, rootPath string) {
|
|
| 641 |
+ walDir := filepath.Join(rootPath, "swarm/raft/wal") |
|
| 642 |
+ if err := os.RemoveAll(walDir); err != nil {
|
|
| 643 |
+ t.Logf("error removing %v: %v", walDir, err)
|
|
| 644 |
+ } |
|
| 645 |
+} |
| ... | ... |
@@ -9,7 +9,7 @@ import ( |
| 9 | 9 |
"golang.org/x/sys/unix" |
| 10 | 10 |
) |
| 11 | 11 |
|
| 12 |
-func cleanupExecRoot(t testingT, execRoot string) {
|
|
| 12 |
+func cleanupNetworkNamespace(t testingT, execRoot string) {
|
|
| 13 | 13 |
// Cleanup network namespaces in the exec root of this |
| 14 | 14 |
// daemon because this exec root is specific to this |
| 15 | 15 |
// daemon instance and has no chance of getting |