2021-08-23 13:14:53 +00:00
|
|
|
//go:build !windows
|
2016-06-17 00:04:56 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-10-24 21:44:51 +00:00
|
|
|
"bytes"
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2016-10-15 17:20:34 +00:00
|
|
|
"encoding/json"
|
2017-06-06 13:28:40 +00:00
|
|
|
"encoding/pem"
|
2016-10-15 17:20:34 +00:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"os"
|
2016-07-20 06:58:32 +00:00
|
|
|
"path/filepath"
|
2018-12-23 11:39:58 +00:00
|
|
|
"runtime"
|
2016-06-30 02:48:53 +00:00
|
|
|
"strings"
|
2019-09-09 21:06:12 +00:00
|
|
|
"testing"
|
2016-06-17 00:04:56 +00:00
|
|
|
"time"
|
|
|
|
|
2017-04-16 19:40:11 +00:00
|
|
|
"github.com/cloudflare/cfssl/helpers"
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2016-12-30 17:23:00 +00:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2017-03-23 17:35:22 +00:00
|
|
|
"github.com/docker/docker/integration-cli/cli"
|
2016-12-09 09:17:53 +00:00
|
|
|
"github.com/docker/docker/integration-cli/daemon"
|
2021-04-06 00:24:47 +00:00
|
|
|
"github.com/docker/docker/libnetwork/driverapi"
|
|
|
|
"github.com/docker/docker/libnetwork/ipamapi"
|
|
|
|
remoteipam "github.com/docker/docker/libnetwork/ipams/remote/api"
|
2023-07-19 08:20:49 +00:00
|
|
|
"github.com/docker/docker/pkg/plugins"
|
2023-07-14 18:02:38 +00:00
|
|
|
"github.com/docker/docker/testutil"
|
2024-01-02 20:29:32 +00:00
|
|
|
testdaemon "github.com/docker/docker/testutil/daemon"
|
2022-04-21 21:33:07 +00:00
|
|
|
"github.com/moby/swarmkit/v2/ca/keyutils"
|
2016-10-15 17:20:34 +00:00
|
|
|
"github.com/vishvananda/netlink"
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
"gotest.tools/v3/fs"
|
|
|
|
"gotest.tools/v3/icmd"
|
|
|
|
"gotest.tools/v3/poll"
|
2016-06-17 00:04:56 +00:00
|
|
|
)
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmUpdate(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-06-17 00:04:56 +00:00
|
|
|
|
|
|
|
getSpec := func() swarm.Spec {
|
2016-12-09 09:17:53 +00:00
|
|
|
sw := d.GetSwarm(c)
|
2016-07-24 08:53:52 +00:00
|
|
|
return sw.Spec
|
2016-06-17 00:04:56 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 18:15:08 +00:00
|
|
|
out, err := d.Cmd("swarm", "update", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-06-17 00:04:56 +00:00
|
|
|
|
|
|
|
spec := getSpec()
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, spec.CAConfig.NodeCertExpiry, 30*time.Hour)
|
|
|
|
assert.Equal(c, spec.Dispatcher.HeartbeatPeriod, 11*time.Second)
|
2016-06-17 00:04:56 +00:00
|
|
|
|
|
|
|
// setting anything under 30m for cert-expiry is not allowed
|
|
|
|
out, err = d.Cmd("swarm", "update", "--cert-expiry", "15m")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "minimum certificate expiry time"))
|
2016-06-17 00:04:56 +00:00
|
|
|
spec = getSpec()
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, spec.CAConfig.NodeCertExpiry, 30*time.Hour)
|
2017-04-12 22:10:18 +00:00
|
|
|
|
|
|
|
// passing an external CA (this is without starting a root rotation) does not fail
|
2017-04-25 22:40:46 +00:00
|
|
|
cli.Docker(cli.Args("swarm", "update", "--external-ca", "protocol=cfssl,url=https://something.org",
|
|
|
|
"--external-ca", "protocol=cfssl,url=https://somethingelse.org,cacert=fixtures/https/ca.pem"),
|
2018-04-11 10:10:17 +00:00
|
|
|
cli.Daemon(d)).Assert(c, icmd.Success)
|
2017-04-25 22:40:46 +00:00
|
|
|
|
2021-08-24 10:10:50 +00:00
|
|
|
expected, err := os.ReadFile("fixtures/https/ca.pem")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2017-04-12 22:10:18 +00:00
|
|
|
|
|
|
|
spec = getSpec()
|
2019-09-09 21:05:57 +00:00
|
|
|
assert.Equal(c, len(spec.CAConfig.ExternalCAs), 2)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, spec.CAConfig.ExternalCAs[0].CACert, "")
|
|
|
|
assert.Equal(c, spec.CAConfig.ExternalCAs[1].CACert, string(expected))
|
2017-04-25 22:40:46 +00:00
|
|
|
|
|
|
|
// passing an invalid external CA fails
|
2017-08-23 21:25:00 +00:00
|
|
|
tempFile := fs.NewFile(c, "testfile", fs.WithContent("fakecert"))
|
2017-04-25 22:40:46 +00:00
|
|
|
defer tempFile.Remove()
|
|
|
|
|
|
|
|
result := cli.Docker(cli.Args("swarm", "update",
|
2017-08-23 21:25:00 +00:00
|
|
|
"--external-ca", fmt.Sprintf("protocol=cfssl,url=https://something.org,cacert=%s", tempFile.Path())),
|
2018-04-11 10:10:17 +00:00
|
|
|
cli.Daemon(d))
|
2017-04-25 22:40:46 +00:00
|
|
|
result.Assert(c, icmd.Expected{
|
|
|
|
ExitCode: 125,
|
|
|
|
Err: "must be in PEM format",
|
|
|
|
})
|
2016-06-17 00:04:56 +00:00
|
|
|
}
|
2016-06-21 21:27:04 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmInit(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, false, false)
|
2016-06-21 21:27:04 +00:00
|
|
|
|
|
|
|
getSpec := func() swarm.Spec {
|
2016-12-09 09:17:53 +00:00
|
|
|
sw := d.GetSwarm(c)
|
2016-07-24 08:53:52 +00:00
|
|
|
return sw.Spec
|
2016-06-21 21:27:04 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:40:46 +00:00
|
|
|
// passing an invalid external CA fails
|
2017-08-23 21:25:00 +00:00
|
|
|
tempFile := fs.NewFile(c, "testfile", fs.WithContent("fakecert"))
|
2017-04-25 22:40:46 +00:00
|
|
|
defer tempFile.Remove()
|
|
|
|
|
|
|
|
result := cli.Docker(cli.Args("swarm", "init", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s",
|
2017-08-23 21:25:00 +00:00
|
|
|
"--external-ca", fmt.Sprintf("protocol=cfssl,url=https://somethingelse.org,cacert=%s", tempFile.Path())),
|
2018-04-11 10:10:17 +00:00
|
|
|
cli.Daemon(d))
|
2017-04-25 22:40:46 +00:00
|
|
|
result.Assert(c, icmd.Expected{
|
|
|
|
ExitCode: 125,
|
|
|
|
Err: "must be in PEM format",
|
|
|
|
})
|
|
|
|
|
2017-04-12 22:10:18 +00:00
|
|
|
cli.Docker(cli.Args("swarm", "init", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s",
|
2017-04-25 22:40:46 +00:00
|
|
|
"--external-ca", "protocol=cfssl,url=https://something.org",
|
|
|
|
"--external-ca", "protocol=cfssl,url=https://somethingelse.org,cacert=fixtures/https/ca.pem"),
|
2018-04-11 10:10:17 +00:00
|
|
|
cli.Daemon(d)).Assert(c, icmd.Success)
|
2016-06-21 21:27:04 +00:00
|
|
|
|
2021-08-24 10:10:50 +00:00
|
|
|
expected, err := os.ReadFile("fixtures/https/ca.pem")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2017-04-25 22:40:46 +00:00
|
|
|
|
2016-06-21 21:27:04 +00:00
|
|
|
spec := getSpec()
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, spec.CAConfig.NodeCertExpiry, 30*time.Hour)
|
|
|
|
assert.Equal(c, spec.Dispatcher.HeartbeatPeriod, 11*time.Second)
|
2019-09-09 21:05:57 +00:00
|
|
|
assert.Equal(c, len(spec.CAConfig.ExternalCAs), 2)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, spec.CAConfig.ExternalCAs[0].CACert, "")
|
|
|
|
assert.Equal(c, spec.CAConfig.ExternalCAs[1].CACert, string(expected))
|
2016-06-21 21:27:04 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
assert.Assert(c, d.SwarmLeave(ctx, c, true) == nil)
|
2018-04-11 10:10:17 +00:00
|
|
|
cli.Docker(cli.Args("swarm", "init"), cli.Daemon(d)).Assert(c, icmd.Success)
|
2016-06-21 21:27:04 +00:00
|
|
|
|
|
|
|
spec = getSpec()
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, spec.CAConfig.NodeCertExpiry, 90*24*time.Hour)
|
|
|
|
assert.Equal(c, spec.Dispatcher.HeartbeatPeriod, 5*time.Second)
|
2016-06-21 21:27:04 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmInitIPv6(c *testing.T) {
|
2016-06-21 21:27:04 +00:00
|
|
|
testRequires(c, IPv6)
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d1 := s.AddDaemon(ctx, c, false, false)
|
2018-04-11 10:10:17 +00:00
|
|
|
cli.Docker(cli.Args("swarm", "init", "--listen-add", "::1"), cli.Daemon(d1)).Assert(c, icmd.Success)
|
2016-06-21 21:27:04 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
d2 := s.AddDaemon(ctx, c, false, false)
|
2018-04-11 10:10:17 +00:00
|
|
|
cli.Docker(cli.Args("swarm", "join", "::1"), cli.Daemon(d2)).Assert(c, icmd.Success)
|
2016-06-21 21:27:04 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
out := cli.Docker(cli.Args("info"), cli.Daemon(d2)).Assert(c, icmd.Success).Combined()
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "Swarm: active"))
|
2016-06-21 21:27:04 +00:00
|
|
|
}
|
2016-06-28 21:20:52 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmInitUnspecifiedAdvertiseAddr(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, false, false)
|
2016-11-28 23:16:59 +00:00
|
|
|
out, err := d.Cmd("swarm", "init", "--advertise-addr", "0.0.0.0")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "advertise address must be a non-zero IP address"))
|
2016-11-28 23:16:59 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmIncompatibleDaemon(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
2016-06-28 21:20:52 +00:00
|
|
|
// init swarm mode and stop a daemon
|
2023-07-14 18:02:38 +00:00
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
|
|
|
info := d.SwarmInfo(ctx, c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
2016-12-09 22:20:14 +00:00
|
|
|
d.Stop(c)
|
2016-06-28 21:20:52 +00:00
|
|
|
|
|
|
|
// start a daemon with --live-restore
|
2021-12-15 17:58:06 +00:00
|
|
|
err := d.StartWithError("--live-restore")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2021-12-15 17:58:06 +00:00
|
|
|
content, err := d.ReadLogFile()
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Assert(c, strings.Contains(string(content), "--live-restore daemon configuration is incompatible with swarm mode"))
|
2016-06-28 21:20:52 +00:00
|
|
|
// restart for teardown
|
2018-10-25 18:47:56 +00:00
|
|
|
d.StartNode(c)
|
2016-06-28 21:20:52 +00:00
|
|
|
}
|
2016-06-30 02:48:53 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmServiceTemplatingHostname(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-08-30 19:45:05 +00:00
|
|
|
hostname, err := d.Cmd("node", "inspect", "--format", "{{.Description.Hostname}}", "self")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 10:36:00 +00:00
|
|
|
assert.Assert(c, err == nil, hostname)
|
2016-11-09 22:28:06 +00:00
|
|
|
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "test", "--hostname", "{{.Service.Name}}-{{.Task.Slot}}-{{.Node.Hostname}}", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-09 22:28:06 +00:00
|
|
|
|
|
|
|
// make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-11-09 22:28:06 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
containers := d.ActiveContainers(testutil.GetContext(c), c)
|
2016-11-09 22:28:06 +00:00
|
|
|
out, err = d.Cmd("inspect", "--type", "container", "--format", "{{.Config.Hostname}}", containers[0])
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Equal(c, strings.Split(out, "\n")[0], "test-1-"+strings.Split(hostname, "\n")[0], "hostname with templating invalid")
|
2016-11-09 22:28:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 02:09:07 +00:00
|
|
|
// Test case for #24270
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmServiceListFilter(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-07-14 02:09:07 +00:00
|
|
|
|
|
|
|
name1 := "redis-cluster-md5"
|
|
|
|
name2 := "redis-cluster"
|
|
|
|
name3 := "other-cluster"
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name1, "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-07-14 02:09:07 +00:00
|
|
|
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name2, "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-07-14 02:09:07 +00:00
|
|
|
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name3, "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-07-14 02:09:07 +00:00
|
|
|
|
|
|
|
filter1 := "name=redis-cluster-md5"
|
|
|
|
filter2 := "name=redis-cluster"
|
|
|
|
|
|
|
|
// We search checker.Contains with `name+" "` to prevent prefix only.
|
|
|
|
out, err = d.Cmd("service", "ls", "--filter", filter1)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, name1+" "), out)
|
|
|
|
assert.Assert(c, !strings.Contains(out, name2+" "), out)
|
|
|
|
assert.Assert(c, !strings.Contains(out, name3+" "), out)
|
2016-07-14 02:09:07 +00:00
|
|
|
out, err = d.Cmd("service", "ls", "--filter", filter2)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, name1+" "), out)
|
|
|
|
assert.Assert(c, strings.Contains(out, name2+" "), out)
|
|
|
|
assert.Assert(c, !strings.Contains(out, name3+" "), out)
|
2016-07-14 02:09:07 +00:00
|
|
|
out, err = d.Cmd("service", "ls")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, name1+" "), out)
|
|
|
|
assert.Assert(c, strings.Contains(out, name2+" "), out)
|
|
|
|
assert.Assert(c, strings.Contains(out, name3+" "), out)
|
2016-07-14 02:09:07 +00:00
|
|
|
}
|
2016-07-17 20:21:29 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmNodeListFilter(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-07-17 20:21:29 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("node", "inspect", "--format", "{{ .Description.Hostname }}", "self")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-07-17 20:21:29 +00:00
|
|
|
name := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
filter := "name=" + name[:4]
|
|
|
|
|
|
|
|
out, err = d.Cmd("node", "ls", "--filter", filter)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, name), out)
|
2016-07-17 20:21:29 +00:00
|
|
|
out, err = d.Cmd("node", "ls", "--filter", "name=none")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(out, name), out)
|
2016-07-17 20:21:29 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmNodeTaskListFilter(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-07-17 20:21:29 +00:00
|
|
|
|
|
|
|
name := "redis-cluster-md5"
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "--replicas=3", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-07-17 20:21:29 +00:00
|
|
|
|
2016-07-26 18:40:15 +00:00
|
|
|
// make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(3)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-07-26 18:40:15 +00:00
|
|
|
|
2016-07-17 20:21:29 +00:00
|
|
|
filter := "name=redis-cluster"
|
|
|
|
|
2016-07-19 21:01:31 +00:00
|
|
|
out, err = d.Cmd("node", "ps", "--filter", filter, "self")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, name+".1"), out)
|
|
|
|
assert.Assert(c, strings.Contains(out, name+".2"), out)
|
|
|
|
assert.Assert(c, strings.Contains(out, name+".3"), out)
|
2016-07-19 21:01:31 +00:00
|
|
|
out, err = d.Cmd("node", "ps", "--filter", "name=none", "self")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(out, name+".1"), out)
|
|
|
|
assert.Assert(c, !strings.Contains(out, name+".2"), out)
|
|
|
|
assert.Assert(c, !strings.Contains(out, name+".3"), out)
|
2016-07-17 20:21:29 +00:00
|
|
|
}
|
2016-08-05 03:51:28 +00:00
|
|
|
|
|
|
|
// Test case for #25375
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmPublishAdd(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-08-05 03:51:28 +00:00
|
|
|
|
2016-12-25 21:23:35 +00:00
|
|
|
name := "top"
|
2019-07-18 17:58:21 +00:00
|
|
|
// this first command does not have to be retried because service creates
|
|
|
|
// don't return out of sequence errors.
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "--label", "x=y", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-08-05 03:51:28 +00:00
|
|
|
|
2019-07-18 17:58:21 +00:00
|
|
|
out, err = d.CmdRetryOutOfSequence("service", "update", "--detach", "--publish-add", "80:80", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-08-05 03:51:28 +00:00
|
|
|
|
2019-07-18 17:58:21 +00:00
|
|
|
out, err = d.CmdRetryOutOfSequence("service", "update", "--detach", "--publish-add", "80:80", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-08-05 03:51:28 +00:00
|
|
|
|
2019-07-18 17:58:21 +00:00
|
|
|
_, err = d.CmdRetryOutOfSequence("service", "update", "--detach", "--publish-add", "80:80", "--publish-add", "80:20", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2016-12-08 21:32:10 +00:00
|
|
|
|
2019-07-18 17:58:21 +00:00
|
|
|
// this last command does not have to be retried because service inspect
|
|
|
|
// does not return out of sequence errors.
|
2016-12-25 21:23:35 +00:00
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.EndpointSpec.Ports }}", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), "[{ tcp 80 80 ingress}]")
|
2016-08-05 03:51:28 +00:00
|
|
|
}
|
2016-08-02 01:34:51 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmServiceWithGroup(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-08-02 01:34:51 +00:00
|
|
|
|
|
|
|
name := "top"
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "--user", "root:root", "--group", "wheel", "--group", "audio", "--group", "staff", "--group", "777", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-08-02 01:34:51 +00:00
|
|
|
|
|
|
|
// make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-08-02 01:34:51 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("ps", "-q")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-08-02 01:34:51 +00:00
|
|
|
|
|
|
|
container := strings.TrimSpace(out)
|
|
|
|
|
2016-09-20 19:07:30 +00:00
|
|
|
out, err = d.Cmd("exec", container, "id")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
Update some tests for supplementary group permissions
Update tests checking for groups to adjust for new policy updated in
de7af816e76a7fd3fbf06bffa6832959289fba32, which caused those tests
to fail:
=== FAIL: amd64.integration-cli TestDockerSwarmSuite/TestSwarmServiceWithGroup (1.94s)
docker_cli_swarm_test.go:311: assertion failed: uid=0(root) gid=0(root) groups=0(root),10(wheel),29(audio),50(staff),777 (string) != uid=0(root) gid=0(root) groups=10(wheel),29(audio),50(staff),777
(string)
--- FAIL: TestDockerSwarmSuite/TestSwarmServiceWithGroup (1.94s)
=== FAIL: amd64.integration-cli TestDockerCLIRunSuite/TestRunGroupAdd (0.41s)
docker_cli_run_test.go:1091: expected output uid=0(root) gid=0(root) groups=10(wheel),29(audio),50(staff),777 received uid=0(root) gid=0(root) groups=0(root),10(wheel),29(audio),50(staff),777
--- FAIL: TestDockerCLIRunSuite/TestRunGroupAdd (0.41s)
=== FAIL: amd64.integration-cli TestDockerCLIRunSuite/TestRunUserByIDZero (0.41s)
docker_cli_run_test.go:790: expected daemon user got uid=0(root) gid=0(root) groups=0(root),10(wheel)
--- FAIL: TestDockerCLIRunSuite/TestRunUserByIDZero (0.41s)
=== FAIL: amd64.integration-cli TestDockerCLIRunSuite (195.70s)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-09-08 21:27:59 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "uid=0(root) gid=0(root) groups=0(root),10(wheel),29(audio),50(staff),777")
|
2016-08-02 01:34:51 +00:00
|
|
|
}
|
2016-09-09 16:55:57 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmContainerAutoStart(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-09-09 16:55:57 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("network", "create", "--attachable", "-d", "overlay", "foo")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-09-09 16:55:57 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("run", "-id", "--restart=always", "--net=foo", "--name=test", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-09-09 16:55:57 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("ps", "-q")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-09-09 16:55:57 +00:00
|
|
|
|
2018-10-25 18:47:56 +00:00
|
|
|
d.RestartNode(c)
|
2016-09-09 16:55:57 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("ps", "-q")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-09-09 16:55:57 +00:00
|
|
|
}
|
2016-09-15 02:16:08 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmContainerEndpointOptions(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-10-29 22:02:15 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("network", "create", "--attachable", "-d", "overlay", "foo")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-10-29 22:02:15 +00:00
|
|
|
|
2018-10-03 06:38:47 +00:00
|
|
|
out, err = d.Cmd("run", "-d", "--net=foo", "--name=first", "--net-alias=first-alias", "busybox:glibc", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-10-29 22:02:15 +00:00
|
|
|
|
2018-10-03 06:38:47 +00:00
|
|
|
out, err = d.Cmd("run", "-d", "--net=foo", "--name=second", "busybox:glibc", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-10-29 22:02:15 +00:00
|
|
|
|
2018-10-03 06:38:47 +00:00
|
|
|
out, err = d.Cmd("run", "-d", "--net=foo", "--net-alias=third-alias", "busybox:glibc", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-03-03 21:04:04 +00:00
|
|
|
|
|
|
|
// ping first container and its alias, also ping third and anonymous container by its alias
|
2018-10-03 06:38:47 +00:00
|
|
|
out, err = d.Cmd("exec", "second", "ping", "-c", "1", "first")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2018-10-03 06:38:47 +00:00
|
|
|
out, err = d.Cmd("exec", "second", "ping", "-c", "1", "first-alias")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2018-10-03 06:38:47 +00:00
|
|
|
out, err = d.Cmd("exec", "second", "ping", "-c", "1", "third-alias")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-10-29 22:02:15 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmContainerAttachByNetworkId(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-11-03 22:44:45 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("network", "create", "--attachable", "-d", "overlay", "testnet")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-11-03 22:44:45 +00:00
|
|
|
networkID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
out, err = d.Cmd("run", "-d", "--net", networkID, "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-03 22:44:45 +00:00
|
|
|
cID := strings.TrimSpace(out)
|
2016-12-09 09:17:53 +00:00
|
|
|
d.WaitRun(cID)
|
2016-11-03 22:44:45 +00:00
|
|
|
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err = d.Cmd("rm", "-f", cID)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-03 22:44:45 +00:00
|
|
|
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err = d.Cmd("network", "rm", "testnet")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-03 22:44:45 +00:00
|
|
|
|
2019-09-09 21:08:22 +00:00
|
|
|
checkNetwork := func(*testing.T) (interface{}, string) {
|
2016-11-03 22:44:45 +00:00
|
|
|
out, err := d.Cmd("network", "ls")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 21:09:27 +00:00
|
|
|
return out, ""
|
2016-11-03 22:44:45 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 23:36:18 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, checkNetwork, checker.Not(checker.Contains("testnet"))), poll.WithTimeout(3*time.Second))
|
2016-11-03 22:44:45 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestOverlayAttachable(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-11-22 19:33:00 +00:00
|
|
|
|
2016-11-29 22:05:12 +00:00
|
|
|
out, err := d.Cmd("network", "create", "-d", "overlay", "--attachable", "ovnet")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-22 19:33:00 +00:00
|
|
|
|
|
|
|
// validate attachable
|
2016-11-29 22:05:12 +00:00
|
|
|
out, err = d.Cmd("network", "inspect", "--format", "{{json .Attachable}}", "ovnet")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), "true")
|
2016-11-22 19:33:00 +00:00
|
|
|
|
2018-10-05 18:43:14 +00:00
|
|
|
// validate containers can attach to this overlay network
|
2016-11-29 22:05:12 +00:00
|
|
|
out, err = d.Cmd("run", "-d", "--network", "ovnet", "--name", "c1", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-22 19:33:00 +00:00
|
|
|
|
|
|
|
// redo validation, there was a bug that the value of attachable changes after
|
|
|
|
// containers attach to the network
|
2016-11-29 22:05:12 +00:00
|
|
|
out, err = d.Cmd("network", "inspect", "--format", "{{json .Attachable}}", "ovnet")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), "true")
|
2016-11-22 19:33:00 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestOverlayAttachableOnSwarmLeave(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-01-14 04:14:03 +00:00
|
|
|
|
|
|
|
// Create an attachable swarm network
|
|
|
|
nwName := "attovl"
|
|
|
|
out, err := d.Cmd("network", "create", "-d", "overlay", "--attachable", nwName)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-01-14 04:14:03 +00:00
|
|
|
|
|
|
|
// Connect a container to the network
|
|
|
|
out, err = d.Cmd("run", "-d", "--network", nwName, "--name", "c1", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-01-14 04:14:03 +00:00
|
|
|
|
|
|
|
// Leave the swarm
|
2023-07-14 18:02:38 +00:00
|
|
|
assert.Assert(c, d.SwarmLeave(ctx, c, true) == nil)
|
2017-01-14 04:14:03 +00:00
|
|
|
|
|
|
|
// Check the container is disconnected
|
|
|
|
out, err = d.Cmd("inspect", "c1", "--format", "{{.NetworkSettings.Networks."+nwName+"}}")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), "<no value>")
|
2017-01-14 04:14:03 +00:00
|
|
|
|
|
|
|
// Check the network is gone
|
|
|
|
out, err = d.Cmd("network", "ls", "--format", "{{.Name}}")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(out, nwName), out)
|
2017-01-14 04:14:03 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestOverlayAttachableReleaseResourcesOnFailure(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-02-16 03:53:51 +00:00
|
|
|
|
|
|
|
// Create attachable network
|
|
|
|
out, err := d.Cmd("network", "create", "-d", "overlay", "--attachable", "--subnet", "10.10.9.0/24", "ovnet")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-02-16 03:53:51 +00:00
|
|
|
|
|
|
|
// Attach a container with specific IP
|
|
|
|
out, err = d.Cmd("run", "-d", "--network", "ovnet", "--name", "c1", "--ip", "10.10.9.33", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-02-16 03:53:51 +00:00
|
|
|
|
2017-06-01 11:21:01 +00:00
|
|
|
// Attempt to attach another container with same IP, must fail
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err = d.Cmd("run", "-d", "--network", "ovnet", "--name", "c2", "--ip", "10.10.9.33", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "", out)
|
2017-02-16 03:53:51 +00:00
|
|
|
|
|
|
|
// Remove first container
|
|
|
|
out, err = d.Cmd("rm", "-f", "c1")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-02-16 03:53:51 +00:00
|
|
|
|
|
|
|
// Verify the network can be removed, no phantom network attachment task left over
|
|
|
|
out, err = d.Cmd("network", "rm", "ovnet")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-02-16 03:53:51 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmIngressNetwork(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-09-15 02:16:08 +00:00
|
|
|
|
2017-03-09 19:52:25 +00:00
|
|
|
// Ingress network can be removed
|
2017-08-22 21:07:52 +00:00
|
|
|
removeNetwork := func(name string) *icmd.Result {
|
|
|
|
return cli.Docker(
|
|
|
|
cli.Args("-H", d.Sock(), "network", "rm", name),
|
|
|
|
cli.WithStdin(strings.NewReader("Y")))
|
|
|
|
}
|
|
|
|
|
|
|
|
result := removeNetwork("ingress")
|
|
|
|
result.Assert(c, icmd.Success)
|
2017-03-09 19:52:25 +00:00
|
|
|
|
|
|
|
// And recreated
|
2017-08-22 21:07:52 +00:00
|
|
|
out, err := d.Cmd("network", "create", "-d", "overlay", "--ingress", "new-ingress")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-03-09 19:52:25 +00:00
|
|
|
|
|
|
|
// But only one is allowed
|
|
|
|
out, err = d.Cmd("network", "create", "-d", "overlay", "--ingress", "another-ingress")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "is already present"), out)
|
2017-03-09 19:52:25 +00:00
|
|
|
// It cannot be removed if it is being used
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "srv1", "-p", "9000:8000", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-08-22 21:07:52 +00:00
|
|
|
|
|
|
|
result = removeNetwork("new-ingress")
|
|
|
|
result.Assert(c, icmd.Expected{
|
|
|
|
ExitCode: 1,
|
|
|
|
Err: "ingress network cannot be removed because service",
|
|
|
|
})
|
2017-03-09 19:52:25 +00:00
|
|
|
|
|
|
|
// But it can be removed once no more services depend on it
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err = d.Cmd("service", "update", "--detach", "--publish-rm", "9000:8000", "srv1")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-08-22 21:07:52 +00:00
|
|
|
|
|
|
|
result = removeNetwork("new-ingress")
|
|
|
|
result.Assert(c, icmd.Success)
|
2017-03-09 19:52:25 +00:00
|
|
|
|
|
|
|
// A service which needs the ingress network cannot be created if no ingress is present
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "srv2", "-p", "500:500", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "no ingress network is present"), out)
|
2017-03-09 19:52:25 +00:00
|
|
|
// An existing service cannot be updated to use the ingress nw if the nw is not present
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err = d.Cmd("service", "update", "--detach", "--publish-add", "9000:8000", "srv1")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "no ingress network is present"), out)
|
2017-03-09 19:52:25 +00:00
|
|
|
// But services which do not need routing mesh can be created regardless
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "srv3", "--endpoint-mode", "dnsrr", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-09-15 02:16:08 +00:00
|
|
|
}
|
2016-07-23 16:58:58 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmCreateServiceWithNoIngressNetwork(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-03-30 23:12:48 +00:00
|
|
|
|
|
|
|
// Remove ingress network
|
2017-08-22 21:07:52 +00:00
|
|
|
result := cli.Docker(
|
|
|
|
cli.Args("-H", d.Sock(), "network", "rm", "ingress"),
|
|
|
|
cli.WithStdin(strings.NewReader("Y")))
|
|
|
|
result.Assert(c, icmd.Success)
|
2017-03-30 23:12:48 +00:00
|
|
|
|
|
|
|
// Create a overlay network and launch a service on it
|
|
|
|
// Make sure nothing panics because ingress network is missing
|
2017-08-22 21:07:52 +00:00
|
|
|
out, err := d.Cmd("network", "create", "-d", "overlay", "another-network")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "srv4", "--network", "another-network", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-03-30 23:12:48 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 16:58:58 +00:00
|
|
|
// Test case for #24108, also the case from:
|
|
|
|
// https://github.com/docker/docker/pull/24620#issuecomment-233715656
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmTaskListFilter(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-07-23 16:58:58 +00:00
|
|
|
|
|
|
|
name := "redis-cluster-md5"
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "--replicas=3", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-07-23 16:58:58 +00:00
|
|
|
|
|
|
|
filter := "name=redis-cluster"
|
|
|
|
|
2019-09-09 21:08:22 +00:00
|
|
|
checkNumTasks := func(*testing.T) (interface{}, string) {
|
2016-10-11 18:50:35 +00:00
|
|
|
out, err := d.Cmd("service", "ps", "--filter", filter, name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-09-09 21:09:27 +00:00
|
|
|
return len(strings.Split(out, "\n")) - 2, "" // includes header and nl in last line
|
2016-10-11 18:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// wait until all tasks have been created
|
2019-08-26 15:51:40 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, checkNumTasks, checker.Equals(3)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-10-11 18:50:35 +00:00
|
|
|
|
2016-07-23 16:58:58 +00:00
|
|
|
out, err = d.Cmd("service", "ps", "--filter", filter, name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, name+".1"), out)
|
|
|
|
assert.Assert(c, strings.Contains(out, name+".2"), out)
|
|
|
|
assert.Assert(c, strings.Contains(out, name+".3"), out)
|
2016-07-23 16:58:58 +00:00
|
|
|
out, err = d.Cmd("service", "ps", "--filter", "name="+name+".1", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, name+".1"), out)
|
|
|
|
assert.Assert(c, !strings.Contains(out, name+".2"), out)
|
|
|
|
assert.Assert(c, !strings.Contains(out, name+".3"), out)
|
2016-07-23 16:58:58 +00:00
|
|
|
out, err = d.Cmd("service", "ps", "--filter", "name=none", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(out, name+".1"), out)
|
|
|
|
assert.Assert(c, !strings.Contains(out, name+".2"), out)
|
|
|
|
assert.Assert(c, !strings.Contains(out, name+".3"), out)
|
2016-07-23 16:58:58 +00:00
|
|
|
name = "redis-cluster-sha1"
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "--mode=global", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-07-23 16:58:58 +00:00
|
|
|
|
2019-08-26 15:51:40 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, checkNumTasks, checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-10-11 18:50:35 +00:00
|
|
|
|
2016-07-23 16:58:58 +00:00
|
|
|
filter = "name=redis-cluster"
|
|
|
|
out, err = d.Cmd("service", "ps", "--filter", filter, name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, name), out)
|
2016-07-23 16:58:58 +00:00
|
|
|
out, err = d.Cmd("service", "ps", "--filter", "name="+name, name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, name), out)
|
2016-07-23 16:58:58 +00:00
|
|
|
out, err = d.Cmd("service", "ps", "--filter", "name=none", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(out, name), out)
|
2016-07-23 16:58:58 +00:00
|
|
|
}
|
2016-09-28 10:45:30 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestPsListContainersFilterIsTask(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-09-28 10:45:30 +00:00
|
|
|
|
|
|
|
// Create a bare container
|
|
|
|
out, err := d.Cmd("run", "-d", "--name=bare-container", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-09-28 10:45:30 +00:00
|
|
|
bareID := strings.TrimSpace(out)[:12]
|
|
|
|
// Create a service
|
|
|
|
name := "busybox-top"
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-09-28 10:45:30 +00:00
|
|
|
|
|
|
|
// make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckServiceRunningTasks(ctx, name), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-09-28 10:45:30 +00:00
|
|
|
|
|
|
|
// Filter non-tasks
|
|
|
|
out, err = d.Cmd("ps", "-a", "-q", "--filter=is-task=false")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-09-28 10:45:30 +00:00
|
|
|
psOut := strings.TrimSpace(out)
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Equal(c, psOut, bareID, fmt.Sprintf("Expected id %s, got %s for is-task label, output %q", bareID, psOut, out))
|
2016-09-28 10:45:30 +00:00
|
|
|
|
|
|
|
// Filter tasks
|
|
|
|
out, err = d.Cmd("ps", "-a", "-q", "--filter=is-task=true")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-09-28 10:45:30 +00:00
|
|
|
lines := strings.Split(strings.Trim(out, "\n "), "\n")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, len(lines), 1)
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, lines[0] != bareID, "Expected not %s, but got it for is-task label, output %q", bareID, out)
|
2016-09-28 10:45:30 +00:00
|
|
|
}
|
2016-10-15 17:20:34 +00:00
|
|
|
|
2022-01-20 12:43:42 +00:00
|
|
|
const (
|
|
|
|
globalNetworkPlugin = "global-network-plugin"
|
|
|
|
globalIPAMPlugin = "global-ipam-plugin"
|
|
|
|
)
|
2016-10-15 17:20:34 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func setupRemoteGlobalNetworkPlugin(c *testing.T, mux *http.ServeMux, url, netDrv, ipamDrv string) {
|
2016-10-15 17:20:34 +00:00
|
|
|
mux.HandleFunc("/Plugin.Activate", func(w http.ResponseWriter, r *http.Request) {
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
fmt.Fprintf(w, `{"Implements": ["%s", "%s"]}`, driverapi.NetworkPluginEndpointType, ipamapi.PluginEndpointType)
|
|
|
|
})
|
|
|
|
|
|
|
|
// Network driver implementation
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.GetCapabilities", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
fmt.Fprintf(w, `{"Scope":"global"}`)
|
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.AllocateNetwork", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := json.NewDecoder(r.Body).Decode(&remoteDriverNetworkRequest)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
fmt.Fprintf(w, "null")
|
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.FreeNetwork", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
fmt.Fprintf(w, "null")
|
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.CreateNetwork", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := json.NewDecoder(r.Body).Decode(&remoteDriverNetworkRequest)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
fmt.Fprintf(w, "null")
|
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.DeleteNetwork", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
fmt.Fprintf(w, "null")
|
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.CreateEndpoint", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
fmt.Fprintf(w, `{"Interface":{"MacAddress":"a0:b1:c2:d3:e4:f5"}}`)
|
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.Join", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
|
|
|
|
veth := &netlink.Veth{
|
2022-01-20 12:43:42 +00:00
|
|
|
LinkAttrs: netlink.LinkAttrs{Name: "randomIfName", TxQLen: 0}, PeerName: "cnt0",
|
|
|
|
}
|
2016-10-15 17:20:34 +00:00
|
|
|
if err := netlink.LinkAdd(veth); err != nil {
|
|
|
|
fmt.Fprintf(w, `{"Error":"failed to add veth pair: `+err.Error()+`"}`)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintf(w, `{"InterfaceName":{ "SrcName":"cnt0", "DstPrefix":"veth"}}`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.Leave", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
fmt.Fprintf(w, "null")
|
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.DeleteEndpoint", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
if link, err := netlink.LinkByName("cnt0"); err == nil {
|
|
|
|
netlink.LinkDel(link)
|
|
|
|
}
|
|
|
|
fmt.Fprintf(w, "null")
|
|
|
|
})
|
|
|
|
|
|
|
|
// IPAM Driver implementation
|
|
|
|
var (
|
|
|
|
poolRequest remoteipam.RequestPoolRequest
|
|
|
|
poolReleaseReq remoteipam.ReleasePoolRequest
|
|
|
|
addressRequest remoteipam.RequestAddressRequest
|
|
|
|
addressReleaseReq remoteipam.ReleaseAddressRequest
|
|
|
|
lAS = "localAS"
|
|
|
|
gAS = "globalAS"
|
|
|
|
pool = "172.28.0.0/16"
|
|
|
|
poolID = lAS + "/" + pool
|
|
|
|
gw = "172.28.255.254/16"
|
|
|
|
)
|
|
|
|
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.GetDefaultAddressSpaces", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
fmt.Fprintf(w, `{"LocalDefaultAddressSpace":"`+lAS+`", "GlobalDefaultAddressSpace": "`+gAS+`"}`)
|
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.RequestPool", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := json.NewDecoder(r.Body).Decode(&poolRequest)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
if poolRequest.AddressSpace != lAS && poolRequest.AddressSpace != gAS {
|
|
|
|
fmt.Fprintf(w, `{"Error":"Unknown address space in pool request: `+poolRequest.AddressSpace+`"}`)
|
|
|
|
} else if poolRequest.Pool != "" && poolRequest.Pool != pool {
|
|
|
|
fmt.Fprintf(w, `{"Error":"Cannot handle explicit pool requests yet"}`)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintf(w, `{"PoolID":"`+poolID+`", "Pool":"`+pool+`"}`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.RequestAddress", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := json.NewDecoder(r.Body).Decode(&addressRequest)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
// make sure libnetwork is now querying on the expected pool id
|
|
|
|
if addressRequest.PoolID != poolID {
|
|
|
|
fmt.Fprintf(w, `{"Error":"unknown pool id"}`)
|
|
|
|
} else if addressRequest.Address != "" {
|
|
|
|
fmt.Fprintf(w, `{"Error":"Cannot handle explicit address requests yet"}`)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintf(w, `{"Address":"`+gw+`"}`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.ReleaseAddress", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := json.NewDecoder(r.Body).Decode(&addressReleaseReq)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
// make sure libnetwork is now asking to release the expected address from the expected poolid
|
|
|
|
if addressRequest.PoolID != poolID {
|
|
|
|
fmt.Fprintf(w, `{"Error":"unknown pool id"}`)
|
|
|
|
} else if addressReleaseReq.Address != gw {
|
|
|
|
fmt.Fprintf(w, `{"Error":"unknown address"}`)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintf(w, "null")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc(fmt.Sprintf("/%s.ReleasePool", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := json.NewDecoder(r.Body).Decode(&poolReleaseReq)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
2023-07-19 08:20:49 +00:00
|
|
|
w.Header().Set("Content-Type", plugins.VersionMimetype)
|
2016-10-15 17:20:34 +00:00
|
|
|
// make sure libnetwork is now asking to release the expected poolid
|
|
|
|
if addressRequest.PoolID != poolID {
|
|
|
|
fmt.Fprintf(w, `{"Error":"unknown pool id"}`)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintf(w, "null")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-01-20 12:43:42 +00:00
|
|
|
err := os.MkdirAll("/etc/docker/plugins", 0o755)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-10-15 17:20:34 +00:00
|
|
|
|
|
|
|
fileName := fmt.Sprintf("/etc/docker/plugins/%s.spec", netDrv)
|
2022-01-20 12:43:42 +00:00
|
|
|
err = os.WriteFile(fileName, []byte(url), 0o644)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-10-15 17:20:34 +00:00
|
|
|
|
|
|
|
ipamFileName := fmt.Sprintf("/etc/docker/plugins/%s.spec", ipamDrv)
|
2022-01-20 12:43:42 +00:00
|
|
|
err = os.WriteFile(ipamFileName, []byte(url), 0o644)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-10-15 17:20:34 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmNetworkPlugin(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
2016-12-21 23:21:55 +00:00
|
|
|
mux := http.NewServeMux()
|
|
|
|
s.server = httptest.NewServer(mux)
|
2019-09-09 21:05:57 +00:00
|
|
|
assert.Assert(c, s.server != nil) // check that HTTP server has started
|
2016-12-21 23:21:55 +00:00
|
|
|
setupRemoteGlobalNetworkPlugin(c, mux, s.server.URL, globalNetworkPlugin, globalIPAMPlugin)
|
|
|
|
defer func() {
|
|
|
|
s.server.Close()
|
|
|
|
err := os.RemoveAll("/etc/docker/plugins")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-12-21 23:21:55 +00:00
|
|
|
}()
|
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-10-15 17:20:34 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("network", "create", "-d", globalNetworkPlugin, "foo")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "", out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "not supported in swarm mode"), out)
|
2016-10-15 17:20:34 +00:00
|
|
|
}
|
2016-07-20 06:58:32 +00:00
|
|
|
|
|
|
|
// Test case for #24712
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmServiceEnvFile(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-07-20 06:58:32 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
path := filepath.Join(d.Folder, "env.txt")
|
2022-01-20 12:43:42 +00:00
|
|
|
err := os.WriteFile(path, []byte("VAR1=A\nVAR2=A\n"), 0o644)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-07-20 06:58:32 +00:00
|
|
|
|
|
|
|
name := "worker"
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--env-file", path, "--env", "VAR1=B", "--env", "VAR1=C", "--env", "VAR2=", "--env", "VAR2", "--name", name, "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-07-20 06:58:32 +00:00
|
|
|
|
|
|
|
// The complete env is [VAR1=A VAR2=A VAR1=B VAR1=C VAR2= VAR2] and duplicates will be removed => [VAR1=C VAR2]
|
|
|
|
out, err = d.Cmd("inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.Env }}", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "[VAR1=C VAR2]"), out)
|
2016-07-20 06:58:32 +00:00
|
|
|
}
|
2016-11-04 18:31:44 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-11-04 18:31:44 +00:00
|
|
|
|
|
|
|
name := "top"
|
|
|
|
|
2019-09-09 17:44:11 +00:00
|
|
|
ttyCheck := "if [ -t 0 ]; then echo TTY > /status; else echo none > /status; fi; exec top"
|
2016-11-04 18:31:44 +00:00
|
|
|
|
|
|
|
// Without --tty
|
|
|
|
expectedOutput := "none"
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "busybox", "sh", "-c", ttyCheck)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-04 18:31:44 +00:00
|
|
|
|
|
|
|
// Make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-11-04 18:31:44 +00:00
|
|
|
|
|
|
|
// We need to get the container id.
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err = d.Cmd("ps", "-q", "--no-trunc")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-04 18:31:44 +00:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
out, err = d.Cmd("exec", id, "cat", "/status")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, expectedOutput), "Expected '%s', but got %q", expectedOutput, out)
|
2016-11-04 18:31:44 +00:00
|
|
|
// Remove service
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err = d.Cmd("service", "rm", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-04 18:31:44 +00:00
|
|
|
// Make sure container has been destroyed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-11-04 18:31:44 +00:00
|
|
|
|
|
|
|
// With --tty
|
|
|
|
expectedOutput = "TTY"
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "--tty", "busybox", "sh", "-c", ttyCheck)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-04 18:31:44 +00:00
|
|
|
|
|
|
|
// Make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-11-04 18:31:44 +00:00
|
|
|
|
|
|
|
// We need to get the container id.
|
2017-12-05 22:30:16 +00:00
|
|
|
out, err = d.Cmd("ps", "-q", "--no-trunc")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-04 18:31:44 +00:00
|
|
|
id = strings.TrimSpace(out)
|
|
|
|
|
|
|
|
out, err = d.Cmd("exec", id, "cat", "/status")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, expectedOutput), "Expected '%s', but got %q", expectedOutput, out)
|
2016-11-04 18:31:44 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmServiceTTYUpdate(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-11-04 18:31:44 +00:00
|
|
|
|
|
|
|
// Create a service
|
|
|
|
name := "top"
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-04 18:31:44 +00:00
|
|
|
|
|
|
|
// Make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-11-04 18:31:44 +00:00
|
|
|
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.TTY }}", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), "false")
|
2016-11-04 18:31:44 +00:00
|
|
|
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err = d.Cmd("service", "update", "--detach", "--tty", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-04 18:31:44 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.TTY }}", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), "true")
|
2016-11-04 18:31:44 +00:00
|
|
|
}
|
2016-10-20 00:07:44 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmServiceNetworkUpdate(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-03-24 00:51:57 +00:00
|
|
|
|
|
|
|
result := icmd.RunCmd(d.Command("network", "create", "-d", "overlay", "foo"))
|
|
|
|
result.Assert(c, icmd.Success)
|
2019-08-05 15:54:15 +00:00
|
|
|
fooNetwork := strings.TrimSpace(result.Combined())
|
2017-03-24 00:51:57 +00:00
|
|
|
|
|
|
|
result = icmd.RunCmd(d.Command("network", "create", "-d", "overlay", "bar"))
|
|
|
|
result.Assert(c, icmd.Success)
|
2019-08-05 15:54:15 +00:00
|
|
|
barNetwork := strings.TrimSpace(result.Combined())
|
2017-03-24 00:51:57 +00:00
|
|
|
|
|
|
|
result = icmd.RunCmd(d.Command("network", "create", "-d", "overlay", "baz"))
|
|
|
|
result.Assert(c, icmd.Success)
|
2019-08-05 15:54:15 +00:00
|
|
|
bazNetwork := strings.TrimSpace(result.Combined())
|
2017-03-24 00:51:57 +00:00
|
|
|
|
|
|
|
// Create a service
|
|
|
|
name := "top"
|
2017-09-27 23:17:55 +00:00
|
|
|
result = icmd.RunCmd(d.Command("service", "create", "--detach", "--no-resolve-image", "--network", "foo", "--network", "bar", "--name", name, "busybox", "top"))
|
2017-03-24 00:51:57 +00:00
|
|
|
result.Assert(c, icmd.Success)
|
|
|
|
|
|
|
|
// Make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskNetworks(ctx), checker.DeepEquals(map[string]int{fooNetwork: 1, barNetwork: 1})), poll.WithTimeout(defaultReconciliationTimeout))
|
2017-03-24 00:51:57 +00:00
|
|
|
|
|
|
|
// Remove a network
|
2017-09-27 23:17:55 +00:00
|
|
|
result = icmd.RunCmd(d.Command("service", "update", "--detach", "--network-rm", "foo", name))
|
2017-03-24 00:51:57 +00:00
|
|
|
result.Assert(c, icmd.Success)
|
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskNetworks(ctx), checker.DeepEquals(map[string]int{barNetwork: 1})), poll.WithTimeout(defaultReconciliationTimeout))
|
2017-03-24 00:51:57 +00:00
|
|
|
|
|
|
|
// Add a network
|
2017-09-27 23:17:55 +00:00
|
|
|
result = icmd.RunCmd(d.Command("service", "update", "--detach", "--network-add", "baz", name))
|
2017-03-24 00:51:57 +00:00
|
|
|
result.Assert(c, icmd.Success)
|
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskNetworks(ctx), checker.DeepEquals(map[string]int{barNetwork: 1, bazNetwork: 1})), poll.WithTimeout(defaultReconciliationTimeout))
|
2017-03-24 00:51:57 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestDNSConfig(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-10-20 00:07:44 +00:00
|
|
|
|
|
|
|
// Create a service
|
|
|
|
name := "top"
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "--dns=1.2.3.4", "--dns-search=example.com", "--dns-option=timeout:3", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-10-20 00:07:44 +00:00
|
|
|
|
|
|
|
// Make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-10-20 00:07:44 +00:00
|
|
|
|
|
|
|
// We need to get the container id.
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err = d.Cmd("ps", "-a", "-q", "--no-trunc")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-10-20 00:07:44 +00:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
// Compare against expected output.
|
|
|
|
expectedOutput1 := "nameserver 1.2.3.4"
|
|
|
|
expectedOutput2 := "search example.com"
|
|
|
|
expectedOutput3 := "options timeout:3"
|
|
|
|
out, err = d.Cmd("exec", id, "cat", "/etc/resolv.conf")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, expectedOutput1), "Expected '%s', but got %q", expectedOutput1, out)
|
|
|
|
assert.Assert(c, strings.Contains(out, expectedOutput2), "Expected '%s', but got %q", expectedOutput2, out)
|
|
|
|
assert.Assert(c, strings.Contains(out, expectedOutput3), "Expected '%s', but got %q", expectedOutput3, out)
|
2016-10-20 00:07:44 +00:00
|
|
|
}
|
2016-10-27 03:05:39 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestDNSConfigUpdate(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-10-27 03:05:39 +00:00
|
|
|
|
|
|
|
// Create a service
|
|
|
|
name := "top"
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-10-27 03:05:39 +00:00
|
|
|
|
|
|
|
// Make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-10-27 03:05:39 +00:00
|
|
|
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err = d.Cmd("service", "update", "--detach", "--dns-add=1.2.3.4", "--dns-search-add=example.com", "--dns-option-add=timeout:3", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-10-27 03:05:39 +00:00
|
|
|
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.DNSConfig }}", name)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), "{[1.2.3.4] [example.com] [timeout:3]}")
|
2016-10-27 03:05:39 +00:00
|
|
|
}
|
2016-10-24 21:44:51 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func getNodeStatus(c *testing.T, d *daemon.Daemon) swarm.LocalNodeState {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
info := d.SwarmInfo(ctx, c)
|
2016-11-18 00:51:33 +00:00
|
|
|
return info.LocalNodeState
|
|
|
|
}
|
|
|
|
|
2019-09-09 21:08:22 +00:00
|
|
|
func checkKeyIsEncrypted(d *daemon.Daemon) func(*testing.T) (interface{}, string) {
|
|
|
|
return func(c *testing.T) (interface{}, string) {
|
2021-08-24 10:10:50 +00:00
|
|
|
keyBytes, err := os.ReadFile(filepath.Join(d.Folder, "root", "swarm", "certificates", "swarm-node.key"))
|
2017-06-06 13:28:40 +00:00
|
|
|
if err != nil {
|
2019-09-09 21:09:27 +00:00
|
|
|
return fmt.Errorf("error reading key: %v", err), ""
|
2017-06-06 13:28:40 +00:00
|
|
|
}
|
2016-11-30 19:14:01 +00:00
|
|
|
|
2017-06-06 13:28:40 +00:00
|
|
|
keyBlock, _ := pem.Decode(keyBytes)
|
|
|
|
if keyBlock == nil {
|
2019-09-09 21:09:27 +00:00
|
|
|
return fmt.Errorf("invalid PEM-encoded private key"), ""
|
2017-06-06 13:28:40 +00:00
|
|
|
}
|
2016-11-30 19:14:01 +00:00
|
|
|
|
2019-09-09 21:09:27 +00:00
|
|
|
return keyutils.IsEncryptedPEMBlock(keyBlock), ""
|
2016-11-30 19:14:01 +00:00
|
|
|
}
|
2017-06-06 13:28:40 +00:00
|
|
|
}
|
2016-11-30 19:14:01 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
func checkSwarmLockedToUnlocked(ctx context.Context, c *testing.T, d *daemon.Daemon) {
|
2017-06-06 13:28:40 +00:00
|
|
|
// Wait for the PEM file to become unencrypted
|
2019-08-26 15:51:40 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, checkKeyIsEncrypted(d), checker.Equals(false)), poll.WithTimeout(defaultReconciliationTimeout))
|
2017-06-06 13:28:40 +00:00
|
|
|
|
2018-10-25 18:47:56 +00:00
|
|
|
d.RestartNode(c)
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckLocalNodeState(ctx), checker.Equals(swarm.LocalNodeStateActive)), poll.WithTimeout(time.Second))
|
2016-11-30 19:14:01 +00:00
|
|
|
}
|
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
func checkSwarmUnlockedToLocked(ctx context.Context, c *testing.T, d *daemon.Daemon) {
|
2017-06-06 13:28:40 +00:00
|
|
|
// Wait for the PEM file to become encrypted
|
2019-08-26 15:51:40 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, checkKeyIsEncrypted(d), checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout))
|
2017-06-06 13:28:40 +00:00
|
|
|
|
2018-10-25 18:47:56 +00:00
|
|
|
d.RestartNode(c)
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckLocalNodeState(ctx), checker.Equals(swarm.LocalNodeStateLocked)), poll.WithTimeout(time.Second))
|
2016-11-30 19:14:01 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestUnlockEngineAndUnlockedSwarm(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, false, false)
|
2016-12-07 05:48:01 +00:00
|
|
|
|
2016-12-16 02:36:37 +00:00
|
|
|
// unlocking a normal engine should return an error - it does not even ask for the key
|
2016-12-07 05:48:01 +00:00
|
|
|
cmd := d.Command("swarm", "unlock")
|
2017-01-16 15:39:12 +00:00
|
|
|
result := icmd.RunCmd(cmd)
|
|
|
|
result.Assert(c, icmd.Expected{
|
|
|
|
ExitCode: 1,
|
|
|
|
})
|
2019-10-07 19:24:06 +00:00
|
|
|
out := result.Combined()
|
|
|
|
assert.Assert(c, strings.Contains(result.Combined(), "Error: This node is not part of a swarm"), out)
|
|
|
|
assert.Assert(c, !strings.Contains(result.Combined(), "Please enter unlock key"), out)
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err := d.Cmd("swarm", "init")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-12-07 05:48:01 +00:00
|
|
|
|
2016-12-16 02:36:37 +00:00
|
|
|
// unlocking an unlocked swarm should return an error - it does not even ask for the key
|
2016-12-07 05:48:01 +00:00
|
|
|
cmd = d.Command("swarm", "unlock")
|
2017-01-16 15:39:12 +00:00
|
|
|
result = icmd.RunCmd(cmd)
|
|
|
|
result.Assert(c, icmd.Expected{
|
|
|
|
ExitCode: 1,
|
|
|
|
})
|
2019-10-07 19:24:06 +00:00
|
|
|
out = result.Combined()
|
|
|
|
assert.Assert(c, strings.Contains(result.Combined(), "Error: swarm is not locked"), out)
|
|
|
|
assert.Assert(c, !strings.Contains(result.Combined(), "Please enter unlock key"), out)
|
2016-12-07 05:48:01 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmInitLocked(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, false, false)
|
2016-10-24 21:44:51 +00:00
|
|
|
|
2016-10-31 22:02:34 +00:00
|
|
|
outs, err := d.Cmd("swarm", "init", "--autolock")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 10:36:00 +00:00
|
|
|
assert.Assert(c, err == nil, outs)
|
2018-10-29 20:46:21 +00:00
|
|
|
unlockKey := getUnlockKey(d, c, outs)
|
2016-10-24 21:44:51 +00:00
|
|
|
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateActive)
|
2016-10-24 21:44:51 +00:00
|
|
|
|
2016-11-30 19:14:01 +00:00
|
|
|
// It starts off locked
|
2018-10-25 18:47:56 +00:00
|
|
|
d.RestartNode(c)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateLocked)
|
2016-10-24 21:44:51 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
cmd := d.Command("swarm", "unlock")
|
2016-10-24 21:44:51 +00:00
|
|
|
cmd.Stdin = bytes.NewBufferString("wrong-secret-key")
|
2017-01-16 15:39:12 +00:00
|
|
|
icmd.RunCmd(cmd).Assert(c, icmd.Expected{
|
|
|
|
ExitCode: 1,
|
|
|
|
Err: "invalid key",
|
|
|
|
})
|
2016-10-24 21:44:51 +00:00
|
|
|
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateLocked)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
cmd = d.Command("swarm", "unlock")
|
2016-10-31 22:02:34 +00:00
|
|
|
cmd.Stdin = bytes.NewBufferString(unlockKey)
|
2017-01-16 15:39:12 +00:00
|
|
|
icmd.RunCmd(cmd).Assert(c, icmd.Success)
|
2016-10-24 21:44:51 +00:00
|
|
|
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateActive)
|
2016-10-31 22:02:34 +00:00
|
|
|
|
|
|
|
outs, err = d.Cmd("node", "ls")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 10:36:00 +00:00
|
|
|
assert.Assert(c, err == nil, outs)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(outs, "Swarm is encrypted and needs to be unlocked"), outs)
|
2016-10-31 22:02:34 +00:00
|
|
|
outs, err = d.Cmd("swarm", "update", "--autolock=false")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 10:36:00 +00:00
|
|
|
assert.Assert(c, err == nil, outs)
|
2016-10-31 22:02:34 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
checkSwarmLockedToUnlocked(ctx, c, d)
|
2016-10-31 22:02:34 +00:00
|
|
|
|
|
|
|
outs, err = d.Cmd("node", "ls")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 10:36:00 +00:00
|
|
|
assert.Assert(c, err == nil, outs)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(outs, "Swarm is encrypted and needs to be unlocked"), outs)
|
2016-10-24 21:44:51 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmLeaveLocked(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, false, false)
|
2016-10-24 21:44:51 +00:00
|
|
|
|
2016-10-31 22:02:34 +00:00
|
|
|
outs, err := d.Cmd("swarm", "init", "--autolock")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 10:36:00 +00:00
|
|
|
assert.Assert(c, err == nil, outs)
|
2016-10-24 21:44:51 +00:00
|
|
|
|
2016-11-30 19:14:01 +00:00
|
|
|
// It starts off locked
|
2018-10-25 18:47:56 +00:00
|
|
|
d.RestartNode(c)
|
2016-10-24 21:44:51 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
info := d.SwarmInfo(ctx, c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateLocked)
|
2016-10-24 21:44:51 +00:00
|
|
|
|
2016-10-31 22:02:34 +00:00
|
|
|
outs, _ = d.Cmd("node", "ls")
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(outs, "Swarm is encrypted and needs to be unlocked"), outs)
|
2016-12-02 09:14:32 +00:00
|
|
|
// `docker swarm leave` a locked swarm without --force will return an error
|
|
|
|
outs, _ = d.Cmd("swarm", "leave")
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(outs, "Swarm is encrypted and locked."), outs)
|
2016-12-02 09:14:32 +00:00
|
|
|
// It is OK for user to leave a locked swarm with --force
|
2016-10-31 22:02:34 +00:00
|
|
|
outs, err = d.Cmd("swarm", "leave", "--force")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 10:36:00 +00:00
|
|
|
assert.Assert(c, err == nil, outs)
|
2016-10-24 21:44:51 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
info = d.SwarmInfo(ctx, c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
|
2016-10-24 21:44:51 +00:00
|
|
|
|
|
|
|
outs, err = d.Cmd("swarm", "init")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 10:36:00 +00:00
|
|
|
assert.Assert(c, err == nil, outs)
|
2016-10-24 21:44:51 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
info = d.SwarmInfo(ctx, c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
2016-10-24 21:44:51 +00:00
|
|
|
}
|
2016-10-31 22:02:34 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmLockUnlockCluster(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d1 := s.AddDaemon(ctx, c, true, true)
|
|
|
|
d2 := s.AddDaemon(ctx, c, true, true)
|
|
|
|
d3 := s.AddDaemon(ctx, c, true, true)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// they start off unlocked
|
2018-10-25 18:47:56 +00:00
|
|
|
d2.RestartNode(c)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d2), swarm.LocalNodeStateActive)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// stop this one so it does not get autolock info
|
2016-12-09 22:20:14 +00:00
|
|
|
d2.Stop(c)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// enable autolock
|
|
|
|
outs, err := d1.Cmd("swarm", "update", "--autolock")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 10:36:00 +00:00
|
|
|
assert.Assert(c, err == nil, outs)
|
2018-10-29 20:46:21 +00:00
|
|
|
unlockKey := getUnlockKey(d1, c, outs)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// The ones that got the cluster update should be set to locked
|
2018-04-11 10:10:17 +00:00
|
|
|
for _, d := range []*daemon.Daemon{d1, d3} {
|
2023-07-14 18:02:38 +00:00
|
|
|
checkSwarmUnlockedToLocked(ctx, c, d)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
cmd := d.Command("swarm", "unlock")
|
2016-11-18 00:51:33 +00:00
|
|
|
cmd.Stdin = bytes.NewBufferString(unlockKey)
|
2017-01-16 15:39:12 +00:00
|
|
|
icmd.RunCmd(cmd).Assert(c, icmd.Success)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateActive)
|
2016-11-18 00:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// d2 never got the cluster update, so it is still set to unlocked
|
2018-10-25 18:47:56 +00:00
|
|
|
d2.StartNode(c)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d2), swarm.LocalNodeStateActive)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// d2 is now set to lock
|
2023-07-14 18:02:38 +00:00
|
|
|
checkSwarmUnlockedToLocked(ctx, c, d2)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// leave it locked, and set the cluster to no longer autolock
|
|
|
|
outs, err = d1.Cmd("swarm", "update", "--autolock=false")
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, err == nil, "out: %v", outs)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// the ones that got the update are now set to unlocked
|
2018-04-11 10:10:17 +00:00
|
|
|
for _, d := range []*daemon.Daemon{d1, d3} {
|
2023-07-14 18:02:38 +00:00
|
|
|
checkSwarmLockedToUnlocked(ctx, c, d)
|
2016-11-18 00:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// d2 still locked
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d2), swarm.LocalNodeStateLocked)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// unlock it
|
2016-12-09 09:17:53 +00:00
|
|
|
cmd := d2.Command("swarm", "unlock")
|
2016-11-18 00:51:33 +00:00
|
|
|
cmd.Stdin = bytes.NewBufferString(unlockKey)
|
2017-01-16 15:39:12 +00:00
|
|
|
icmd.RunCmd(cmd).Assert(c, icmd.Success)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d2), swarm.LocalNodeStateActive)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// once it's caught up, d2 is set to not be locked
|
2023-07-14 18:02:38 +00:00
|
|
|
checkSwarmLockedToUnlocked(ctx, c, d2)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2016-11-30 19:14:01 +00:00
|
|
|
// managers who join now are never set to locked in the first place
|
2023-07-14 18:02:38 +00:00
|
|
|
d4 := s.AddDaemon(ctx, c, true, true)
|
2018-10-25 18:47:56 +00:00
|
|
|
d4.RestartNode(c)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d4), swarm.LocalNodeStateActive)
|
2016-11-18 00:51:33 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d1 := s.AddDaemon(ctx, c, true, true)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// enable autolock
|
|
|
|
outs, err := d1.Cmd("swarm", "update", "--autolock")
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, err == nil, "out: %v", outs)
|
2018-10-29 20:46:21 +00:00
|
|
|
unlockKey := getUnlockKey(d1, c, outs)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// joined workers start off unlocked
|
2023-07-14 18:02:38 +00:00
|
|
|
d2 := s.AddDaemon(ctx, c, true, false)
|
2018-10-25 18:47:56 +00:00
|
|
|
d2.RestartNode(c)
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d2.CheckLocalNodeState(ctx), checker.Equals(swarm.LocalNodeStateActive)), poll.WithTimeout(time.Second))
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// promote worker
|
2018-04-11 10:10:17 +00:00
|
|
|
outs, err = d1.Cmd("node", "promote", d2.NodeID())
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(outs, "promoted to a manager in the swarm"), outs)
|
2016-11-18 00:51:33 +00:00
|
|
|
// join new manager node
|
2023-07-14 18:02:38 +00:00
|
|
|
d3 := s.AddDaemon(ctx, c, true, true)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// both new nodes are locked
|
2018-04-11 10:10:17 +00:00
|
|
|
for _, d := range []*daemon.Daemon{d2, d3} {
|
2023-07-14 18:02:38 +00:00
|
|
|
checkSwarmUnlockedToLocked(ctx, c, d)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
cmd := d.Command("swarm", "unlock")
|
2016-11-18 00:51:33 +00:00
|
|
|
cmd.Stdin = bytes.NewBufferString(unlockKey)
|
2017-01-16 15:39:12 +00:00
|
|
|
icmd.RunCmd(cmd).Assert(c, icmd.Success)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateActive)
|
2016-11-18 00:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// demote manager back to worker - workers are not locked
|
2018-04-11 10:10:17 +00:00
|
|
|
outs, err = d1.Cmd("node", "demote", d3.NodeID())
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(outs, "demoted in the swarm"), outs)
|
2016-12-03 00:28:27 +00:00
|
|
|
// Wait for it to actually be demoted, for the key and cert to be replaced.
|
|
|
|
// Then restart and assert that the node is not locked. If we don't wait for the cert
|
|
|
|
// to be replaced, then the node still has the manager TLS key which is still locked
|
|
|
|
// (because we never want a manager TLS key to be on disk unencrypted if the cluster
|
|
|
|
// is set to autolock)
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d3.CheckControlAvailable(ctx), checker.False()), poll.WithTimeout(defaultReconciliationTimeout))
|
2019-08-26 15:51:40 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {
|
2021-08-24 10:10:50 +00:00
|
|
|
certBytes, err := os.ReadFile(filepath.Join(d3.Folder, "root", "swarm", "certificates", "swarm-node.crt"))
|
2016-12-03 00:28:27 +00:00
|
|
|
if err != nil {
|
2019-09-09 21:08:22 +00:00
|
|
|
return "", fmt.Sprintf("error: %v", err)
|
2016-12-03 00:28:27 +00:00
|
|
|
}
|
2017-04-16 19:40:11 +00:00
|
|
|
certs, err := helpers.ParseCertificatesPEM(certBytes)
|
|
|
|
if err == nil && len(certs) > 0 && len(certs[0].Subject.OrganizationalUnit) > 0 {
|
2019-09-09 21:09:27 +00:00
|
|
|
return certs[0].Subject.OrganizationalUnit[0], ""
|
2017-04-16 19:40:11 +00:00
|
|
|
}
|
2019-09-09 21:08:22 +00:00
|
|
|
return "", "could not get organizational unit from certificate"
|
2019-08-26 15:51:40 +00:00
|
|
|
}, checker.Equals("swarm-worker")), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2016-12-03 00:28:27 +00:00
|
|
|
// by now, it should *never* be locked on restart
|
2018-10-25 18:47:56 +00:00
|
|
|
d3.RestartNode(c)
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d3.CheckLocalNodeState(ctx), checker.Equals(swarm.LocalNodeStateActive)), poll.WithTimeout(time.Second))
|
2016-11-18 00:51:33 +00:00
|
|
|
}
|
|
|
|
|
2024-01-02 20:29:32 +00:00
|
|
|
const swarmIsEncryptedMsg = "Swarm is encrypted and needs to be unlocked"
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-10-31 22:02:34 +00:00
|
|
|
|
|
|
|
outs, err := d.Cmd("swarm", "update", "--autolock")
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, err == nil, "out: %v", outs)
|
2018-10-29 20:46:21 +00:00
|
|
|
unlockKey := getUnlockKey(d, c, outs)
|
2016-10-31 22:02:34 +00:00
|
|
|
|
|
|
|
// Rotate multiple times
|
|
|
|
for i := 0; i != 3; i++ {
|
|
|
|
outs, err = d.Cmd("swarm", "unlock-key", "-q", "--rotate")
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, err == nil, "out: %v", outs)
|
2016-10-31 22:02:34 +00:00
|
|
|
// Strip \n
|
|
|
|
newUnlockKey := outs[:len(outs)-1]
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Assert(c, newUnlockKey != "")
|
|
|
|
assert.Assert(c, newUnlockKey != unlockKey)
|
2016-10-31 22:02:34 +00:00
|
|
|
|
2018-10-25 18:47:56 +00:00
|
|
|
d.RestartNode(c)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateLocked)
|
2016-10-31 22:02:34 +00:00
|
|
|
|
2024-01-02 20:29:32 +00:00
|
|
|
unlock := func(d *daemon.Daemon, key string) *icmd.Result {
|
|
|
|
cmd := d.Command("swarm", "unlock")
|
|
|
|
cmd.Stdin = strings.NewReader(key)
|
|
|
|
return icmd.RunCmd(cmd)
|
|
|
|
}
|
|
|
|
|
2016-10-31 22:02:34 +00:00
|
|
|
outs, _ = d.Cmd("node", "ls")
|
2024-01-02 20:29:32 +00:00
|
|
|
assert.Assert(c, strings.Contains(outs, swarmIsEncryptedMsg), outs)
|
2016-10-31 22:02:34 +00:00
|
|
|
|
2024-01-02 20:29:32 +00:00
|
|
|
result := unlock(d, unlockKey)
|
2017-01-16 15:39:12 +00:00
|
|
|
if result.Error == nil {
|
2016-10-31 22:02:34 +00:00
|
|
|
// On occasion, the daemon may not have finished
|
|
|
|
// rotating the KEK before restarting. The test is
|
|
|
|
// intentionally written to explore this behavior.
|
|
|
|
// When this happens, unlocking with the old key will
|
|
|
|
// succeed. If we wait for the rotation to happen and
|
|
|
|
// restart again, the new key should be required this
|
|
|
|
// time.
|
|
|
|
|
2024-01-02 20:29:32 +00:00
|
|
|
// Wait for the rotation to happen
|
|
|
|
// Since there are multiple rotations, we need to wait until for the number of rotations we are currently on to be reflected in the logs
|
|
|
|
// This is a little janky... its depending on specific log messages AND these are debug logs... but it is the best we can do for now.
|
|
|
|
matcher := testdaemon.ScanLogsMatchCount(testdaemon.ScanLogsMatchString("successfully rotated KEK"), i+1)
|
|
|
|
poll.WaitOn(c, d.PollCheckLogs(ctx, matcher), poll.WithDelay(3*time.Second), poll.WithTimeout(time.Minute))
|
|
|
|
d.Restart(c)
|
2016-10-31 22:02:34 +00:00
|
|
|
|
2018-10-25 18:47:56 +00:00
|
|
|
d.RestartNode(c)
|
2016-10-31 22:02:34 +00:00
|
|
|
|
2024-01-02 20:29:32 +00:00
|
|
|
result = unlock(d, unlockKey)
|
2016-10-31 22:02:34 +00:00
|
|
|
}
|
2017-01-16 15:39:12 +00:00
|
|
|
result.Assert(c, icmd.Expected{
|
|
|
|
ExitCode: 1,
|
|
|
|
Err: "invalid key",
|
|
|
|
})
|
2016-10-31 22:02:34 +00:00
|
|
|
|
|
|
|
outs, _ = d.Cmd("node", "ls")
|
2024-01-02 20:29:32 +00:00
|
|
|
assert.Assert(c, strings.Contains(outs, swarmIsEncryptedMsg), outs)
|
|
|
|
unlock(d, newUnlockKey).Assert(c, icmd.Success)
|
2016-10-31 22:02:34 +00:00
|
|
|
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateActive)
|
2016-10-31 22:02:34 +00:00
|
|
|
|
2024-01-02 20:29:32 +00:00
|
|
|
checkNodeLs := func(t poll.LogT) poll.Result {
|
2019-07-16 21:07:26 +00:00
|
|
|
// an issue sometimes prevents leader to be available right away
|
2024-01-02 20:29:32 +00:00
|
|
|
out, err := d.Cmd("node", "ls")
|
|
|
|
if err != nil {
|
|
|
|
return poll.Continue("error running node ls: %v: %s", err, out)
|
2019-07-16 21:07:26 +00:00
|
|
|
}
|
2024-01-02 20:29:32 +00:00
|
|
|
return poll.Success()
|
2019-07-16 21:07:26 +00:00
|
|
|
}
|
2024-01-02 20:29:32 +00:00
|
|
|
poll.WaitOn(c, checkNodeLs, poll.WithDelay(3*time.Second), poll.WithTimeout(time.Minute))
|
2016-11-10 18:39:14 +00:00
|
|
|
|
|
|
|
unlockKey = newUnlockKey
|
2016-10-31 22:02:34 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-03 15:05:00 +00:00
|
|
|
|
2016-11-18 00:51:33 +00:00
|
|
|
// This differs from `TestSwarmRotateUnlockKey` because that one rotates a single node, which is the leader.
|
|
|
|
// This one keeps the leader up, and asserts that other manager nodes in the cluster also have their unlock
|
|
|
|
// key rotated.
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmClusterRotateUnlockKey(c *testing.T) {
|
2018-12-23 11:39:58 +00:00
|
|
|
if runtime.GOARCH == "s390x" {
|
|
|
|
c.Skip("Disabled on s390x")
|
|
|
|
}
|
|
|
|
if runtime.GOARCH == "ppc64le" {
|
|
|
|
c.Skip("Disabled on ppc64le")
|
|
|
|
}
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
2018-12-23 11:39:58 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
d1 := s.AddDaemon(ctx, c, true, true) // leader - don't restart this one, we don't want leader election delays
|
|
|
|
d2 := s.AddDaemon(ctx, c, true, true)
|
|
|
|
d3 := s.AddDaemon(ctx, c, true, true)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
outs, err := d1.Cmd("swarm", "update", "--autolock")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 10:36:00 +00:00
|
|
|
assert.Assert(c, err == nil, outs)
|
2018-10-29 20:46:21 +00:00
|
|
|
unlockKey := getUnlockKey(d1, c, outs)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
// Rotate multiple times
|
|
|
|
for i := 0; i != 3; i++ {
|
|
|
|
outs, err = d1.Cmd("swarm", "unlock-key", "-q", "--rotate")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 10:36:00 +00:00
|
|
|
assert.Assert(c, err == nil, outs)
|
2016-11-18 00:51:33 +00:00
|
|
|
// Strip \n
|
|
|
|
newUnlockKey := outs[:len(outs)-1]
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Assert(c, newUnlockKey != "")
|
|
|
|
assert.Assert(c, newUnlockKey != unlockKey)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2018-10-25 18:47:56 +00:00
|
|
|
d2.RestartNode(c)
|
|
|
|
d3.RestartNode(c)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2024-01-02 20:29:32 +00:00
|
|
|
unlock := func(d *daemon.Daemon, key string) *icmd.Result {
|
|
|
|
cmd := d.Command("swarm", "unlock")
|
|
|
|
cmd.Stdin = strings.NewReader(key)
|
|
|
|
return icmd.RunCmd(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
const swarmIsEncryptedMsg = "Swarm is encrypted and needs to be unlocked"
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
for _, d := range []*daemon.Daemon{d2, d3} {
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateLocked)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
outs, _ := d.Cmd("node", "ls")
|
2024-01-02 20:29:32 +00:00
|
|
|
assert.Assert(c, strings.Contains(outs, swarmIsEncryptedMsg), outs)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2024-01-02 20:29:32 +00:00
|
|
|
// unlock with the original key should fail
|
|
|
|
// Use poll here because the daemon may not have finished
|
|
|
|
result := unlock(d, unlockKey)
|
2017-01-16 15:39:12 +00:00
|
|
|
if result.Error == nil {
|
2016-11-18 00:51:33 +00:00
|
|
|
// On occasion, the daemon may not have finished
|
|
|
|
// rotating the KEK before restarting. The test is
|
|
|
|
// intentionally written to explore this behavior.
|
|
|
|
// When this happens, unlocking with the old key will
|
|
|
|
// succeed. If we wait for the rotation to happen and
|
|
|
|
// restart again, the new key should be required this
|
|
|
|
// time.
|
|
|
|
|
2024-01-02 20:29:32 +00:00
|
|
|
// Wait for the rotation to happen
|
|
|
|
// Since there are multiple rotations, we need to wait until for the number of rotations we are currently on to be reflected in the logs
|
|
|
|
// This is a little janky... its depending on specific log messages AND these are debug logs... but it is the best we can do for now.
|
|
|
|
matcher := testdaemon.ScanLogsMatchCount(testdaemon.ScanLogsMatchString("successfully rotated KEK"), i+1)
|
|
|
|
poll.WaitOn(c, d.PollCheckLogs(ctx, matcher), poll.WithDelay(3*time.Second), poll.WithTimeout(time.Minute))
|
|
|
|
d.Restart(c)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2024-01-02 20:29:32 +00:00
|
|
|
result = unlock(d, unlockKey)
|
2016-11-18 00:51:33 +00:00
|
|
|
}
|
2017-01-16 15:39:12 +00:00
|
|
|
result.Assert(c, icmd.Expected{
|
|
|
|
ExitCode: 1,
|
|
|
|
Err: "invalid key",
|
|
|
|
})
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
outs, _ = d.Cmd("node", "ls")
|
2024-01-02 20:29:32 +00:00
|
|
|
assert.Assert(c, strings.Contains(outs, swarmIsEncryptedMsg), outs)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2024-01-02 20:29:32 +00:00
|
|
|
// now unlock with the rotated key, this should succeed
|
|
|
|
unlock(d, newUnlockKey).Assert(c, icmd.Success)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateActive)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2024-01-02 20:29:32 +00:00
|
|
|
checkNodeLs := func(t poll.LogT) poll.Result {
|
2019-07-16 21:07:26 +00:00
|
|
|
// an issue sometimes prevents leader to be available right away
|
2024-01-02 20:29:32 +00:00
|
|
|
out, err := d.Cmd("node", "ls")
|
|
|
|
if err != nil {
|
|
|
|
return poll.Continue("error running node ls: %v: %s", err, out)
|
2019-07-16 21:07:26 +00:00
|
|
|
}
|
2024-01-02 20:29:32 +00:00
|
|
|
return poll.Success()
|
2019-07-16 21:07:26 +00:00
|
|
|
}
|
2024-01-02 20:29:32 +00:00
|
|
|
poll.WaitOn(c, checkNodeLs, poll.WithDelay(3*time.Second), poll.WithTimeout(time.Minute))
|
2016-11-18 00:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unlockKey = newUnlockKey
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmAlternateLockUnlock(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
// set to lock
|
|
|
|
outs, err := d.Cmd("swarm", "update", "--autolock")
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, err == nil, "out: %v", outs)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(outs, "docker swarm unlock"), outs)
|
2018-10-29 20:46:21 +00:00
|
|
|
unlockKey := getUnlockKey(d, c, outs)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
checkSwarmUnlockedToLocked(ctx, c, d)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
cmd := d.Command("swarm", "unlock")
|
2016-11-18 00:51:33 +00:00
|
|
|
cmd.Stdin = bytes.NewBufferString(unlockKey)
|
2017-01-16 15:39:12 +00:00
|
|
|
icmd.RunCmd(cmd).Assert(c, icmd.Success)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateActive)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
|
|
|
outs, err = d.Cmd("swarm", "update", "--autolock=false")
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, err == nil, "out: %v", outs)
|
2016-11-18 00:51:33 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
checkSwarmLockedToUnlocked(ctx, c, d)
|
2016-11-18 00:51:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestExtraHosts(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-11-03 15:05:00 +00:00
|
|
|
|
|
|
|
// Create a service
|
|
|
|
name := "top"
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "--host=example.com:1.2.3.4", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-03 15:05:00 +00:00
|
|
|
|
|
|
|
// Make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-11-03 15:05:00 +00:00
|
|
|
|
|
|
|
// We need to get the container id.
|
2018-08-14 07:51:22 +00:00
|
|
|
out, err = d.Cmd("ps", "-a", "-q", "--no-trunc")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-03 15:05:00 +00:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
// Compare against expected output.
|
|
|
|
expectedOutput := "1.2.3.4\texample.com"
|
|
|
|
out, err = d.Cmd("exec", id, "cat", "/etc/hosts")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, expectedOutput), "Expected '%s', but got %q", expectedOutput, out)
|
2016-11-03 15:05:00 +00:00
|
|
|
}
|
2016-11-03 18:23:58 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmManagerAddress(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d1 := s.AddDaemon(ctx, c, true, true)
|
|
|
|
d2 := s.AddDaemon(ctx, c, true, false)
|
|
|
|
d3 := s.AddDaemon(ctx, c, true, false)
|
2016-11-03 18:23:58 +00:00
|
|
|
|
|
|
|
// Manager Addresses will always show Node 1's address
|
2020-05-11 12:07:04 +00:00
|
|
|
expectedOutput := fmt.Sprintf("127.0.0.1:%d", d1.SwarmPort)
|
2016-11-03 18:23:58 +00:00
|
|
|
|
2020-05-11 12:07:04 +00:00
|
|
|
out, err := d1.Cmd("info", "--format", "{{ (index .Swarm.RemoteManagers 0).Addr }}")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, expectedOutput), out)
|
2016-11-03 18:23:58 +00:00
|
|
|
|
2020-05-11 12:07:04 +00:00
|
|
|
out, err = d2.Cmd("info", "--format", "{{ (index .Swarm.RemoteManagers 0).Addr }}")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, expectedOutput), out)
|
2016-11-03 18:23:58 +00:00
|
|
|
|
2020-05-11 12:07:04 +00:00
|
|
|
out, err = d3.Cmd("info", "--format", "{{ (index .Swarm.RemoteManagers 0).Addr }}")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, expectedOutput), out)
|
2016-11-03 18:23:58 +00:00
|
|
|
}
|
2016-11-17 00:46:31 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmNetworkIPAMOptions(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-12-02 16:11:30 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("network", "create", "-d", "overlay", "--ipam-opt", "foo=bar", "foo")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-12-02 16:11:30 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("network", "inspect", "--format", "{{.IPAM.Options}}", "foo")
|
2019-10-07 19:24:06 +00:00
|
|
|
out = strings.TrimSpace(out)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "foo:bar"), out)
|
|
|
|
assert.Assert(c, strings.Contains(out, "com.docker.network.ipam.serial:true"), out)
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--network=foo", "--name", "top", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-12-02 16:11:30 +00:00
|
|
|
|
|
|
|
// make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-12-02 16:11:30 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("network", "inspect", "--format", "{{.IPAM.Options}}", "foo")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "foo:bar"), out)
|
|
|
|
assert.Assert(c, strings.Contains(out, "com.docker.network.ipam.serial:true"), out)
|
2016-12-02 16:11:30 +00:00
|
|
|
}
|
2016-11-30 21:23:18 +00:00
|
|
|
|
2016-11-01 05:49:39 +00:00
|
|
|
// Test case for issue #27866, which did not allow NW name that is the prefix of a swarm NW ID.
|
|
|
|
// e.g. if the ingress ID starts with "n1", it was impossible to create a NW named "n1".
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmNetworkCreateIssue27866(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-11-01 05:49:39 +00:00
|
|
|
out, err := d.Cmd("network", "inspect", "-f", "{{.Id}}", "ingress")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, "out: %v", out)
|
2016-11-01 05:49:39 +00:00
|
|
|
ingressID := strings.TrimSpace(out)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Assert(c, ingressID != "")
|
2016-11-01 05:49:39 +00:00
|
|
|
|
|
|
|
// create a network of which name is the prefix of the ID of an overlay network
|
|
|
|
// (ingressID in this case)
|
|
|
|
newNetName := ingressID[0:2]
|
|
|
|
out, err = d.Cmd("network", "create", "--driver", "overlay", newNetName)
|
|
|
|
// In #27866, it was failing because of "network with name %s already exists"
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, "out: %v", out)
|
2016-11-01 05:49:39 +00:00
|
|
|
out, err = d.Cmd("network", "rm", newNetName)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, "out: %v", out)
|
2016-11-01 05:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test case for https://github.com/docker/docker/pull/27938#issuecomment-265768303
|
|
|
|
// This test creates two networks with the same name sequentially, with various drivers.
|
|
|
|
// Since the operations in this test are done sequentially, the 2nd call should fail with
|
|
|
|
// "network with name FOO already exists".
|
|
|
|
// Note that it is to ok have multiple networks with the same name if the operations are done
|
|
|
|
// in parallel. (#18864)
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmNetworkCreateDup(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-11-01 05:49:39 +00:00
|
|
|
drivers := []string{"bridge", "overlay"}
|
|
|
|
for i, driver1 := range drivers {
|
|
|
|
for _, driver2 := range drivers {
|
integration-cli: use subtests for TestSwarmNetworkCreateDup
This makes the test less noisy, and won't print the `failed: Error ...` messages,
which were confusing.
Also, running as a subtest allows tracking failures individually through the
junit.xml files.
Before:
=== RUN TestDockerSwarmSuite/TestSwarmNetworkCreateDup
--- PASS: TestDockerSwarmSuite/TestSwarmNetworkCreateDup (3.00s)
daemon.go:26: Creating a new daemon at: "/go/src/github.com/docker/docker/bundles/test-integration/TestDockerSwarmSuite/TestSwarmNetworkCreateDup"
docker_cli_swarm_test.go:1527: Creating a network named "network-test-0" with "bridge", then "bridge"
docker_cli_swarm_test.go:1534: As expected, the attempt to network "network-test-0" with "bridge" failed: Error response from daemon: network with name network-test-0 already exists
docker_cli_swarm_test.go:1527: Creating a network named "network-test-0" with "bridge", then "overlay"
docker_cli_swarm_test.go:1534: As expected, the attempt to network "network-test-0" with "overlay" failed: Error response from daemon: network with name network-test-0 already exists
docker_cli_swarm_test.go:1527: Creating a network named "network-test-1" with "overlay", then "bridge"
docker_cli_swarm_test.go:1534: As expected, the attempt to network "network-test-1" with "bridge" failed: Error response from daemon: network with name network-test-1 already exists
docker_cli_swarm_test.go:1527: Creating a network named "network-test-1" with "overlay", then "overlay"
docker_cli_swarm_test.go:1534: As expected, the attempt to network "network-test-1" with "overlay" failed: Error response from daemon: network with name network-test-1 already exists
After:
=== RUN TestDockerSwarmSuite
=== RUN TestDockerSwarmSuite/TestSwarmNetworkCreateDup
=== RUN TestDockerSwarmSuite/TestSwarmNetworkCreateDup/driver_bridge_then_bridge
=== RUN TestDockerSwarmSuite/TestSwarmNetworkCreateDup/driver_bridge_then_overlay
=== RUN TestDockerSwarmSuite/TestSwarmNetworkCreateDup/driver_overlay_then_bridge
=== RUN TestDockerSwarmSuite/TestSwarmNetworkCreateDup/driver_overlay_then_overlay
--- PASS: TestDockerSwarmSuite (8.12s)
--- PASS: TestDockerSwarmSuite/TestSwarmNetworkCreateDup (8.12s)
daemon.go:26: Creating a new daemon at: "/go/src/github.com/docker/docker/bundles/test-integration/TestDockerSwarmSuite/TestSwarmNetworkCreateDup"
--- PASS: TestDockerSwarmSuite/TestSwarmNetworkCreateDup/driver_bridge_then_bridge (0.52s)
--- PASS: TestDockerSwarmSuite/TestSwarmNetworkCreateDup/driver_bridge_then_overlay (0.31s)
--- PASS: TestDockerSwarmSuite/TestSwarmNetworkCreateDup/driver_overlay_then_bridge (0.17s)
--- PASS: TestDockerSwarmSuite/TestSwarmNetworkCreateDup/driver_overlay_then_overlay (0.12s)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-10-21 12:06:35 +00:00
|
|
|
c.Run(fmt.Sprintf("driver %s then %s", driver1, driver2), func(c *testing.T) {
|
|
|
|
nwName := fmt.Sprintf("network-test-%d", i)
|
|
|
|
out, err := d.Cmd("network", "create", "--driver", driver1, nwName)
|
|
|
|
assert.NilError(c, err, "out: %v", out)
|
|
|
|
out, err = d.Cmd("network", "create", "--driver", driver2, nwName)
|
|
|
|
assert.Assert(c, strings.Contains(out, fmt.Sprintf("network with name %s already exists", nwName)), out)
|
|
|
|
assert.ErrorContains(c, err, "")
|
|
|
|
out, err = d.Cmd("network", "rm", nwName)
|
|
|
|
assert.NilError(c, err, "out: %v", out)
|
|
|
|
})
|
2016-11-01 05:49:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-29 15:20:03 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmPublishDuplicatePorts(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-12-27 21:43:21 +00:00
|
|
|
|
2017-05-18 19:23:28 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--no-resolve-image", "--detach=true", "--publish", "5005:80", "--publish", "5006:80", "--publish", "80", "--publish", "80", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2016-12-27 21:43:21 +00:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
// make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2016-12-27 21:43:21 +00:00
|
|
|
|
|
|
|
// Total len = 4, with 2 dynamic ports and 2 non-dynamic ports
|
|
|
|
// Dynamic ports are likely to be 30000 and 30001 but doesn't matter
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{.Endpoint.Ports}} len={{len .Endpoint.Ports}}", id)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "len=4"), out)
|
|
|
|
assert.Assert(c, strings.Contains(out, "{ tcp 80 5005 ingress}"), out)
|
|
|
|
assert.Assert(c, strings.Contains(out, "{ tcp 80 5006 ingress}"), out)
|
2016-12-27 21:43:21 +00:00
|
|
|
}
|
2016-12-22 02:06:16 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmJoinWithDrain(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2016-12-22 02:06:16 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("node", "ls")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(out, "Drain"), out)
|
2016-12-22 02:06:16 +00:00
|
|
|
out, err = d.Cmd("swarm", "join-token", "-q", "manager")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-12-22 02:06:16 +00:00
|
|
|
|
|
|
|
token := strings.TrimSpace(out)
|
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
d1 := s.AddDaemon(ctx, c, false, false)
|
2016-12-22 02:06:16 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
out, err = d1.Cmd("swarm", "join", "--availability=drain", "--token", token, d.SwarmListenAddr())
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-12-22 02:06:16 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("node", "ls")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "Drain"), out)
|
2016-12-22 02:06:16 +00:00
|
|
|
out, err = d1.Cmd("node", "ls")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "Drain"), out)
|
2016-12-22 02:06:16 +00:00
|
|
|
}
|
2016-12-22 02:13:31 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmInitWithDrain(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, false, false)
|
2016-12-22 02:13:31 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("swarm", "init", "--availability", "drain")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, "out: %v", out)
|
2016-12-22 02:13:31 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("node", "ls")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 21:08:22 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "Drain"))
|
2016-12-22 02:13:31 +00:00
|
|
|
}
|
2017-01-14 08:12:19 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmReadonlyRootfs(c *testing.T) {
|
2017-01-14 08:12:19 +00:00
|
|
|
testRequires(c, DaemonIsLinux, UserNamespaceROMount)
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
2017-01-14 08:12:19 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-01-14 08:12:19 +00:00
|
|
|
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "top", "--read-only", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-01-14 08:12:19 +00:00
|
|
|
|
|
|
|
// make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2017-01-14 08:12:19 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.ReadOnly }}", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), "true")
|
2017-01-14 08:12:19 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
containers := d.ActiveContainers(testutil.GetContext(c), c)
|
2017-01-14 08:12:19 +00:00
|
|
|
out, err = d.Cmd("inspect", "--type", "container", "--format", "{{.HostConfig.ReadonlyRootfs}}", containers[0])
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), "true")
|
2017-01-14 08:12:19 +00:00
|
|
|
}
|
2017-01-19 11:04:26 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmStopSignal(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
2017-02-06 05:22:57 +00:00
|
|
|
testRequires(c, DaemonIsLinux, UserNamespaceROMount)
|
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-02-06 05:22:57 +00:00
|
|
|
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "top", "--stop-signal=SIGHUP", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-02-06 05:22:57 +00:00
|
|
|
|
|
|
|
// make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(1)), poll.WithTimeout(defaultReconciliationTimeout))
|
2017-02-06 05:22:57 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.StopSignal }}", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), "SIGHUP")
|
2017-02-06 05:22:57 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
containers := d.ActiveContainers(testutil.GetContext(c), c)
|
2017-02-06 05:22:57 +00:00
|
|
|
out, err = d.Cmd("inspect", "--type", "container", "--format", "{{.Config.StopSignal}}", containers[0])
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), "SIGHUP")
|
2017-02-06 05:22:57 +00:00
|
|
|
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err = d.Cmd("service", "update", "--detach", "--stop-signal=SIGUSR1", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-02-06 05:22:57 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.StopSignal }}", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), "SIGUSR1")
|
2017-02-06 05:22:57 +00:00
|
|
|
}
|
2017-03-03 22:08:49 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmServiceLsFilterMode(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-03-03 22:08:49 +00:00
|
|
|
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "top1", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2017-03-03 22:08:49 +00:00
|
|
|
|
2017-09-27 23:17:55 +00:00
|
|
|
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "top2", "--mode=global", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2017-03-03 22:08:49 +00:00
|
|
|
|
|
|
|
// make sure task has been deployed.
|
2023-07-14 18:02:38 +00:00
|
|
|
poll.WaitOn(c, pollCheck(c, d.CheckActiveContainerCount(ctx), checker.Equals(2)), poll.WithTimeout(defaultReconciliationTimeout))
|
2017-03-03 22:08:49 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("service", "ls")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "top1"), out)
|
|
|
|
assert.Assert(c, strings.Contains(out, "top2"), out)
|
|
|
|
assert.Assert(c, !strings.Contains(out, "localnet"), out)
|
2017-03-03 22:08:49 +00:00
|
|
|
out, err = d.Cmd("service", "ls", "--filter", "mode=global")
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(out, "top1"), out)
|
|
|
|
assert.Assert(c, strings.Contains(out, "top2"), out)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-03-03 22:08:49 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("service", "ls", "--filter", "mode=replicated")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "top1"), out)
|
|
|
|
assert.Assert(c, !strings.Contains(out, "top2"), out)
|
2017-03-03 22:08:49 +00:00
|
|
|
}
|
2017-04-14 23:54:17 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmInitUnspecifiedDataPathAddr(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, false, false)
|
2017-04-14 23:54:17 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("swarm", "init", "--data-path-addr", "0.0.0.0")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "data path address must be a non-zero IP"), out)
|
2017-04-14 23:54:17 +00:00
|
|
|
out, err = d.Cmd("swarm", "init", "--data-path-addr", "0.0.0.0:2000")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "data path address must be a non-zero IP"), out)
|
2017-04-14 23:54:17 +00:00
|
|
|
}
|
2017-04-30 21:51:43 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmJoinLeave(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-04-30 21:51:43 +00:00
|
|
|
|
|
|
|
out, err := d.Cmd("swarm", "join-token", "-q", "worker")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2017-04-30 21:51:43 +00:00
|
|
|
|
|
|
|
token := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
// Verify that back to back join/leave does not cause panics
|
2023-07-14 18:02:38 +00:00
|
|
|
d1 := s.AddDaemon(ctx, c, false, false)
|
2017-04-30 21:51:43 +00:00
|
|
|
for i := 0; i < 10; i++ {
|
2018-04-11 10:10:17 +00:00
|
|
|
out, err = d1.Cmd("swarm", "join", "--token", token, d.SwarmListenAddr())
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2017-04-30 21:51:43 +00:00
|
|
|
|
|
|
|
_, err = d1.Cmd("swarm", "leave")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2017-04-30 21:51:43 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
const defaultRetryCount = 10
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func waitForEvent(c *testing.T, d *daemon.Daemon, since string, filter string, event string, retry int) string {
|
2017-05-19 10:25:14 +00:00
|
|
|
if retry < 1 {
|
|
|
|
c.Fatalf("retry count %d is invalid. It should be no less than 1", retry)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
var out string
|
|
|
|
for i := 0; i < retry; i++ {
|
|
|
|
until := daemonUnixTime(c)
|
|
|
|
var err error
|
|
|
|
if len(filter) > 0 {
|
|
|
|
out, err = d.Cmd("events", "--since", since, "--until", until, filter)
|
|
|
|
} else {
|
|
|
|
out, err = d.Cmd("events", "--since", since, "--until", until)
|
|
|
|
}
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-05-19 10:25:14 +00:00
|
|
|
if strings.Contains(out, event) {
|
|
|
|
return strings.TrimSpace(out)
|
|
|
|
}
|
|
|
|
// no need to sleep after last retry
|
|
|
|
if i < retry-1 {
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.Fatalf("docker events output '%s' doesn't contain event '%s'", out, event)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmClusterEventsSource(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d1 := s.AddDaemon(ctx, c, true, true)
|
|
|
|
d2 := s.AddDaemon(ctx, c, true, true)
|
|
|
|
d3 := s.AddDaemon(ctx, c, true, false)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
|
|
|
// create a network
|
|
|
|
out, err := d1.Cmd("network", "create", "--attachable", "-d", "overlay", "foo")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-04-02 22:21:56 +00:00
|
|
|
networkID := strings.TrimSpace(out)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Assert(c, networkID != "")
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
// d1, d2 are managers that can get swarm events
|
|
|
|
waitForEvent(c, d1, "0", "-f scope=swarm", "network create "+networkID, defaultRetryCount)
|
|
|
|
waitForEvent(c, d2, "0", "-f scope=swarm", "network create "+networkID, defaultRetryCount)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
|
|
|
// d3 is a worker, not able to get cluster events
|
2017-05-19 10:25:14 +00:00
|
|
|
out = waitForEvent(c, d3, "0", "-f scope=swarm", "", 1)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(out, "network create "), out)
|
2017-04-02 22:21:56 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmClusterEventsScope(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
|
|
|
// create a service
|
2017-05-18 19:23:28 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--no-resolve-image", "--name", "test", "--detach=false", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-04-02 22:21:56 +00:00
|
|
|
serviceID := strings.Split(out, "\n")[0]
|
|
|
|
|
|
|
|
// scope swarm filters cluster events
|
2017-05-19 10:25:14 +00:00
|
|
|
out = waitForEvent(c, d, "0", "-f scope=swarm", "service create "+serviceID, defaultRetryCount)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(out, "container create "), out)
|
2017-05-19 10:25:14 +00:00
|
|
|
// all events are returned if scope is not specified
|
|
|
|
waitForEvent(c, d, "0", "", "service create "+serviceID, 1)
|
|
|
|
waitForEvent(c, d, "0", "", "container create ", defaultRetryCount)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
// scope local only shows non-cluster events
|
|
|
|
out = waitForEvent(c, d, "0", "-f scope=local", "container create ", 1)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(out, "service create "), out)
|
2017-04-02 22:21:56 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmClusterEventsType(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
|
|
|
// create a service
|
2017-05-18 19:23:28 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--no-resolve-image", "--name", "test", "--detach=false", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-04-02 22:21:56 +00:00
|
|
|
serviceID := strings.Split(out, "\n")[0]
|
|
|
|
|
|
|
|
// create a network
|
|
|
|
out, err = d.Cmd("network", "create", "--attachable", "-d", "overlay", "foo")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-04-02 22:21:56 +00:00
|
|
|
networkID := strings.TrimSpace(out)
|
2019-09-09 21:05:56 +00:00
|
|
|
assert.Assert(c, networkID != "")
|
2017-04-02 22:21:56 +00:00
|
|
|
|
|
|
|
// filter by service
|
2017-05-19 10:25:14 +00:00
|
|
|
out = waitForEvent(c, d, "0", "-f type=service", "service create "+serviceID, defaultRetryCount)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(out, "network create"), out)
|
2017-04-02 22:21:56 +00:00
|
|
|
// filter by network
|
2017-05-19 10:25:14 +00:00
|
|
|
out = waitForEvent(c, d, "0", "-f type=network", "network create "+networkID, defaultRetryCount)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, !strings.Contains(out, "service create"), out)
|
2017-04-02 22:21:56 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmClusterEventsService(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
|
|
|
// create a service
|
2017-05-18 19:23:28 +00:00
|
|
|
out, err := d.Cmd("service", "create", "--no-resolve-image", "--name", "test", "--detach=false", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-04-02 22:21:56 +00:00
|
|
|
serviceID := strings.Split(out, "\n")[0]
|
|
|
|
|
|
|
|
// validate service create event
|
2017-05-19 10:25:14 +00:00
|
|
|
waitForEvent(c, d, "0", "-f scope=swarm", "service create "+serviceID, defaultRetryCount)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
t1 := daemonUnixTime(c)
|
2017-04-02 22:21:56 +00:00
|
|
|
out, err = d.Cmd("service", "update", "--force", "--detach=false", "test")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
// wait for service update start
|
|
|
|
out = waitForEvent(c, d, t1, "-f scope=swarm", "service update "+serviceID, defaultRetryCount)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "updatestate.new=updating"), out)
|
2017-05-19 10:25:14 +00:00
|
|
|
// allow service update complete. This is a service with 1 instance
|
|
|
|
time.Sleep(400 * time.Millisecond)
|
|
|
|
out = waitForEvent(c, d, t1, "-f scope=swarm", "service update "+serviceID, defaultRetryCount)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "updatestate.new=completed, updatestate.old=updating"), out)
|
2017-04-02 22:21:56 +00:00
|
|
|
// scale service
|
2017-05-19 10:25:14 +00:00
|
|
|
t2 := daemonUnixTime(c)
|
2017-09-28 00:47:51 +00:00
|
|
|
out, err = d.Cmd("service", "scale", "test=3")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
out = waitForEvent(c, d, t2, "-f scope=swarm", "service update "+serviceID, defaultRetryCount)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "replicas.new=3, replicas.old=1"), out)
|
2017-04-02 22:21:56 +00:00
|
|
|
// remove service
|
2017-05-19 10:25:14 +00:00
|
|
|
t3 := daemonUnixTime(c)
|
2017-04-02 22:21:56 +00:00
|
|
|
out, err = d.Cmd("service", "rm", "test")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
waitForEvent(c, d, t3, "-f scope=swarm", "service remove "+serviceID, defaultRetryCount)
|
2017-04-02 22:21:56 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmClusterEventsNode(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d1 := s.AddDaemon(ctx, c, true, true)
|
|
|
|
s.AddDaemon(ctx, c, true, true)
|
|
|
|
d3 := s.AddDaemon(ctx, c, true, true)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
d3ID := d3.NodeID()
|
2017-05-19 10:25:14 +00:00
|
|
|
waitForEvent(c, d1, "0", "-f scope=swarm", "node create "+d3ID, defaultRetryCount)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
t1 := daemonUnixTime(c)
|
|
|
|
out, err := d1.Cmd("node", "update", "--availability=pause", d3ID)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
|
|
|
// filter by type
|
2017-05-19 10:25:14 +00:00
|
|
|
out = waitForEvent(c, d1, t1, "-f type=node", "node update "+d3ID, defaultRetryCount)
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(out, "availability.new=pause, availability.old=active"), out)
|
2017-05-19 10:25:14 +00:00
|
|
|
t2 := daemonUnixTime(c)
|
2017-04-02 22:21:56 +00:00
|
|
|
out, err = d1.Cmd("node", "demote", d3ID)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
waitForEvent(c, d1, t2, "-f type=node", "node update "+d3ID, defaultRetryCount)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
t3 := daemonUnixTime(c)
|
2017-04-02 22:21:56 +00:00
|
|
|
out, err = d1.Cmd("node", "rm", "-f", d3ID)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
// filter by scope
|
|
|
|
waitForEvent(c, d1, t3, "-f scope=swarm", "node remove "+d3ID, defaultRetryCount)
|
2017-04-02 22:21:56 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmClusterEventsNetwork(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
|
|
|
// create a network
|
|
|
|
out, err := d.Cmd("network", "create", "--attachable", "-d", "overlay", "foo")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-04-02 22:21:56 +00:00
|
|
|
networkID := strings.TrimSpace(out)
|
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
waitForEvent(c, d, "0", "-f scope=swarm", "network create "+networkID, defaultRetryCount)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
|
|
|
// remove network
|
2017-05-19 10:25:14 +00:00
|
|
|
t1 := daemonUnixTime(c)
|
2017-04-02 22:21:56 +00:00
|
|
|
out, err = d.Cmd("network", "rm", "foo")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
|
|
|
// filtered by network
|
2017-05-19 10:25:14 +00:00
|
|
|
waitForEvent(c, d, t1, "-f type=network", "network remove "+networkID, defaultRetryCount)
|
2017-04-02 22:21:56 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmClusterEventsSecret(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
|
|
|
testName := "test_secret"
|
|
|
|
id := d.CreateSecret(c, swarm.SecretSpec{
|
|
|
|
Annotations: swarm.Annotations{
|
|
|
|
Name: testName,
|
|
|
|
},
|
|
|
|
Data: []byte("TESTINGDATA"),
|
|
|
|
})
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, id != "", "secrets: %s", id)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
waitForEvent(c, d, "0", "-f scope=swarm", "secret create "+id, defaultRetryCount)
|
2017-04-02 22:21:56 +00:00
|
|
|
|
2017-05-19 10:25:14 +00:00
|
|
|
t1 := daemonUnixTime(c)
|
2017-04-02 22:21:56 +00:00
|
|
|
d.DeleteSecret(c, id)
|
|
|
|
// filtered by secret
|
2017-05-19 10:25:14 +00:00
|
|
|
waitForEvent(c, d, t1, "-f type=secret", "secret remove "+id, defaultRetryCount)
|
2017-04-02 22:21:56 +00:00
|
|
|
}
|
2017-07-10 03:41:25 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerSwarmSuite) TestSwarmClusterEventsConfig(c *testing.T) {
|
2023-07-14 18:02:38 +00:00
|
|
|
ctx := testutil.GetContext(c)
|
|
|
|
d := s.AddDaemon(ctx, c, true, true)
|
2017-07-10 03:41:25 +00:00
|
|
|
|
|
|
|
testName := "test_config"
|
|
|
|
id := d.CreateConfig(c, swarm.ConfigSpec{
|
|
|
|
Annotations: swarm.Annotations{
|
|
|
|
Name: testName,
|
|
|
|
},
|
|
|
|
Data: []byte("TESTINGDATA"),
|
|
|
|
})
|
2019-09-11 10:57:29 +00:00
|
|
|
assert.Assert(c, id != "", "configs: %s", id)
|
2017-07-10 03:41:25 +00:00
|
|
|
|
|
|
|
waitForEvent(c, d, "0", "-f scope=swarm", "config create "+id, defaultRetryCount)
|
|
|
|
|
|
|
|
t1 := daemonUnixTime(c)
|
|
|
|
d.DeleteConfig(c, id)
|
|
|
|
// filtered by config
|
|
|
|
waitForEvent(c, d, t1, "-f type=config", "config remove "+id, defaultRetryCount)
|
|
|
|
}
|
2018-10-29 20:46:21 +00:00
|
|
|
|
2019-09-09 21:05:55 +00:00
|
|
|
func getUnlockKey(d *daemon.Daemon, c *testing.T, autolockOutput string) string {
|
2018-10-29 20:46:21 +00:00
|
|
|
unlockKey, err := d.Cmd("swarm", "unlock-key", "-q")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 10:36:00 +00:00
|
|
|
assert.Assert(c, err == nil, unlockKey)
|
2018-10-29 20:46:21 +00:00
|
|
|
unlockKey = strings.TrimSuffix(unlockKey, "\n")
|
|
|
|
|
|
|
|
// Check that "docker swarm init --autolock" or "docker swarm update --autolock"
|
|
|
|
// contains all the expected strings, including the unlock key
|
2019-10-07 19:24:06 +00:00
|
|
|
assert.Assert(c, strings.Contains(autolockOutput, "docker swarm unlock"), autolockOutput)
|
|
|
|
assert.Assert(c, strings.Contains(autolockOutput, unlockKey), autolockOutput)
|
2018-10-29 20:46:21 +00:00
|
|
|
return unlockKey
|
|
|
|
}
|