From 59772b34d92447b1502b6d9a836c7a26b3903053 Mon Sep 17 00:00:00 2001 From: Arash Deshmeh Date: Thu, 5 Apr 2018 17:26:29 -0400 Subject: [PATCH 1/3] refactored network integration tests to make use of swarm.CreateService Signed-off-by: Arash Deshmeh Upstream-commit: 8e335e00bb839be07ec3e1aca85deacf57a7c46a Component: engine --- .../integration/internal/swarm/service.go | 15 +++++++ .../integration/network/inspect_test.go | 42 +++++------------- .../integration/network/service_test.go | 44 +++++++++---------- 3 files changed, 45 insertions(+), 56 deletions(-) diff --git a/components/engine/integration/internal/swarm/service.go b/components/engine/integration/internal/swarm/service.go index 506bb778de..6634243fbc 100644 --- a/components/engine/integration/internal/swarm/service.go +++ b/components/engine/integration/internal/swarm/service.go @@ -136,6 +136,21 @@ func ServiceWithName(name string) ServiceSpecOpt { } } +// ServiceWithNetwork sets the network of the service +func ServiceWithNetwork(network string) ServiceSpecOpt { + return func(spec *swarmtypes.ServiceSpec) { + spec.TaskTemplate.Networks = append(spec.TaskTemplate.Networks, + swarmtypes.NetworkAttachmentConfig{Target: network}) + } +} + +// ServiceWithEndpoint sets the Endpoint of the service +func ServiceWithEndpoint(endpoint *swarmtypes.EndpointSpec) ServiceSpecOpt { + return func(spec *swarmtypes.ServiceSpec) { + spec.EndpointSpec = endpoint + } +} + // GetRunningTasks gets the list of running tasks for a service func GetRunningTasks(t *testing.T, d *daemon.Daemon, serviceID string) []swarmtypes.Task { t.Helper() diff --git a/components/engine/integration/network/inspect_test.go b/components/engine/integration/network/inspect_test.go index 8142ecdef2..e15e1b126d 100644 --- a/components/engine/integration/network/inspect_test.go +++ b/components/engine/integration/network/inspect_test.go @@ -35,16 +35,13 @@ func TestInspectNetwork(t *testing.T) { var instances uint64 = 4 serviceName := "TestService" - // FIXME(vdemeester) consolidate with swarm.CreateService - serviceSpec := swarmServiceSpec(serviceName, instances) - serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: overlayName}) - serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ - QueryRegistry: false, - }) - assert.NilError(t, err) + serviceID := swarm.CreateService(t, d, + swarm.ServiceWithReplicas(instances), + swarm.ServiceWithName(serviceName), + swarm.ServiceWithNetwork(overlayName), + ) - serviceID := serviceResp.ID poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), swarm.ServicePoll) _, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) @@ -78,12 +75,12 @@ func TestInspectNetwork(t *testing.T) { poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll) poll.WaitOn(t, noTasks(client), swarm.ServicePoll) - serviceResp, err = client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ - QueryRegistry: false, - }) - assert.NilError(t, err) + serviceID2 := swarm.CreateService(t, d, + swarm.ServiceWithReplicas(instances), + swarm.ServiceWithName(serviceName), + swarm.ServiceWithNetwork(overlayName), + ) - serviceID2 := serviceResp.ID poll.WaitOn(t, serviceRunningTasksCount(client, serviceID2, instances), swarm.ServicePoll) err = client.ServiceRemove(context.Background(), serviceID2) @@ -98,25 +95,6 @@ func TestInspectNetwork(t *testing.T) { poll.WaitOn(t, networkIsRemoved(client, overlayID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) } -func swarmServiceSpec(name string, replicas uint64) swarmtypes.ServiceSpec { - return swarmtypes.ServiceSpec{ - Annotations: swarmtypes.Annotations{ - Name: name, - }, - TaskTemplate: swarmtypes.TaskSpec{ - ContainerSpec: &swarmtypes.ContainerSpec{ - Image: "busybox:latest", - Command: []string{"/bin/top"}, - }, - }, - Mode: swarmtypes.ServiceMode{ - Replicated: &swarmtypes.ReplicatedService{ - Replicas: &replicas, - }, - }, - } -} - func serviceRunningTasksCount(client client.ServiceAPIClient, serviceID string, instances uint64) func(log poll.LogT) poll.Result { return func(log poll.LogT) poll.Result { filter := filters.NewArgs() diff --git a/components/engine/integration/network/service_test.go b/components/engine/integration/network/service_test.go index 8efd7d1fac..d1def1ec88 100644 --- a/components/engine/integration/network/service_test.go +++ b/components/engine/integration/network/service_test.go @@ -23,18 +23,16 @@ func TestServiceWithPredefinedNetwork(t *testing.T) { hostName := "host" var instances uint64 = 1 serviceName := "TestService" - serviceSpec := swarmServiceSpec(serviceName, instances) - serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: hostName}) - serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ - QueryRegistry: false, - }) - assert.NilError(t, err) + serviceID := swarm.CreateService(t, d, + swarm.ServiceWithReplicas(instances), + swarm.ServiceWithName(serviceName), + swarm.ServiceWithNetwork(hostName), + ) - serviceID := serviceResp.ID poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), swarm.ServicePoll) - _, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) + _, _, err := client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) assert.NilError(t, err) err = client.ServiceRemove(context.Background(), serviceID) @@ -53,26 +51,24 @@ func TestServiceRemoveKeepsIngressNetwork(t *testing.T) { poll.WaitOn(t, swarmIngressReady(client), swarm.NetworkPoll) var instances uint64 = 1 - serviceSpec := swarmServiceSpec(t.Name()+"-service", instances) - serviceSpec.EndpointSpec = &swarmtypes.EndpointSpec{ - Ports: []swarmtypes.PortConfig{ - { - Protocol: swarmtypes.PortConfigProtocolTCP, - TargetPort: 80, - PublishMode: swarmtypes.PortConfigPublishModeIngress, + + serviceID := swarm.CreateService(t, d, + swarm.ServiceWithReplicas(instances), + swarm.ServiceWithName(t.Name()+"-service"), + swarm.ServiceWithEndpoint(&swarmtypes.EndpointSpec{ + Ports: []swarmtypes.PortConfig{ + { + Protocol: swarmtypes.PortConfigProtocolTCP, + TargetPort: 80, + PublishMode: swarmtypes.PortConfigPublishModeIngress, + }, }, - }, - } + }), + ) - serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ - QueryRegistry: false, - }) - assert.NilError(t, err) - - serviceID := serviceResp.ID poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), swarm.ServicePoll) - _, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) + _, _, err := client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) assert.NilError(t, err) err = client.ServiceRemove(context.Background(), serviceID) From 7fc438fe9abb641626db9fcd85679cef7cf16ebf Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 15 Mar 2018 20:07:26 -0700 Subject: [PATCH 2/3] TestPostContainerAttach: minor improvements When this test fails, the error looks like this: > FAIL: docker_api_attach_test.go:98: DockerSuite.TestPostContainersAttach > docker_api_attach_test.go:211: > c.Assert(actualStdout.Bytes(), checker.DeepEquals, []byte("hello\nsuccess"), check.Commentf("Attach didn't return the expected data from stdout")) > ... obtained []uint8 = []byte{0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73} > ... expected []uint8 = []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f, 0xa, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73} > ... Attach didn't return the expected data from stdout Let's use strings for comparisons to make the output more readable. While at it, - get the container's stderr as well, and make sure it's empty; - check that stdcopy.StdCopy() did not return an error, except for the timeout which is expected; - move/remove comments, simplify var names. Signed-off-by: Kir Kolyshkin Upstream-commit: ecc54889c9a233d558b578dfd48eb5d84506a62a Component: engine --- .../integration-cli/docker_api_attach_test.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/components/engine/integration-cli/docker_api_attach_test.go b/components/engine/integration-cli/docker_api_attach_test.go index e191f278f7..bcf890a761 100644 --- a/components/engine/integration-cli/docker_api_attach_test.go +++ b/components/engine/integration-cli/docker_api_attach_test.go @@ -18,6 +18,7 @@ import ( "github.com/docker/docker/integration-cli/request" "github.com/docker/docker/pkg/stdcopy" "github.com/go-check/check" + "github.com/pkg/errors" "golang.org/x/net/websocket" ) @@ -176,7 +177,6 @@ func (s *DockerSuite) TestPostContainersAttach(c *check.C) { expectTimeout(conn, br, "stdout") // Test the client API - // Make sure we don't see "hello" if Logs is false client, err := client.NewEnvClient() c.Assert(err, checker.IsNil) defer client.Close() @@ -184,10 +184,13 @@ func (s *DockerSuite) TestPostContainersAttach(c *check.C) { cid, _ = dockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "echo hello; cat") cid = strings.TrimSpace(cid) + // Make sure we don't see "hello" if Logs is false attachOpts := types.ContainerAttachOptions{ Stream: true, Stdin: true, Stdout: true, + Stderr: true, + Logs: false, } resp, err := client.ContainerAttach(context.Background(), cid, attachOpts) @@ -205,10 +208,15 @@ func (s *DockerSuite) TestPostContainersAttach(c *check.C) { _, err = resp.Conn.Write([]byte("success")) c.Assert(err, checker.IsNil) - actualStdout := new(bytes.Buffer) - actualStderr := new(bytes.Buffer) - stdcopy.StdCopy(actualStdout, actualStderr, resp.Reader) - c.Assert(actualStdout.Bytes(), checker.DeepEquals, []byte("hello\nsuccess"), check.Commentf("Attach didn't return the expected data from stdout")) + var outBuf, errBuf bytes.Buffer + _, err = stdcopy.StdCopy(&outBuf, &errBuf, resp.Reader) + if err != nil && errors.Cause(err).(net.Error).Timeout() { + // ignore the timeout error as it is expected + err = nil + } + c.Assert(err, checker.IsNil) + c.Assert(errBuf.String(), checker.Equals, "") + c.Assert(outBuf.String(), checker.Equals, "hello\nsuccess") } // SockRequestHijack creates a connection to specified host (with method, contenttype, …) and returns a hijacked connection From 267d640e44cb5862732c86359a1bdba95478e266 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Tue, 1 May 2018 13:40:27 -0400 Subject: [PATCH 3/3] Bump go version to 1.10.2 Signed-off-by: Brian Goff Upstream-commit: 9e5bebb1f58d4085d1b5fc1edb0ece1edd418c15 Component: engine --- components/engine/Dockerfile | 4 ++-- components/engine/Dockerfile.e2e | 2 +- components/engine/Dockerfile.simple | 2 +- components/engine/Dockerfile.windows | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/engine/Dockerfile b/components/engine/Dockerfile index 5e21982081..c4651b7b50 100644 --- a/components/engine/Dockerfile +++ b/components/engine/Dockerfile @@ -32,10 +32,10 @@ # the case. Therefore, you don't have to disable it anymore. # -FROM golang:1.10.1 AS base +FROM golang:1.10.2 AS base # FIXME(vdemeester) this is kept for other script depending on it to not fail right away # Remove this once the other scripts uses something else to detect the version -ENV GO_VERSION 1.10.1 +ENV GO_VERSION 1.10.2 # allow replacing httpredir or deb mirror ARG APT_MIRROR=deb.debian.org RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list diff --git a/components/engine/Dockerfile.e2e b/components/engine/Dockerfile.e2e index 78e863b1a4..77c9205d45 100644 --- a/components/engine/Dockerfile.e2e +++ b/components/engine/Dockerfile.e2e @@ -1,5 +1,5 @@ ## Step 1: Build tests -FROM golang:1.10.1-alpine3.7 as builder +FROM golang:1.10.2-alpine3.7 as builder RUN apk add --update \ bash \ diff --git a/components/engine/Dockerfile.simple b/components/engine/Dockerfile.simple index 5c07a4f929..67a78003e1 100644 --- a/components/engine/Dockerfile.simple +++ b/components/engine/Dockerfile.simple @@ -42,7 +42,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ # will need updating, to avoid errors. Ping #docker-maintainers on IRC # with a heads-up. # IMPORTANT: When updating this please note that stdlib archive/tar pkg is vendored -ENV GO_VERSION 1.10.1 +ENV GO_VERSION 1.10.2 RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" \ | tar -xzC /usr/local ENV PATH /go/bin:/usr/local/go/bin:$PATH diff --git a/components/engine/Dockerfile.windows b/components/engine/Dockerfile.windows index 0b539375a6..0cc7aa4f5b 100644 --- a/components/engine/Dockerfile.windows +++ b/components/engine/Dockerfile.windows @@ -161,7 +161,7 @@ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPref # Environment variable notes: # - GO_VERSION must be consistent with 'Dockerfile' used by Linux. # - FROM_DOCKERFILE is used for detection of building within a container. -ENV GO_VERSION=1.10.1 ` +ENV GO_VERSION=1.10.2 ` GIT_VERSION=2.11.1 ` GOPATH=C:\go ` FROM_DOCKERFILE=1