From 4d643fb18a5f998b9028b309ce6b60f64d2ee95d Mon Sep 17 00:00:00 2001 From: Christopher Crone Date: Tue, 12 Sep 2017 14:53:20 +0200 Subject: [PATCH] Fixes for dnephin review Signed-off-by: Christopher Crone Upstream-commit: 86f9eb4a085a61b3355dc38452c47def806bf7c9 Component: engine --- components/engine/Dockerfile.e2e | 38 ++++++++++------- .../e2e/run.sh => hack/test/e2e-run.sh} | 2 + .../cli/build/fakestorage/fixtures.go | 41 +++++++++++-------- .../integration-cli/docker_api_build_test.go | 20 +-------- .../docker_api_containers_test.go | 2 +- .../integration-cli/docker_api_images_test.go | 2 +- .../docker_api_inspect_unix_test.go | 3 +- .../docker_cli_authz_plugin_v2_test.go | 11 +---- .../docker_cli_authz_unix_test.go | 8 ---- .../integration-cli/docker_cli_build_test.go | 27 +----------- .../integration-cli/docker_cli_health_test.go | 8 ++-- .../integration-cli/docker_cli_kill_test.go | 3 +- .../integration-cli/docker_cli_port_test.go | 1 + .../integration-cli/docker_utils_test.go | 2 +- .../engine/integration-cli/request/request.go | 12 ++++++ .../engine/integration-cli/utils_test.go | 19 +-------- 16 files changed, 79 insertions(+), 120 deletions(-) rename components/engine/{internal/e2e/run.sh => hack/test/e2e-run.sh} (83%) diff --git a/components/engine/Dockerfile.e2e b/components/engine/Dockerfile.e2e index 6d8e5dfbd6..6ce92dd1fc 100644 --- a/components/engine/Dockerfile.e2e +++ b/components/engine/Dockerfile.e2e @@ -1,3 +1,4 @@ +## Step 1: Build tests FROM golang:1.8.3-alpine3.6 as builder RUN apk add --update \ @@ -11,26 +12,31 @@ RUN apk add --update \ RUN mkdir -p /go/src/github.com/docker/docker/ WORKDIR /go/src/github.com/docker/docker/ -COPY contrib contrib +# Generate frozen images +COPY contrib/download-frozen-image-v2.sh contrib/download-frozen-image-v2.sh RUN contrib/download-frozen-image-v2.sh /output/docker-frozen-images \ buildpack-deps:jessie@sha256:85b379ec16065e4fe4127eb1c5fb1bcc03c559bd36dbb2e22ff496de55925fa6 \ busybox:latest@sha256:32f093055929dbc23dec4d03e09dfe971f5973a9ca5cf059cbfb644c206aa83f \ debian:jessie@sha256:72f784399fd2719b4cb4e16ef8e369a39dc67f53d978cd3e2e7bf4e502c7b793 \ hello-world:latest@sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7 +# Download Docker CLI binary +COPY hack/dockerfile hack/dockerfile +RUN hack/dockerfile/install-binaries.sh dockercli + +# Set tag and add sources ARG DOCKER_GITCOMMIT - ENV DOCKER_GITCOMMIT=$DOCKER_GITCOMMIT - -# integration-cli tests are frozen to 17.06 -# Newer CLI tests can be found in the docker/cli repository -RUN curl https://download.docker.com/linux/static/stable/x86_64/docker-17.06.2-ce.tgz | tar xzf - -C /output - ADD . . +# Build DockerSuite.TestBuild* dependency +RUN CGO_ENABLED=0 go build -o /output/httpserver github.com/docker/docker/contrib/httpserver + +# Build the integration tests and copy the resulting binaries to /output/tests RUN hack/make.sh build-integration-test-binary RUN mkdir -p /output/tests && find . -name test.main -exec cp --parents '{}' /output/tests \; +## Step 2: Generate testing image FROM alpine:3.6 as runner # GNU tar is used for generating the emptyfs image @@ -47,15 +53,17 @@ RUN apk add --update \ # Add an unprivileged user to be used for tests which need it RUN addgroup docker && adduser -D -G docker unprivilegeduser -s /bin/ash -ENV DOCKER_E2E=1 DOCKER_REMOTE_DAEMON=1 DOCKER_INTEGRATION_DAEMON_DEST=/ - -COPY --from=builder /output/docker/docker /usr/bin/docker -COPY --from=builder /output/docker-frozen-images /docker-frozen-images -COPY --from=builder /output/tests /tests - -COPY contrib /tests/contrib +COPY contrib/httpserver/Dockerfile /tests/contrib/httpserver/Dockerfile +COPY contrib/syscall-test /tests/contrib/syscall-test +COPY hack/test/e2e-run.sh /run.sh COPY hack/make/.ensure-emptyfs /ensure-emptyfs.sh COPY integration-cli/fixtures /tests/integration-cli/fixtures -COPY internal/e2e/run.sh /run.sh + +COPY --from=builder /output/docker-frozen-images /docker-frozen-images +COPY --from=builder /output/httpserver /tests/contrib/httpserver/httpserver +COPY --from=builder /output/tests /tests +COPY --from=builder /usr/local/bin/docker /usr/bin/docker + +ENV DOCKER_E2E=1 DOCKER_REMOTE_DAEMON=1 DOCKER_INTEGRATION_DAEMON_DEST=/ ENTRYPOINT ["/run.sh"] diff --git a/components/engine/internal/e2e/run.sh b/components/engine/hack/test/e2e-run.sh similarity index 83% rename from components/engine/internal/e2e/run.sh rename to components/engine/hack/test/e2e-run.sh index 83b88ae509..e7a2c5420b 100755 --- a/components/engine/internal/e2e/run.sh +++ b/components/engine/hack/test/e2e-run.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash set -e +export DOCKER_ENGINE_GOARCH=${DOCKER_ENGINE_GOARCH:-amd64} + echo "Ensure emptyfs image is loaded" bash /ensure-emptyfs.sh diff --git a/components/engine/integration-cli/cli/build/fakestorage/fixtures.go b/components/engine/integration-cli/cli/build/fakestorage/fixtures.go index 8a6bb137ad..b76a7d9207 100644 --- a/components/engine/integration-cli/cli/build/fakestorage/fixtures.go +++ b/components/engine/integration-cli/cli/build/fakestorage/fixtures.go @@ -39,27 +39,34 @@ func ensureHTTPServerImage(t testingT) { goarch = "amd64" } - goCmd, lookErr := exec.LookPath("go") - if lookErr != nil { - t.Fatalf("could not build http server: %v", lookErr) - } - - cmd := exec.Command(goCmd, "build", "-o", filepath.Join(tmp, "httpserver"), "github.com/docker/docker/contrib/httpserver") - cmd.Env = append(os.Environ(), []string{ - "CGO_ENABLED=0", - "GOOS=" + goos, - "GOARCH=" + goarch, - }...) - var out []byte - if out, err = cmd.CombinedOutput(); err != nil { - t.Fatalf("could not build http server: %s", string(out)) - } - cpCmd, lookErr := exec.LookPath("cp") if lookErr != nil { t.Fatalf("could not build http server: %v", lookErr) } - if out, err = exec.Command(cpCmd, "../contrib/httpserver/Dockerfile", filepath.Join(tmp, "Dockerfile")).CombinedOutput(); err != nil { + + if _, err = os.Stat("../contrib/httpserver/httpserver"); os.IsNotExist(err) { + goCmd, lookErr := exec.LookPath("go") + if lookErr != nil { + t.Fatalf("could not build http server: %v", lookErr) + } + + cmd := exec.Command(goCmd, "build", "-o", filepath.Join(tmp, "httpserver"), "github.com/docker/docker/contrib/httpserver") + cmd.Env = append(os.Environ(), []string{ + "CGO_ENABLED=0", + "GOOS=" + goos, + "GOARCH=" + goarch, + }...) + var out []byte + if out, err = cmd.CombinedOutput(); err != nil { + t.Fatalf("could not build http server: %s", string(out)) + } + } else { + if out, err := exec.Command(cpCmd, "../contrib/httpserver/httpserver", filepath.Join(tmp, "httpserver")).CombinedOutput(); err != nil { + t.Fatalf("could not copy http server: %v", string(out)) + } + } + + if out, err := exec.Command(cpCmd, "../contrib/httpserver/Dockerfile", filepath.Join(tmp, "Dockerfile")).CombinedOutput(); err != nil { t.Fatalf("could not build http server: %v", string(out)) } diff --git a/components/engine/integration-cli/docker_api_build_test.go b/components/engine/integration-cli/docker_api_build_test.go index 22b6e5c501..d428d78f0a 100644 --- a/components/engine/integration-cli/docker_api_build_test.go +++ b/components/engine/integration-cli/docker_api_build_test.go @@ -27,8 +27,7 @@ import ( ) func (s *DockerSuite) TestBuildAPIDockerFileRemote(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, NotUserNamespace, NotE2E) + testRequires(c, NotUserNamespace) var testD string if testEnv.DaemonPlatform() == "windows" { @@ -59,9 +58,6 @@ RUN find /tmp/` } func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, NotE2E) - buffer := new(bytes.Buffer) tw := tar.NewWriter(buffer) defer tw.Close() @@ -93,9 +89,6 @@ func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) { } func (s *DockerSuite) TestBuildAPIRemoteTarballContextWithCustomDockerfile(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, NotE2E) - buffer := new(bytes.Buffer) tw := tar.NewWriter(buffer) defer tw.Close() @@ -150,8 +143,6 @@ RUN echo 'right' } func (s *DockerSuite) TestBuildAPILowerDockerfile(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, NotE2E) git := fakegit.New(c, "repo", map[string]string{ "dockerfile": `FROM busybox RUN echo from dockerfile`, @@ -170,9 +161,6 @@ RUN echo from dockerfile`, } func (s *DockerSuite) TestBuildAPIBuildGitWithF(c *check.C) { - // E2E: Test requires go and contrib source. - testRequires(c, NotE2E) - git := fakegit.New(c, "repo", map[string]string{ "baz": `FROM busybox RUN echo from baz`, @@ -194,8 +182,7 @@ RUN echo from Dockerfile`, } func (s *DockerSuite) TestBuildAPIDoubleDockerfile(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, UnixCli, NotE2E) // dockerfile overwrites Dockerfile on Windows + testRequires(c, UnixCli) // dockerfile overwrites Dockerfile on Windows git := fakegit.New(c, "repo", map[string]string{ "Dockerfile": `FROM busybox RUN echo from Dockerfile`, @@ -380,9 +367,6 @@ func (s *DockerRegistrySuite) TestBuildCopyFromForcePull(c *check.C) { } func (s *DockerSuite) TestBuildAddRemoteNoDecompress(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, NotE2E) - buffer := new(bytes.Buffer) tw := tar.NewWriter(buffer) dt := []byte("contents") diff --git a/components/engine/integration-cli/docker_api_containers_test.go b/components/engine/integration-cli/docker_api_containers_test.go index ddc5a43603..dbec3dc76c 100644 --- a/components/engine/integration-cli/docker_api_containers_test.go +++ b/components/engine/integration-cli/docker_api_containers_test.go @@ -1372,7 +1372,7 @@ func (s *DockerSuite) TestContainerAPICreateNoHostConfig118(c *check.C) { Image: "busybox", } - cli, err := NewEnvClientWithVersion("v1.18") + cli, err := request.NewEnvClientWithVersion("v1.18") _, err = cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networktypes.NetworkingConfig{}, "") c.Assert(err, checker.IsNil) diff --git a/components/engine/integration-cli/docker_api_images_test.go b/components/engine/integration-cli/docker_api_images_test.go index e380543210..b9dae7aab7 100644 --- a/components/engine/integration-cli/docker_api_images_test.go +++ b/components/engine/integration-cli/docker_api_images_test.go @@ -180,7 +180,7 @@ func (s *DockerSuite) TestAPIImagesSizeCompatibility(c *check.C) { Labels map[string]string } - cli, err = NewEnvClientWithVersion("v1.24") + cli, err = request.NewEnvClientWithVersion("v1.24") c.Assert(err, checker.IsNil) defer cli.Close() diff --git a/components/engine/integration-cli/docker_api_inspect_unix_test.go b/components/engine/integration-cli/docker_api_inspect_unix_test.go index 7fc4cb0b45..dae64be2a7 100644 --- a/components/engine/integration-cli/docker_api_inspect_unix_test.go +++ b/components/engine/integration-cli/docker_api_inspect_unix_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "github.com/docker/docker/integration-cli/checker" + "github.com/docker/docker/integration-cli/request" "github.com/go-check/check" "golang.org/x/net/context" ) @@ -17,7 +18,7 @@ func (s *DockerSuite) TestInspectAPICpusetInConfigPre120(c *check.C) { name := "cpusetinconfig-pre120" dockerCmd(c, "run", "--name", name, "--cpuset-cpus", "0", "busybox", "true") - cli, err := NewEnvClientWithVersion("v1.19") + cli, err := request.NewEnvClientWithVersion("v1.19") c.Assert(err, checker.IsNil) defer cli.Close() _, body, err := cli.ContainerInspectWithRaw(context.Background(), name, false) diff --git a/components/engine/integration-cli/docker_cli_authz_plugin_v2_test.go b/components/engine/integration-cli/docker_cli_authz_plugin_v2_test.go index 025d5aeb7f..bdc3f15e5b 100644 --- a/components/engine/integration-cli/docker_cli_authz_plugin_v2_test.go +++ b/components/engine/integration-cli/docker_cli_authz_plugin_v2_test.go @@ -4,7 +4,6 @@ package main import ( "fmt" - "strings" "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/daemon" @@ -48,8 +47,6 @@ func (s *DockerAuthzV2Suite) TearDownTest(c *check.C) { func (s *DockerAuthzV2Suite) TestAuthZPluginAllowNonVolumeRequest(c *check.C) { testRequires(c, DaemonIsLinux, IsAmd64, Network) - existingContainers := ExistingContainerIDs(c) - // Install authz plugin _, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", authzPluginNameWithTag) c.Assert(err, checker.IsNil) @@ -68,14 +65,8 @@ func (s *DockerAuthzV2Suite) TestAuthZPluginAllowNonVolumeRequest(c *check.C) { }() // Ensure docker run command and accompanying docker ps are successful - out, err := s.d.Cmd("run", "-d", "busybox", "top") + _, err = s.d.Cmd("run", "-d", "busybox", "top") c.Assert(err, check.IsNil) - - id := strings.TrimSpace(out) - - out, err = s.d.Cmd("ps") - c.Assert(err, check.IsNil) - c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{id}), check.Equals, true) } func (s *DockerAuthzV2Suite) TestAuthZPluginDisable(c *check.C) { diff --git a/components/engine/integration-cli/docker_cli_authz_unix_test.go b/components/engine/integration-cli/docker_cli_authz_unix_test.go index cf3d88e12a..5b7b9fab14 100644 --- a/components/engine/integration-cli/docker_cli_authz_unix_test.go +++ b/components/engine/integration-cli/docker_cli_authz_unix_test.go @@ -204,8 +204,6 @@ func (s *DockerAuthzSuite) TearDownSuite(c *check.C) { } func (s *DockerAuthzSuite) TestAuthZPluginAllowRequest(c *check.C) { - existingContainers := ExistingContainerIDs(c) - // start the daemon and load busybox, --net=none build fails otherwise // cause it needs to pull busybox s.d.Start(c, "--authorization-plugin="+testAuthZPlugin) @@ -220,12 +218,6 @@ func (s *DockerAuthzSuite) TestAuthZPluginAllowRequest(c *check.C) { id := strings.TrimSpace(out) assertURIRecorded(c, s.ctrl.requestsURIs, "/containers/create") assertURIRecorded(c, s.ctrl.requestsURIs, fmt.Sprintf("/containers/%s/start", id)) - - out, err = s.d.Cmd("ps") - c.Assert(err, check.IsNil) - c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{id}), check.Equals, true) - c.Assert(s.ctrl.psRequestCnt, check.Equals, 1) - c.Assert(s.ctrl.psResponseCnt, check.Equals, 1) } func (s *DockerAuthzSuite) TestAuthZPluginTls(c *check.C) { diff --git a/components/engine/integration-cli/docker_cli_build_test.go b/components/engine/integration-cli/docker_cli_build_test.go index 3d0b49dcf9..59213e5404 100644 --- a/components/engine/integration-cli/docker_cli_build_test.go +++ b/components/engine/integration-cli/docker_cli_build_test.go @@ -368,8 +368,7 @@ ONBUILD ENTRYPOINT ["echo"]`)) } func (s *DockerSuite) TestBuildCacheAdd(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, DaemonIsLinux, NotE2E) // Windows doesn't have httpserver image yet + testRequires(c, DaemonIsLinux) // Windows doesn't have httpserver image yet name := "testbuildtwoimageswithadd" server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{ "robots.txt": "hello", @@ -389,9 +388,6 @@ func (s *DockerSuite) TestBuildCacheAdd(c *check.C) { } func (s *DockerSuite) TestBuildLastModified(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, NotE2E) - // Temporary fix for #30890. TODO @jhowardmsft figure out what // has changed in the master busybox image. testRequires(c, DaemonIsLinux) @@ -521,8 +517,7 @@ RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' } func (s *DockerSuite) TestBuildCopyAddMultipleFiles(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, DaemonIsLinux, NotE2E) // Linux specific test + testRequires(c, DaemonIsLinux) // Linux specific test server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{ "robots.txt": "hello", })) @@ -637,9 +632,6 @@ RUN find "test6" "C:/test dir/test_file6"` } func (s *DockerSuite) TestBuildCopyWildcard(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, NotE2E) - name := "testcopywildcard" server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{ "robots.txt": "hello", @@ -1935,9 +1927,6 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithoutCache(c *check.C) { } func (s *DockerSuite) TestBuildAddRemoteFileWithAndWithoutCache(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, NotE2E) - name := "testbuildaddremotefilewithcache" server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{ "baz": "hello", @@ -1963,9 +1952,6 @@ func (s *DockerSuite) TestBuildAddRemoteFileWithAndWithoutCache(c *check.C) { } func (s *DockerSuite) TestBuildAddRemoteFileMTime(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, NotE2E) - name := "testbuildaddremotefilemtime" name2 := name + "2" name3 := name + "3" @@ -2009,9 +1995,6 @@ func (s *DockerSuite) TestBuildAddRemoteFileMTime(c *check.C) { // FIXME(vdemeester) this really seems to test the same thing as before (combined) func (s *DockerSuite) TestBuildAddLocalAndRemoteFilesWithAndWithoutCache(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, NotE2E) - name := "testbuildaddlocalandremotefilewithcache" server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{ "baz": "hello", @@ -3112,9 +3095,6 @@ func (s *DockerSuite) TestBuildFromGitWithF(c *check.C) { } func (s *DockerSuite) TestBuildFromRemoteTarball(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, NotE2E) - name := "testbuildfromremotetarball" buffer := new(bytes.Buffer) @@ -3781,9 +3761,6 @@ func (s *DockerSuite) TestBuildFromMixedcaseDockerfile(c *check.C) { } func (s *DockerSuite) TestBuildFromURLWithF(c *check.C) { - // E2E: Requires built httpserver. - testRequires(c, NotE2E) - server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{"baz": `FROM busybox RUN echo from baz COPY * /tmp/ diff --git a/components/engine/integration-cli/docker_cli_health_test.go b/components/engine/integration-cli/docker_cli_health_test.go index f6228075be..20b2bc255d 100644 --- a/components/engine/integration-cli/docker_cli_health_test.go +++ b/components/engine/integration-cli/docker_cli_health_test.go @@ -39,7 +39,7 @@ func getHealth(c *check.C, name string) *types.Health { func (s *DockerSuite) TestHealth(c *check.C) { testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows - existingContainers := ExistingContainerNames(c) + existingContainers := ExistingContainerIDs(c) imageName := "testhealth" buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox @@ -51,10 +51,10 @@ func (s *DockerSuite) TestHealth(c *check.C) { // No health status before starting name := "test_health" - dockerCmd(c, "create", "--name", name, imageName) - out, _ := dockerCmd(c, "ps", "-a", "--format={{.Status}}") + cid, _ := dockerCmd(c, "create", "--name", name, imageName) + out, _ := dockerCmd(c, "ps", "-a", "--format={{.ID}} {{.Status}}") out = RemoveOutputForExistingElements(out, existingContainers) - c.Check(out, checker.Equals, "Created\n") + c.Check(out, checker.Equals, cid[:12]+" Created\n") // Inspect the options out, _ = dockerCmd(c, "inspect", diff --git a/components/engine/integration-cli/docker_cli_kill_test.go b/components/engine/integration-cli/docker_cli_kill_test.go index a949bdb37f..0a5aac5f8c 100644 --- a/components/engine/integration-cli/docker_cli_kill_test.go +++ b/components/engine/integration-cli/docker_cli_kill_test.go @@ -6,6 +6,7 @@ import ( "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/cli" + "github.com/docker/docker/integration-cli/request" "github.com/go-check/check" "github.com/gotestyourself/gotestyourself/icmd" "golang.org/x/net/context" @@ -129,7 +130,7 @@ func (s *DockerSuite) TestKillStoppedContainerAPIPre120(c *check.C) { testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later runSleepingContainer(c, "--name", "docker-kill-test-api", "-d") dockerCmd(c, "stop", "docker-kill-test-api") - cli, err := NewEnvClientWithVersion("v1.19") + cli, err := request.NewEnvClientWithVersion("v1.19") c.Assert(err, check.IsNil) defer cli.Close() err = cli.ContainerKill(context.Background(), "docker-kill-test-api", "SIGKILL") diff --git a/components/engine/integration-cli/docker_cli_port_test.go b/components/engine/integration-cli/docker_cli_port_test.go index 7450dd4837..84058cda10 100644 --- a/components/engine/integration-cli/docker_cli_port_test.go +++ b/components/engine/integration-cli/docker_cli_port_test.go @@ -149,6 +149,7 @@ func (s *DockerSuite) TestPortList(c *check.C) { out, _ = dockerCmd(c, "port", ID) + // Running this test multiple times causes the TCP port to increment. err = assertPortRange(c, out, []int{8000, 8080}, []int{8000, 8080}) // Port list is not correct c.Assert(err, checker.IsNil) diff --git a/components/engine/integration-cli/docker_utils_test.go b/components/engine/integration-cli/docker_utils_test.go index 194e0660f2..1bda2c7239 100644 --- a/components/engine/integration-cli/docker_utils_test.go +++ b/components/engine/integration-cli/docker_utils_test.go @@ -372,7 +372,7 @@ func waitInspectWithArgs(name, expr, expected string, timeout time.Duration, arg } func getInspectBody(c *check.C, version, id string) []byte { - cli, err := NewEnvClientWithVersion(version) + cli, err := request.NewEnvClientWithVersion(version) c.Assert(err, check.IsNil) defer cli.Close() _, body, err := cli.ContainerInspectWithRaw(context.Background(), id, false) diff --git a/components/engine/integration-cli/request/request.go b/components/engine/integration-cli/request/request.go index f2b0320bd0..495a1b0eae 100644 --- a/components/engine/integration-cli/request/request.go +++ b/components/engine/integration-cli/request/request.go @@ -18,6 +18,7 @@ import ( "time" "github.com/docker/docker/api" + "github.com/docker/docker/api/types" dclient "github.com/docker/docker/client" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/ioutils" @@ -323,3 +324,14 @@ func DaemonHost() string { } return daemonURLStr } + +// NewEnvClientWithVersion returns a docker client with a specified version. +// See: github.com/docker/docker/client `NewEnvClient()` +func NewEnvClientWithVersion(version string) (*dclient.Client, error) { + cli, err := dclient.NewEnvClient() + if err != nil { + return nil, err + } + cli.NegotiateAPIVersionPing(types.Ping{APIVersion: version}) + return cli, nil +} diff --git a/components/engine/integration-cli/utils_test.go b/components/engine/integration-cli/utils_test.go index 9d8ec60812..f6f111ec25 100644 --- a/components/engine/integration-cli/utils_test.go +++ b/components/engine/integration-cli/utils_test.go @@ -7,8 +7,6 @@ import ( "path/filepath" "strings" - "github.com/docker/docker/api/types" - "github.com/docker/docker/client" "github.com/docker/docker/pkg/parsers/kernel" "github.com/docker/docker/pkg/stringutils" "github.com/go-check/check" @@ -185,17 +183,6 @@ func RemoveOutputForExistingElements(output string, existing []string) string { return strings.Join(res, "\n") } -// NewEnvClientWithVersion returns a docker client with a specified version. -// See: github.com/docker/docker/client `NewEnvClient()` -func NewEnvClientWithVersion(version string) (*client.Client, error) { - cli, err := client.NewEnvClient() - if err != nil { - return nil, err - } - cli.NegotiateAPIVersionPing(types.Ping{APIVersion: version}) - return cli, nil -} - // GetKernelVersion gets the current kernel version. func GetKernelVersion() *kernel.VersionInfo { v, _ := kernel.ParseRelease(testEnv.DaemonInfo.KernelVersion) @@ -205,9 +192,5 @@ func GetKernelVersion() *kernel.VersionInfo { // CheckKernelVersion checks if current kernel is newer than (or equal to) // the given version. func CheckKernelVersion(k, major, minor int) bool { - v := GetKernelVersion() - if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: k, Major: major, Minor: minor}) < 0 { - return false - } - return true + return kernel.CompareKernelVersion(*GetKernelVersion(), kernel.VersionInfo{Kernel: k, Major: major, Minor: minor}) > 0 }