diff --git a/integration-cli/check_test.go b/integration-cli/check_test.go index 6bab50f907410c9f2daa3a5ab7f6139fb4b7a9fa..e98a5be4e04608d4e2ed07eec02b31f91be624a9 100644 --- a/integration-cli/check_test.go +++ b/integration-cli/check_test.go @@ -13,7 +13,6 @@ import ( "testing" "time" - "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/cli" "github.com/docker/docker/integration-cli/cli/build/fakestorage" @@ -129,9 +128,7 @@ func (s *DockerRegistrySuite) SetUpTest(c *check.C) { testRequires(c, DaemonIsLinux, RegistryHosting, SameHostDaemon) s.reg = registry.NewV2(c) s.reg.WaitReady(c) - s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) } func (s *DockerRegistrySuite) TearDownTest(c *check.C) { @@ -164,9 +161,7 @@ func (s *DockerSchema1RegistrySuite) SetUpTest(c *check.C) { testRequires(c, DaemonIsLinux, RegistryHosting, NotArm64, SameHostDaemon) s.reg = registry.NewV2(c, registry.Schema1) s.reg.WaitReady(c) - s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) } func (s *DockerSchema1RegistrySuite) TearDownTest(c *check.C) { @@ -199,9 +194,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) SetUpTest(c *check.C) { testRequires(c, DaemonIsLinux, RegistryHosting, SameHostDaemon) s.reg = registry.NewV2(c, registry.Htpasswd) s.reg.WaitReady(c) - s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) } func (s *DockerRegistryAuthHtpasswdSuite) TearDownTest(c *check.C) { @@ -234,9 +227,7 @@ func (s *DockerRegistryAuthTokenSuite) OnTimeout(c *check.C) { func (s *DockerRegistryAuthTokenSuite) SetUpTest(c *check.C) { testRequires(c, DaemonIsLinux, RegistryHosting, SameHostDaemon) - s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) } func (s *DockerRegistryAuthTokenSuite) TearDownTest(c *check.C) { @@ -276,9 +267,7 @@ func (s *DockerDaemonSuite) OnTimeout(c *check.C) { func (s *DockerDaemonSuite) SetUpTest(c *check.C) { testRequires(c, DaemonIsLinux, SameHostDaemon) - s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) } func (s *DockerDaemonSuite) TearDownTest(c *check.C) { @@ -333,26 +322,18 @@ func (s *DockerSwarmSuite) SetUpTest(c *check.C) { } func (s *DockerSwarmSuite) AddDaemon(c *check.C, joinSwarm, manager bool) *daemon.Daemon { - d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }, testdaemon.WithSwarmPort(defaultSwarmPort+s.portIndex)) - args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"} // avoid networking conflicts - d.StartWithBusybox(c, args...) - + d := daemon.New(c, dockerBinary, dockerdBinary, + testdaemon.WithEnvironment(testEnv.Execution), + testdaemon.WithSwarmPort(defaultSwarmPort+s.portIndex), + ) if joinSwarm { if len(s.daemons) > 0 { - tokens := s.daemons[0].JoinTokens(c) - token := tokens.Worker - if manager { - token = tokens.Manager - } - d.SwarmJoin(c, swarm.JoinRequest{ - RemoteAddrs: []string{s.daemons[0].SwarmListenAddr()}, - JoinToken: token, - }) + d.StartAndSwarmJoin(c, s.daemons[0].Daemon, manager) } else { - d.SwarmInit(c, swarm.InitRequest{}) + d.StartAndSwarmInit(c) } + } else { + d.StartWithBusybox(c, "--iptables=false", "--swarm-default-advertise-addr=lo") } s.portIndex++ diff --git a/integration-cli/daemon/daemon.go b/integration-cli/daemon/daemon.go index 0ec9e892b2249a64497a3504883656a21230e09d..3087416ee07b21efe3207738ced6b4e2fd041f50 100644 --- a/integration-cli/daemon/daemon.go +++ b/integration-cli/daemon/daemon.go @@ -30,21 +30,12 @@ type Daemon struct { dockerBinary string } -// Config holds docker daemon integration configuration -type Config struct { - Experimental bool -} - // New returns a Daemon instance to be used for testing. // This will create a directory such as d123456789 in the folder specified by $DOCKER_INTEGRATION_DAEMON_DEST or $DEST. // The daemon will not automatically start. -func New(t testingT, dockerBinary string, dockerdBinary string, config Config, ops ...func(*daemon.Daemon)) *Daemon { +func New(t testingT, dockerBinary string, dockerdBinary string, ops ...func(*daemon.Daemon)) *Daemon { ops = append(ops, daemon.WithDockerdBinary(dockerdBinary)) - if config.Experimental { - ops = append(ops, daemon.WithExperimental) - } d := daemon.New(t, ops...) - return &Daemon{ Daemon: d, dockerBinary: dockerBinary, diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index 2646de3fb77c07c26af2aec6913d2dd4750c741e..975f06d2b4d6a100f98d09d5b82e82f63424f028 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -32,6 +32,7 @@ import ( "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/cli" "github.com/docker/docker/integration-cli/daemon" + testdaemon "github.com/docker/docker/internal/test/daemon" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/stringid" @@ -1432,9 +1433,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithSocketAsVolume(c *check.C) { // os.Kill should kill daemon ungracefully, leaving behind container mounts. // A subsequent daemon restart should clean up said mounts. func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonAndContainerKill(c *check.C) { - d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) d.StartWithBusybox(c) out, err := d.Cmd("run", "-d", "busybox", "top") @@ -1472,9 +1471,7 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonAndContainerKill(c *chec // os.Interrupt should perform a graceful daemon shutdown and hence cleanup mounts. func (s *DockerDaemonSuite) TestCleanupMountsAfterGracefulShutdown(c *check.C) { - d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) d.StartWithBusybox(c) out, err := d.Cmd("run", "-d", "busybox", "top") @@ -1693,9 +1690,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartLocalVolumes(c *check.C) { // FIXME(vdemeester) should be a unit test func (s *DockerDaemonSuite) TestDaemonCorruptedLogDriverAddress(c *check.C) { - d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) c.Assert(d.StartWithError("--log-driver=syslog", "--log-opt", "syslog-address=corrupted:42"), check.NotNil) expected := "syslog-address should be in form proto://address" icmd.RunCommand("grep", expected, d.LogFileName()).Assert(c, icmd.Success) @@ -1703,9 +1698,7 @@ func (s *DockerDaemonSuite) TestDaemonCorruptedLogDriverAddress(c *check.C) { // FIXME(vdemeester) should be a unit test func (s *DockerDaemonSuite) TestDaemonCorruptedFluentdAddress(c *check.C) { - d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) c.Assert(d.StartWithError("--log-driver=fluentd", "--log-opt", "fluentd-address=corrupted:c"), check.NotNil) expected := "invalid fluentd-address corrupted:c: " icmd.RunCommand("grep", expected, d.LogFileName()).Assert(c, icmd.Success) @@ -3080,9 +3073,7 @@ func (s *DockerDaemonSuite) TestDaemonIpcModeShareableFromConfig(c *check.C) { } func testDaemonStartIpcMode(c *check.C, from, mode string, valid bool) { - d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) c.Logf("Checking IpcMode %s set from %s\n", mode, from) var serr error switch from { @@ -3183,7 +3174,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartIpcMode(c *check.C) { // the daemon from starting func (s *DockerDaemonSuite) TestFailedPluginRemove(c *check.C) { testRequires(c, DaemonIsLinux, IsAmd64, SameHostDaemon) - d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{}) + d := daemon.New(c, dockerBinary, dockerdBinary) d.Start(c) cli, err := client.NewClient(d.Sock(), api.DefaultVersion, nil, nil) c.Assert(err, checker.IsNil) diff --git a/integration-cli/docker_cli_external_graphdriver_unix_test.go b/integration-cli/docker_cli_external_graphdriver_unix_test.go index e356154049b9e3f14066ebc658f8725184982267..a52e58b2d2681c315c4cdca6100f90953b516305 100644 --- a/integration-cli/docker_cli_external_graphdriver_unix_test.go +++ b/integration-cli/docker_cli_external_graphdriver_unix_test.go @@ -15,6 +15,7 @@ import ( "github.com/docker/docker/daemon/graphdriver" "github.com/docker/docker/daemon/graphdriver/vfs" "github.com/docker/docker/integration-cli/daemon" + testdaemon "github.com/docker/docker/internal/test/daemon" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/plugins" "github.com/go-check/check" @@ -52,9 +53,7 @@ type graphEventsCounter struct { } func (s *DockerExternalGraphdriverSuite) SetUpTest(c *check.C) { - s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) } func (s *DockerExternalGraphdriverSuite) OnTimeout(c *check.C) { diff --git a/integration-cli/docker_cli_external_volume_driver_unix_test.go b/integration-cli/docker_cli_external_volume_driver_unix_test.go index ff3d50fb03443e2a56af0353e3935d99270d8187..1553abda287e3408e7c7741b2d320cd0e4b761de 100644 --- a/integration-cli/docker_cli_external_volume_driver_unix_test.go +++ b/integration-cli/docker_cli_external_volume_driver_unix_test.go @@ -18,6 +18,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/daemon" + testdaemon "github.com/docker/docker/internal/test/daemon" "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/volume" "github.com/go-check/check" @@ -51,9 +52,7 @@ type DockerExternalVolumeSuite struct { func (s *DockerExternalVolumeSuite) SetUpTest(c *check.C) { testRequires(c, SameHostDaemon) - s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) s.ec = &eventCounter{} } diff --git a/integration-cli/docker_cli_info_test.go b/integration-cli/docker_cli_info_test.go index 35a2532196ab40befa2150f3955894f09a6aaf53..65091029eec2385d4772f7b4184c5f9b39626b2c 100644 --- a/integration-cli/docker_cli_info_test.go +++ b/integration-cli/docker_cli_info_test.go @@ -8,6 +8,7 @@ import ( "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/daemon" + testdaemon "github.com/docker/docker/internal/test/daemon" "github.com/go-check/check" ) @@ -71,9 +72,7 @@ func (s *DockerSuite) TestInfoFormat(c *check.C) { func (s *DockerSuite) TestInfoDiscoveryBackend(c *check.C) { testRequires(c, SameHostDaemon, DaemonIsLinux) - d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) discoveryBackend := "consul://consuladdr:consulport/some/path" discoveryAdvertise := "1.1.1.1:2375" d.Start(c, fmt.Sprintf("--cluster-store=%s", discoveryBackend), fmt.Sprintf("--cluster-advertise=%s", discoveryAdvertise)) @@ -90,9 +89,7 @@ func (s *DockerSuite) TestInfoDiscoveryBackend(c *check.C) { func (s *DockerSuite) TestInfoDiscoveryInvalidAdvertise(c *check.C) { testRequires(c, SameHostDaemon, DaemonIsLinux) - d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) discoveryBackend := "consul://consuladdr:consulport/some/path" // --cluster-advertise with an invalid string is an error @@ -109,9 +106,7 @@ func (s *DockerSuite) TestInfoDiscoveryInvalidAdvertise(c *check.C) { func (s *DockerSuite) TestInfoDiscoveryAdvertiseInterfaceName(c *check.C) { testRequires(c, SameHostDaemon, Network, DaemonIsLinux) - d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) discoveryBackend := "consul://consuladdr:consulport/some/path" discoveryAdvertise := "eth0" @@ -182,9 +177,7 @@ func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) { func (s *DockerSuite) TestInfoDebug(c *check.C) { testRequires(c, SameHostDaemon, DaemonIsLinux) - d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) d.Start(c, "--debug") defer d.Stop(c) @@ -205,9 +198,7 @@ func (s *DockerSuite) TestInsecureRegistries(c *check.C) { registryCIDR := "192.168.1.0/24" registryHost := "insecurehost.com:5000" - d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) d.Start(c, "--insecure-registry="+registryCIDR, "--insecure-registry="+registryHost) defer d.Stop(c) diff --git a/integration-cli/docker_cli_network_unix_test.go b/integration-cli/docker_cli_network_unix_test.go index bd3cf54342f626b668f5442e7932a6399df3f304..f3ecd621871ba5d946608bb2a5842f9c9cb5306b 100644 --- a/integration-cli/docker_cli_network_unix_test.go +++ b/integration-cli/docker_cli_network_unix_test.go @@ -18,6 +18,7 @@ import ( "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/cli" "github.com/docker/docker/integration-cli/daemon" + testdaemon "github.com/docker/docker/internal/test/daemon" "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/runconfig" "github.com/docker/libnetwork/driverapi" @@ -49,9 +50,7 @@ type DockerNetworkSuite struct { } func (s *DockerNetworkSuite) SetUpTest(c *check.C) { - s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) } func (s *DockerNetworkSuite) TearDownTest(c *check.C) { diff --git a/integration-cli/docker_cli_plugins_test.go b/integration-cli/docker_cli_plugins_test.go index 8a936e3e44600998727e2974234fb0287935237b..c773fec5d5b72499f0fa303469d4020df04f9ff3 100644 --- a/integration-cli/docker_cli_plugins_test.go +++ b/integration-cli/docker_cli_plugins_test.go @@ -473,7 +473,7 @@ func (s *DockerSuite) TestPluginUpgrade(c *check.C) { func (s *DockerSuite) TestPluginMetricsCollector(c *check.C) { testRequires(c, DaemonIsLinux, Network, SameHostDaemon, IsAmd64) - d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{}) + d := daemon.New(c, dockerBinary, dockerdBinary) d.Start(c) defer d.Stop(c) diff --git a/integration-cli/docker_hub_pull_suite_test.go b/integration-cli/docker_hub_pull_suite_test.go index a8d6aedad35c5a57b21851e3a23e12b43f69aaf9..125b8c10aa76526bc8e9163c5eb7bfed40e74dad 100644 --- a/integration-cli/docker_hub_pull_suite_test.go +++ b/integration-cli/docker_hub_pull_suite_test.go @@ -7,6 +7,7 @@ import ( "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/daemon" + testdaemon "github.com/docker/docker/internal/test/daemon" "github.com/go-check/check" ) @@ -40,9 +41,7 @@ func newDockerHubPullSuite() *DockerHubPullSuite { // SetUpSuite starts the suite daemon. func (s *DockerHubPullSuite) SetUpSuite(c *check.C) { testRequires(c, DaemonIsLinux, SameHostDaemon) - s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{ - Experimental: testEnv.DaemonInfo.ExperimentalBuild, - }) + s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) s.d.Start(c) } diff --git a/integration/build/build_session_test.go b/integration/build/build_session_test.go index 1fde6a0f9aa92902ca775c43c00a087266e3823b..af1a5367699ce2ced1f2cca30649b12fef6a0b59 100644 --- a/integration/build/build_session_test.go +++ b/integration/build/build_session_test.go @@ -9,8 +9,8 @@ import ( dclient "github.com/docker/docker/client" "github.com/docker/docker/integration-cli/cli/build/fakecontext" - "github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/integration-cli/request" + "github.com/docker/docker/internal/test/daemon" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/moby/buildkit/session" @@ -19,9 +19,7 @@ import ( ) func TestBuildWithSession(t *testing.T) { - d := daemon.New(t, "", "dockerd", daemon.Config{ - Experimental: true, - }) + d := daemon.New(t, daemon.WithExperimental) d.StartWithBusybox(t) defer d.Stop(t) diff --git a/integration/build/build_squash_test.go b/integration/build/build_squash_test.go index 7f264f14773bee94e90b19b023efec05ff41992d..e8097fd811bb353df94d639eba06467e48547379 100644 --- a/integration/build/build_squash_test.go +++ b/integration/build/build_squash_test.go @@ -10,17 +10,15 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/integration-cli/cli/build/fakecontext" - "github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/integration/internal/container" + "github.com/docker/docker/internal/test/daemon" "github.com/docker/docker/pkg/stdcopy" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestBuildSquashParent(t *testing.T) { - d := daemon.New(t, "", "dockerd", daemon.Config{ - Experimental: true, - }) + d := daemon.New(t, daemon.WithExperimental) d.StartWithBusybox(t) defer d.Stop(t) diff --git a/integration/config/config_test.go b/integration/config/config_test.go index 6c72f2f8f987c2adecf1e91e68ff69c5a4492d8d..26888b17845093171210b262a667676350a13ffc 100644 --- a/integration/config/config_test.go +++ b/integration/config/config_test.go @@ -26,8 +26,8 @@ func TestConfigList(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() @@ -117,8 +117,8 @@ func TestConfigsCreateAndDelete(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() @@ -145,8 +145,8 @@ func TestConfigsUpdate(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() @@ -196,9 +196,9 @@ func TestConfigsUpdate(t *testing.T) { func TestTemplatedConfig(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() - client := swarm.GetClient(t, d) referencedSecretName := "referencedsecret-" + t.Name() referencedSecretSpec := swarmtypes.SecretSpec{ @@ -338,8 +338,8 @@ func TestConfigInspect(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() diff --git a/integration/internal/swarm/service.go b/integration/internal/swarm/service.go index 031995f87a695739e6bd6e274444ed72215f7a80..3f5032976be087acf877e1122411953615adba28 100644 --- a/integration/internal/swarm/service.go +++ b/integration/internal/swarm/service.go @@ -9,7 +9,6 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" swarmtypes "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/client" "github.com/docker/docker/internal/test/daemon" "github.com/docker/docker/internal/test/environment" "github.com/gotestyourself/gotestyourself/assert" @@ -55,11 +54,7 @@ func NewSwarm(t *testing.T, testEnv *environment.Execution, ops ...func(*daemon. ops = append(ops, daemon.WithExperimental) } d := daemon.New(t, ops...) - // avoid networking conflicts - args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"} - d.StartWithBusybox(t, args...) - - d.SwarmInit(t, swarmtypes.InitRequest{}) + d.StartAndSwarmInit(t) return d } @@ -73,7 +68,8 @@ func CreateService(t *testing.T, d *daemon.Daemon, opts ...ServiceSpecOpt) strin o(&spec) } - client := GetClient(t, d) + client := d.NewClientT(t) + defer client.Close() resp, err := client.ServiceCreate(context.Background(), spec, types.ServiceCreateOptions{}) assert.NilError(t, err, "error creating service") @@ -140,7 +136,8 @@ func ServiceWithName(name string) ServiceSpecOpt { // GetRunningTasks gets the list of running tasks for a service func GetRunningTasks(t *testing.T, d *daemon.Daemon, serviceID string) []swarmtypes.Task { - client := GetClient(t, d) + client := d.NewClientT(t) + defer client.Close() filterArgs := filters.NewArgs() filterArgs.Add("desired-state", "running") @@ -156,7 +153,8 @@ func GetRunningTasks(t *testing.T, d *daemon.Daemon, serviceID string) []swarmty // ExecTask runs the passed in exec config on the given task func ExecTask(t *testing.T, d *daemon.Daemon, task swarmtypes.Task, config types.ExecConfig) types.HijackedResponse { - client := GetClient(t, d) + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() resp, err := client.ContainerExecCreate(ctx, task.Status.ContainerStatus.ContainerID, config) @@ -173,10 +171,3 @@ func ensureContainerSpec(spec *swarmtypes.ServiceSpec) { spec.TaskTemplate.ContainerSpec = &swarmtypes.ContainerSpec{} } } - -// GetClient creates a new client for the passed in swarm daemon. -func GetClient(t *testing.T, d *daemon.Daemon) client.APIClient { - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) - return client -} diff --git a/integration/network/inspect_test.go b/integration/network/inspect_test.go index 3f23c61ae259cf240e0acf2b4c9bdf39f03f9219..8142ecdef2f38c00ecfc0857733e17f0ae9fa42f 100644 --- a/integration/network/inspect_test.go +++ b/integration/network/inspect_test.go @@ -20,8 +20,8 @@ func TestInspectNetwork(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() overlayName := "overlay1" networkCreate := types.NetworkCreate{ diff --git a/integration/network/ipvlan/ipvlan_test.go b/integration/network/ipvlan/ipvlan_test.go index 9de78f41bb59583369f18a74fe803e5a36c560f4..d42917db277f97929a37e9d13f4c7636b0a06735 100644 --- a/integration/network/ipvlan/ipvlan_test.go +++ b/integration/network/ipvlan/ipvlan_test.go @@ -8,9 +8,9 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/network" dclient "github.com/docker/docker/client" - "github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/integration/internal/container" n "github.com/docker/docker/integration/network" + "github.com/docker/docker/internal/test/daemon" "github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/skip" "golang.org/x/net/context" @@ -22,9 +22,7 @@ func TestDockerNetworkIpvlanPersistance(t *testing.T) { skip.If(t, testEnv.IsRemoteDaemon()) skip.If(t, !ipvlanKernelSupport(), "Kernel doesn't support ipvlan") - d := daemon.New(t, "", "dockerd", daemon.Config{ - Experimental: true, - }) + d := daemon.New(t, daemon.WithExperimental) d.StartWithBusybox(t) defer d.Stop(t) @@ -88,9 +86,7 @@ func TestDockerNetworkIpvlan(t *testing.T) { test: testIpvlanAddressing, }, } { - d := daemon.New(t, "", "dockerd", daemon.Config{ - Experimental: true, - }) + d := daemon.New(t, daemon.WithExperimental) d.StartWithBusybox(t) client, err := d.NewClient() diff --git a/integration/network/service_test.go b/integration/network/service_test.go index c619f54a2b75ba14e563d51a9d7c8f7b0b20cb63..8efd7d1fac9c3df04def2052cd4223384502be2f 100644 --- a/integration/network/service_test.go +++ b/integration/network/service_test.go @@ -17,8 +17,8 @@ func TestServiceWithPredefinedNetwork(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() hostName := "host" var instances uint64 = 1 @@ -47,9 +47,8 @@ func TestServiceRemoveKeepsIngressNetwork(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() poll.WaitOn(t, swarmIngressReady(client), swarm.NetworkPoll) diff --git a/integration/secret/secret_test.go b/integration/secret/secret_test.go index 4a1e1b3dc7a2434c558037e77795d00b10dee13a..5ad763a6015494f0da03a755b54759a78ceebe44 100644 --- a/integration/secret/secret_test.go +++ b/integration/secret/secret_test.go @@ -25,8 +25,8 @@ func TestSecretInspect(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() @@ -48,9 +48,8 @@ func TestSecretList(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) - + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() testName0 := "test0" @@ -135,16 +134,15 @@ func TestSecretsCreateAndDelete(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) - + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() testName := "test_secret" secretID := createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), nil) // create an already existin secret, daemon should return a status code of 409 - _, err = client.SecretCreate(ctx, swarmtypes.SecretSpec{ + _, err := client.SecretCreate(ctx, swarmtypes.SecretSpec{ Annotations: swarmtypes.Annotations{ Name: testName, }, @@ -183,14 +181,12 @@ func TestSecretsUpdate(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) - + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() testName := "test_secret" secretID := createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), nil) - assert.NilError(t, err) insp, _, err := client.SecretInspectWithRaw(ctx, secretID) assert.NilError(t, err) @@ -233,9 +229,9 @@ func TestSecretsUpdate(t *testing.T) { func TestTemplatedSecret(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() - client := swarm.GetClient(t, d) referencedSecretSpec := swarmtypes.SecretSpec{ Annotations: swarmtypes.Annotations{ diff --git a/integration/service/create_test.go b/integration/service/create_test.go index 9522b059ef5dd793d6dec9b2a98162ea58a7c4ea..767d78b3685bc6d63a6cc0342436b9fbe514eea9 100644 --- a/integration/service/create_test.go +++ b/integration/service/create_test.go @@ -20,8 +20,8 @@ func TestCreateServiceMultipleTimes(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() overlayName := "overlay1" networkCreate := types.NetworkCreate{ @@ -78,8 +78,8 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() name := "foo" networkCreate := types.NetworkCreate{ @@ -140,8 +140,8 @@ func TestCreateServiceSecretFileMode(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() secretResp, err := client.SecretCreate(ctx, swarmtypes.SecretSpec{ @@ -221,8 +221,8 @@ func TestCreateServiceConfigFileMode(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() configResp, err := client.ConfigCreate(ctx, swarmtypes.ConfigSpec{ diff --git a/integration/service/inspect_test.go b/integration/service/inspect_test.go index d4d342e6439f9611c0cabc9d6d47201ce65b7726..e437f35888bd4cc5c3483474e56d0020acef4679 100644 --- a/integration/service/inspect_test.go +++ b/integration/service/inspect_test.go @@ -23,8 +23,8 @@ func TestInspect(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() var now = time.Now() var instances uint64 = 2 diff --git a/integration/service/network_test.go b/integration/service/network_test.go index 6b8c891cd847d73a9ff37dffae258b455138cb2a..7db171a1253169a330345024e5ec285749576c88 100644 --- a/integration/service/network_test.go +++ b/integration/service/network_test.go @@ -6,7 +6,6 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/network" - "github.com/docker/docker/client" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/swarm" "github.com/gotestyourself/gotestyourself/assert" @@ -17,12 +16,12 @@ func TestDockerNetworkConnectAlias(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - assert.NilError(t, err) + client := d.NewClientT(t) + defer client.Close() ctx := context.Background() name := "test-alias" - _, err = client.NetworkCreate(ctx, name, types.NetworkCreate{ + _, err := client.NetworkCreate(ctx, name, types.NetworkCreate{ Driver: "overlay", Attachable: true, }) diff --git a/internal/test/daemon/ops.go b/internal/test/daemon/ops.go index 0176c19d93cb72708ffae9b815e8d8c90e0b227e..288fe8807050e691d7d3b71350d9cec75b277907 100644 --- a/internal/test/daemon/ops.go +++ b/internal/test/daemon/ops.go @@ -1,5 +1,7 @@ package daemon +import "github.com/docker/docker/internal/test/environment" + // WithExperimental sets the daemon in experimental mode func WithExperimental(d *Daemon) { d.experimental = true @@ -25,3 +27,12 @@ func WithSwarmListenAddr(listenAddr string) func(*Daemon) { d.swarmListenAddr = listenAddr } } + +// WithEnvironment sets options from internal/test/environment.Execution struct +func WithEnvironment(e environment.Execution) func(*Daemon) { + return func(d *Daemon) { + if e.DaemonInfo.ExperimentalBuild { + d.experimental = true + } + } +} diff --git a/internal/test/daemon/service.go b/internal/test/daemon/service.go index 26e6004ae115f08b533a5e5c835bc9ac74717294..a0541e9716265eec41b7969b771d76e5d7207e18 100644 --- a/internal/test/daemon/service.go +++ b/internal/test/daemon/service.go @@ -13,9 +13,7 @@ import ( // ServiceConstructor defines a swarm service constructor function type ServiceConstructor func(*swarm.Service) -// CreateServiceWithOptions creates a swarm service given the specified service constructors -// and auth config -func (d *Daemon) CreateServiceWithOptions(t assert.TestingT, opts types.ServiceCreateOptions, f ...ServiceConstructor) string { +func (d *Daemon) createServiceWithOptions(t assert.TestingT, opts types.ServiceCreateOptions, f ...ServiceConstructor) string { var service swarm.Service for _, fn := range f { fn(&service) @@ -34,7 +32,7 @@ func (d *Daemon) CreateServiceWithOptions(t assert.TestingT, opts types.ServiceC // CreateService creates a swarm service given the specified service constructor func (d *Daemon) CreateService(t assert.TestingT, f ...ServiceConstructor) string { - return d.CreateServiceWithOptions(t, types.ServiceCreateOptions{}, f...) + return d.createServiceWithOptions(t, types.ServiceCreateOptions{}, f...) } // GetService returns the swarm service corresponding to the specified id diff --git a/internal/test/daemon/swarm.go b/internal/test/daemon/swarm.go index f0cf373468017f5bf21f6df2788fcdd83bfcee0a..f66c447ccba421ffb81b1cda54e02d7fc4f60f0c 100644 --- a/internal/test/daemon/swarm.go +++ b/internal/test/daemon/swarm.go @@ -14,6 +14,32 @@ const ( defaultSwarmListenAddr = "0.0.0.0" ) +// StartAndSwarmInit starts the daemon (with busybox) and init the swarm +func (d *Daemon) StartAndSwarmInit(t testingT) { + // avoid networking conflicts + args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"} + d.StartWithBusybox(t, args...) + + d.SwarmInit(t, swarm.InitRequest{}) +} + +// StartAndSwarmJoin starts the daemon (with busybox) and join the specified swarm as worker or manager +func (d *Daemon) StartAndSwarmJoin(t testingT, leader *Daemon, manager bool) { + // avoid networking conflicts + args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"} + d.StartWithBusybox(t, args...) + + tokens := leader.JoinTokens(t) + token := tokens.Worker + if manager { + token = tokens.Manager + } + d.SwarmJoin(t, swarm.JoinRequest{ + RemoteAddrs: []string{leader.SwarmListenAddr()}, + JoinToken: token, + }) +} + // SpecConstructor defines a swarm spec constructor type SpecConstructor func(*swarm.Spec)