Bläddra i källkod

integration/*: make e2e run without failure

… mainly by skipping if daemon is remote.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Vincent Demeester 7 år sedan
förälder
incheckning
6016e79d25

+ 3 - 3
hack/test/e2e-run.sh

@@ -13,8 +13,8 @@ export DOCKER_ENGINE_GOARCH=${DOCKER_ENGINE_GOARCH:-${ARCH}}
 : ${TESTDEBUG:=}
 
 integration_api_dirs=${TEST_INTEGRATION_DIR:-"$(
-	find ./integration -type d |
-	grep -vE '(^./integration($|/internal)|/testdata)')"}
+	find /tests/integration -type d |
+	grep -vE '(^/tests/integration($|/internal)|/testdata)')"}
 
 run_test_integration() {
 	[[ "$TESTFLAGS" != *-check.f* ]] && run_test_integration_suites
@@ -35,7 +35,7 @@ run_test_integration_suites() {
 run_test_integration_legacy_suites() {
 	(
 		flags="-check.v -check.timeout=${TIMEOUT} -test.timeout=360m $TESTFLAGS"
-		cd test/integration-cli
+		cd /tests/integration-cli
 		echo "Running $PWD"
 		test_env ./test.main $flags
 	)

+ 6 - 0
integration/build/build_test.go

@@ -5,6 +5,7 @@ import (
 	"bytes"
 	"context"
 	"encoding/json"
+	"fmt"
 	"io"
 	"io/ioutil"
 	"strings"
@@ -12,11 +13,13 @@ import (
 
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types/filters"
+	"github.com/docker/docker/api/types/versions"
 	"github.com/docker/docker/integration-cli/cli/build/fakecontext"
 	"github.com/docker/docker/integration/internal/request"
 	"github.com/docker/docker/pkg/jsonmessage"
 	"github.com/gotestyourself/gotestyourself/assert"
 	is "github.com/gotestyourself/gotestyourself/assert/cmp"
+	"github.com/gotestyourself/gotestyourself/skip"
 )
 
 func TestBuildWithRemoveAndForceRemove(t *testing.T) {
@@ -304,6 +307,9 @@ COPY bar /`
 // docker/for-linux#135
 // #35641
 func TestBuildMultiStageLayerLeak(t *testing.T) {
+	fmt.Println(testEnv.DaemonAPIVersion())
+	skip.IfCondition(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.38"),
+		"Don't run on API lower than 1.38 as it has been fixed starting from that version")
 	ctx := context.TODO()
 	defer setupTest(t)()
 

+ 2 - 0
integration/internal/swarm/service.go

@@ -12,6 +12,7 @@ import (
 	"github.com/docker/docker/integration-cli/daemon"
 	"github.com/docker/docker/internal/test/environment"
 	"github.com/gotestyourself/gotestyourself/assert"
+	"github.com/gotestyourself/gotestyourself/skip"
 )
 
 const (
@@ -21,6 +22,7 @@ const (
 
 // NewSwarm creates a swarm daemon for testing
 func NewSwarm(t *testing.T, testEnv *environment.Execution) *daemon.Swarm {
+	skip.IfCondition(t, testEnv.IsRemoteDaemon())
 	d := &daemon.Swarm{
 		Daemon: daemon.New(t, "", dockerdBinary, daemon.Config{
 			Experimental: testEnv.DaemonInfo.ExperimentalBuild,

+ 13 - 32
integration/network/inspect_test.go

@@ -1,16 +1,15 @@
 package network // import "github.com/docker/docker/integration/network"
 
 import (
-	"fmt"
 	"runtime"
 	"testing"
 	"time"
 
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types/filters"
-	"github.com/docker/docker/api/types/swarm"
+	swarmtypes "github.com/docker/docker/api/types/swarm"
 	"github.com/docker/docker/client"
-	"github.com/docker/docker/integration-cli/daemon"
+	"github.com/docker/docker/integration/internal/swarm"
 	"github.com/gotestyourself/gotestyourself/assert"
 	"github.com/gotestyourself/gotestyourself/poll"
 	"golang.org/x/net/context"
@@ -21,7 +20,7 @@ const dockerdBinary = "dockerd"
 
 func TestInspectNetwork(t *testing.T) {
 	defer setupTest(t)()
-	d := newSwarm(t)
+	d := swarm.NewSwarm(t, testEnv)
 	defer d.Stop(t)
 	client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
 	assert.NilError(t, err)
@@ -38,8 +37,9 @@ 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, swarm.NetworkAttachmentConfig{Target: overlayName})
+	serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: overlayName})
 
 	serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{
 		QueryRegistry: false,
@@ -107,38 +107,19 @@ func TestInspectNetwork(t *testing.T) {
 	poll.WaitOn(t, networkIsRemoved(client, overlayID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
 }
 
-func newSwarm(t *testing.T) *daemon.Swarm {
-	d := &daemon.Swarm{
-		Daemon: daemon.New(t, "", dockerdBinary, daemon.Config{
-			Experimental: testEnv.DaemonInfo.ExperimentalBuild,
-		}),
-		// TODO: better method of finding an unused port
-		Port: defaultSwarmPort,
-	}
-	// TODO: move to a NewSwarm constructor
-	d.ListenAddr = fmt.Sprintf("0.0.0.0:%d", d.Port)
-
-	// avoid networking conflicts
-	args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"}
-	d.StartWithBusybox(t, args...)
-
-	assert.NilError(t, d.Init(swarm.InitRequest{}))
-	return d
-}
-
-func swarmServiceSpec(name string, replicas uint64) swarm.ServiceSpec {
-	return swarm.ServiceSpec{
-		Annotations: swarm.Annotations{
+func swarmServiceSpec(name string, replicas uint64) swarmtypes.ServiceSpec {
+	return swarmtypes.ServiceSpec{
+		Annotations: swarmtypes.Annotations{
 			Name: name,
 		},
-		TaskTemplate: swarm.TaskSpec{
-			ContainerSpec: &swarm.ContainerSpec{
+		TaskTemplate: swarmtypes.TaskSpec{
+			ContainerSpec: &swarmtypes.ContainerSpec{
 				Image:   "busybox:latest",
 				Command: []string{"/bin/top"},
 			},
 		},
-		Mode: swarm.ServiceMode{
-			Replicated: &swarm.ReplicatedService{
+		Mode: swarmtypes.ServiceMode{
+			Replicated: &swarmtypes.ReplicatedService{
 				Replicas: &replicas,
 			},
 		},
@@ -157,7 +138,7 @@ func serviceRunningTasksCount(client client.ServiceAPIClient, serviceID string,
 			return poll.Error(err)
 		case len(tasks) == int(instances):
 			for _, task := range tasks {
-				if task.Status.State != swarm.TaskStateRunning {
+				if task.Status.State != swarmtypes.TaskStateRunning {
 					return poll.Continue("waiting for tasks to enter run state")
 				}
 			}

+ 10 - 9
integration/network/service_test.go

@@ -7,8 +7,9 @@ import (
 
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types/filters"
-	"github.com/docker/docker/api/types/swarm"
+	swarmtypes "github.com/docker/docker/api/types/swarm"
 	"github.com/docker/docker/client"
+	"github.com/docker/docker/integration/internal/swarm"
 	"github.com/gotestyourself/gotestyourself/assert"
 	"github.com/gotestyourself/gotestyourself/poll"
 	"golang.org/x/net/context"
@@ -16,7 +17,7 @@ import (
 
 func TestServiceWithPredefinedNetwork(t *testing.T) {
 	defer setupTest(t)()
-	d := newSwarm(t)
+	d := swarm.NewSwarm(t, testEnv)
 	defer d.Stop(t)
 	client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
 	assert.NilError(t, err)
@@ -25,7 +26,7 @@ func TestServiceWithPredefinedNetwork(t *testing.T) {
 	var instances uint64 = 1
 	serviceName := "TestService"
 	serviceSpec := swarmServiceSpec(serviceName, instances)
-	serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarm.NetworkAttachmentConfig{Target: hostName})
+	serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: hostName})
 
 	serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{
 		QueryRegistry: false,
@@ -60,7 +61,7 @@ const ingressNet = "ingress"
 
 func TestServiceWithIngressNetwork(t *testing.T) {
 	defer setupTest(t)()
-	d := newSwarm(t)
+	d := swarm.NewSwarm(t, testEnv)
 	defer d.Stop(t)
 
 	client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
@@ -81,13 +82,13 @@ func TestServiceWithIngressNetwork(t *testing.T) {
 	var instances uint64 = 1
 	serviceName := "TestIngressService"
 	serviceSpec := swarmServiceSpec(serviceName, instances)
-	serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarm.NetworkAttachmentConfig{Target: ingressNet})
-	serviceSpec.EndpointSpec = &swarm.EndpointSpec{
-		Ports: []swarm.PortConfig{
+	serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: ingressNet})
+	serviceSpec.EndpointSpec = &swarmtypes.EndpointSpec{
+		Ports: []swarmtypes.PortConfig{
 			{
-				Protocol:    swarm.PortConfigProtocolTCP,
+				Protocol:    swarmtypes.PortConfigProtocolTCP,
 				TargetPort:  80,
-				PublishMode: swarm.PortConfigPublishModeIngress,
+				PublishMode: swarmtypes.PortConfigPublishModeIngress,
 			},
 		},
 	}

+ 2 - 0
integration/plugin/authz/main_test.go

@@ -16,6 +16,7 @@ import (
 	"github.com/docker/docker/internal/test/environment"
 	"github.com/docker/docker/pkg/authorization"
 	"github.com/docker/docker/pkg/plugins"
+	"github.com/gotestyourself/gotestyourself/skip"
 )
 
 var (
@@ -48,6 +49,7 @@ func TestMain(m *testing.M) {
 }
 
 func setupTest(t *testing.T) func() {
+	skip.IfCondition(t, testEnv.IsRemoteDaemon(), "cannot run daemon when remote daemon")
 	environment.ProtectAll(t, testEnv)
 
 	d = daemon.New(t, "", dockerdBinary, daemon.Config{

+ 0 - 2
integration/plugin/logging/helpers_test.go

@@ -14,8 +14,6 @@ import (
 	"github.com/pkg/errors"
 )
 
-const dockerdBinary = "dockerd"
-
 var pluginBuildLock = locker.New()
 
 func ensurePlugin(t *testing.T, name string) string {

+ 31 - 0
integration/plugin/logging/main_test.go

@@ -0,0 +1,31 @@
+package logging // import "github.com/docker/docker/integration/plugin/logging"
+
+import (
+	"fmt"
+	"os"
+	"testing"
+
+	"github.com/docker/docker/internal/test/environment"
+)
+
+var (
+	testEnv *environment.Execution
+)
+
+const dockerdBinary = "dockerd"
+
+func TestMain(m *testing.M) {
+	var err error
+	testEnv, err = environment.New()
+	if err != nil {
+		fmt.Println(err)
+		os.Exit(1)
+	}
+	err = environment.EnsureFrozenImagesLinux(testEnv)
+	if err != nil {
+		fmt.Println(err)
+		os.Exit(1)
+	}
+	testEnv.Print()
+	os.Exit(m.Run())
+}

+ 2 - 0
integration/plugin/logging/validation_test.go

@@ -7,12 +7,14 @@ import (
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/integration-cli/daemon"
 	"github.com/gotestyourself/gotestyourself/assert"
+	"github.com/gotestyourself/gotestyourself/skip"
 )
 
 // Regression test for #35553
 // Ensure that a daemon with a log plugin set as the default logger for containers
 // does not keep the daemon from starting.
 func TestDaemonStartWithLogOpt(t *testing.T) {
+	skip.IfCondition(t, testEnv.IsRemoteDaemon(), "cannot run daemon when remote daemon")
 	t.Parallel()
 
 	d := daemon.New(t, "", dockerdBinary, daemon.Config{})

+ 9 - 0
internal/test/environment/environment.go

@@ -121,6 +121,15 @@ func (e *Execution) IsRemoteDaemon() bool {
 	return !e.IsLocalDaemon()
 }
 
+// DaemonAPIVersion returns the negociated daemon api version
+func (e *Execution) DaemonAPIVersion() string {
+	version, err := e.APIClient().ServerVersion(context.TODO())
+	if err != nil {
+		return ""
+	}
+	return version.APIVersion
+}
+
 // Print the execution details to stdout
 // TODO: print everything
 func (e *Execution) Print() {