2016-06-14 02:54:20 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2016-07-08 19:01:58 +00:00
|
|
|
"fmt"
|
2017-03-04 00:24:15 +00:00
|
|
|
"io/ioutil"
|
2017-01-05 23:46:07 +00:00
|
|
|
"net"
|
2016-06-14 02:54:20 +00:00
|
|
|
"net/http"
|
2016-07-08 21:54:18 +00:00
|
|
|
"path/filepath"
|
2018-12-23 11:39:58 +00:00
|
|
|
"runtime"
|
2016-06-14 02:54:20 +00:00
|
|
|
"strings"
|
2016-07-08 21:54:18 +00:00
|
|
|
"sync"
|
2016-06-14 02:54:20 +00:00
|
|
|
"time"
|
|
|
|
|
2017-05-09 00:14:34 +00:00
|
|
|
"github.com/cloudflare/cfssl/csr"
|
2017-03-04 00:24:15 +00:00
|
|
|
"github.com/cloudflare/cfssl/helpers"
|
2017-05-09 00:14:34 +00:00
|
|
|
"github.com/cloudflare/cfssl/initca"
|
2017-01-18 15:48:09 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
2017-01-17 05:53:31 +00:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2017-09-19 20:12:29 +00:00
|
|
|
"github.com/docker/docker/client"
|
2016-12-30 17:23:00 +00:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2016-12-09 09:17:53 +00:00
|
|
|
"github.com/docker/docker/integration-cli/daemon"
|
2018-04-11 10:10:17 +00:00
|
|
|
testdaemon "github.com/docker/docker/internal/test/daemon"
|
2018-04-17 08:22:04 +00:00
|
|
|
"github.com/docker/docker/internal/test/request"
|
2017-05-09 00:14:34 +00:00
|
|
|
"github.com/docker/swarmkit/ca"
|
2016-06-14 02:54:20 +00:00
|
|
|
"github.com/go-check/check"
|
2018-06-11 13:32:11 +00:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
2016-06-14 02:54:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var defaultReconciliationTimeout = 30 * time.Second
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmInit(c *check.C) {
|
2016-06-14 02:54:20 +00:00
|
|
|
// todo: should find a better way to verify that components are running than /info
|
|
|
|
d1 := s.AddDaemon(c, true, true)
|
2018-04-11 10:10:17 +00:00
|
|
|
info := d1.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.ControlAvailable, true)
|
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
|
|
|
assert.Equal(c, info.Cluster.RootRotationInProgress, false)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
|
|
|
d2 := s.AddDaemon(c, true, false)
|
2018-04-11 10:10:17 +00:00
|
|
|
info = d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.ControlAvailable, false)
|
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
|
|
|
// Leaving cluster
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, d2.SwarmLeave(c, false))
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
info = d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.ControlAvailable, false)
|
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
d2.SwarmJoin(c, swarm.JoinRequest{
|
|
|
|
ListenAddr: d1.SwarmListenAddr(),
|
|
|
|
JoinToken: d1.JoinTokens(c).Worker,
|
|
|
|
RemoteAddrs: []string{d1.SwarmListenAddr()},
|
|
|
|
})
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
info = d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.ControlAvailable, false)
|
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
|
|
|
// Current state restoring after restarts
|
2016-12-09 22:20:14 +00:00
|
|
|
d1.Stop(c)
|
|
|
|
d2.Stop(c)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2018-10-25 18:47:56 +00:00
|
|
|
d1.StartNode(c)
|
|
|
|
d2.StartNode(c)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
info = d1.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.ControlAvailable, true)
|
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
info = d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.ControlAvailable, false)
|
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
2016-06-14 02:54:20 +00:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmJoinToken(c *check.C) {
|
2016-06-14 02:54:20 +00:00
|
|
|
d1 := s.AddDaemon(c, false, false)
|
2018-04-11 10:10:17 +00:00
|
|
|
d1.SwarmInit(c, swarm.InitRequest{})
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2016-11-16 22:17:18 +00:00
|
|
|
// todo: error message differs depending if some components of token are valid
|
|
|
|
|
2016-06-14 02:54:20 +00:00
|
|
|
d2 := s.AddDaemon(c, false, false)
|
2018-04-11 10:10:17 +00:00
|
|
|
c2 := d2.NewClientT(c)
|
|
|
|
err := c2.SwarmJoin(context.Background(), swarm.JoinRequest{
|
|
|
|
ListenAddr: d2.SwarmListenAddr(),
|
|
|
|
RemoteAddrs: []string{d1.SwarmListenAddr()},
|
|
|
|
})
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "join token is necessary")
|
2018-04-11 10:10:17 +00:00
|
|
|
info := d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
err = c2.SwarmJoin(context.Background(), swarm.JoinRequest{
|
|
|
|
ListenAddr: d2.SwarmListenAddr(),
|
|
|
|
JoinToken: "foobaz",
|
|
|
|
RemoteAddrs: []string{d1.SwarmListenAddr()},
|
|
|
|
})
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "invalid join token")
|
2018-04-11 10:10:17 +00:00
|
|
|
info = d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
workerToken := d1.JoinTokens(c).Worker
|
2016-07-20 18:15:08 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
d2.SwarmJoin(c, swarm.JoinRequest{
|
|
|
|
ListenAddr: d2.SwarmListenAddr(),
|
|
|
|
JoinToken: workerToken,
|
|
|
|
RemoteAddrs: []string{d1.SwarmListenAddr()},
|
|
|
|
})
|
|
|
|
info = d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
|
|
|
assert.NilError(c, d2.SwarmLeave(c, false))
|
2018-04-11 10:10:17 +00:00
|
|
|
info = d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
|
2016-06-16 19:12:38 +00:00
|
|
|
|
2016-07-20 18:15:08 +00:00
|
|
|
// change tokens
|
2016-12-09 09:17:53 +00:00
|
|
|
d1.RotateTokens(c)
|
2016-06-16 19:12:38 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
err = c2.SwarmJoin(context.Background(), swarm.JoinRequest{
|
|
|
|
ListenAddr: d2.SwarmListenAddr(),
|
|
|
|
JoinToken: workerToken,
|
|
|
|
RemoteAddrs: []string{d1.SwarmListenAddr()},
|
|
|
|
})
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "join token is necessary")
|
2018-04-11 10:10:17 +00:00
|
|
|
info = d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
|
2016-06-16 19:12:38 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
workerToken = d1.JoinTokens(c).Worker
|
2016-07-20 18:15:08 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
d2.SwarmJoin(c, swarm.JoinRequest{JoinToken: workerToken, RemoteAddrs: []string{d1.SwarmListenAddr()}})
|
|
|
|
info = d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
|
|
|
assert.NilError(c, d2.SwarmLeave(c, false))
|
2018-04-11 10:10:17 +00:00
|
|
|
info = d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
|
2016-06-16 19:12:38 +00:00
|
|
|
|
2016-07-20 18:15:08 +00:00
|
|
|
// change spec, don't change tokens
|
2016-12-09 09:17:53 +00:00
|
|
|
d1.UpdateSwarm(c, func(s *swarm.Spec) {})
|
2016-06-16 19:12:38 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
err = c2.SwarmJoin(context.Background(), swarm.JoinRequest{
|
|
|
|
ListenAddr: d2.SwarmListenAddr(),
|
|
|
|
RemoteAddrs: []string{d1.SwarmListenAddr()},
|
|
|
|
})
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "join token is necessary")
|
2018-04-11 10:10:17 +00:00
|
|
|
info = d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
|
2016-06-16 19:12:38 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
d2.SwarmJoin(c, swarm.JoinRequest{JoinToken: workerToken, RemoteAddrs: []string{d1.SwarmListenAddr()}})
|
|
|
|
info = d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
|
|
|
assert.NilError(c, d2.SwarmLeave(c, false))
|
2018-04-11 10:10:17 +00:00
|
|
|
info = d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
|
2016-06-14 02:54:20 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 22:10:18 +00:00
|
|
|
func (s *DockerSwarmSuite) TestUpdateSwarmAddExternalCA(c *check.C) {
|
|
|
|
d1 := s.AddDaemon(c, false, false)
|
2018-04-11 10:10:17 +00:00
|
|
|
d1.SwarmInit(c, swarm.InitRequest{})
|
2017-04-12 22:10:18 +00:00
|
|
|
d1.UpdateSwarm(c, func(s *swarm.Spec) {
|
|
|
|
s.CAConfig.ExternalCAs = []*swarm.ExternalCA{
|
|
|
|
{
|
|
|
|
Protocol: swarm.ExternalCAProtocolCFSSL,
|
|
|
|
URL: "https://thishasnoca.org",
|
|
|
|
},
|
2017-04-25 22:40:46 +00:00
|
|
|
{
|
|
|
|
Protocol: swarm.ExternalCAProtocolCFSSL,
|
|
|
|
URL: "https://thishasacacert.org",
|
|
|
|
CACert: "cacert",
|
|
|
|
},
|
2017-04-12 22:10:18 +00:00
|
|
|
}
|
|
|
|
})
|
2018-04-11 10:10:17 +00:00
|
|
|
info := d1.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, len(info.Cluster.Spec.CAConfig.ExternalCAs), 2)
|
|
|
|
assert.Equal(c, info.Cluster.Spec.CAConfig.ExternalCAs[0].CACert, "")
|
|
|
|
assert.Equal(c, info.Cluster.Spec.CAConfig.ExternalCAs[1].CACert, "cacert")
|
2017-04-12 22:10:18 +00:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmCAHash(c *check.C) {
|
2016-06-14 02:54:20 +00:00
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, false, false)
|
2016-12-09 09:17:53 +00:00
|
|
|
splitToken := strings.Split(d1.JoinTokens(c).Worker, "-")
|
2016-07-20 18:15:08 +00:00
|
|
|
splitToken[2] = "1kxftv4ofnc6mt30lmgipg6ngf9luhwqopfk1tz6bdmnkubg0e"
|
|
|
|
replacementToken := strings.Join(splitToken, "-")
|
2018-04-11 10:10:17 +00:00
|
|
|
c2 := d2.NewClientT(c)
|
|
|
|
err := c2.SwarmJoin(context.Background(), swarm.JoinRequest{
|
|
|
|
ListenAddr: d2.SwarmListenAddr(),
|
|
|
|
JoinToken: replacementToken,
|
|
|
|
RemoteAddrs: []string{d1.SwarmListenAddr()},
|
|
|
|
})
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "remote CA does not match fingerprint")
|
2016-06-14 02:54:20 +00:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *check.C) {
|
2016-06-14 02:54:20 +00:00
|
|
|
d1 := s.AddDaemon(c, false, false)
|
2018-04-11 10:10:17 +00:00
|
|
|
d1.SwarmInit(c, swarm.InitRequest{})
|
2016-06-14 02:54:20 +00:00
|
|
|
d2 := s.AddDaemon(c, true, false)
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
info := d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.ControlAvailable, false)
|
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
2016-06-14 02:54:20 +00:00
|
|
|
n.Spec.Role = swarm.NodeRoleManager
|
|
|
|
})
|
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckControlAvailable, checker.True)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
2016-06-14 02:54:20 +00:00
|
|
|
n.Spec.Role = swarm.NodeRoleWorker
|
|
|
|
})
|
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckControlAvailable, checker.False)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2017-03-04 00:24:15 +00:00
|
|
|
// Wait for the role to change to worker in the cert. This is partially
|
|
|
|
// done because it's something worth testing in its own right, and
|
|
|
|
// partially because changing the role from manager to worker and then
|
|
|
|
// back to manager quickly might cause the node to pause for awhile
|
|
|
|
// while waiting for the role to change to worker, and the test can
|
|
|
|
// time out during this interval.
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
certBytes, err := ioutil.ReadFile(filepath.Join(d2.Folder, "root", "swarm", "certificates", "swarm-node.crt"))
|
|
|
|
if err != nil {
|
|
|
|
return "", check.Commentf("error: %v", err)
|
|
|
|
}
|
|
|
|
certs, err := helpers.ParseCertificatesPEM(certBytes)
|
|
|
|
if err == nil && len(certs) > 0 && len(certs[0].Subject.OrganizationalUnit) > 0 {
|
|
|
|
return certs[0].Subject.OrganizationalUnit[0], nil
|
|
|
|
}
|
|
|
|
return "", check.Commentf("could not get organizational unit from certificate")
|
|
|
|
}, checker.Equals, "swarm-worker")
|
|
|
|
|
2016-07-08 19:01:58 +00:00
|
|
|
// Demoting last node should fail
|
2018-04-11 10:10:17 +00:00
|
|
|
node := d1.GetNode(c, d1.NodeID())
|
2016-07-08 19:01:58 +00:00
|
|
|
node.Spec.Role = swarm.NodeRoleWorker
|
|
|
|
url := fmt.Sprintf("/nodes/%s/update?version=%d", node.ID, node.Version.Index)
|
2018-04-17 08:22:04 +00:00
|
|
|
res, body, err := request.Post(url, request.Host(d1.Sock()), request.JSONBody(node.Spec))
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2017-05-24 03:56:26 +00:00
|
|
|
b, err := request.ReadBody(body)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, res.StatusCode, http.StatusBadRequest, "output: %q", string(b))
|
2017-05-24 03:56:26 +00:00
|
|
|
|
2017-02-27 19:51:00 +00:00
|
|
|
// The warning specific to demoting the last manager is best-effort and
|
|
|
|
// won't appear until the Role field of the demoted manager has been
|
|
|
|
// updated.
|
|
|
|
// Yes, I know this looks silly, but checker.Matches is broken, since
|
|
|
|
// it anchors the regexp contrary to the documentation, and this makes
|
|
|
|
// it impossible to match something that includes a line break.
|
2017-05-24 03:56:26 +00:00
|
|
|
if !strings.Contains(string(b), "last manager of the swarm") {
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Assert(c, strings.Contains(string(b), "this would result in a loss of quorum"))
|
2017-02-27 19:51:00 +00:00
|
|
|
}
|
2018-04-11 10:10:17 +00:00
|
|
|
info = d1.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
|
|
|
assert.Equal(c, info.ControlAvailable, true)
|
2016-07-08 19:01:58 +00:00
|
|
|
|
|
|
|
// Promote already demoted node
|
2018-04-11 10:10:17 +00:00
|
|
|
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
2016-07-08 19:01:58 +00:00
|
|
|
n.Spec.Role = swarm.NodeRoleManager
|
|
|
|
})
|
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckControlAvailable, checker.True)
|
2016-06-14 02:54:20 +00:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmLeaderProxy(c *check.C) {
|
2016-07-15 20:28:09 +00:00
|
|
|
// add three managers, one of these is leader
|
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, true)
|
|
|
|
d3 := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
// start a service by hitting each of the 3 managers
|
2016-12-09 09:17:53 +00:00
|
|
|
d1.CreateService(c, simpleTestService, func(s *swarm.Service) {
|
2016-07-15 20:28:09 +00:00
|
|
|
s.Spec.Name = "test1"
|
|
|
|
})
|
2016-12-09 09:17:53 +00:00
|
|
|
d2.CreateService(c, simpleTestService, func(s *swarm.Service) {
|
2016-07-15 20:28:09 +00:00
|
|
|
s.Spec.Name = "test2"
|
|
|
|
})
|
2016-12-09 09:17:53 +00:00
|
|
|
d3.CreateService(c, simpleTestService, func(s *swarm.Service) {
|
2016-07-15 20:28:09 +00:00
|
|
|
s.Spec.Name = "test3"
|
|
|
|
})
|
|
|
|
|
|
|
|
// 3 services should be started now, because the requests were proxied to leader
|
|
|
|
// query each node and make sure it returns 3 services
|
2018-04-11 10:10:17 +00:00
|
|
|
for _, d := range []*daemon.Daemon{d1, d2, d3} {
|
2016-12-09 09:17:53 +00:00
|
|
|
services := d.ListServices(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, len(services), 3)
|
2016-07-15 20:28:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *check.C) {
|
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")
|
|
|
|
}
|
|
|
|
|
2016-07-18 23:31:43 +00:00
|
|
|
// Create 3 nodes
|
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, true)
|
|
|
|
d3 := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
// assert that the first node we made is the leader, and the other two are followers
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, d1.GetNode(c, d1.NodeID()).ManagerStatus.Leader, true)
|
|
|
|
assert.Equal(c, d1.GetNode(c, d2.NodeID()).ManagerStatus.Leader, false)
|
|
|
|
assert.Equal(c, d1.GetNode(c, d3.NodeID()).ManagerStatus.Leader, false)
|
2016-07-18 23:31:43 +00:00
|
|
|
|
2016-12-09 22:20:14 +00:00
|
|
|
d1.Stop(c)
|
2016-07-27 02:11:17 +00:00
|
|
|
|
|
|
|
var (
|
2018-04-11 10:10:17 +00:00
|
|
|
leader *daemon.Daemon // keep track of leader
|
|
|
|
followers []*daemon.Daemon // keep track of followers
|
2016-07-27 02:11:17 +00:00
|
|
|
)
|
2018-04-11 10:10:17 +00:00
|
|
|
checkLeader := func(nodes ...*daemon.Daemon) checkF {
|
2016-07-27 02:11:17 +00:00
|
|
|
return func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
// clear these out before each run
|
|
|
|
leader = nil
|
|
|
|
followers = nil
|
|
|
|
for _, d := range nodes {
|
2018-04-11 10:10:17 +00:00
|
|
|
if d.GetNode(c, d.NodeID()).ManagerStatus.Leader {
|
2016-07-27 02:11:17 +00:00
|
|
|
leader = d
|
|
|
|
} else {
|
|
|
|
followers = append(followers, d)
|
|
|
|
}
|
|
|
|
}
|
2016-07-18 23:31:43 +00:00
|
|
|
|
2016-07-27 02:11:17 +00:00
|
|
|
if leader == nil {
|
|
|
|
return false, check.Commentf("no leader elected")
|
|
|
|
}
|
2016-07-18 23:31:43 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
return true, check.Commentf("elected %v", leader.ID())
|
2016-07-18 23:31:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 02:11:17 +00:00
|
|
|
// wait for an election to occur
|
2018-09-13 02:30:09 +00:00
|
|
|
c.Logf("Waiting for election to occur...")
|
2016-07-27 02:11:17 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, checkLeader(d2, d3), checker.True)
|
|
|
|
|
2016-07-18 23:31:43 +00:00
|
|
|
// assert that we have a new leader
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Assert(c, leader != nil)
|
2016-07-27 02:11:17 +00:00
|
|
|
|
|
|
|
// Keep track of the current leader, since we want that to be chosen.
|
|
|
|
stableleader := leader
|
2016-07-18 23:31:43 +00:00
|
|
|
|
2016-07-27 02:11:17 +00:00
|
|
|
// add the d1, the initial leader, back
|
2018-10-25 18:47:56 +00:00
|
|
|
d1.StartNode(c)
|
2016-07-18 23:31:43 +00:00
|
|
|
|
2016-07-27 02:11:17 +00:00
|
|
|
// wait for possible election
|
2018-09-13 02:30:09 +00:00
|
|
|
c.Logf("Waiting for possible election...")
|
2016-07-27 02:11:17 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, checkLeader(d1, d2, d3), checker.True)
|
2016-07-18 23:31:43 +00:00
|
|
|
// pick out the leader and the followers again
|
|
|
|
|
|
|
|
// verify that we still only have 1 leader and 2 followers
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Assert(c, leader != nil)
|
|
|
|
assert.Equal(c, len(followers), 2)
|
2016-07-18 23:31:43 +00:00
|
|
|
// and that after we added d1 back, the leader hasn't changed
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, leader.NodeID(), stableleader.NodeID())
|
2016-07-18 23:31:43 +00:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *check.C) {
|
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")
|
|
|
|
}
|
|
|
|
|
2016-06-14 02:54:20 +00:00
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, true)
|
|
|
|
d3 := s.AddDaemon(c, true, true)
|
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
d1.CreateService(c, simpleTestService)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2016-12-09 22:20:14 +00:00
|
|
|
d2.Stop(c)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2016-07-27 01:32:56 +00:00
|
|
|
// make sure there is a leader
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckLeader, checker.IsNil)
|
2016-07-27 01:32:56 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
d1.CreateService(c, simpleTestService, func(s *swarm.Service) {
|
2016-06-14 02:54:20 +00:00
|
|
|
s.Spec.Name = "top1"
|
|
|
|
})
|
|
|
|
|
2016-12-09 22:20:14 +00:00
|
|
|
d3.Stop(c)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
|
|
|
var service swarm.Service
|
|
|
|
simpleTestService(&service)
|
|
|
|
service.Spec.Name = "top2"
|
2018-12-22 14:53:02 +00:00
|
|
|
cli := d1.NewClientT(c)
|
2017-05-24 03:56:26 +00:00
|
|
|
defer cli.Close()
|
2017-10-11 18:23:55 +00:00
|
|
|
|
|
|
|
// d1 will eventually step down from leader because there is no longer an active quorum, wait for that to happen
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
|
2018-12-22 14:53:02 +00:00
|
|
|
_, err := cli.ServiceCreate(context.Background(), service.Spec, types.ServiceCreateOptions{})
|
2017-10-11 18:23:55 +00:00
|
|
|
return err.Error(), nil
|
|
|
|
}, checker.Contains, "Make sure more than half of the managers are online.")
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2018-10-25 18:47:56 +00:00
|
|
|
d2.StartNode(c)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2016-07-27 01:32:56 +00:00
|
|
|
// make sure there is a leader
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckLeader, checker.IsNil)
|
2016-07-27 01:32:56 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
d1.CreateService(c, simpleTestService, func(s *swarm.Service) {
|
2016-06-14 02:54:20 +00:00
|
|
|
s.Spec.Name = "top3"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmLeaveRemovesContainer(c *check.C) {
|
2016-06-14 02:54:20 +00:00
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
instances := 2
|
2016-12-09 09:17:53 +00:00
|
|
|
d.CreateService(c, simpleTestService, setInstances(instances))
|
2016-06-14 02:54:20 +00:00
|
|
|
|
|
|
|
id, err := d.Cmd("run", "-d", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, id)
|
2016-06-14 02:54:20 +00:00
|
|
|
id = strings.TrimSpace(id)
|
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances+1)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, d.SwarmLeave(c, false), "")
|
|
|
|
assert.NilError(c, d.SwarmLeave(c, true))
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
|
|
|
id2, err := d.Cmd("ps", "-q")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, id2)
|
|
|
|
assert.Assert(c, strings.HasPrefix(id, strings.TrimSpace(id2)))
|
2016-06-14 02:54:20 +00:00
|
|
|
}
|
|
|
|
|
2016-06-16 23:08:15 +00:00
|
|
|
// #23629
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmLeaveOnPendingJoin(c *check.C) {
|
2016-10-11 22:17:20 +00:00
|
|
|
testRequires(c, Network)
|
2016-06-16 23:08:15 +00:00
|
|
|
s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, false, false)
|
|
|
|
|
|
|
|
id, err := d2.Cmd("run", "-d", "busybox", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, id)
|
2016-06-16 23:08:15 +00:00
|
|
|
id = strings.TrimSpace(id)
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
c2 := d2.NewClientT(c)
|
|
|
|
err = c2.SwarmJoin(context.Background(), swarm.JoinRequest{
|
|
|
|
ListenAddr: d2.SwarmListenAddr(),
|
2016-08-02 17:53:33 +00:00
|
|
|
RemoteAddrs: []string{"123.123.123.123:1234"},
|
2016-07-01 01:07:35 +00:00
|
|
|
})
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "Timeout was reached")
|
2016-06-16 23:08:15 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
info := d2.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStatePending)
|
2016-08-02 17:53:33 +00:00
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, d2.SwarmLeave(c, true))
|
2016-06-16 23:08:15 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 1)
|
2016-06-16 23:08:15 +00:00
|
|
|
|
|
|
|
id2, err := d2.Cmd("ps", "-q")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, id2)
|
|
|
|
assert.Assert(c, strings.HasPrefix(id, strings.TrimSpace(id2)))
|
2016-06-16 23:08:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-19 02:43:47 +00:00
|
|
|
// #23705
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmRestoreOnPendingJoin(c *check.C) {
|
2016-10-11 22:17:20 +00:00
|
|
|
testRequires(c, Network)
|
2016-06-19 02:43:47 +00:00
|
|
|
d := s.AddDaemon(c, false, false)
|
2018-04-11 10:10:17 +00:00
|
|
|
client := d.NewClientT(c)
|
|
|
|
err := client.SwarmJoin(context.Background(), swarm.JoinRequest{
|
|
|
|
ListenAddr: d.SwarmListenAddr(),
|
2016-08-02 17:53:33 +00:00
|
|
|
RemoteAddrs: []string{"123.123.123.123:1234"},
|
2016-07-01 01:07:35 +00:00
|
|
|
})
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "Timeout was reached")
|
2016-06-19 02:43:47 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckLocalNodeState, checker.Equals, swarm.LocalNodeStatePending)
|
2016-06-19 02:43:47 +00:00
|
|
|
|
2018-10-25 18:47:56 +00:00
|
|
|
d.RestartNode(c)
|
2016-06-19 02:43:47 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
info := d.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
|
2016-06-19 02:43:47 +00:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmManagerRestore(c *check.C) {
|
2016-06-14 02:54:20 +00:00
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
instances := 2
|
2016-12-09 09:17:53 +00:00
|
|
|
id := d1.CreateService(c, simpleTestService, setInstances(instances))
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
d1.GetService(c, id)
|
2018-10-25 18:47:56 +00:00
|
|
|
d1.RestartNode(c)
|
2016-12-09 09:17:53 +00:00
|
|
|
d1.GetService(c, id)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
|
|
|
d2 := s.AddDaemon(c, true, true)
|
2016-12-09 09:17:53 +00:00
|
|
|
d2.GetService(c, id)
|
2018-10-25 18:47:56 +00:00
|
|
|
d2.RestartNode(c)
|
2016-12-09 09:17:53 +00:00
|
|
|
d2.GetService(c, id)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
|
|
|
d3 := s.AddDaemon(c, true, true)
|
2016-12-09 09:17:53 +00:00
|
|
|
d3.GetService(c, id)
|
2018-10-25 18:47:56 +00:00
|
|
|
d3.RestartNode(c)
|
2016-12-09 09:17:53 +00:00
|
|
|
d3.GetService(c, id)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2019-01-13 20:11:50 +00:00
|
|
|
err := d3.Kill()
|
|
|
|
assert.NilError(c, err)
|
2016-06-14 02:54:20 +00:00
|
|
|
time.Sleep(1 * time.Second) // time to handle signal
|
2018-10-25 18:47:56 +00:00
|
|
|
d3.StartNode(c)
|
2016-12-09 09:17:53 +00:00
|
|
|
d3.GetService(c, id)
|
2016-06-14 02:54:20 +00:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmScaleNoRollingUpdate(c *check.C) {
|
2016-06-14 02:54:20 +00:00
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
instances := 2
|
2016-12-09 09:17:53 +00:00
|
|
|
id := d.CreateService(c, simpleTestService, setInstances(instances))
|
2016-06-14 02:54:20 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
2018-04-11 13:52:13 +00:00
|
|
|
containers := d.ActiveContainers(c)
|
2016-06-14 02:54:20 +00:00
|
|
|
instances = 4
|
2016-12-09 09:17:53 +00:00
|
|
|
d.UpdateService(c, d.GetService(c, id), setInstances(instances))
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
2018-04-11 13:52:13 +00:00
|
|
|
containers2 := d.ActiveContainers(c)
|
2016-06-14 02:54:20 +00:00
|
|
|
|
|
|
|
loop0:
|
|
|
|
for _, c1 := range containers {
|
|
|
|
for _, c2 := range containers2 {
|
|
|
|
if c1 == c2 {
|
|
|
|
continue loop0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.Errorf("container %v not found in new set %#v", c1, containers2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmInvalidAddress(c *check.C) {
|
2016-06-21 21:27:04 +00:00
|
|
|
d := s.AddDaemon(c, false, false)
|
|
|
|
req := swarm.InitRequest{
|
|
|
|
ListenAddr: "",
|
|
|
|
}
|
2018-04-17 08:22:04 +00:00
|
|
|
res, _, err := request.Post("/swarm/init", request.Host(d.Sock()), request.JSONBody(req))
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
|
2016-06-21 21:27:04 +00:00
|
|
|
|
|
|
|
req2 := swarm.JoinRequest{
|
|
|
|
ListenAddr: "0.0.0.0:2377",
|
|
|
|
RemoteAddrs: []string{""},
|
|
|
|
}
|
2018-04-17 08:22:04 +00:00
|
|
|
res, _, err = request.Post("/swarm/join", request.Host(d.Sock()), request.JSONBody(req2))
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
|
2016-06-21 21:27:04 +00:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *check.C) {
|
2016-06-20 23:36:13 +00:00
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
instances := 2
|
2016-12-09 09:17:53 +00:00
|
|
|
id := d1.CreateService(c, simpleTestService, setInstances(instances))
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances)
|
2016-06-20 23:36:13 +00:00
|
|
|
|
2016-07-29 16:57:28 +00:00
|
|
|
// drain d2, all containers should move to d1
|
2018-04-11 10:10:17 +00:00
|
|
|
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
2016-07-29 16:57:28 +00:00
|
|
|
n.Spec.Availability = swarm.NodeAvailabilityDrain
|
|
|
|
})
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 0)
|
2016-06-20 23:36:13 +00:00
|
|
|
|
2016-12-09 22:20:14 +00:00
|
|
|
d2.Stop(c)
|
2016-06-20 23:36:13 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
d1.SwarmInit(c, swarm.InitRequest{
|
2016-06-20 23:36:13 +00:00
|
|
|
ForceNewCluster: true,
|
2016-07-20 18:15:08 +00:00
|
|
|
Spec: swarm.Spec{},
|
2018-04-11 10:10:17 +00:00
|
|
|
})
|
2016-06-20 23:36:13 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances)
|
2016-06-20 23:36:13 +00:00
|
|
|
|
|
|
|
d3 := s.AddDaemon(c, true, true)
|
2018-04-11 10:10:17 +00:00
|
|
|
info := d3.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.ControlAvailable, true)
|
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
2016-06-20 23:36:13 +00:00
|
|
|
|
|
|
|
instances = 4
|
2016-12-09 09:17:53 +00:00
|
|
|
d3.UpdateService(c, d3.GetService(c, id), setInstances(instances))
|
2016-06-20 23:36:13 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
2016-06-20 23:36:13 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 02:54:20 +00:00
|
|
|
func simpleTestService(s *swarm.Service) {
|
2016-07-26 18:49:46 +00:00
|
|
|
ureplicas := uint64(1)
|
|
|
|
restartDelay := time.Duration(100 * time.Millisecond)
|
|
|
|
|
2016-06-14 02:54:20 +00:00
|
|
|
s.Spec = swarm.ServiceSpec{
|
|
|
|
TaskTemplate: swarm.TaskSpec{
|
2017-06-07 17:07:01 +00:00
|
|
|
ContainerSpec: &swarm.ContainerSpec{
|
2016-06-14 02:54:20 +00:00
|
|
|
Image: "busybox:latest",
|
|
|
|
Command: []string{"/bin/top"},
|
|
|
|
},
|
2016-07-26 18:49:46 +00:00
|
|
|
RestartPolicy: &swarm.RestartPolicy{
|
|
|
|
Delay: &restartDelay,
|
|
|
|
},
|
2016-06-14 02:54:20 +00:00
|
|
|
},
|
|
|
|
Mode: swarm.ServiceMode{
|
|
|
|
Replicated: &swarm.ReplicatedService{
|
|
|
|
Replicas: &ureplicas,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
s.Spec.Name = "top"
|
|
|
|
}
|
|
|
|
|
2016-07-12 00:15:30 +00:00
|
|
|
func serviceForUpdate(s *swarm.Service) {
|
2016-07-26 18:49:46 +00:00
|
|
|
ureplicas := uint64(1)
|
|
|
|
restartDelay := time.Duration(100 * time.Millisecond)
|
|
|
|
|
2016-07-12 00:15:30 +00:00
|
|
|
s.Spec = swarm.ServiceSpec{
|
|
|
|
TaskTemplate: swarm.TaskSpec{
|
2017-06-07 17:07:01 +00:00
|
|
|
ContainerSpec: &swarm.ContainerSpec{
|
2016-07-12 00:15:30 +00:00
|
|
|
Image: "busybox:latest",
|
|
|
|
Command: []string{"/bin/top"},
|
|
|
|
},
|
2016-07-26 18:49:46 +00:00
|
|
|
RestartPolicy: &swarm.RestartPolicy{
|
|
|
|
Delay: &restartDelay,
|
|
|
|
},
|
2016-07-12 00:15:30 +00:00
|
|
|
},
|
|
|
|
Mode: swarm.ServiceMode{
|
|
|
|
Replicated: &swarm.ReplicatedService{
|
|
|
|
Replicas: &ureplicas,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
UpdateConfig: &swarm.UpdateConfig{
|
2016-07-22 18:35:51 +00:00
|
|
|
Parallelism: 2,
|
2016-07-26 18:49:46 +00:00
|
|
|
Delay: 4 * time.Second,
|
2016-07-22 18:35:51 +00:00
|
|
|
FailureAction: swarm.UpdateFailureActionContinue,
|
2016-07-12 00:15:30 +00:00
|
|
|
},
|
2017-02-16 17:27:01 +00:00
|
|
|
RollbackConfig: &swarm.UpdateConfig{
|
|
|
|
Parallelism: 3,
|
|
|
|
Delay: 4 * time.Second,
|
|
|
|
FailureAction: swarm.UpdateFailureActionContinue,
|
|
|
|
},
|
2016-07-12 00:15:30 +00:00
|
|
|
}
|
|
|
|
s.Spec.Name = "updatetest"
|
|
|
|
}
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
func setInstances(replicas int) testdaemon.ServiceConstructor {
|
2016-06-14 02:54:20 +00:00
|
|
|
ureplicas := uint64(replicas)
|
|
|
|
return func(s *swarm.Service) {
|
|
|
|
s.Spec.Mode = swarm.ServiceMode{
|
|
|
|
Replicated: &swarm.ReplicatedService{
|
|
|
|
Replicas: &ureplicas,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
func setUpdateOrder(order string) testdaemon.ServiceConstructor {
|
2017-01-18 22:16:47 +00:00
|
|
|
return func(s *swarm.Service) {
|
|
|
|
if s.Spec.UpdateConfig == nil {
|
|
|
|
s.Spec.UpdateConfig = &swarm.UpdateConfig{}
|
|
|
|
}
|
|
|
|
s.Spec.UpdateConfig.Order = order
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
func setRollbackOrder(order string) testdaemon.ServiceConstructor {
|
2017-01-18 22:16:47 +00:00
|
|
|
return func(s *swarm.Service) {
|
|
|
|
if s.Spec.RollbackConfig == nil {
|
|
|
|
s.Spec.RollbackConfig = &swarm.UpdateConfig{}
|
|
|
|
}
|
|
|
|
s.Spec.RollbackConfig.Order = order
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
func setImage(image string) testdaemon.ServiceConstructor {
|
2016-07-12 00:15:30 +00:00
|
|
|
return func(s *swarm.Service) {
|
2017-06-07 17:07:01 +00:00
|
|
|
if s.Spec.TaskTemplate.ContainerSpec == nil {
|
|
|
|
s.Spec.TaskTemplate.ContainerSpec = &swarm.ContainerSpec{}
|
|
|
|
}
|
2016-07-12 00:15:30 +00:00
|
|
|
s.Spec.TaskTemplate.ContainerSpec.Image = image
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
func setFailureAction(failureAction string) testdaemon.ServiceConstructor {
|
2016-09-02 21:12:05 +00:00
|
|
|
return func(s *swarm.Service) {
|
|
|
|
s.Spec.UpdateConfig.FailureAction = failureAction
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
func setMaxFailureRatio(maxFailureRatio float32) testdaemon.ServiceConstructor {
|
2016-09-02 21:12:05 +00:00
|
|
|
return func(s *swarm.Service) {
|
|
|
|
s.Spec.UpdateConfig.MaxFailureRatio = maxFailureRatio
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
func setParallelism(parallelism uint64) testdaemon.ServiceConstructor {
|
2016-09-02 21:12:05 +00:00
|
|
|
return func(s *swarm.Service) {
|
|
|
|
s.Spec.UpdateConfig.Parallelism = parallelism
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
func setConstraints(constraints []string) testdaemon.ServiceConstructor {
|
2016-07-21 02:16:19 +00:00
|
|
|
return func(s *swarm.Service) {
|
|
|
|
if s.Spec.TaskTemplate.Placement == nil {
|
|
|
|
s.Spec.TaskTemplate.Placement = &swarm.Placement{}
|
|
|
|
}
|
|
|
|
s.Spec.TaskTemplate.Placement.Constraints = constraints
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
func setPlacementPrefs(prefs []swarm.PlacementPreference) testdaemon.ServiceConstructor {
|
2017-01-19 23:27:37 +00:00
|
|
|
return func(s *swarm.Service) {
|
|
|
|
if s.Spec.TaskTemplate.Placement == nil {
|
|
|
|
s.Spec.TaskTemplate.Placement = &swarm.Placement{}
|
|
|
|
}
|
|
|
|
s.Spec.TaskTemplate.Placement.Preferences = prefs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-14 02:54:20 +00:00
|
|
|
func setGlobalMode(s *swarm.Service) {
|
|
|
|
s.Spec.Mode = swarm.ServiceMode{
|
|
|
|
Global: &swarm.GlobalService{},
|
|
|
|
}
|
|
|
|
}
|
2016-07-08 21:54:18 +00:00
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
func checkClusterHealth(c *check.C, cl []*daemon.Daemon, managerCount, workerCount int) {
|
2016-07-08 21:54:18 +00:00
|
|
|
var totalMCount, totalWCount int
|
2016-07-26 15:44:46 +00:00
|
|
|
|
2016-07-08 21:54:18 +00:00
|
|
|
for _, d := range cl {
|
2016-07-26 15:44:46 +00:00
|
|
|
var (
|
|
|
|
info swarm.Info
|
|
|
|
)
|
|
|
|
|
|
|
|
// check info in a waitAndAssert, because if the cluster doesn't have a leader, `info` will return an error
|
|
|
|
checkInfo := func(c *check.C) (interface{}, check.CommentInterface) {
|
2018-04-11 10:10:17 +00:00
|
|
|
client := d.NewClientT(c)
|
|
|
|
daemonInfo, err := client.Info(context.Background())
|
|
|
|
info = daemonInfo.Swarm
|
2016-07-26 15:44:46 +00:00
|
|
|
return err, check.Commentf("cluster not ready in time")
|
|
|
|
}
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, checkInfo, checker.IsNil)
|
2016-07-08 21:54:18 +00:00
|
|
|
if !info.ControlAvailable {
|
|
|
|
totalWCount++
|
|
|
|
continue
|
|
|
|
}
|
2016-07-26 15:44:46 +00:00
|
|
|
|
2016-07-08 21:54:18 +00:00
|
|
|
var leaderFound bool
|
|
|
|
totalMCount++
|
|
|
|
var mCount, wCount int
|
2016-07-26 15:44:46 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
for _, n := range d.ListNodes(c) {
|
2016-07-26 15:44:46 +00:00
|
|
|
waitReady := func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
if n.Status.State == swarm.NodeStateReady {
|
|
|
|
return true, nil
|
|
|
|
}
|
2016-12-09 09:17:53 +00:00
|
|
|
nn := d.GetNode(c, n.ID)
|
2016-07-26 15:44:46 +00:00
|
|
|
n = *nn
|
2018-04-11 10:10:17 +00:00
|
|
|
return n.Status.State == swarm.NodeStateReady, check.Commentf("state of node %s, reported by %s", n.ID, d.NodeID())
|
2016-07-26 15:44:46 +00:00
|
|
|
}
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, waitReady, checker.True)
|
|
|
|
|
|
|
|
waitActive := func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
if n.Spec.Availability == swarm.NodeAvailabilityActive {
|
|
|
|
return true, nil
|
|
|
|
}
|
2016-12-09 09:17:53 +00:00
|
|
|
nn := d.GetNode(c, n.ID)
|
2016-07-26 15:44:46 +00:00
|
|
|
n = *nn
|
2018-04-11 10:10:17 +00:00
|
|
|
return n.Spec.Availability == swarm.NodeAvailabilityActive, check.Commentf("availability of node %s, reported by %s", n.ID, d.NodeID())
|
2016-07-26 15:44:46 +00:00
|
|
|
}
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, waitActive, checker.True)
|
|
|
|
|
2016-07-08 21:54:18 +00:00
|
|
|
if n.Spec.Role == swarm.NodeRoleManager {
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Assert(c, n.ManagerStatus != nil, "manager status of node %s (manager), reported by %s", n.ID, d.NodeID())
|
2016-07-08 21:54:18 +00:00
|
|
|
if n.ManagerStatus.Leader {
|
|
|
|
leaderFound = true
|
|
|
|
}
|
|
|
|
mCount++
|
|
|
|
} else {
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Assert(c, n.ManagerStatus == nil, "manager status of node %s (worker), reported by %s", n.ID, d.NodeID())
|
2016-07-08 21:54:18 +00:00
|
|
|
wCount++
|
|
|
|
}
|
|
|
|
}
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, leaderFound, true, "lack of leader reported by node %s", info.NodeID)
|
|
|
|
assert.Equal(c, mCount, managerCount, "managers count reported by node %s", info.NodeID)
|
|
|
|
assert.Equal(c, wCount, workerCount, "workers count reported by node %s", info.NodeID)
|
2016-07-08 21:54:18 +00:00
|
|
|
}
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, totalMCount, managerCount)
|
|
|
|
assert.Equal(c, totalWCount, workerCount)
|
2016-07-08 21:54:18 +00:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmRestartCluster(c *check.C) {
|
2016-07-08 21:54:18 +00:00
|
|
|
mCount, wCount := 5, 1
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
var nodes []*daemon.Daemon
|
2016-07-08 21:54:18 +00:00
|
|
|
for i := 0; i < mCount; i++ {
|
|
|
|
manager := s.AddDaemon(c, true, true)
|
2018-04-11 10:10:17 +00:00
|
|
|
info := manager.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.ControlAvailable, true)
|
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
2016-07-08 21:54:18 +00:00
|
|
|
nodes = append(nodes, manager)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < wCount; i++ {
|
|
|
|
worker := s.AddDaemon(c, true, false)
|
2018-04-11 10:10:17 +00:00
|
|
|
info := worker.SwarmInfo(c)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.ControlAvailable, false)
|
|
|
|
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
|
2016-07-08 21:54:18 +00:00
|
|
|
nodes = append(nodes, worker)
|
|
|
|
}
|
|
|
|
|
|
|
|
// stop whole cluster
|
|
|
|
{
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(len(nodes))
|
|
|
|
errs := make(chan error, len(nodes))
|
|
|
|
|
|
|
|
for _, d := range nodes {
|
2018-04-11 10:10:17 +00:00
|
|
|
go func(daemon *daemon.Daemon) {
|
2016-07-08 21:54:18 +00:00
|
|
|
defer wg.Done()
|
2016-12-09 22:20:14 +00:00
|
|
|
if err := daemon.StopWithError(); err != nil {
|
2016-07-08 21:54:18 +00:00
|
|
|
errs <- err
|
|
|
|
}
|
|
|
|
}(d)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
close(errs)
|
|
|
|
for err := range errs {
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-07-08 21:54:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// start whole cluster
|
|
|
|
{
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(len(nodes))
|
|
|
|
errs := make(chan error, len(nodes))
|
|
|
|
|
|
|
|
for _, d := range nodes {
|
2018-04-11 10:10:17 +00:00
|
|
|
go func(daemon *daemon.Daemon) {
|
2016-07-08 21:54:18 +00:00
|
|
|
defer wg.Done()
|
2016-12-09 22:20:14 +00:00
|
|
|
if err := daemon.StartWithError("--iptables=false"); err != nil {
|
2016-07-08 21:54:18 +00:00
|
|
|
errs <- err
|
|
|
|
}
|
|
|
|
}(d)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
close(errs)
|
|
|
|
for err := range errs {
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-07-08 21:54:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkClusterHealth(c, nodes, mCount, wCount)
|
|
|
|
}
|
2016-08-29 04:15:03 +00:00
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateWithName(c *check.C) {
|
2016-08-29 04:15:03 +00:00
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
instances := 2
|
2016-12-09 09:17:53 +00:00
|
|
|
id := d.CreateService(c, simpleTestService, setInstances(instances))
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
2016-08-29 04:15:03 +00:00
|
|
|
|
2016-12-09 09:17:53 +00:00
|
|
|
service := d.GetService(c, id)
|
2016-08-29 04:15:03 +00:00
|
|
|
instances = 5
|
|
|
|
|
|
|
|
setInstances(instances)(service)
|
2018-12-22 14:53:02 +00:00
|
|
|
cli := d.NewClientT(c)
|
2017-05-24 03:56:26 +00:00
|
|
|
defer cli.Close()
|
2018-12-22 14:53:02 +00:00
|
|
|
_, err := cli.ServiceUpdate(context.Background(), service.Spec.Name, service.Version, service.Spec, types.ServiceUpdateOptions{})
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-12-09 09:17:53 +00:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
2016-08-29 04:15:03 +00:00
|
|
|
}
|
2016-10-26 20:30:53 +00:00
|
|
|
|
2016-12-16 02:36:37 +00:00
|
|
|
// Unlocking an unlocked swarm results in an error
|
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmUnlockNotLocked(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
2019-02-06 23:33:07 +00:00
|
|
|
err := d.SwarmUnlock(c, swarm.UnlockRequest{UnlockKey: "wrong-key"})
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "swarm is not locked")
|
2016-12-16 02:36:37 +00:00
|
|
|
}
|
2017-01-05 23:46:07 +00:00
|
|
|
|
|
|
|
// #29885
|
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmErrorHandling(c *check.C) {
|
|
|
|
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", defaultSwarmPort))
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2017-01-05 23:46:07 +00:00
|
|
|
defer ln.Close()
|
|
|
|
d := s.AddDaemon(c, false, false)
|
2018-04-11 10:10:17 +00:00
|
|
|
client := d.NewClientT(c)
|
|
|
|
_, err = client.SwarmInit(context.Background(), swarm.InitRequest{
|
|
|
|
ListenAddr: d.SwarmListenAddr(),
|
|
|
|
})
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "address already in use")
|
2017-01-05 23:46:07 +00:00
|
|
|
}
|
2017-01-18 15:48:09 +00:00
|
|
|
|
|
|
|
// Test case for 30242, where duplicate networks, with different drivers `bridge` and `overlay`,
|
|
|
|
// caused both scopes to be `swarm` for `docker network inspect` and `docker network ls`.
|
|
|
|
// This test makes sure the fixes correctly output scopes instead.
|
|
|
|
func (s *DockerSwarmSuite) TestAPIDuplicateNetworks(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
2018-12-22 14:53:02 +00:00
|
|
|
cli := d.NewClientT(c)
|
2017-05-24 03:56:26 +00:00
|
|
|
defer cli.Close()
|
2017-01-18 15:48:09 +00:00
|
|
|
|
|
|
|
name := "foo"
|
2017-05-24 03:56:26 +00:00
|
|
|
networkCreate := types.NetworkCreate{
|
|
|
|
CheckDuplicate: false,
|
2017-01-18 15:48:09 +00:00
|
|
|
}
|
|
|
|
|
2017-05-24 03:56:26 +00:00
|
|
|
networkCreate.Driver = "bridge"
|
2017-01-18 15:48:09 +00:00
|
|
|
|
2017-05-24 03:56:26 +00:00
|
|
|
n1, err := cli.NetworkCreate(context.Background(), name, networkCreate)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2017-01-18 15:48:09 +00:00
|
|
|
|
2017-05-24 03:56:26 +00:00
|
|
|
networkCreate.Driver = "overlay"
|
2017-01-18 15:48:09 +00:00
|
|
|
|
2017-05-24 03:56:26 +00:00
|
|
|
n2, err := cli.NetworkCreate(context.Background(), name, networkCreate)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2017-01-18 15:48:09 +00:00
|
|
|
|
2017-05-24 03:56:26 +00:00
|
|
|
r1, err := cli.NetworkInspect(context.Background(), n1.ID, types.NetworkInspectOptions{})
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, r1.Scope, "local")
|
2017-01-18 15:48:09 +00:00
|
|
|
|
2017-05-24 03:56:26 +00:00
|
|
|
r2, err := cli.NetworkInspect(context.Background(), n2.ID, types.NetworkInspectOptions{})
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, r2.Scope, "swarm")
|
2017-01-18 15:48:09 +00:00
|
|
|
}
|
2017-01-17 05:53:31 +00:00
|
|
|
|
|
|
|
// Test case for 30178
|
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmHealthcheckNone(c *check.C) {
|
2018-02-27 06:49:30 +00:00
|
|
|
// Issue #36386 can be a independent one, which is worth further investigation.
|
|
|
|
c.Skip("Root cause of Issue #36386 is needed")
|
2017-01-17 05:53:31 +00:00
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
out, err := d.Cmd("network", "create", "-d", "overlay", "lb")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-01-17 05:53:31 +00:00
|
|
|
|
|
|
|
instances := 1
|
|
|
|
d.CreateService(c, simpleTestService, setInstances(instances), func(s *swarm.Service) {
|
2017-06-07 17:07:01 +00:00
|
|
|
if s.Spec.TaskTemplate.ContainerSpec == nil {
|
|
|
|
s.Spec.TaskTemplate.ContainerSpec = &swarm.ContainerSpec{}
|
|
|
|
}
|
2017-01-17 05:53:31 +00:00
|
|
|
s.Spec.TaskTemplate.ContainerSpec.Healthcheck = &container.HealthConfig{}
|
|
|
|
s.Spec.TaskTemplate.Networks = []swarm.NetworkAttachmentConfig{
|
|
|
|
{Target: "lb"},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
|
|
|
|
2018-04-11 13:52:13 +00:00
|
|
|
containers := d.ActiveContainers(c)
|
2017-01-17 05:53:31 +00:00
|
|
|
|
|
|
|
out, err = d.Cmd("exec", containers[0], "ping", "-c1", "-W3", "top")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err, out)
|
2017-01-17 05:53:31 +00:00
|
|
|
}
|
2017-05-09 00:14:34 +00:00
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestSwarmRepeatedRootRotation(c *check.C) {
|
|
|
|
m := s.AddDaemon(c, true, true)
|
|
|
|
w := s.AddDaemon(c, true, false)
|
|
|
|
|
2018-04-11 10:10:17 +00:00
|
|
|
info := m.SwarmInfo(c)
|
2017-05-09 00:14:34 +00:00
|
|
|
|
|
|
|
currentTrustRoot := info.Cluster.TLSInfo.TrustRoot
|
|
|
|
|
|
|
|
// rotate multiple times
|
|
|
|
for i := 0; i < 4; i++ {
|
2018-04-11 10:10:17 +00:00
|
|
|
var err error
|
2017-05-09 00:14:34 +00:00
|
|
|
var cert, key []byte
|
|
|
|
if i%2 != 0 {
|
|
|
|
cert, _, key, err = initca.New(&csr.CertificateRequest{
|
|
|
|
CN: "newRoot",
|
|
|
|
KeyRequest: csr.NewBasicKeyRequest(),
|
|
|
|
CA: &csr.CAConfig{Expiry: ca.RootCAExpiration},
|
|
|
|
})
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2017-05-09 00:14:34 +00:00
|
|
|
}
|
|
|
|
expectedCert := string(cert)
|
|
|
|
m.UpdateSwarm(c, func(s *swarm.Spec) {
|
|
|
|
s.CAConfig.SigningCACert = expectedCert
|
|
|
|
s.CAConfig.SigningCAKey = string(key)
|
|
|
|
s.CAConfig.ForceRotate++
|
|
|
|
})
|
|
|
|
|
|
|
|
// poll to make sure update succeeds
|
|
|
|
var clusterTLSInfo swarm.TLSInfo
|
|
|
|
for j := 0; j < 18; j++ {
|
2018-04-11 10:10:17 +00:00
|
|
|
info := m.SwarmInfo(c)
|
2017-06-16 01:11:14 +00:00
|
|
|
|
|
|
|
// the desired CA cert and key is always redacted
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, info.Cluster.Spec.CAConfig.SigningCAKey, "")
|
|
|
|
assert.Equal(c, info.Cluster.Spec.CAConfig.SigningCACert, "")
|
2017-05-09 00:14:34 +00:00
|
|
|
|
|
|
|
clusterTLSInfo = info.Cluster.TLSInfo
|
|
|
|
|
2017-06-16 01:11:14 +00:00
|
|
|
// if root rotation is done and the trust root has changed, we don't have to poll anymore
|
|
|
|
if !info.Cluster.RootRotationInProgress && clusterTLSInfo.TrustRoot != currentTrustRoot {
|
2017-05-09 00:14:34 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// root rotation not done
|
|
|
|
time.Sleep(250 * time.Millisecond)
|
|
|
|
}
|
|
|
|
if cert != nil {
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, clusterTLSInfo.TrustRoot, expectedCert)
|
2017-05-09 00:14:34 +00:00
|
|
|
}
|
2017-05-21 23:24:07 +00:00
|
|
|
// could take another second or two for the nodes to trust the new roots after they've all gotten
|
2017-05-09 00:14:34 +00:00
|
|
|
// new TLS certificates
|
|
|
|
for j := 0; j < 18; j++ {
|
2018-04-11 10:10:17 +00:00
|
|
|
mInfo := m.GetNode(c, m.NodeID()).Description.TLSInfo
|
|
|
|
wInfo := m.GetNode(c, w.NodeID()).Description.TLSInfo
|
2017-05-09 00:14:34 +00:00
|
|
|
|
|
|
|
if mInfo.TrustRoot == clusterTLSInfo.TrustRoot && wInfo.TrustRoot == clusterTLSInfo.TrustRoot {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// nodes don't trust root certs yet
|
|
|
|
time.Sleep(250 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.DeepEqual(c, m.GetNode(c, m.NodeID()).Description.TLSInfo, clusterTLSInfo)
|
|
|
|
assert.DeepEqual(c, m.GetNode(c, w.NodeID()).Description.TLSInfo, clusterTLSInfo)
|
2017-05-09 00:14:34 +00:00
|
|
|
currentTrustRoot = clusterTLSInfo.TrustRoot
|
|
|
|
}
|
|
|
|
}
|
2017-06-11 18:04:35 +00:00
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestAPINetworkInspectWithScope(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
2017-09-19 20:12:29 +00:00
|
|
|
name := "test-scoped-network"
|
|
|
|
ctx := context.Background()
|
2018-12-22 14:53:02 +00:00
|
|
|
apiclient := d.NewClientT(c)
|
2017-06-11 18:04:35 +00:00
|
|
|
|
2017-09-19 20:12:29 +00:00
|
|
|
resp, err := apiclient.NetworkCreate(ctx, name, types.NetworkCreate{Driver: "overlay"})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(c, err)
|
2017-06-11 18:04:35 +00:00
|
|
|
|
2017-09-19 20:12:29 +00:00
|
|
|
network, err := apiclient.NetworkInspect(ctx, name, types.NetworkInspectOptions{})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Check(c, is.Equal("swarm", network.Scope))
|
|
|
|
assert.Check(c, is.Equal(resp.ID, network.ID))
|
2017-06-11 18:04:35 +00:00
|
|
|
|
2017-09-19 20:12:29 +00:00
|
|
|
_, err = apiclient.NetworkInspect(ctx, name, types.NetworkInspectOptions{Scope: "local"})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Check(c, client.IsErrNotFound(err))
|
2017-06-11 18:04:35 +00:00
|
|
|
}
|