Merge component 'engine' from git@github.com:moby/moby master
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func startServerContainer(c *check.C, msg string, port int) string {
|
||||
name := "server"
|
||||
cmd := []string{
|
||||
"run",
|
||||
"--name",
|
||||
name,
|
||||
"-d",
|
||||
"-p", fmt.Sprintf("%d:%d", port, port),
|
||||
"busybox",
|
||||
"sh", "-c", fmt.Sprintf("echo %q | nc -lp %d", msg, port),
|
||||
}
|
||||
cli.DockerCmd(c, cmd...)
|
||||
cli.WaitRun(c, name)
|
||||
return name
|
||||
}
|
||||
|
||||
func getExternalAddress(c *check.C) net.IP {
|
||||
iface, err := net.InterfaceByName("eth0")
|
||||
if err != nil {
|
||||
c.Skip(fmt.Sprintf("Test not running with `make test`. Interface eth0 not found: %v", err))
|
||||
}
|
||||
|
||||
ifaceAddrs, err := iface.Addrs()
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(ifaceAddrs, checker.Not(checker.HasLen), 0)
|
||||
|
||||
ifaceIP, _, err := net.ParseCIDR(ifaceAddrs[0].String())
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
return ifaceIP
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestNetworkNat(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, SameHostDaemon)
|
||||
msg := "it works"
|
||||
startServerContainer(c, msg, 8080)
|
||||
endpoint := getExternalAddress(c)
|
||||
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", endpoint.String(), 8080))
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
data, err := ioutil.ReadAll(conn)
|
||||
conn.Close()
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
final := strings.TrimRight(string(data), "\n")
|
||||
c.Assert(final, checker.Equals, msg)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestNetworkLocalhostTCPNat(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, SameHostDaemon)
|
||||
var (
|
||||
msg = "hi yall"
|
||||
)
|
||||
startServerContainer(c, msg, 8081)
|
||||
conn, err := net.Dial("tcp", "localhost:8081")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
data, err := ioutil.ReadAll(conn)
|
||||
conn.Close()
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
final := strings.TrimRight(string(data), "\n")
|
||||
c.Assert(final, checker.Equals, msg)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestNetworkLoopbackNat(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, SameHostDaemon, NotUserNamespace)
|
||||
msg := "it works"
|
||||
startServerContainer(c, msg, 8080)
|
||||
endpoint := getExternalAddress(c)
|
||||
out, _ := dockerCmd(c, "run", "-t", "--net=container:server", "busybox",
|
||||
"sh", "-c", fmt.Sprintf("stty raw && nc -w 5 %s 8080", endpoint.String()))
|
||||
final := strings.TrimRight(string(out), "\n")
|
||||
c.Assert(final, checker.Equals, msg)
|
||||
}
|
||||
@@ -10,29 +10,6 @@ import (
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSwarmSuite) TestSecretInspect(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
testName := "test_secret"
|
||||
id := d.CreateSecret(c, swarm.SecretSpec{
|
||||
Annotations: swarm.Annotations{
|
||||
Name: testName,
|
||||
},
|
||||
Data: []byte("TESTINGDATA"),
|
||||
})
|
||||
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
||||
|
||||
secret := d.GetSecret(c, id)
|
||||
c.Assert(secret.Spec.Name, checker.Equals, testName)
|
||||
|
||||
out, err := d.Cmd("secret", "inspect", testName)
|
||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||
|
||||
var secrets []swarm.Secret
|
||||
c.Assert(json.Unmarshal([]byte(out), &secrets), checker.IsNil)
|
||||
c.Assert(secrets, checker.HasLen, 1)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestSecretInspectMultiple(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package container
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/integration/util/request"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/gotestyourself/gotestyourself/poll"
|
||||
"github.com/gotestyourself/gotestyourself/skip"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNetworkNat(t *testing.T) {
|
||||
skip.If(t, !testEnv.IsLocalDaemon())
|
||||
|
||||
defer setupTest(t)()
|
||||
|
||||
msg := "it works"
|
||||
startServerContainer(t, msg, 8080)
|
||||
|
||||
endpoint := getExternalAddress(t)
|
||||
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", endpoint.String(), 8080))
|
||||
require.NoError(t, err)
|
||||
defer conn.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(conn)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, strings.TrimSpace(string(data)), msg)
|
||||
}
|
||||
|
||||
func TestNetworkLocalhostTCPNat(t *testing.T) {
|
||||
skip.If(t, !testEnv.IsLocalDaemon())
|
||||
|
||||
defer setupTest(t)()
|
||||
|
||||
msg := "hi yall"
|
||||
startServerContainer(t, msg, 8081)
|
||||
|
||||
conn, err := net.Dial("tcp", "localhost:8081")
|
||||
require.NoError(t, err)
|
||||
defer conn.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(conn)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, strings.TrimSpace(string(data)), msg)
|
||||
}
|
||||
|
||||
func TestNetworkLoopbackNat(t *testing.T) {
|
||||
skip.If(t, !testEnv.IsLocalDaemon())
|
||||
|
||||
msg := "it works"
|
||||
startServerContainer(t, msg, 8080)
|
||||
|
||||
endpoint := getExternalAddress(t)
|
||||
|
||||
client := request.NewAPIClient(t)
|
||||
ctx := context.Background()
|
||||
c, err := client.ContainerCreate(ctx,
|
||||
&container.Config{
|
||||
Image: "busybox",
|
||||
Cmd: []string{"sh", "-c", fmt.Sprintf("stty raw && nc -w 5 %s 8080", endpoint.String())},
|
||||
Tty: true,
|
||||
},
|
||||
&container.HostConfig{
|
||||
NetworkMode: "container:server",
|
||||
},
|
||||
nil,
|
||||
"")
|
||||
require.NoError(t, err)
|
||||
|
||||
err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
poll.WaitOn(t, containerIsStopped(ctx, client, c.ID), poll.WithDelay(100*time.Millisecond))
|
||||
|
||||
body, err := client.ContainerLogs(ctx, c.ID, types.ContainerLogsOptions{
|
||||
ShowStdout: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer body.Close()
|
||||
|
||||
var b bytes.Buffer
|
||||
_, err = io.Copy(&b, body)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, strings.TrimSpace(b.String()), msg)
|
||||
}
|
||||
|
||||
func startServerContainer(t *testing.T, msg string, port int) string {
|
||||
client := request.NewAPIClient(t)
|
||||
ctx := context.Background()
|
||||
|
||||
c, err := client.ContainerCreate(ctx,
|
||||
&container.Config{
|
||||
Image: "busybox",
|
||||
Cmd: []string{"sh", "-c", fmt.Sprintf("echo %q | nc -lp %d", msg, port)},
|
||||
ExposedPorts: map[nat.Port]struct{}{
|
||||
nat.Port(fmt.Sprintf("%d/tcp", port)): {},
|
||||
},
|
||||
},
|
||||
&container.HostConfig{
|
||||
PortBindings: nat.PortMap{
|
||||
nat.Port(fmt.Sprintf("%d/tcp", port)): []nat.PortBinding{
|
||||
{
|
||||
HostPort: fmt.Sprintf("%d", port),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&network.NetworkingConfig{},
|
||||
"server",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
poll.WaitOn(t, containerIsInState(ctx, client, c.ID, "running"), poll.WithDelay(100*time.Millisecond))
|
||||
|
||||
return c.ID
|
||||
}
|
||||
|
||||
func getExternalAddress(t *testing.T) net.IP {
|
||||
iface, err := net.InterfaceByName("eth0")
|
||||
skip.If(t, err != nil, "Test not running with `make test-integration`. Interface eth0 not found: %s", err)
|
||||
|
||||
ifaceAddrs, err := iface.Addrs()
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, len(ifaceAddrs), 0)
|
||||
|
||||
ifaceIP, _, err := net.ParseCIDR(ifaceAddrs[0].String())
|
||||
require.NoError(t, err)
|
||||
|
||||
return ifaceIP
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package secret
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
func setupTest(t *testing.T) func() {
|
||||
environment.ProtectAll(t, testEnv)
|
||||
return func() { testEnv.Clean(t) }
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package secret
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
swarmtypes "github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/integration-cli/request"
|
||||
"github.com/docker/docker/integration/util/swarm"
|
||||
"github.com/gotestyourself/gotestyourself/skip"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestSecretInspect(t *testing.T) {
|
||||
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
|
||||
|
||||
defer setupTest(t)()
|
||||
d := swarm.NewSwarm(t, testEnv)
|
||||
defer d.Stop(t)
|
||||
client, err := request.NewClientForHost(d.Sock())
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
testName := "test_secret"
|
||||
secretResp, err := client.SecretCreate(ctx, swarmtypes.SecretSpec{
|
||||
Annotations: swarmtypes.Annotations{
|
||||
Name: testName,
|
||||
},
|
||||
Data: []byte("TESTINGDATA"),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, secretResp.ID, "")
|
||||
|
||||
secret, _, err := client.SecretInspectWithRaw(context.Background(), secretResp.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, secret.Spec.Name, testName)
|
||||
|
||||
secret, _, err = client.SecretInspectWithRaw(context.Background(), testName)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, secret.ID, secretResp.ID)
|
||||
}
|
||||
@@ -8,9 +8,10 @@ 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-cli/request"
|
||||
"github.com/docker/docker/integration/util/swarm"
|
||||
"github.com/gotestyourself/gotestyourself/poll"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -19,7 +20,7 @@ import (
|
||||
|
||||
func TestCreateServiceMultipleTimes(t *testing.T) {
|
||||
defer setupTest(t)()
|
||||
d := newSwarm(t)
|
||||
d := swarm.NewSwarm(t, testEnv)
|
||||
defer d.Stop(t)
|
||||
client, err := request.NewClientForHost(d.Sock())
|
||||
require.NoError(t, err)
|
||||
@@ -36,7 +37,7 @@ func TestCreateServiceMultipleTimes(t *testing.T) {
|
||||
|
||||
var instances uint64 = 4
|
||||
serviceSpec := swarmServiceSpec("TestService", 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,
|
||||
@@ -85,7 +86,7 @@ func TestCreateServiceMultipleTimes(t *testing.T) {
|
||||
|
||||
func TestCreateWithDuplicateNetworkNames(t *testing.T) {
|
||||
defer setupTest(t)()
|
||||
d := newSwarm(t)
|
||||
d := swarm.NewSwarm(t, testEnv)
|
||||
defer d.Stop(t)
|
||||
client, err := request.NewClientForHost(d.Sock())
|
||||
require.NoError(t, err)
|
||||
@@ -111,7 +112,7 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) {
|
||||
var instances uint64 = 1
|
||||
serviceSpec := swarmServiceSpec("top", instances)
|
||||
|
||||
serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarm.NetworkAttachmentConfig{Target: name})
|
||||
serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: name})
|
||||
|
||||
service, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{})
|
||||
require.NoError(t, err)
|
||||
@@ -147,14 +148,14 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) {
|
||||
|
||||
func TestCreateServiceSecretFileMode(t *testing.T) {
|
||||
defer setupTest(t)()
|
||||
d := newSwarm(t)
|
||||
d := swarm.NewSwarm(t, testEnv)
|
||||
defer d.Stop(t)
|
||||
client, err := request.NewClientForHost(d.Sock())
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
secretResp, err := client.SecretCreate(ctx, swarm.SecretSpec{
|
||||
Annotations: swarm.Annotations{
|
||||
secretResp, err := client.SecretCreate(ctx, swarmtypes.SecretSpec{
|
||||
Annotations: swarmtypes.Annotations{
|
||||
Name: "TestSecret",
|
||||
},
|
||||
Data: []byte("TESTSECRET"),
|
||||
@@ -162,17 +163,17 @@ func TestCreateServiceSecretFileMode(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
var instances uint64 = 1
|
||||
serviceSpec := swarm.ServiceSpec{
|
||||
Annotations: swarm.Annotations{
|
||||
serviceSpec := swarmtypes.ServiceSpec{
|
||||
Annotations: swarmtypes.Annotations{
|
||||
Name: "TestService",
|
||||
},
|
||||
TaskTemplate: swarm.TaskSpec{
|
||||
ContainerSpec: &swarm.ContainerSpec{
|
||||
TaskTemplate: swarmtypes.TaskSpec{
|
||||
ContainerSpec: &swarmtypes.ContainerSpec{
|
||||
Image: "busybox:latest",
|
||||
Command: []string{"/bin/sh", "-c", "ls -l /etc/secret || /bin/top"},
|
||||
Secrets: []*swarm.SecretReference{
|
||||
Secrets: []*swarmtypes.SecretReference{
|
||||
{
|
||||
File: &swarm.SecretReferenceFileTarget{
|
||||
File: &swarmtypes.SecretReferenceFileTarget{
|
||||
Name: "/etc/secret",
|
||||
UID: "0",
|
||||
GID: "0",
|
||||
@@ -184,8 +185,8 @@ func TestCreateServiceSecretFileMode(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Mode: swarm.ServiceMode{
|
||||
Replicated: &swarm.ReplicatedService{
|
||||
Mode: swarmtypes.ServiceMode{
|
||||
Replicated: &swarmtypes.ReplicatedService{
|
||||
Replicas: &instances,
|
||||
},
|
||||
},
|
||||
@@ -228,14 +229,14 @@ func TestCreateServiceSecretFileMode(t *testing.T) {
|
||||
|
||||
func TestCreateServiceConfigFileMode(t *testing.T) {
|
||||
defer setupTest(t)()
|
||||
d := newSwarm(t)
|
||||
d := swarm.NewSwarm(t, testEnv)
|
||||
defer d.Stop(t)
|
||||
client, err := request.NewClientForHost(d.Sock())
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
configResp, err := client.ConfigCreate(ctx, swarm.ConfigSpec{
|
||||
Annotations: swarm.Annotations{
|
||||
configResp, err := client.ConfigCreate(ctx, swarmtypes.ConfigSpec{
|
||||
Annotations: swarmtypes.Annotations{
|
||||
Name: "TestConfig",
|
||||
},
|
||||
Data: []byte("TESTCONFIG"),
|
||||
@@ -243,17 +244,17 @@ func TestCreateServiceConfigFileMode(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
var instances uint64 = 1
|
||||
serviceSpec := swarm.ServiceSpec{
|
||||
Annotations: swarm.Annotations{
|
||||
serviceSpec := swarmtypes.ServiceSpec{
|
||||
Annotations: swarmtypes.Annotations{
|
||||
Name: "TestService",
|
||||
},
|
||||
TaskTemplate: swarm.TaskSpec{
|
||||
ContainerSpec: &swarm.ContainerSpec{
|
||||
TaskTemplate: swarmtypes.TaskSpec{
|
||||
ContainerSpec: &swarmtypes.ContainerSpec{
|
||||
Image: "busybox:latest",
|
||||
Command: []string{"/bin/sh", "-c", "ls -l /etc/config || /bin/top"},
|
||||
Configs: []*swarm.ConfigReference{
|
||||
Configs: []*swarmtypes.ConfigReference{
|
||||
{
|
||||
File: &swarm.ConfigReferenceFileTarget{
|
||||
File: &swarmtypes.ConfigReferenceFileTarget{
|
||||
Name: "/etc/config",
|
||||
UID: "0",
|
||||
GID: "0",
|
||||
@@ -265,8 +266,8 @@ func TestCreateServiceConfigFileMode(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Mode: swarm.ServiceMode{
|
||||
Replicated: &swarm.ReplicatedService{
|
||||
Mode: swarmtypes.ServiceMode{
|
||||
Replicated: &swarmtypes.ReplicatedService{
|
||||
Replicas: &instances,
|
||||
},
|
||||
},
|
||||
@@ -307,19 +308,19 @@ func TestCreateServiceConfigFileMode(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
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,
|
||||
},
|
||||
},
|
||||
@@ -338,7 +339,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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"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-cli/request"
|
||||
"github.com/docker/docker/integration/util/swarm"
|
||||
"github.com/gotestyourself/gotestyourself/poll"
|
||||
"github.com/gotestyourself/gotestyourself/skip"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -22,7 +21,7 @@ import (
|
||||
func TestInspect(t *testing.T) {
|
||||
skip.IfCondition(t, !testEnv.IsLocalDaemon())
|
||||
defer setupTest(t)()
|
||||
d := newSwarm(t)
|
||||
d := swarm.NewSwarm(t, testEnv)
|
||||
defer d.Stop(t)
|
||||
client, err := request.NewClientForHost(d.Sock())
|
||||
require.NoError(t, err)
|
||||
@@ -49,19 +48,19 @@ func TestInspect(t *testing.T) {
|
||||
assert.WithinDuration(t, before, service.UpdatedAt, 30*time.Second)
|
||||
}
|
||||
|
||||
func fullSwarmServiceSpec(name string, replicas uint64) swarm.ServiceSpec {
|
||||
func fullSwarmServiceSpec(name string, replicas uint64) swarmtypes.ServiceSpec {
|
||||
restartDelay := 100 * time.Millisecond
|
||||
maxAttempts := uint64(4)
|
||||
|
||||
return swarm.ServiceSpec{
|
||||
Annotations: swarm.Annotations{
|
||||
return swarmtypes.ServiceSpec{
|
||||
Annotations: swarmtypes.Annotations{
|
||||
Name: name,
|
||||
Labels: map[string]string{
|
||||
"service-label": "service-label-value",
|
||||
},
|
||||
},
|
||||
TaskTemplate: swarm.TaskSpec{
|
||||
ContainerSpec: &swarm.ContainerSpec{
|
||||
TaskTemplate: swarmtypes.TaskSpec{
|
||||
ContainerSpec: &swarmtypes.ContainerSpec{
|
||||
Image: "busybox:latest",
|
||||
Labels: map[string]string{"container-label": "container-value"},
|
||||
Command: []string{"/bin/top"},
|
||||
@@ -73,64 +72,43 @@ func fullSwarmServiceSpec(name string, replicas uint64) swarm.ServiceSpec {
|
||||
StopSignal: "SIGINT",
|
||||
StopGracePeriod: &restartDelay,
|
||||
Hosts: []string{"8.8.8.8 google"},
|
||||
DNSConfig: &swarm.DNSConfig{
|
||||
DNSConfig: &swarmtypes.DNSConfig{
|
||||
Nameservers: []string{"8.8.8.8"},
|
||||
Search: []string{"somedomain"},
|
||||
},
|
||||
Isolation: container.IsolationDefault,
|
||||
},
|
||||
RestartPolicy: &swarm.RestartPolicy{
|
||||
RestartPolicy: &swarmtypes.RestartPolicy{
|
||||
Delay: &restartDelay,
|
||||
Condition: swarm.RestartPolicyConditionOnFailure,
|
||||
Condition: swarmtypes.RestartPolicyConditionOnFailure,
|
||||
MaxAttempts: &maxAttempts,
|
||||
},
|
||||
Runtime: swarm.RuntimeContainer,
|
||||
Runtime: swarmtypes.RuntimeContainer,
|
||||
},
|
||||
Mode: swarm.ServiceMode{
|
||||
Replicated: &swarm.ReplicatedService{
|
||||
Mode: swarmtypes.ServiceMode{
|
||||
Replicated: &swarmtypes.ReplicatedService{
|
||||
Replicas: &replicas,
|
||||
},
|
||||
},
|
||||
UpdateConfig: &swarm.UpdateConfig{
|
||||
UpdateConfig: &swarmtypes.UpdateConfig{
|
||||
Parallelism: 2,
|
||||
Delay: 200 * time.Second,
|
||||
FailureAction: swarm.UpdateFailureActionContinue,
|
||||
FailureAction: swarmtypes.UpdateFailureActionContinue,
|
||||
Monitor: 2 * time.Second,
|
||||
MaxFailureRatio: 0.2,
|
||||
Order: swarm.UpdateOrderStopFirst,
|
||||
Order: swarmtypes.UpdateOrderStopFirst,
|
||||
},
|
||||
RollbackConfig: &swarm.UpdateConfig{
|
||||
RollbackConfig: &swarmtypes.UpdateConfig{
|
||||
Parallelism: 3,
|
||||
Delay: 300 * time.Second,
|
||||
FailureAction: swarm.UpdateFailureActionPause,
|
||||
FailureAction: swarmtypes.UpdateFailureActionPause,
|
||||
Monitor: 3 * time.Second,
|
||||
MaxFailureRatio: 0.3,
|
||||
Order: swarm.UpdateOrderStartFirst,
|
||||
Order: swarmtypes.UpdateOrderStartFirst,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const defaultSwarmPort = 2477
|
||||
|
||||
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...)
|
||||
|
||||
require.NoError(t, d.Init(swarm.InitRequest{}))
|
||||
return d
|
||||
}
|
||||
|
||||
func serviceContainerCount(client client.ServiceAPIClient, id string, count uint64) func(log poll.LogT) poll.Result {
|
||||
return func(log poll.LogT) poll.Result {
|
||||
filter := filters.NewArgs()
|
||||
|
||||
@@ -8,13 +8,14 @@ import (
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/integration-cli/request"
|
||||
"github.com/docker/docker/integration/util/swarm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDockerNetworkConnectAlias(t *testing.T) {
|
||||
defer setupTest(t)()
|
||||
d := newSwarm(t)
|
||||
d := swarm.NewSwarm(t, testEnv)
|
||||
defer d.Stop(t)
|
||||
client, err := request.NewClientForHost(d.Sock())
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package swarm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
swarmtypes "github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
"github.com/docker/docker/internal/test/environment"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
dockerdBinary = "dockerd"
|
||||
defaultSwarmPort = 2477
|
||||
)
|
||||
|
||||
// NewSwarm creates a swarm daemon for testing
|
||||
func NewSwarm(t *testing.T, testEnv *environment.Execution) *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...)
|
||||
|
||||
require.NoError(t, d.Init(swarmtypes.InitRequest{}))
|
||||
return d
|
||||
}
|
||||
Reference in New Issue
Block a user