2018-02-14 23:23:35 -05:00
|
|
|
package network // import "github.com/docker/docker/integration/network"
|
|
|
|
|
|
|
|
import (
|
2018-04-19 18:30:59 -04:00
|
|
|
"context"
|
2018-02-14 23:23:35 -05:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2018-03-14 06:21:21 -04:00
|
|
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
2018-05-29 18:09:11 -04:00
|
|
|
"github.com/docker/docker/api/types/versions"
|
2018-02-14 23:23:35 -05:00
|
|
|
"github.com/docker/docker/client"
|
2018-06-12 14:31:01 -04:00
|
|
|
"github.com/docker/docker/integration/internal/network"
|
2018-03-14 06:21:21 -04:00
|
|
|
"github.com/docker/docker/integration/internal/swarm"
|
2019-08-29 16:52:40 -04:00
|
|
|
"github.com/docker/docker/testutil/daemon"
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
"gotest.tools/icmd"
|
|
|
|
"gotest.tools/poll"
|
|
|
|
"gotest.tools/skip"
|
2018-02-14 23:23:35 -05:00
|
|
|
)
|
|
|
|
|
2016-12-13 18:04:59 -05:00
|
|
|
// delInterface removes given network interface
|
|
|
|
func delInterface(t *testing.T, ifName string) {
|
|
|
|
icmd.RunCommand("ip", "link", "delete", ifName).Assert(t, icmd.Success)
|
|
|
|
icmd.RunCommand("iptables", "-t", "nat", "--flush").Assert(t, icmd.Success)
|
|
|
|
icmd.RunCommand("iptables", "--flush").Assert(t, icmd.Success)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDaemonRestartWithLiveRestore(t *testing.T) {
|
2018-08-02 16:24:51 -04:00
|
|
|
skip.If(t, testEnv.OSType == "windows")
|
2019-01-03 06:19:15 -05:00
|
|
|
skip.If(t, testEnv.IsRemoteDaemon)
|
2018-05-30 19:58:06 -04:00
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.38"), "skip test from new feature")
|
2016-12-13 18:04:59 -05:00
|
|
|
d := daemon.New(t)
|
|
|
|
defer d.Stop(t)
|
|
|
|
d.Start(t)
|
2018-12-22 09:53:02 -05:00
|
|
|
d.Restart(t,
|
|
|
|
"--live-restore=true",
|
2016-12-13 18:04:59 -05:00
|
|
|
"--default-address-pool", "base=175.30.0.0/16,size=16",
|
2018-12-22 09:53:02 -05:00
|
|
|
"--default-address-pool", "base=175.33.0.0/16,size=24",
|
|
|
|
)
|
2016-12-13 18:04:59 -05:00
|
|
|
|
|
|
|
// Verify bridge network's subnet
|
2018-12-22 09:53:02 -05:00
|
|
|
c := d.NewClientT(t)
|
|
|
|
defer c.Close()
|
|
|
|
out, err := c.NetworkInspect(context.Background(), "bridge", types.NetworkInspectOptions{})
|
2016-12-13 18:04:59 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
// Make sure docker0 doesn't get override with new IP in live restore case
|
|
|
|
assert.Equal(t, out.IPAM.Config[0].Subnet, "172.18.0.0/16")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDaemonDefaultNetworkPools(t *testing.T) {
|
2018-08-02 16:24:51 -04:00
|
|
|
skip.If(t, testEnv.OSType == "windows")
|
2016-12-13 18:04:59 -05:00
|
|
|
// Remove docker0 bridge and the start daemon defining the predefined address pools
|
2019-01-03 06:19:15 -05:00
|
|
|
skip.If(t, testEnv.IsRemoteDaemon)
|
2018-05-30 19:58:06 -04:00
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.38"), "skip test from new feature")
|
2016-12-13 18:04:59 -05:00
|
|
|
defaultNetworkBridge := "docker0"
|
|
|
|
delInterface(t, defaultNetworkBridge)
|
|
|
|
d := daemon.New(t)
|
|
|
|
defer d.Stop(t)
|
|
|
|
d.Start(t,
|
|
|
|
"--default-address-pool", "base=175.30.0.0/16,size=16",
|
2018-12-22 09:53:02 -05:00
|
|
|
"--default-address-pool", "base=175.33.0.0/16,size=24",
|
|
|
|
)
|
|
|
|
|
|
|
|
c := d.NewClientT(t)
|
|
|
|
defer c.Close()
|
2016-12-13 18:04:59 -05:00
|
|
|
|
|
|
|
// Verify bridge network's subnet
|
2018-12-22 09:53:02 -05:00
|
|
|
out, err := c.NetworkInspect(context.Background(), "bridge", types.NetworkInspectOptions{})
|
2016-12-13 18:04:59 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, out.IPAM.Config[0].Subnet, "175.30.0.0/16")
|
|
|
|
|
|
|
|
// Create a bridge network and verify its subnet is the second default pool
|
2018-06-27 03:56:52 -04:00
|
|
|
name := "elango" + t.Name()
|
2019-06-06 06:00:19 -04:00
|
|
|
network.CreateNoError(context.Background(), t, c, name,
|
2018-06-12 14:31:01 -04:00
|
|
|
network.WithDriver("bridge"),
|
|
|
|
)
|
2018-12-22 09:53:02 -05:00
|
|
|
out, err = c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
|
2016-12-13 18:04:59 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, out.IPAM.Config[0].Subnet, "175.33.0.0/24")
|
|
|
|
|
|
|
|
// Create a bridge network and verify its subnet is the third default pool
|
2018-06-27 03:56:52 -04:00
|
|
|
name = "saanvi" + t.Name()
|
2019-06-06 06:00:19 -04:00
|
|
|
network.CreateNoError(context.Background(), t, c, name,
|
2018-06-12 14:31:01 -04:00
|
|
|
network.WithDriver("bridge"),
|
|
|
|
)
|
2018-12-22 09:53:02 -05:00
|
|
|
out, err = c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
|
2016-12-13 18:04:59 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, out.IPAM.Config[0].Subnet, "175.33.1.0/24")
|
|
|
|
delInterface(t, defaultNetworkBridge)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDaemonRestartWithExistingNetwork(t *testing.T) {
|
2018-08-02 16:24:51 -04:00
|
|
|
skip.If(t, testEnv.OSType == "windows")
|
2019-01-03 06:19:15 -05:00
|
|
|
skip.If(t, testEnv.IsRemoteDaemon)
|
2018-05-30 19:58:06 -04:00
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.38"), "skip test from new feature")
|
2016-12-13 18:04:59 -05:00
|
|
|
defaultNetworkBridge := "docker0"
|
|
|
|
d := daemon.New(t)
|
|
|
|
d.Start(t)
|
|
|
|
defer d.Stop(t)
|
2018-12-22 09:53:02 -05:00
|
|
|
c := d.NewClientT(t)
|
|
|
|
defer c.Close()
|
2016-12-13 18:04:59 -05:00
|
|
|
|
|
|
|
// Create a bridge network
|
2018-06-27 03:56:52 -04:00
|
|
|
name := "elango" + t.Name()
|
2019-06-06 06:00:19 -04:00
|
|
|
network.CreateNoError(context.Background(), t, c, name,
|
2018-06-12 14:31:01 -04:00
|
|
|
network.WithDriver("bridge"),
|
|
|
|
)
|
2018-12-22 09:53:02 -05:00
|
|
|
|
|
|
|
// Verify bridge network's subnet
|
|
|
|
out, err := c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
|
2016-12-13 18:04:59 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
networkip := out.IPAM.Config[0].Subnet
|
|
|
|
|
|
|
|
// Restart daemon with default address pool option
|
|
|
|
d.Restart(t,
|
|
|
|
"--default-address-pool", "base=175.30.0.0/16,size=16",
|
|
|
|
"--default-address-pool", "base=175.33.0.0/16,size=24")
|
|
|
|
|
2018-12-22 09:53:02 -05:00
|
|
|
out1, err := c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
|
2016-12-13 18:04:59 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, out1.IPAM.Config[0].Subnet, networkip)
|
|
|
|
delInterface(t, defaultNetworkBridge)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDaemonRestartWithExistingNetworkWithDefaultPoolRange(t *testing.T) {
|
2018-08-02 16:24:51 -04:00
|
|
|
skip.If(t, testEnv.OSType == "windows")
|
2019-01-03 06:19:15 -05:00
|
|
|
skip.If(t, testEnv.IsRemoteDaemon)
|
2018-05-30 19:58:06 -04:00
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.38"), "skip test from new feature")
|
2016-12-13 18:04:59 -05:00
|
|
|
defaultNetworkBridge := "docker0"
|
|
|
|
d := daemon.New(t)
|
|
|
|
d.Start(t)
|
|
|
|
defer d.Stop(t)
|
2018-12-22 09:53:02 -05:00
|
|
|
c := d.NewClientT(t)
|
|
|
|
defer c.Close()
|
2016-12-13 18:04:59 -05:00
|
|
|
|
|
|
|
// Create a bridge network
|
2018-06-27 03:56:52 -04:00
|
|
|
name := "elango" + t.Name()
|
2019-06-06 06:00:19 -04:00
|
|
|
network.CreateNoError(context.Background(), t, c, name,
|
2018-06-12 14:31:01 -04:00
|
|
|
network.WithDriver("bridge"),
|
|
|
|
)
|
2018-12-22 09:53:02 -05:00
|
|
|
|
|
|
|
// Verify bridge network's subnet
|
|
|
|
out, err := c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
|
2016-12-13 18:04:59 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
networkip := out.IPAM.Config[0].Subnet
|
|
|
|
|
|
|
|
// Create a bridge network
|
2018-06-27 03:56:52 -04:00
|
|
|
name = "sthira" + t.Name()
|
2019-06-06 06:00:19 -04:00
|
|
|
network.CreateNoError(context.Background(), t, c, name,
|
2018-06-12 14:31:01 -04:00
|
|
|
network.WithDriver("bridge"),
|
|
|
|
)
|
2018-12-22 09:53:02 -05:00
|
|
|
out, err = c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
|
2016-12-13 18:04:59 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
networkip2 := out.IPAM.Config[0].Subnet
|
|
|
|
|
|
|
|
// Restart daemon with default address pool option
|
|
|
|
d.Restart(t,
|
|
|
|
"--default-address-pool", "base=175.18.0.0/16,size=16",
|
2018-12-22 09:53:02 -05:00
|
|
|
"--default-address-pool", "base=175.19.0.0/16,size=24",
|
|
|
|
)
|
2016-12-13 18:04:59 -05:00
|
|
|
|
|
|
|
// Create a bridge network
|
2018-06-27 03:56:52 -04:00
|
|
|
name = "saanvi" + t.Name()
|
2019-06-06 06:00:19 -04:00
|
|
|
network.CreateNoError(context.Background(), t, c, name,
|
2018-06-12 14:31:01 -04:00
|
|
|
network.WithDriver("bridge"),
|
|
|
|
)
|
2018-12-22 09:53:02 -05:00
|
|
|
out1, err := c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
|
2016-12-13 18:04:59 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
|
2018-05-19 07:38:54 -04:00
|
|
|
assert.Check(t, out1.IPAM.Config[0].Subnet != networkip)
|
|
|
|
assert.Check(t, out1.IPAM.Config[0].Subnet != networkip2)
|
2016-12-13 18:04:59 -05:00
|
|
|
delInterface(t, defaultNetworkBridge)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDaemonWithBipAndDefaultNetworkPool(t *testing.T) {
|
2018-08-02 16:24:51 -04:00
|
|
|
skip.If(t, testEnv.OSType == "windows")
|
2019-01-03 06:19:15 -05:00
|
|
|
skip.If(t, testEnv.IsRemoteDaemon)
|
2018-05-30 19:58:06 -04:00
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.38"), "skip test from new feature")
|
2016-12-13 18:04:59 -05:00
|
|
|
defaultNetworkBridge := "docker0"
|
|
|
|
d := daemon.New(t)
|
|
|
|
defer d.Stop(t)
|
2018-12-22 09:53:02 -05:00
|
|
|
d.Start(t,
|
|
|
|
"--bip=172.60.0.1/16",
|
2016-12-13 18:04:59 -05:00
|
|
|
"--default-address-pool", "base=175.30.0.0/16,size=16",
|
2018-12-22 09:53:02 -05:00
|
|
|
"--default-address-pool", "base=175.33.0.0/16,size=24",
|
|
|
|
)
|
|
|
|
|
|
|
|
c := d.NewClientT(t)
|
|
|
|
defer c.Close()
|
2016-12-13 18:04:59 -05:00
|
|
|
|
|
|
|
// Verify bridge network's subnet
|
2018-12-22 09:53:02 -05:00
|
|
|
out, err := c.NetworkInspect(context.Background(), "bridge", types.NetworkInspectOptions{})
|
2016-12-13 18:04:59 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
// Make sure BIP IP doesn't get override with new default address pool .
|
|
|
|
assert.Equal(t, out.IPAM.Config[0].Subnet, "172.60.0.1/16")
|
|
|
|
delInterface(t, defaultNetworkBridge)
|
|
|
|
}
|
|
|
|
|
2018-02-14 23:23:35 -05:00
|
|
|
func TestServiceWithPredefinedNetwork(t *testing.T) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.OSType == "windows")
|
2018-02-14 23:23:35 -05:00
|
|
|
defer setupTest(t)()
|
2018-03-14 06:21:21 -04:00
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
2018-02-14 23:23:35 -05:00
|
|
|
defer d.Stop(t)
|
2018-12-22 09:53:02 -05:00
|
|
|
c := d.NewClientT(t)
|
|
|
|
defer c.Close()
|
2018-02-14 23:23:35 -05:00
|
|
|
|
|
|
|
hostName := "host"
|
|
|
|
var instances uint64 = 1
|
2018-05-28 18:57:52 -04:00
|
|
|
serviceName := "TestService" + t.Name()
|
2018-02-14 23:23:35 -05:00
|
|
|
|
2018-04-05 17:26:29 -04:00
|
|
|
serviceID := swarm.CreateService(t, d,
|
|
|
|
swarm.ServiceWithReplicas(instances),
|
|
|
|
swarm.ServiceWithName(serviceName),
|
|
|
|
swarm.ServiceWithNetwork(hostName),
|
|
|
|
)
|
2018-02-14 23:23:35 -05:00
|
|
|
|
2019-08-05 16:57:48 -04:00
|
|
|
poll.WaitOn(t, swarm.RunningTasksCount(c, serviceID, instances), swarm.ServicePoll)
|
2018-03-07 16:47:16 -05:00
|
|
|
|
2018-12-22 09:53:02 -05:00
|
|
|
_, _, err := c.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
|
2017-12-22 16:30:49 -05:00
|
|
|
assert.NilError(t, err)
|
2018-03-07 16:47:16 -05:00
|
|
|
|
2018-12-22 09:53:02 -05:00
|
|
|
err = c.ServiceRemove(context.Background(), serviceID)
|
2017-12-22 16:30:49 -05:00
|
|
|
assert.NilError(t, err)
|
2018-03-07 16:47:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const ingressNet = "ingress"
|
|
|
|
|
2018-03-26 15:29:15 -04:00
|
|
|
func TestServiceRemoveKeepsIngressNetwork(t *testing.T) {
|
2019-07-02 16:33:25 -04:00
|
|
|
t.Skip("FLAKY_TEST")
|
|
|
|
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.OSType == "windows")
|
2018-03-07 16:47:16 -05:00
|
|
|
defer setupTest(t)()
|
2018-03-14 06:21:21 -04:00
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
2018-03-07 16:47:16 -05:00
|
|
|
defer d.Stop(t)
|
2018-12-22 09:53:02 -05:00
|
|
|
c := d.NewClientT(t)
|
|
|
|
defer c.Close()
|
2018-03-07 16:47:16 -05:00
|
|
|
|
2018-12-22 09:53:02 -05:00
|
|
|
poll.WaitOn(t, swarmIngressReady(c), swarm.NetworkPoll)
|
2018-03-07 16:47:16 -05:00
|
|
|
|
|
|
|
var instances uint64 = 1
|
|
|
|
|
2018-04-05 17:26:29 -04:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
)
|
2018-03-07 16:47:16 -05:00
|
|
|
|
2019-08-05 16:57:48 -04:00
|
|
|
poll.WaitOn(t, swarm.RunningTasksCount(c, serviceID, instances), swarm.ServicePoll)
|
2018-02-14 23:23:35 -05:00
|
|
|
|
2019-01-13 20:20:09 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
_, _, err := c.ServiceInspectWithRaw(ctx, serviceID, types.ServiceInspectOptions{})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-14 23:23:35 -05:00
|
|
|
|
2019-01-13 20:20:09 -05:00
|
|
|
err = c.ServiceRemove(ctx, serviceID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-14 23:23:35 -05:00
|
|
|
|
2019-01-13 20:20:09 -05:00
|
|
|
poll.WaitOn(t, noServices(ctx, c), swarm.ServicePoll)
|
|
|
|
poll.WaitOn(t, swarm.NoTasks(ctx, c), swarm.ServicePoll)
|
2018-02-14 23:23:35 -05:00
|
|
|
|
2018-03-07 16:47:16 -05:00
|
|
|
// Ensure that "ingress" is not removed or corrupted
|
|
|
|
time.Sleep(10 * time.Second)
|
2019-01-13 20:20:09 -05:00
|
|
|
netInfo, err := c.NetworkInspect(ctx, ingressNet, types.NetworkInspectOptions{
|
2018-03-07 16:47:16 -05:00
|
|
|
Verbose: true,
|
|
|
|
Scope: "swarm",
|
|
|
|
})
|
2017-12-22 16:30:49 -05:00
|
|
|
assert.NilError(t, err, "Ingress network was removed after removing service!")
|
|
|
|
assert.Assert(t, len(netInfo.Containers) != 0, "No load balancing endpoints in ingress network")
|
|
|
|
assert.Assert(t, len(netInfo.Peers) != 0, "No peers (including self) in ingress network")
|
2018-03-07 16:47:16 -05:00
|
|
|
_, ok := netInfo.Containers["ingress-sbox"]
|
2017-12-22 16:30:49 -05:00
|
|
|
assert.Assert(t, ok, "ingress-sbox not present in ingress network")
|
2018-02-14 23:23:35 -05:00
|
|
|
}
|
|
|
|
|
2018-03-07 16:47:16 -05:00
|
|
|
func swarmIngressReady(client client.NetworkAPIClient) func(log poll.LogT) poll.Result {
|
|
|
|
return func(log poll.LogT) poll.Result {
|
|
|
|
netInfo, err := client.NetworkInspect(context.Background(), ingressNet, types.NetworkInspectOptions{
|
|
|
|
Verbose: true,
|
|
|
|
Scope: "swarm",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return poll.Error(err)
|
|
|
|
}
|
|
|
|
np := len(netInfo.Peers)
|
|
|
|
nc := len(netInfo.Containers)
|
|
|
|
if np == 0 || nc == 0 {
|
|
|
|
return poll.Continue("ingress not ready: %d peers and %d containers", nc, np)
|
|
|
|
}
|
|
|
|
_, ok := netInfo.Containers["ingress-sbox"]
|
|
|
|
if !ok {
|
|
|
|
return poll.Continue("ingress not ready: does not contain the ingress-sbox")
|
|
|
|
}
|
|
|
|
return poll.Success()
|
|
|
|
}
|
|
|
|
}
|
2018-03-09 17:03:59 -05:00
|
|
|
|
2019-01-13 20:20:09 -05:00
|
|
|
func noServices(ctx context.Context, client client.ServiceAPIClient) func(log poll.LogT) poll.Result {
|
2018-03-09 17:03:59 -05:00
|
|
|
return func(log poll.LogT) poll.Result {
|
2019-01-13 20:20:09 -05:00
|
|
|
services, err := client.ServiceList(ctx, types.ServiceListOptions{})
|
2018-03-09 17:03:59 -05:00
|
|
|
switch {
|
|
|
|
case err != nil:
|
|
|
|
return poll.Error(err)
|
|
|
|
case len(services) == 0:
|
|
|
|
return poll.Success()
|
|
|
|
default:
|
2019-01-13 20:20:09 -05:00
|
|
|
return poll.Continue("waiting for all services to be removed: service count at %d", len(services))
|
2018-03-09 17:03:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 11:25:02 -04:00
|
|
|
|
2018-11-20 16:44:40 -05:00
|
|
|
func TestServiceWithDataPathPortInit(t *testing.T) {
|
|
|
|
skip.If(t, testEnv.OSType == "windows")
|
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.40"), "DataPathPort was added in API v1.40")
|
|
|
|
defer setupTest(t)()
|
|
|
|
var datapathPort uint32 = 7777
|
2019-08-05 16:57:48 -04:00
|
|
|
d := swarm.NewSwarm(t, testEnv, daemon.WithSwarmDataPathPort(datapathPort))
|
2018-12-22 09:53:02 -05:00
|
|
|
c := d.NewClientT(t)
|
2019-08-05 16:57:48 -04:00
|
|
|
ctx := context.Background()
|
2018-11-20 16:44:40 -05:00
|
|
|
// Create a overlay network
|
|
|
|
name := "saanvisthira" + t.Name()
|
2019-08-05 16:57:48 -04:00
|
|
|
overlayID := network.CreateNoError(context.Background(), t, c, name,
|
2018-11-20 16:44:40 -05:00
|
|
|
network.WithDriver("overlay"))
|
|
|
|
|
|
|
|
var instances uint64 = 1
|
|
|
|
serviceID := swarm.CreateService(t, d,
|
|
|
|
swarm.ServiceWithReplicas(instances),
|
2019-08-05 16:57:48 -04:00
|
|
|
swarm.ServiceWithName(name),
|
2018-11-20 16:44:40 -05:00
|
|
|
swarm.ServiceWithNetwork(name),
|
|
|
|
)
|
|
|
|
|
2019-08-05 16:57:48 -04:00
|
|
|
poll.WaitOn(t, swarm.RunningTasksCount(c, serviceID, instances), swarm.ServicePoll)
|
2018-11-20 16:44:40 -05:00
|
|
|
|
|
|
|
info := d.Info(t)
|
|
|
|
assert.Equal(t, info.Swarm.Cluster.DataPathPort, datapathPort)
|
2019-08-05 16:57:48 -04:00
|
|
|
err := c.ServiceRemove(ctx, serviceID)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
poll.WaitOn(t, noServices(ctx, c), swarm.ServicePoll)
|
|
|
|
poll.WaitOn(t, swarm.NoTasks(ctx, c), swarm.ServicePoll)
|
|
|
|
err = c.NetworkRemove(ctx, overlayID)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
c.Close()
|
|
|
|
err = d.SwarmLeave(t, true)
|
2018-11-20 16:44:40 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
d.Stop(t)
|
|
|
|
|
|
|
|
// Clean up , set it back to original one to make sure other tests don't fail
|
|
|
|
// call without datapath port option.
|
2019-08-05 16:57:48 -04:00
|
|
|
d = swarm.NewSwarm(t, testEnv)
|
2019-08-15 17:09:47 -04:00
|
|
|
defer d.Stop(t)
|
2019-08-05 16:57:48 -04:00
|
|
|
nc := d.NewClientT(t)
|
|
|
|
defer nc.Close()
|
2018-11-20 16:44:40 -05:00
|
|
|
// Create a overlay network
|
2019-08-05 16:57:48 -04:00
|
|
|
name = "not-saanvisthira" + t.Name()
|
|
|
|
overlayID = network.CreateNoError(ctx, t, nc, name,
|
2018-11-20 16:44:40 -05:00
|
|
|
network.WithDriver("overlay"))
|
|
|
|
|
|
|
|
serviceID = swarm.CreateService(t, d,
|
|
|
|
swarm.ServiceWithReplicas(instances),
|
2019-08-05 16:57:48 -04:00
|
|
|
swarm.ServiceWithName(name),
|
2018-11-20 16:44:40 -05:00
|
|
|
swarm.ServiceWithNetwork(name),
|
|
|
|
)
|
|
|
|
|
2019-08-05 16:57:48 -04:00
|
|
|
poll.WaitOn(t, swarm.RunningTasksCount(nc, serviceID, instances), swarm.ServicePoll)
|
2018-11-20 16:44:40 -05:00
|
|
|
|
|
|
|
info = d.Info(t)
|
|
|
|
var defaultDataPathPort uint32 = 4789
|
|
|
|
assert.Equal(t, info.Swarm.Cluster.DataPathPort, defaultDataPathPort)
|
2019-08-05 16:57:48 -04:00
|
|
|
err = nc.ServiceRemove(ctx, serviceID)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
poll.WaitOn(t, noServices(ctx, nc), swarm.ServicePoll)
|
|
|
|
poll.WaitOn(t, swarm.NoTasks(ctx, nc), swarm.ServicePoll)
|
|
|
|
err = nc.NetworkRemove(ctx, overlayID)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
err = d.SwarmLeave(t, true)
|
2018-11-20 16:44:40 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
}
|
|
|
|
|
2018-07-30 11:25:02 -04:00
|
|
|
func TestServiceWithDefaultAddressPoolInit(t *testing.T) {
|
2018-08-02 16:24:51 -04:00
|
|
|
skip.If(t, testEnv.OSType == "windows")
|
2018-07-30 11:25:02 -04:00
|
|
|
defer setupTest(t)()
|
2019-08-05 16:57:48 -04:00
|
|
|
d := swarm.NewSwarm(t, testEnv,
|
|
|
|
daemon.WithSwarmDefaultAddrPool([]string{"20.20.0.0/16"}),
|
|
|
|
daemon.WithSwarmDefaultAddrPoolSubnetSize(24))
|
2019-08-15 17:09:47 -04:00
|
|
|
defer d.Stop(t)
|
2018-07-30 11:25:02 -04:00
|
|
|
cli := d.NewClientT(t)
|
|
|
|
defer cli.Close()
|
2019-08-05 16:57:48 -04:00
|
|
|
ctx := context.Background()
|
2018-07-30 11:25:02 -04:00
|
|
|
|
|
|
|
// Create a overlay network
|
2018-09-12 23:06:24 -04:00
|
|
|
name := "sthira" + t.Name()
|
2019-08-05 16:57:48 -04:00
|
|
|
overlayID := network.CreateNoError(ctx, t, cli, name,
|
2018-09-12 23:06:24 -04:00
|
|
|
network.WithDriver("overlay"),
|
|
|
|
network.WithCheckDuplicate(),
|
|
|
|
)
|
2018-07-30 11:25:02 -04:00
|
|
|
|
|
|
|
var instances uint64 = 1
|
|
|
|
serviceName := "TestService" + t.Name()
|
|
|
|
serviceID := swarm.CreateService(t, d,
|
|
|
|
swarm.ServiceWithReplicas(instances),
|
|
|
|
swarm.ServiceWithName(serviceName),
|
|
|
|
swarm.ServiceWithNetwork(name),
|
|
|
|
)
|
|
|
|
|
2019-08-05 16:57:48 -04:00
|
|
|
poll.WaitOn(t, swarm.RunningTasksCount(cli, serviceID, instances), swarm.ServicePoll)
|
2018-07-30 11:25:02 -04:00
|
|
|
|
2019-08-05 16:57:48 -04:00
|
|
|
_, _, err := cli.ServiceInspectWithRaw(ctx, serviceID, types.ServiceInspectOptions{})
|
2018-07-30 11:25:02 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
|
2019-08-05 16:57:48 -04:00
|
|
|
out, err := cli.NetworkInspect(ctx, overlayID, types.NetworkInspectOptions{Verbose: true})
|
2018-07-30 11:25:02 -04:00
|
|
|
assert.NilError(t, err)
|
2018-09-06 00:57:03 -04:00
|
|
|
t.Logf("%s: NetworkInspect: %+v", t.Name(), out)
|
|
|
|
assert.Assert(t, len(out.IPAM.Config) > 0)
|
2018-07-30 11:25:02 -04:00
|
|
|
assert.Equal(t, out.IPAM.Config[0].Subnet, "20.20.0.0/24")
|
|
|
|
|
2019-08-05 16:57:48 -04:00
|
|
|
err = cli.ServiceRemove(ctx, serviceID)
|
|
|
|
poll.WaitOn(t, noServices(ctx, cli), swarm.ServicePoll)
|
|
|
|
poll.WaitOn(t, swarm.NoTasks(ctx, cli), swarm.ServicePoll)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
err = cli.NetworkRemove(ctx, overlayID)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
err = d.SwarmLeave(t, true)
|
2018-07-30 11:25:02 -04:00
|
|
|
assert.NilError(t, err)
|
2019-08-05 16:57:48 -04:00
|
|
|
|
2018-07-30 11:25:02 -04:00
|
|
|
}
|