Browse code

integration/*: make e2e run without failure

… mainly by skipping if daemon is remote.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2018/03/14 19:21:21
Showing 10 changed files
... ...
@@ -13,8 +13,8 @@ export DOCKER_ENGINE_GOARCH=${DOCKER_ENGINE_GOARCH:-${ARCH}}
13 13
 : ${TESTDEBUG:=}
14 14
 
15 15
 integration_api_dirs=${TEST_INTEGRATION_DIR:-"$(
16
-	find ./integration -type d |
17
-	grep -vE '(^./integration($|/internal)|/testdata)')"}
16
+	find /tests/integration -type d |
17
+	grep -vE '(^/tests/integration($|/internal)|/testdata)')"}
18 18
 
19 19
 run_test_integration() {
20 20
 	[[ "$TESTFLAGS" != *-check.f* ]] && run_test_integration_suites
... ...
@@ -35,7 +35,7 @@ run_test_integration_suites() {
35 35
 run_test_integration_legacy_suites() {
36 36
 	(
37 37
 		flags="-check.v -check.timeout=${TIMEOUT} -test.timeout=360m $TESTFLAGS"
38
-		cd test/integration-cli
38
+		cd /tests/integration-cli
39 39
 		echo "Running $PWD"
40 40
 		test_env ./test.main $flags
41 41
 	)
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"bytes"
6 6
 	"context"
7 7
 	"encoding/json"
8
+	"fmt"
8 9
 	"io"
9 10
 	"io/ioutil"
10 11
 	"strings"
... ...
@@ -12,11 +13,13 @@ import (
12 12
 
13 13
 	"github.com/docker/docker/api/types"
14 14
 	"github.com/docker/docker/api/types/filters"
15
+	"github.com/docker/docker/api/types/versions"
15 16
 	"github.com/docker/docker/integration-cli/cli/build/fakecontext"
16 17
 	"github.com/docker/docker/integration/internal/request"
17 18
 	"github.com/docker/docker/pkg/jsonmessage"
18 19
 	"github.com/gotestyourself/gotestyourself/assert"
19 20
 	is "github.com/gotestyourself/gotestyourself/assert/cmp"
21
+	"github.com/gotestyourself/gotestyourself/skip"
20 22
 )
21 23
 
22 24
 func TestBuildWithRemoveAndForceRemove(t *testing.T) {
... ...
@@ -304,6 +307,9 @@ COPY bar /`
304 304
 // docker/for-linux#135
305 305
 // #35641
306 306
 func TestBuildMultiStageLayerLeak(t *testing.T) {
307
+	fmt.Println(testEnv.DaemonAPIVersion())
308
+	skip.IfCondition(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.38"),
309
+		"Don't run on API lower than 1.38 as it has been fixed starting from that version")
307 310
 	ctx := context.TODO()
308 311
 	defer setupTest(t)()
309 312
 
... ...
@@ -12,6 +12,7 @@ import (
12 12
 	"github.com/docker/docker/integration-cli/daemon"
13 13
 	"github.com/docker/docker/internal/test/environment"
14 14
 	"github.com/gotestyourself/gotestyourself/assert"
15
+	"github.com/gotestyourself/gotestyourself/skip"
15 16
 )
16 17
 
17 18
 const (
... ...
@@ -21,6 +22,7 @@ const (
21 21
 
22 22
 // NewSwarm creates a swarm daemon for testing
23 23
 func NewSwarm(t *testing.T, testEnv *environment.Execution) *daemon.Swarm {
24
+	skip.IfCondition(t, testEnv.IsRemoteDaemon())
24 25
 	d := &daemon.Swarm{
25 26
 		Daemon: daemon.New(t, "", dockerdBinary, daemon.Config{
26 27
 			Experimental: testEnv.DaemonInfo.ExperimentalBuild,
... ...
@@ -1,16 +1,15 @@
1 1
 package network // import "github.com/docker/docker/integration/network"
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"runtime"
6 5
 	"testing"
7 6
 	"time"
8 7
 
9 8
 	"github.com/docker/docker/api/types"
10 9
 	"github.com/docker/docker/api/types/filters"
11
-	"github.com/docker/docker/api/types/swarm"
10
+	swarmtypes "github.com/docker/docker/api/types/swarm"
12 11
 	"github.com/docker/docker/client"
13
-	"github.com/docker/docker/integration-cli/daemon"
12
+	"github.com/docker/docker/integration/internal/swarm"
14 13
 	"github.com/gotestyourself/gotestyourself/assert"
15 14
 	"github.com/gotestyourself/gotestyourself/poll"
16 15
 	"golang.org/x/net/context"
... ...
@@ -21,7 +20,7 @@ const dockerdBinary = "dockerd"
21 21
 
22 22
 func TestInspectNetwork(t *testing.T) {
23 23
 	defer setupTest(t)()
24
-	d := newSwarm(t)
24
+	d := swarm.NewSwarm(t, testEnv)
25 25
 	defer d.Stop(t)
26 26
 	client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
27 27
 	assert.NilError(t, err)
... ...
@@ -38,8 +37,9 @@ func TestInspectNetwork(t *testing.T) {
38 38
 
39 39
 	var instances uint64 = 4
40 40
 	serviceName := "TestService"
41
+	// FIXME(vdemeester) consolidate with swarm.CreateService
41 42
 	serviceSpec := swarmServiceSpec(serviceName, instances)
42
-	serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarm.NetworkAttachmentConfig{Target: overlayName})
43
+	serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: overlayName})
43 44
 
44 45
 	serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{
45 46
 		QueryRegistry: false,
... ...
@@ -107,38 +107,19 @@ func TestInspectNetwork(t *testing.T) {
107 107
 	poll.WaitOn(t, networkIsRemoved(client, overlayID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
108 108
 }
109 109
 
110
-func newSwarm(t *testing.T) *daemon.Swarm {
111
-	d := &daemon.Swarm{
112
-		Daemon: daemon.New(t, "", dockerdBinary, daemon.Config{
113
-			Experimental: testEnv.DaemonInfo.ExperimentalBuild,
114
-		}),
115
-		// TODO: better method of finding an unused port
116
-		Port: defaultSwarmPort,
117
-	}
118
-	// TODO: move to a NewSwarm constructor
119
-	d.ListenAddr = fmt.Sprintf("0.0.0.0:%d", d.Port)
120
-
121
-	// avoid networking conflicts
122
-	args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"}
123
-	d.StartWithBusybox(t, args...)
124
-
125
-	assert.NilError(t, d.Init(swarm.InitRequest{}))
126
-	return d
127
-}
128
-
129
-func swarmServiceSpec(name string, replicas uint64) swarm.ServiceSpec {
130
-	return swarm.ServiceSpec{
131
-		Annotations: swarm.Annotations{
110
+func swarmServiceSpec(name string, replicas uint64) swarmtypes.ServiceSpec {
111
+	return swarmtypes.ServiceSpec{
112
+		Annotations: swarmtypes.Annotations{
132 113
 			Name: name,
133 114
 		},
134
-		TaskTemplate: swarm.TaskSpec{
135
-			ContainerSpec: &swarm.ContainerSpec{
115
+		TaskTemplate: swarmtypes.TaskSpec{
116
+			ContainerSpec: &swarmtypes.ContainerSpec{
136 117
 				Image:   "busybox:latest",
137 118
 				Command: []string{"/bin/top"},
138 119
 			},
139 120
 		},
140
-		Mode: swarm.ServiceMode{
141
-			Replicated: &swarm.ReplicatedService{
121
+		Mode: swarmtypes.ServiceMode{
122
+			Replicated: &swarmtypes.ReplicatedService{
142 123
 				Replicas: &replicas,
143 124
 			},
144 125
 		},
... ...
@@ -157,7 +138,7 @@ func serviceRunningTasksCount(client client.ServiceAPIClient, serviceID string,
157 157
 			return poll.Error(err)
158 158
 		case len(tasks) == int(instances):
159 159
 			for _, task := range tasks {
160
-				if task.Status.State != swarm.TaskStateRunning {
160
+				if task.Status.State != swarmtypes.TaskStateRunning {
161 161
 					return poll.Continue("waiting for tasks to enter run state")
162 162
 				}
163 163
 			}
... ...
@@ -7,8 +7,9 @@ import (
7 7
 
8 8
 	"github.com/docker/docker/api/types"
9 9
 	"github.com/docker/docker/api/types/filters"
10
-	"github.com/docker/docker/api/types/swarm"
10
+	swarmtypes "github.com/docker/docker/api/types/swarm"
11 11
 	"github.com/docker/docker/client"
12
+	"github.com/docker/docker/integration/internal/swarm"
12 13
 	"github.com/gotestyourself/gotestyourself/assert"
13 14
 	"github.com/gotestyourself/gotestyourself/poll"
14 15
 	"golang.org/x/net/context"
... ...
@@ -16,7 +17,7 @@ import (
16 16
 
17 17
 func TestServiceWithPredefinedNetwork(t *testing.T) {
18 18
 	defer setupTest(t)()
19
-	d := newSwarm(t)
19
+	d := swarm.NewSwarm(t, testEnv)
20 20
 	defer d.Stop(t)
21 21
 	client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
22 22
 	assert.NilError(t, err)
... ...
@@ -25,7 +26,7 @@ func TestServiceWithPredefinedNetwork(t *testing.T) {
25 25
 	var instances uint64 = 1
26 26
 	serviceName := "TestService"
27 27
 	serviceSpec := swarmServiceSpec(serviceName, instances)
28
-	serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarm.NetworkAttachmentConfig{Target: hostName})
28
+	serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: hostName})
29 29
 
30 30
 	serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{
31 31
 		QueryRegistry: false,
... ...
@@ -60,7 +61,7 @@ const ingressNet = "ingress"
60 60
 
61 61
 func TestServiceWithIngressNetwork(t *testing.T) {
62 62
 	defer setupTest(t)()
63
-	d := newSwarm(t)
63
+	d := swarm.NewSwarm(t, testEnv)
64 64
 	defer d.Stop(t)
65 65
 
66 66
 	client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
... ...
@@ -81,13 +82,13 @@ func TestServiceWithIngressNetwork(t *testing.T) {
81 81
 	var instances uint64 = 1
82 82
 	serviceName := "TestIngressService"
83 83
 	serviceSpec := swarmServiceSpec(serviceName, instances)
84
-	serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarm.NetworkAttachmentConfig{Target: ingressNet})
85
-	serviceSpec.EndpointSpec = &swarm.EndpointSpec{
86
-		Ports: []swarm.PortConfig{
84
+	serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: ingressNet})
85
+	serviceSpec.EndpointSpec = &swarmtypes.EndpointSpec{
86
+		Ports: []swarmtypes.PortConfig{
87 87
 			{
88
-				Protocol:    swarm.PortConfigProtocolTCP,
88
+				Protocol:    swarmtypes.PortConfigProtocolTCP,
89 89
 				TargetPort:  80,
90
-				PublishMode: swarm.PortConfigPublishModeIngress,
90
+				PublishMode: swarmtypes.PortConfigPublishModeIngress,
91 91
 			},
92 92
 		},
93 93
 	}
... ...
@@ -16,6 +16,7 @@ import (
16 16
 	"github.com/docker/docker/internal/test/environment"
17 17
 	"github.com/docker/docker/pkg/authorization"
18 18
 	"github.com/docker/docker/pkg/plugins"
19
+	"github.com/gotestyourself/gotestyourself/skip"
19 20
 )
20 21
 
21 22
 var (
... ...
@@ -48,6 +49,7 @@ func TestMain(m *testing.M) {
48 48
 }
49 49
 
50 50
 func setupTest(t *testing.T) func() {
51
+	skip.IfCondition(t, testEnv.IsRemoteDaemon(), "cannot run daemon when remote daemon")
51 52
 	environment.ProtectAll(t, testEnv)
52 53
 
53 54
 	d = daemon.New(t, "", dockerdBinary, daemon.Config{
... ...
@@ -14,8 +14,6 @@ import (
14 14
 	"github.com/pkg/errors"
15 15
 )
16 16
 
17
-const dockerdBinary = "dockerd"
18
-
19 17
 var pluginBuildLock = locker.New()
20 18
 
21 19
 func ensurePlugin(t *testing.T, name string) string {
22 20
new file mode 100644
... ...
@@ -0,0 +1,31 @@
0
+package logging // import "github.com/docker/docker/integration/plugin/logging"
1
+
2
+import (
3
+	"fmt"
4
+	"os"
5
+	"testing"
6
+
7
+	"github.com/docker/docker/internal/test/environment"
8
+)
9
+
10
+var (
11
+	testEnv *environment.Execution
12
+)
13
+
14
+const dockerdBinary = "dockerd"
15
+
16
+func TestMain(m *testing.M) {
17
+	var err error
18
+	testEnv, err = environment.New()
19
+	if err != nil {
20
+		fmt.Println(err)
21
+		os.Exit(1)
22
+	}
23
+	err = environment.EnsureFrozenImagesLinux(testEnv)
24
+	if err != nil {
25
+		fmt.Println(err)
26
+		os.Exit(1)
27
+	}
28
+	testEnv.Print()
29
+	os.Exit(m.Run())
30
+}
... ...
@@ -7,12 +7,14 @@ import (
7 7
 	"github.com/docker/docker/api/types"
8 8
 	"github.com/docker/docker/integration-cli/daemon"
9 9
 	"github.com/gotestyourself/gotestyourself/assert"
10
+	"github.com/gotestyourself/gotestyourself/skip"
10 11
 )
11 12
 
12 13
 // Regression test for #35553
13 14
 // Ensure that a daemon with a log plugin set as the default logger for containers
14 15
 // does not keep the daemon from starting.
15 16
 func TestDaemonStartWithLogOpt(t *testing.T) {
17
+	skip.IfCondition(t, testEnv.IsRemoteDaemon(), "cannot run daemon when remote daemon")
16 18
 	t.Parallel()
17 19
 
18 20
 	d := daemon.New(t, "", dockerdBinary, daemon.Config{})
... ...
@@ -121,6 +121,15 @@ func (e *Execution) IsRemoteDaemon() bool {
121 121
 	return !e.IsLocalDaemon()
122 122
 }
123 123
 
124
+// DaemonAPIVersion returns the negociated daemon api version
125
+func (e *Execution) DaemonAPIVersion() string {
126
+	version, err := e.APIClient().ServerVersion(context.TODO())
127
+	if err != nil {
128
+		return ""
129
+	}
130
+	return version.APIVersion
131
+}
132
+
124 133
 // Print the execution details to stdout
125 134
 // TODO: print everything
126 135
 func (e *Execution) Print() {