2016-06-13 22:54:20 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-07-08 15:01:58 -04:00
|
|
|
"fmt"
|
2016-06-13 22:54:20 -04:00
|
|
|
"net/http"
|
2016-07-08 17:54:18 -04:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-06-13 22:54:20 -04:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2016-07-08 17:54:18 -04:00
|
|
|
"sync"
|
2016-06-13 22:54:20 -04:00
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2016-12-09 04:17:53 -05:00
|
|
|
"github.com/docker/docker/integration-cli/daemon"
|
2016-06-13 22:54:20 -04:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmInit(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
// todo: should find a better way to verify that components are running than /info
|
|
|
|
d1 := s.AddDaemon(c, true, true)
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err := d1.SwarmInfo()
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-08 17:17:32 -04:00
|
|
|
c.Assert(info.ControlAvailable, checker.True)
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
|
|
|
|
|
|
|
|
d2 := s.AddDaemon(c, true, false)
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err = d2.SwarmInfo()
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-08 17:17:32 -04:00
|
|
|
c.Assert(info.ControlAvailable, checker.False)
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
|
|
|
|
|
|
|
|
// Leaving cluster
|
|
|
|
c.Assert(d2.Leave(false), checker.IsNil)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err = d2.SwarmInfo()
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-08 17:17:32 -04:00
|
|
|
c.Assert(info.ControlAvailable, checker.False)
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
c.Assert(d2.Join(swarm.JoinRequest{JoinToken: d1.JoinTokens(c).Worker, RemoteAddrs: []string{d1.ListenAddr}}), checker.IsNil)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err = d2.SwarmInfo()
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-08 17:17:32 -04:00
|
|
|
c.Assert(info.ControlAvailable, checker.False)
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
|
|
|
|
|
|
|
|
// Current state restoring after restarts
|
|
|
|
err = d1.Stop()
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
err = d2.Stop()
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
err = d1.Start()
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
err = d2.Start()
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err = d1.SwarmInfo()
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-08 17:17:32 -04:00
|
|
|
c.Assert(info.ControlAvailable, checker.True)
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err = d2.SwarmInfo()
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-08 17:17:32 -04:00
|
|
|
c.Assert(info.ControlAvailable, checker.False)
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
|
|
|
|
}
|
|
|
|
|
[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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmJoinToken(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
d1 := s.AddDaemon(c, false, false)
|
2016-07-20 14:15:08 -04:00
|
|
|
c.Assert(d1.Init(swarm.InitRequest{}), checker.IsNil)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-11-16 17:17:18 -05:00
|
|
|
// todo: error message differs depending if some components of token are valid
|
|
|
|
|
2016-06-13 22:54:20 -04:00
|
|
|
d2 := s.AddDaemon(c, false, false)
|
2016-12-09 04:17:53 -05:00
|
|
|
err := d2.Join(swarm.JoinRequest{RemoteAddrs: []string{d1.ListenAddr}})
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.NotNil)
|
2016-07-20 14:15:08 -04:00
|
|
|
c.Assert(err.Error(), checker.Contains, "join token is necessary")
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err := d2.SwarmInfo()
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
err = d2.Join(swarm.JoinRequest{JoinToken: "foobaz", RemoteAddrs: []string{d1.ListenAddr}})
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.NotNil)
|
2016-11-16 17:17:18 -05:00
|
|
|
c.Assert(err.Error(), checker.Contains, "invalid join token")
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err = d2.SwarmInfo()
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
workerToken := d1.JoinTokens(c).Worker
|
2016-07-20 14:15:08 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
c.Assert(d2.Join(swarm.JoinRequest{JoinToken: workerToken, RemoteAddrs: []string{d1.ListenAddr}}), checker.IsNil)
|
|
|
|
info, err = d2.SwarmInfo()
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
|
|
|
|
c.Assert(d2.Leave(false), checker.IsNil)
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err = d2.SwarmInfo()
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive)
|
2016-06-16 15:12:38 -04:00
|
|
|
|
2016-07-20 14:15:08 -04:00
|
|
|
// change tokens
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.RotateTokens(c)
|
2016-06-16 15:12:38 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
err = d2.Join(swarm.JoinRequest{JoinToken: workerToken, RemoteAddrs: []string{d1.ListenAddr}})
|
2016-06-16 15:12:38 -04:00
|
|
|
c.Assert(err, checker.NotNil)
|
2016-07-20 14:15:08 -04:00
|
|
|
c.Assert(err.Error(), checker.Contains, "join token is necessary")
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err = d2.SwarmInfo()
|
2016-06-16 15:12:38 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
workerToken = d1.JoinTokens(c).Worker
|
2016-07-20 14:15:08 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
c.Assert(d2.Join(swarm.JoinRequest{JoinToken: workerToken, RemoteAddrs: []string{d1.ListenAddr}}), checker.IsNil)
|
|
|
|
info, err = d2.SwarmInfo()
|
2016-06-16 15:12:38 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
|
|
|
|
c.Assert(d2.Leave(false), checker.IsNil)
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err = d2.SwarmInfo()
|
2016-06-16 15:12:38 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive)
|
|
|
|
|
2016-07-20 14:15:08 -04:00
|
|
|
// change spec, don't change tokens
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.UpdateSwarm(c, func(s *swarm.Spec) {})
|
2016-06-16 15:12:38 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
err = d2.Join(swarm.JoinRequest{RemoteAddrs: []string{d1.ListenAddr}})
|
2016-06-16 15:12:38 -04:00
|
|
|
c.Assert(err, checker.NotNil)
|
2016-07-20 14:15:08 -04:00
|
|
|
c.Assert(err.Error(), checker.Contains, "join token is necessary")
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err = d2.SwarmInfo()
|
2016-06-16 15:12:38 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
c.Assert(d2.Join(swarm.JoinRequest{JoinToken: workerToken, RemoteAddrs: []string{d1.ListenAddr}}), checker.IsNil)
|
|
|
|
info, err = d2.SwarmInfo()
|
2016-06-16 15:12:38 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
|
|
|
|
c.Assert(d2.Leave(false), checker.IsNil)
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err = d2.SwarmInfo()
|
2016-06-16 15:12:38 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive)
|
2016-06-13 22:54:20 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmCAHash(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, false, false)
|
2016-12-09 04:17:53 -05:00
|
|
|
splitToken := strings.Split(d1.JoinTokens(c).Worker, "-")
|
2016-07-20 14:15:08 -04:00
|
|
|
splitToken[2] = "1kxftv4ofnc6mt30lmgipg6ngf9luhwqopfk1tz6bdmnkubg0e"
|
|
|
|
replacementToken := strings.Join(splitToken, "-")
|
2016-12-09 04:17:53 -05:00
|
|
|
err := d2.Join(swarm.JoinRequest{JoinToken: replacementToken, RemoteAddrs: []string{d1.ListenAddr}})
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.NotNil)
|
2016-07-20 14:15:08 -04:00
|
|
|
c.Assert(err.Error(), checker.Contains, "remote CA does not match fingerprint")
|
2016-06-13 22:54:20 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
d1 := s.AddDaemon(c, false, false)
|
2016-07-20 14:15:08 -04:00
|
|
|
c.Assert(d1.Init(swarm.InitRequest{}), checker.IsNil)
|
2016-06-13 22:54:20 -04:00
|
|
|
d2 := s.AddDaemon(c, true, false)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err := d2.SwarmInfo()
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-08 17:17:32 -04:00
|
|
|
c.Assert(info.ControlAvailable, checker.False)
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.UpdateNode(c, d2.NodeID, func(n *swarm.Node) {
|
2016-06-13 22:54:20 -04:00
|
|
|
n.Spec.Role = swarm.NodeRoleManager
|
|
|
|
})
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckControlAvailable, checker.True)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.UpdateNode(c, d2.NodeID, func(n *swarm.Node) {
|
2016-06-13 22:54:20 -04:00
|
|
|
n.Spec.Role = swarm.NodeRoleWorker
|
|
|
|
})
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckControlAvailable, checker.False)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-07-08 15:01:58 -04:00
|
|
|
// Demoting last node should fail
|
2016-12-09 04:17:53 -05:00
|
|
|
node := d1.GetNode(c, d1.NodeID)
|
2016-07-08 15:01:58 -04:00
|
|
|
node.Spec.Role = swarm.NodeRoleWorker
|
|
|
|
url := fmt.Sprintf("/nodes/%s/update?version=%d", node.ID, node.Version.Index)
|
|
|
|
status, out, err := d1.SockRequest("POST", url, node.Spec)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusInternalServerError, check.Commentf("output: %q", string(out)))
|
|
|
|
c.Assert(string(out), checker.Contains, "last manager of the swarm")
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err = d1.SwarmInfo()
|
2016-07-08 15:01:58 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
|
2016-07-08 17:17:32 -04:00
|
|
|
c.Assert(info.ControlAvailable, checker.True)
|
2016-07-08 15:01:58 -04:00
|
|
|
|
|
|
|
// Promote already demoted node
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.UpdateNode(c, d2.NodeID, func(n *swarm.Node) {
|
2016-07-08 15:01:58 -04:00
|
|
|
n.Spec.Role = swarm.NodeRoleManager
|
|
|
|
})
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckControlAvailable, checker.True)
|
2016-06-13 22:54:20 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmServicesEmptyList(c *check.C) {
|
2016-07-12 11:31:44 -04:00
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
services := d.ListServices(c)
|
2016-07-12 11:31:44 -04:00
|
|
|
c.Assert(services, checker.NotNil)
|
|
|
|
c.Assert(len(services), checker.Equals, 0, check.Commentf("services: %#v", services))
|
|
|
|
}
|
|
|
|
|
[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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmServicesCreate(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
instances := 2
|
2016-12-09 04:17:53 -05:00
|
|
|
id := d.CreateService(c, simpleTestService, setInstances(instances))
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
service := d.GetService(c, id)
|
2016-06-13 22:54:20 -04:00
|
|
|
instances = 5
|
2016-12-09 04:17:53 -05:00
|
|
|
d.UpdateService(c, service, setInstances(instances))
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d.RemoveService(c, service.ID)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 0)
|
2016-06-13 22:54:20 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmServicesMultipleAgents(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, false)
|
|
|
|
d3 := s.AddDaemon(c, true, false)
|
|
|
|
|
|
|
|
time.Sleep(1 * time.Second) // make sure all daemons are ready to accept tasks
|
|
|
|
|
|
|
|
instances := 9
|
2016-12-09 04:17:53 -05:00
|
|
|
id := d1.CreateService(c, simpleTestService, setInstances(instances))
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.GreaterThan, 0)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.GreaterThan, 0)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d3.CheckActiveContainerCount, checker.GreaterThan, 0)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
// reconciliation on d2 node down
|
|
|
|
c.Assert(d2.Stop(), checker.IsNil)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
// test downscaling
|
|
|
|
instances = 5
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
2016-06-13 22:54:20 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmServicesCreateGlobal(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, false)
|
|
|
|
d3 := s.AddDaemon(c, true, false)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.CreateService(c, simpleTestService, setGlobalMode)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, 1)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 1)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d3.CheckActiveContainerCount, checker.Equals, 1)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
d4 := s.AddDaemon(c, true, false)
|
|
|
|
d5 := s.AddDaemon(c, true, false)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d4.CheckActiveContainerCount, checker.Equals, 1)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d5.CheckActiveContainerCount, checker.Equals, 1)
|
2016-06-13 22:54:20 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *check.C) {
|
2016-07-11 20:15:30 -04:00
|
|
|
const nodeCount = 3
|
2016-12-09 04:17:53 -05:00
|
|
|
var daemons [nodeCount]*daemon.Swarm
|
2016-07-11 20:15:30 -04:00
|
|
|
for i := 0; i < nodeCount; i++ {
|
|
|
|
daemons[i] = s.AddDaemon(c, true, i == 0)
|
|
|
|
}
|
|
|
|
// wait for nodes ready
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount)
|
2016-07-11 20:15:30 -04:00
|
|
|
|
|
|
|
// service image at start
|
|
|
|
image1 := "busybox:latest"
|
|
|
|
// target image in update
|
|
|
|
image2 := "busybox:test"
|
|
|
|
|
|
|
|
// create a different tag
|
|
|
|
for _, d := range daemons {
|
|
|
|
out, err := d.Cmd("tag", image1, image2)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
}
|
|
|
|
|
|
|
|
// create service
|
|
|
|
instances := 5
|
|
|
|
parallelism := 2
|
2016-12-09 04:17:53 -05:00
|
|
|
id := daemons[0].CreateService(c, serviceForUpdate, setInstances(instances))
|
2016-07-11 20:15:30 -04:00
|
|
|
|
|
|
|
// wait for tasks ready
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
2016-07-11 20:15:30 -04:00
|
|
|
map[string]int{image1: instances})
|
|
|
|
|
|
|
|
// issue service update
|
2016-12-09 04:17:53 -05:00
|
|
|
service := daemons[0].GetService(c, id)
|
|
|
|
daemons[0].UpdateService(c, service, setImage(image2))
|
2016-07-11 20:15:30 -04:00
|
|
|
|
|
|
|
// first batch
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
2016-07-11 20:15:30 -04:00
|
|
|
map[string]int{image1: instances - parallelism, image2: parallelism})
|
|
|
|
|
|
|
|
// 2nd batch
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
2016-07-11 20:15:30 -04:00
|
|
|
map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})
|
|
|
|
|
|
|
|
// 3nd batch
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
2016-07-11 20:15:30 -04:00
|
|
|
map[string]int{image2: instances})
|
2016-09-02 17:12:05 -04:00
|
|
|
|
|
|
|
// Roll back to the previous version. This uses the CLI because
|
|
|
|
// rollback is a client-side operation.
|
|
|
|
out, err := daemons[0].Cmd("service", "update", "--rollback", id)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
|
|
|
// first batch
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
2016-09-02 17:12:05 -04:00
|
|
|
map[string]int{image2: instances - parallelism, image1: parallelism})
|
|
|
|
|
|
|
|
// 2nd batch
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
2016-09-02 17:12:05 -04:00
|
|
|
map[string]int{image2: instances - 2*parallelism, image1: 2 * parallelism})
|
|
|
|
|
|
|
|
// 3nd batch
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
2016-09-02 17:12:05 -04:00
|
|
|
map[string]int{image1: instances})
|
|
|
|
}
|
|
|
|
|
2016-10-24 19:45:17 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *check.C) {
|
2016-09-02 17:12:05 -04:00
|
|
|
const nodeCount = 3
|
2016-12-09 04:17:53 -05:00
|
|
|
var daemons [nodeCount]*daemon.Swarm
|
2016-09-02 17:12:05 -04:00
|
|
|
for i := 0; i < nodeCount; i++ {
|
|
|
|
daemons[i] = s.AddDaemon(c, true, i == 0)
|
|
|
|
}
|
|
|
|
// wait for nodes ready
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount)
|
2016-09-02 17:12:05 -04:00
|
|
|
|
|
|
|
// service image at start
|
|
|
|
image1 := "busybox:latest"
|
|
|
|
// target image in update
|
|
|
|
image2 := "busybox:badtag"
|
|
|
|
|
|
|
|
// create service
|
|
|
|
instances := 5
|
2016-12-09 04:17:53 -05:00
|
|
|
id := daemons[0].CreateService(c, serviceForUpdate, setInstances(instances))
|
2016-09-02 17:12:05 -04:00
|
|
|
|
|
|
|
// wait for tasks ready
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
2016-09-02 17:12:05 -04:00
|
|
|
map[string]int{image1: instances})
|
|
|
|
|
|
|
|
// issue service update
|
2016-12-09 04:17:53 -05:00
|
|
|
service := daemons[0].GetService(c, id)
|
|
|
|
daemons[0].UpdateService(c, service, setImage(image2), setFailureAction(swarm.UpdateFailureActionPause), setMaxFailureRatio(0.25), setParallelism(1))
|
2016-09-02 17:12:05 -04:00
|
|
|
|
|
|
|
// should update 2 tasks and then pause
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceUpdateState(id), checker.Equals, swarm.UpdateStatePaused)
|
|
|
|
v, _ := daemons[0].CheckServiceRunningTasks(id)(c)
|
2016-09-02 17:12:05 -04:00
|
|
|
c.Assert(v, checker.Equals, instances-2)
|
|
|
|
|
|
|
|
// Roll back to the previous version. This uses the CLI because
|
|
|
|
// rollback is a client-side operation.
|
|
|
|
out, err := daemons[0].Cmd("service", "update", "--rollback", id)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckRunningTaskImages, checker.DeepEquals,
|
2016-09-02 17:12:05 -04:00
|
|
|
map[string]int{image1: instances})
|
2016-07-11 20:15:30 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *check.C) {
|
2016-07-20 22:16:19 -04:00
|
|
|
const nodeCount = 3
|
2016-12-09 04:17:53 -05:00
|
|
|
var daemons [nodeCount]*daemon.Swarm
|
2016-07-20 22:16:19 -04:00
|
|
|
for i := 0; i < nodeCount; i++ {
|
|
|
|
daemons[i] = s.AddDaemon(c, true, i == 0)
|
|
|
|
}
|
|
|
|
// wait for nodes ready
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount)
|
2016-07-20 22:16:19 -04:00
|
|
|
|
|
|
|
// create service
|
|
|
|
constraints := []string{"node.role==worker"}
|
|
|
|
instances := 3
|
2016-12-09 04:17:53 -05:00
|
|
|
id := daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
2016-07-20 22:16:19 -04:00
|
|
|
// wait for tasks ready
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances)
|
2016-07-20 22:16:19 -04:00
|
|
|
// validate tasks are running on worker nodes
|
2016-12-09 04:17:53 -05:00
|
|
|
tasks := daemons[0].GetServiceTasks(c, id)
|
2016-07-20 22:16:19 -04:00
|
|
|
for _, task := range tasks {
|
2016-12-09 04:17:53 -05:00
|
|
|
node := daemons[0].GetNode(c, task.NodeID)
|
2016-07-20 22:16:19 -04:00
|
|
|
c.Assert(node.Spec.Role, checker.Equals, swarm.NodeRoleWorker)
|
|
|
|
}
|
|
|
|
//remove service
|
2016-12-09 04:17:53 -05:00
|
|
|
daemons[0].RemoveService(c, id)
|
2016-07-20 22:16:19 -04:00
|
|
|
|
|
|
|
// create service
|
|
|
|
constraints = []string{"node.role!=worker"}
|
2016-12-09 04:17:53 -05:00
|
|
|
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
2016-07-20 22:16:19 -04:00
|
|
|
// wait for tasks ready
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances)
|
|
|
|
tasks = daemons[0].GetServiceTasks(c, id)
|
2016-07-20 22:16:19 -04:00
|
|
|
// validate tasks are running on manager nodes
|
|
|
|
for _, task := range tasks {
|
2016-12-09 04:17:53 -05:00
|
|
|
node := daemons[0].GetNode(c, task.NodeID)
|
2016-07-20 22:16:19 -04:00
|
|
|
c.Assert(node.Spec.Role, checker.Equals, swarm.NodeRoleManager)
|
|
|
|
}
|
|
|
|
//remove service
|
2016-12-09 04:17:53 -05:00
|
|
|
daemons[0].RemoveService(c, id)
|
2016-07-20 22:16:19 -04:00
|
|
|
|
|
|
|
// create service
|
|
|
|
constraints = []string{"node.role==nosuchrole"}
|
2016-12-09 04:17:53 -05:00
|
|
|
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
2016-07-20 22:16:19 -04:00
|
|
|
// wait for tasks created
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceTasks(id), checker.Equals, instances)
|
2016-07-20 22:16:19 -04:00
|
|
|
// let scheduler try
|
|
|
|
time.Sleep(250 * time.Millisecond)
|
|
|
|
// validate tasks are not assigned to any node
|
2016-12-09 04:17:53 -05:00
|
|
|
tasks = daemons[0].GetServiceTasks(c, id)
|
2016-07-20 22:16:19 -04:00
|
|
|
for _, task := range tasks {
|
|
|
|
c.Assert(task.NodeID, checker.Equals, "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *check.C) {
|
2016-07-20 22:16:19 -04:00
|
|
|
const nodeCount = 3
|
2016-12-09 04:17:53 -05:00
|
|
|
var daemons [nodeCount]*daemon.Swarm
|
2016-07-20 22:16:19 -04:00
|
|
|
for i := 0; i < nodeCount; i++ {
|
|
|
|
daemons[i] = s.AddDaemon(c, true, i == 0)
|
|
|
|
}
|
|
|
|
// wait for nodes ready
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, 5*time.Second, daemons[0].CheckNodeReadyCount, checker.Equals, nodeCount)
|
|
|
|
nodes := daemons[0].ListNodes(c)
|
2016-07-20 22:16:19 -04:00
|
|
|
c.Assert(len(nodes), checker.Equals, nodeCount)
|
|
|
|
|
|
|
|
// add labels to nodes
|
2016-12-09 04:17:53 -05:00
|
|
|
daemons[0].UpdateNode(c, nodes[0].ID, func(n *swarm.Node) {
|
2016-07-20 22:16:19 -04:00
|
|
|
n.Spec.Annotations.Labels = map[string]string{
|
|
|
|
"security": "high",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
for i := 1; i < nodeCount; i++ {
|
2016-12-09 04:17:53 -05:00
|
|
|
daemons[0].UpdateNode(c, nodes[i].ID, func(n *swarm.Node) {
|
2016-07-20 22:16:19 -04:00
|
|
|
n.Spec.Annotations.Labels = map[string]string{
|
|
|
|
"security": "low",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// create service
|
|
|
|
instances := 3
|
|
|
|
constraints := []string{"node.labels.security==high"}
|
2016-12-09 04:17:53 -05:00
|
|
|
id := daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
2016-07-20 22:16:19 -04:00
|
|
|
// wait for tasks ready
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances)
|
|
|
|
tasks := daemons[0].GetServiceTasks(c, id)
|
2016-07-20 22:16:19 -04:00
|
|
|
// validate all tasks are running on nodes[0]
|
|
|
|
for _, task := range tasks {
|
|
|
|
c.Assert(task.NodeID, checker.Equals, nodes[0].ID)
|
|
|
|
}
|
|
|
|
//remove service
|
2016-12-09 04:17:53 -05:00
|
|
|
daemons[0].RemoveService(c, id)
|
2016-07-20 22:16:19 -04:00
|
|
|
|
|
|
|
// create service
|
|
|
|
constraints = []string{"node.labels.security!=high"}
|
2016-12-09 04:17:53 -05:00
|
|
|
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
2016-07-20 22:16:19 -04:00
|
|
|
// wait for tasks ready
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances)
|
|
|
|
tasks = daemons[0].GetServiceTasks(c, id)
|
2016-07-20 22:16:19 -04:00
|
|
|
// validate all tasks are NOT running on nodes[0]
|
|
|
|
for _, task := range tasks {
|
|
|
|
c.Assert(task.NodeID, checker.Not(checker.Equals), nodes[0].ID)
|
|
|
|
}
|
|
|
|
//remove service
|
2016-12-09 04:17:53 -05:00
|
|
|
daemons[0].RemoveService(c, id)
|
2016-07-20 22:16:19 -04:00
|
|
|
|
|
|
|
constraints = []string{"node.labels.security==medium"}
|
2016-12-09 04:17:53 -05:00
|
|
|
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
2016-07-20 22:16:19 -04:00
|
|
|
// wait for tasks created
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceTasks(id), checker.Equals, instances)
|
2016-07-20 22:16:19 -04:00
|
|
|
// let scheduler try
|
|
|
|
time.Sleep(250 * time.Millisecond)
|
2016-12-09 04:17:53 -05:00
|
|
|
tasks = daemons[0].GetServiceTasks(c, id)
|
2016-07-20 22:16:19 -04:00
|
|
|
// validate tasks are not assigned
|
|
|
|
for _, task := range tasks {
|
|
|
|
c.Assert(task.NodeID, checker.Equals, "")
|
|
|
|
}
|
|
|
|
//remove service
|
2016-12-09 04:17:53 -05:00
|
|
|
daemons[0].RemoveService(c, id)
|
2016-07-20 22:16:19 -04:00
|
|
|
|
|
|
|
// multiple constraints
|
|
|
|
constraints = []string{
|
|
|
|
"node.labels.security==high",
|
|
|
|
fmt.Sprintf("node.id==%s", nodes[1].ID),
|
|
|
|
}
|
2016-12-09 04:17:53 -05:00
|
|
|
id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))
|
2016-07-20 22:16:19 -04:00
|
|
|
// wait for tasks created
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceTasks(id), checker.Equals, instances)
|
2016-07-20 22:16:19 -04:00
|
|
|
// let scheduler try
|
|
|
|
time.Sleep(250 * time.Millisecond)
|
2016-12-09 04:17:53 -05:00
|
|
|
tasks = daemons[0].GetServiceTasks(c, id)
|
2016-07-20 22:16:19 -04:00
|
|
|
// validate tasks are not assigned
|
|
|
|
for _, task := range tasks {
|
|
|
|
c.Assert(task.NodeID, checker.Equals, "")
|
|
|
|
}
|
|
|
|
// make nodes[1] fulfills the constraints
|
2016-12-09 04:17:53 -05:00
|
|
|
daemons[0].UpdateNode(c, nodes[1].ID, func(n *swarm.Node) {
|
2016-07-20 22:16:19 -04:00
|
|
|
n.Spec.Annotations.Labels = map[string]string{
|
|
|
|
"security": "high",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// wait for tasks ready
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, daemons[0].CheckServiceRunningTasks(id), checker.Equals, instances)
|
|
|
|
tasks = daemons[0].GetServiceTasks(c, id)
|
2016-07-20 22:16:19 -04:00
|
|
|
for _, task := range tasks {
|
|
|
|
c.Assert(task.NodeID, checker.Equals, nodes[1].ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmServicesStateReporting(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
testRequires(c, SameHostDaemon)
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, true)
|
|
|
|
d3 := s.AddDaemon(c, true, false)
|
|
|
|
|
|
|
|
time.Sleep(1 * time.Second) // make sure all daemons are ready to accept
|
|
|
|
|
|
|
|
instances := 9
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.CreateService(c, simpleTestService, setInstances(instances))
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
getContainers := func() map[string]*daemon.Swarm {
|
|
|
|
m := make(map[string]*daemon.Swarm)
|
|
|
|
for _, d := range []*daemon.Swarm{d1, d2, d3} {
|
|
|
|
for _, id := range d.ActiveContainers() {
|
2016-06-13 22:54:20 -04:00
|
|
|
m[id] = d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
containers := getContainers()
|
|
|
|
c.Assert(containers, checker.HasLen, instances)
|
|
|
|
var toRemove string
|
|
|
|
for i := range containers {
|
|
|
|
toRemove = i
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := containers[toRemove].Cmd("stop", toRemove)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
containers2 := getContainers()
|
|
|
|
c.Assert(containers2, checker.HasLen, instances)
|
|
|
|
for i := range containers {
|
|
|
|
if i == toRemove {
|
|
|
|
c.Assert(containers2[i], checker.IsNil)
|
|
|
|
} else {
|
|
|
|
c.Assert(containers2[i], checker.NotNil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
containers = containers2
|
|
|
|
for i := range containers {
|
|
|
|
toRemove = i
|
|
|
|
}
|
|
|
|
|
|
|
|
// try with killing process outside of docker
|
|
|
|
pidStr, err := containers[toRemove].Cmd("inspect", "-f", "{{.State.Pid}}", toRemove)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
pid, err := strconv.Atoi(strings.TrimSpace(pidStr))
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(syscall.Kill(pid, syscall.SIGKILL), checker.IsNil)
|
|
|
|
|
|
|
|
time.Sleep(time.Second) // give some time to handle the signal
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
containers2 = getContainers()
|
|
|
|
c.Assert(containers2, checker.HasLen, instances)
|
|
|
|
for i := range containers {
|
|
|
|
if i == toRemove {
|
|
|
|
c.Assert(containers2[i], checker.IsNil)
|
|
|
|
} else {
|
|
|
|
c.Assert(containers2[i], checker.NotNil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmLeaderProxy(c *check.C) {
|
2016-07-15 16:28:09 -04: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 04:17:53 -05:00
|
|
|
d1.CreateService(c, simpleTestService, func(s *swarm.Service) {
|
2016-07-15 16:28:09 -04:00
|
|
|
s.Spec.Name = "test1"
|
|
|
|
})
|
2016-12-09 04:17:53 -05:00
|
|
|
d2.CreateService(c, simpleTestService, func(s *swarm.Service) {
|
2016-07-15 16:28:09 -04:00
|
|
|
s.Spec.Name = "test2"
|
|
|
|
})
|
2016-12-09 04:17:53 -05:00
|
|
|
d3.CreateService(c, simpleTestService, func(s *swarm.Service) {
|
2016-07-15 16:28:09 -04: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
|
2016-12-09 04:17:53 -05:00
|
|
|
for _, d := range []*daemon.Swarm{d1, d2, d3} {
|
|
|
|
services := d.ListServices(c)
|
2016-07-15 16:28:09 -04:00
|
|
|
c.Assert(services, checker.HasLen, 3)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *check.C) {
|
2016-07-18 19:31:43 -04: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
|
2016-12-09 04:17:53 -05:00
|
|
|
c.Assert(d1.GetNode(c, d1.NodeID).ManagerStatus.Leader, checker.True)
|
|
|
|
c.Assert(d1.GetNode(c, d2.NodeID).ManagerStatus.Leader, checker.False)
|
|
|
|
c.Assert(d1.GetNode(c, d3.NodeID).ManagerStatus.Leader, checker.False)
|
2016-07-18 19:31:43 -04:00
|
|
|
|
2016-07-26 22:11:17 -04:00
|
|
|
d1.Stop() // stop the leader
|
|
|
|
|
|
|
|
var (
|
2016-12-09 04:17:53 -05:00
|
|
|
leader *daemon.Swarm // keep track of leader
|
|
|
|
followers []*daemon.Swarm // keep track of followers
|
2016-07-26 22:11:17 -04:00
|
|
|
)
|
2016-12-09 04:17:53 -05:00
|
|
|
checkLeader := func(nodes ...*daemon.Swarm) checkF {
|
2016-07-26 22:11:17 -04:00
|
|
|
return func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
// clear these out before each run
|
|
|
|
leader = nil
|
|
|
|
followers = nil
|
|
|
|
for _, d := range nodes {
|
2016-12-09 04:17:53 -05:00
|
|
|
if d.GetNode(c, d.NodeID).ManagerStatus.Leader {
|
2016-07-26 22:11:17 -04:00
|
|
|
leader = d
|
|
|
|
} else {
|
|
|
|
followers = append(followers, d)
|
|
|
|
}
|
|
|
|
}
|
2016-07-18 19:31:43 -04:00
|
|
|
|
2016-07-26 22:11:17 -04:00
|
|
|
if leader == nil {
|
|
|
|
return false, check.Commentf("no leader elected")
|
|
|
|
}
|
2016-07-18 19:31:43 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
return true, check.Commentf("elected %v", leader.ID())
|
2016-07-18 19:31:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-26 22:11:17 -04:00
|
|
|
// wait for an election to occur
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, checkLeader(d2, d3), checker.True)
|
|
|
|
|
2016-07-18 19:31:43 -04:00
|
|
|
// assert that we have a new leader
|
2016-07-26 22:11:17 -04:00
|
|
|
c.Assert(leader, checker.NotNil)
|
|
|
|
|
|
|
|
// Keep track of the current leader, since we want that to be chosen.
|
|
|
|
stableleader := leader
|
2016-07-18 19:31:43 -04:00
|
|
|
|
2016-07-26 22:11:17 -04:00
|
|
|
// add the d1, the initial leader, back
|
|
|
|
d1.Start()
|
2016-07-18 19:31:43 -04:00
|
|
|
|
2016-07-26 22:11:17 -04:00
|
|
|
// TODO(stevvooe): may need to wait for rejoin here
|
2016-07-18 19:31:43 -04:00
|
|
|
|
2016-07-26 22:11:17 -04:00
|
|
|
// wait for possible election
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, checkLeader(d1, d2, d3), checker.True)
|
2016-07-18 19:31:43 -04:00
|
|
|
// pick out the leader and the followers again
|
|
|
|
|
|
|
|
// verify that we still only have 1 leader and 2 followers
|
|
|
|
c.Assert(leader, checker.NotNil)
|
|
|
|
c.Assert(followers, checker.HasLen, 2)
|
|
|
|
// and that after we added d1 back, the leader hasn't changed
|
2016-07-26 22:11:17 -04:00
|
|
|
c.Assert(leader.NodeID, checker.Equals, stableleader.NodeID)
|
2016-07-18 19:31:43 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, true)
|
|
|
|
d3 := s.AddDaemon(c, true, true)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.CreateService(c, simpleTestService)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
c.Assert(d2.Stop(), checker.IsNil)
|
|
|
|
|
2016-07-26 21:32:56 -04:00
|
|
|
// make sure there is a leader
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckLeader, checker.IsNil)
|
2016-07-26 21:32:56 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.CreateService(c, simpleTestService, func(s *swarm.Service) {
|
2016-06-13 22:54:20 -04:00
|
|
|
s.Spec.Name = "top1"
|
|
|
|
})
|
|
|
|
|
|
|
|
c.Assert(d3.Stop(), checker.IsNil)
|
|
|
|
|
2016-07-26 21:32:56 -04:00
|
|
|
// make sure there is a leader
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckLeader, checker.IsNil)
|
2016-07-26 21:32:56 -04:00
|
|
|
|
2016-06-13 22:54:20 -04:00
|
|
|
var service swarm.Service
|
|
|
|
simpleTestService(&service)
|
|
|
|
service.Spec.Name = "top2"
|
|
|
|
status, out, err := d1.SockRequest("POST", "/services/create", service.Spec)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusInternalServerError, check.Commentf("deadline exceeded", string(out)))
|
|
|
|
|
|
|
|
c.Assert(d2.Start(), checker.IsNil)
|
|
|
|
|
2016-07-26 21:32:56 -04:00
|
|
|
// make sure there is a leader
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckLeader, checker.IsNil)
|
2016-07-26 21:32:56 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.CreateService(c, simpleTestService, func(s *swarm.Service) {
|
2016-06-13 22:54:20 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmListNodes(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, false)
|
|
|
|
d3 := s.AddDaemon(c, true, false)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
nodes := d1.ListNodes(c)
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(len(nodes), checker.Equals, 3, check.Commentf("nodes: %#v", nodes))
|
|
|
|
|
|
|
|
loop0:
|
|
|
|
for _, n := range nodes {
|
2016-12-09 04:17:53 -05:00
|
|
|
for _, d := range []*daemon.Swarm{d1, d2, d3} {
|
2016-06-13 22:54:20 -04:00
|
|
|
if n.ID == d.NodeID {
|
|
|
|
continue loop0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.Errorf("unknown nodeID %v", n.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmNodeUpdate(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
nodes := d.ListNodes(c)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d.UpdateNode(c, nodes[0].ID, func(n *swarm.Node) {
|
2016-06-13 22:54:20 -04:00
|
|
|
n.Spec.Availability = swarm.NodeAvailabilityPause
|
|
|
|
})
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
n := d.GetNode(c, nodes[0].ID)
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(n.Spec.Availability, checker.Equals, swarm.NodeAvailabilityPause)
|
|
|
|
}
|
|
|
|
|
[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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *check.C) {
|
2016-07-28 00:17:00 -04:00
|
|
|
testRequires(c, Network)
|
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, false)
|
|
|
|
_ = s.AddDaemon(c, true, false)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
nodes := d1.ListNodes(c)
|
2016-07-28 00:17:00 -04:00
|
|
|
c.Assert(len(nodes), checker.Equals, 3, check.Commentf("nodes: %#v", nodes))
|
|
|
|
|
|
|
|
// Getting the info so we can take the NodeID
|
2016-12-09 04:17:53 -05:00
|
|
|
d2Info, err := d2.SwarmInfo()
|
2016-07-28 00:17:00 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
// forceful removal of d2 should work
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.RemoveNode(c, d2Info.NodeID, true)
|
2016-07-28 00:17:00 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
nodes = d1.ListNodes(c)
|
2016-07-28 00:17:00 -04:00
|
|
|
c.Assert(len(nodes), checker.Equals, 2, check.Commentf("nodes: %#v", nodes))
|
|
|
|
|
|
|
|
// Restart the node that was removed
|
|
|
|
err = d2.Restart()
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
// Give some time for the node to rejoin
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
|
|
|
// Make sure the node didn't rejoin
|
2016-12-09 04:17:53 -05:00
|
|
|
nodes = d1.ListNodes(c)
|
2016-07-28 00:17:00 -04:00
|
|
|
c.Assert(len(nodes), checker.Equals, 2, check.Commentf("nodes: %#v", nodes))
|
|
|
|
}
|
|
|
|
|
[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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, false)
|
|
|
|
|
|
|
|
time.Sleep(1 * time.Second) // make sure all daemons are ready to accept tasks
|
|
|
|
|
|
|
|
// start a service, expect balanced distribution
|
|
|
|
instances := 8
|
2016-12-09 04:17:53 -05:00
|
|
|
id := d1.CreateService(c, simpleTestService, setInstances(instances))
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.GreaterThan, 0)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.GreaterThan, 0)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
// drain d2, all containers should move to d1
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.UpdateNode(c, d2.NodeID, func(n *swarm.Node) {
|
2016-06-13 22:54:20 -04:00
|
|
|
n.Spec.Availability = swarm.NodeAvailabilityDrain
|
|
|
|
})
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 0)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
// set d2 back to active
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.UpdateNode(c, d2.NodeID, func(n *swarm.Node) {
|
2016-06-13 22:54:20 -04:00
|
|
|
n.Spec.Availability = swarm.NodeAvailabilityActive
|
|
|
|
})
|
|
|
|
|
2016-06-14 20:03:46 -04:00
|
|
|
instances = 1
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
|
2016-06-14 20:03:46 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout*2, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances)
|
2016-06-14 20:03:46 -04:00
|
|
|
|
|
|
|
instances = 8
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
// drained node first so we don't get any old containers
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.GreaterThan, 0)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.GreaterThan, 0)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout*2, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d2ContainerCount := len(d2.ActiveContainers())
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
// set d2 to paused, scale service up, only d1 gets new tasks
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.UpdateNode(c, d2.NodeID, func(n *swarm.Node) {
|
2016-06-13 22:54:20 -04:00
|
|
|
n.Spec.Availability = swarm.NodeAvailabilityPause
|
|
|
|
})
|
|
|
|
|
|
|
|
instances = 14
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances-d2ContainerCount)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, d2ContainerCount)
|
2016-06-13 22:54:20 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmLeaveRemovesContainer(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
instances := 2
|
2016-12-09 04:17:53 -05:00
|
|
|
d.CreateService(c, simpleTestService, setInstances(instances))
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
id, err := d.Cmd("run", "-d", "busybox", "top")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
id = strings.TrimSpace(id)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances+1)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
c.Assert(d.Leave(false), checker.NotNil)
|
|
|
|
c.Assert(d.Leave(true), checker.IsNil)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
id2, err := d.Cmd("ps", "-q")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(id, checker.HasPrefix, strings.TrimSpace(id2))
|
|
|
|
}
|
|
|
|
|
2016-06-16 19:08:15 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmLeaveOnPendingJoin(c *check.C) {
|
2016-10-11 18:17:20 -04:00
|
|
|
testRequires(c, Network)
|
2016-06-16 19:08:15 -04:00
|
|
|
s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, false, false)
|
|
|
|
|
|
|
|
id, err := d2.Cmd("run", "-d", "busybox", "top")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
id = strings.TrimSpace(id)
|
|
|
|
|
2016-08-02 13:53:33 -04:00
|
|
|
err = d2.Join(swarm.JoinRequest{
|
|
|
|
RemoteAddrs: []string{"123.123.123.123:1234"},
|
2016-06-30 21:07:35 -04:00
|
|
|
})
|
2016-08-02 13:53:33 -04:00
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
c.Assert(err.Error(), checker.Contains, "Timeout was reached")
|
2016-06-16 19:08:15 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err := d2.SwarmInfo()
|
2016-08-02 13:53:33 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStatePending)
|
|
|
|
|
|
|
|
c.Assert(d2.Leave(true), checker.IsNil)
|
2016-06-16 19:08:15 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 1)
|
2016-06-16 19:08:15 -04:00
|
|
|
|
|
|
|
id2, err := d2.Cmd("ps", "-q")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(id, checker.HasPrefix, strings.TrimSpace(id2))
|
|
|
|
}
|
|
|
|
|
2016-06-18 22:43:47 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmRestoreOnPendingJoin(c *check.C) {
|
2016-10-11 18:17:20 -04:00
|
|
|
testRequires(c, Network)
|
2016-06-18 22:43:47 -04:00
|
|
|
d := s.AddDaemon(c, false, false)
|
2016-08-02 13:53:33 -04:00
|
|
|
err := d.Join(swarm.JoinRequest{
|
|
|
|
RemoteAddrs: []string{"123.123.123.123:1234"},
|
2016-06-30 21:07:35 -04:00
|
|
|
})
|
2016-08-02 13:53:33 -04:00
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
c.Assert(err.Error(), checker.Contains, "Timeout was reached")
|
2016-06-18 22:43:47 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckLocalNodeState, checker.Equals, swarm.LocalNodeStatePending)
|
2016-06-18 22:43:47 -04:00
|
|
|
|
|
|
|
c.Assert(d.Stop(), checker.IsNil)
|
|
|
|
c.Assert(d.Start(), checker.IsNil)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err := d.SwarmInfo()
|
2016-06-18 22:43:47 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive)
|
|
|
|
}
|
|
|
|
|
[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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmManagerRestore(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
instances := 2
|
2016-12-09 04:17:53 -05:00
|
|
|
id := d1.CreateService(c, simpleTestService, setInstances(instances))
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.GetService(c, id)
|
2016-06-13 22:54:20 -04:00
|
|
|
d1.Stop()
|
|
|
|
d1.Start()
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.GetService(c, id)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
d2 := s.AddDaemon(c, true, true)
|
2016-12-09 04:17:53 -05:00
|
|
|
d2.GetService(c, id)
|
2016-06-13 22:54:20 -04:00
|
|
|
d2.Stop()
|
|
|
|
d2.Start()
|
2016-12-09 04:17:53 -05:00
|
|
|
d2.GetService(c, id)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
d3 := s.AddDaemon(c, true, true)
|
2016-12-09 04:17:53 -05:00
|
|
|
d3.GetService(c, id)
|
2016-06-13 22:54:20 -04:00
|
|
|
d3.Stop()
|
|
|
|
d3.Start()
|
2016-12-09 04:17:53 -05:00
|
|
|
d3.GetService(c, id)
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
d3.Kill()
|
|
|
|
time.Sleep(1 * time.Second) // time to handle signal
|
|
|
|
d3.Start()
|
2016-12-09 04:17:53 -05:00
|
|
|
d3.GetService(c, id)
|
2016-06-13 22:54:20 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmScaleNoRollingUpdate(c *check.C) {
|
2016-06-13 22:54:20 -04:00
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
instances := 2
|
2016-12-09 04:17:53 -05:00
|
|
|
id := d.CreateService(c, simpleTestService, setInstances(instances))
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
|
|
|
containers := d.ActiveContainers()
|
2016-06-13 22:54:20 -04:00
|
|
|
instances = 4
|
2016-12-09 04:17:53 -05:00
|
|
|
d.UpdateService(c, d.GetService(c, id), setInstances(instances))
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
|
|
|
containers2 := d.ActiveContainers()
|
2016-06-13 22:54:20 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmInvalidAddress(c *check.C) {
|
2016-06-21 17:27:04 -04:00
|
|
|
d := s.AddDaemon(c, false, false)
|
|
|
|
req := swarm.InitRequest{
|
|
|
|
ListenAddr: "",
|
|
|
|
}
|
|
|
|
status, _, err := d.SockRequest("POST", "/swarm/init", req)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusInternalServerError)
|
|
|
|
|
|
|
|
req2 := swarm.JoinRequest{
|
|
|
|
ListenAddr: "0.0.0.0:2377",
|
|
|
|
RemoteAddrs: []string{""},
|
|
|
|
}
|
|
|
|
status, _, err = d.SockRequest("POST", "/swarm/join", req2)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
|
[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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *check.C) {
|
2016-06-20 19:36:13 -04:00
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
instances := 2
|
2016-12-09 04:17:53 -05:00
|
|
|
id := d1.CreateService(c, simpleTestService, setInstances(instances))
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances)
|
2016-06-20 19:36:13 -04:00
|
|
|
|
2016-07-29 12:57:28 -04:00
|
|
|
// drain d2, all containers should move to d1
|
2016-12-09 04:17:53 -05:00
|
|
|
d1.UpdateNode(c, d2.NodeID, func(n *swarm.Node) {
|
2016-07-29 12:57:28 -04:00
|
|
|
n.Spec.Availability = swarm.NodeAvailabilityDrain
|
|
|
|
})
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 0)
|
2016-06-20 19:36:13 -04:00
|
|
|
|
2016-07-29 12:57:28 -04:00
|
|
|
c.Assert(d2.Stop(), checker.IsNil)
|
2016-06-20 19:36:13 -04:00
|
|
|
|
|
|
|
c.Assert(d1.Init(swarm.InitRequest{
|
|
|
|
ForceNewCluster: true,
|
2016-07-20 14:15:08 -04:00
|
|
|
Spec: swarm.Spec{},
|
2016-06-20 19:36:13 -04:00
|
|
|
}), checker.IsNil)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances)
|
2016-06-20 19:36:13 -04:00
|
|
|
|
|
|
|
d3 := s.AddDaemon(c, true, true)
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err := d3.SwarmInfo()
|
2016-06-20 19:36:13 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-08 17:17:32 -04:00
|
|
|
c.Assert(info.ControlAvailable, checker.True)
|
2016-06-20 19:36:13 -04:00
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
|
|
|
|
|
|
|
|
instances = 4
|
2016-12-09 04:17:53 -05:00
|
|
|
d3.UpdateService(c, d3.GetService(c, id), setInstances(instances))
|
2016-06-20 19:36:13 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d3.CheckActiveContainerCount), checker.Equals, instances)
|
2016-06-20 19:36:13 -04:00
|
|
|
}
|
|
|
|
|
2016-06-13 22:54:20 -04:00
|
|
|
func simpleTestService(s *swarm.Service) {
|
2016-07-26 14:49:46 -04:00
|
|
|
ureplicas := uint64(1)
|
|
|
|
restartDelay := time.Duration(100 * time.Millisecond)
|
|
|
|
|
2016-06-13 22:54:20 -04:00
|
|
|
s.Spec = swarm.ServiceSpec{
|
|
|
|
TaskTemplate: swarm.TaskSpec{
|
|
|
|
ContainerSpec: swarm.ContainerSpec{
|
|
|
|
Image: "busybox:latest",
|
|
|
|
Command: []string{"/bin/top"},
|
|
|
|
},
|
2016-07-26 14:49:46 -04:00
|
|
|
RestartPolicy: &swarm.RestartPolicy{
|
|
|
|
Delay: &restartDelay,
|
|
|
|
},
|
2016-06-13 22:54:20 -04:00
|
|
|
},
|
|
|
|
Mode: swarm.ServiceMode{
|
|
|
|
Replicated: &swarm.ReplicatedService{
|
|
|
|
Replicas: &ureplicas,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
s.Spec.Name = "top"
|
|
|
|
}
|
|
|
|
|
2016-07-11 20:15:30 -04:00
|
|
|
func serviceForUpdate(s *swarm.Service) {
|
2016-07-26 14:49:46 -04:00
|
|
|
ureplicas := uint64(1)
|
|
|
|
restartDelay := time.Duration(100 * time.Millisecond)
|
|
|
|
|
2016-07-11 20:15:30 -04:00
|
|
|
s.Spec = swarm.ServiceSpec{
|
|
|
|
TaskTemplate: swarm.TaskSpec{
|
|
|
|
ContainerSpec: swarm.ContainerSpec{
|
|
|
|
Image: "busybox:latest",
|
|
|
|
Command: []string{"/bin/top"},
|
|
|
|
},
|
2016-07-26 14:49:46 -04:00
|
|
|
RestartPolicy: &swarm.RestartPolicy{
|
|
|
|
Delay: &restartDelay,
|
|
|
|
},
|
2016-07-11 20:15:30 -04:00
|
|
|
},
|
|
|
|
Mode: swarm.ServiceMode{
|
|
|
|
Replicated: &swarm.ReplicatedService{
|
|
|
|
Replicas: &ureplicas,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
UpdateConfig: &swarm.UpdateConfig{
|
2016-07-22 14:35:51 -04:00
|
|
|
Parallelism: 2,
|
2016-07-26 14:49:46 -04:00
|
|
|
Delay: 4 * time.Second,
|
2016-07-22 14:35:51 -04:00
|
|
|
FailureAction: swarm.UpdateFailureActionContinue,
|
2016-07-11 20:15:30 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
s.Spec.Name = "updatetest"
|
|
|
|
}
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
func setInstances(replicas int) daemon.ServiceConstructor {
|
2016-06-13 22:54:20 -04:00
|
|
|
ureplicas := uint64(replicas)
|
|
|
|
return func(s *swarm.Service) {
|
|
|
|
s.Spec.Mode = swarm.ServiceMode{
|
|
|
|
Replicated: &swarm.ReplicatedService{
|
|
|
|
Replicas: &ureplicas,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
func setImage(image string) daemon.ServiceConstructor {
|
2016-07-11 20:15:30 -04:00
|
|
|
return func(s *swarm.Service) {
|
|
|
|
s.Spec.TaskTemplate.ContainerSpec.Image = image
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
func setFailureAction(failureAction string) daemon.ServiceConstructor {
|
2016-09-02 17:12:05 -04:00
|
|
|
return func(s *swarm.Service) {
|
|
|
|
s.Spec.UpdateConfig.FailureAction = failureAction
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
func setMaxFailureRatio(maxFailureRatio float32) daemon.ServiceConstructor {
|
2016-09-02 17:12:05 -04:00
|
|
|
return func(s *swarm.Service) {
|
|
|
|
s.Spec.UpdateConfig.MaxFailureRatio = maxFailureRatio
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
func setParallelism(parallelism uint64) daemon.ServiceConstructor {
|
2016-09-02 17:12:05 -04:00
|
|
|
return func(s *swarm.Service) {
|
|
|
|
s.Spec.UpdateConfig.Parallelism = parallelism
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
func setConstraints(constraints []string) daemon.ServiceConstructor {
|
2016-07-20 22:16:19 -04:00
|
|
|
return func(s *swarm.Service) {
|
|
|
|
if s.Spec.TaskTemplate.Placement == nil {
|
|
|
|
s.Spec.TaskTemplate.Placement = &swarm.Placement{}
|
|
|
|
}
|
|
|
|
s.Spec.TaskTemplate.Placement.Constraints = constraints
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-13 22:54:20 -04:00
|
|
|
func setGlobalMode(s *swarm.Service) {
|
|
|
|
s.Spec.Mode = swarm.ServiceMode{
|
|
|
|
Global: &swarm.GlobalService{},
|
|
|
|
}
|
|
|
|
}
|
2016-07-08 17:54:18 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
func checkClusterHealth(c *check.C, cl []*daemon.Swarm, managerCount, workerCount int) {
|
2016-07-08 17:54:18 -04:00
|
|
|
var totalMCount, totalWCount int
|
2016-07-26 11:44:46 -04:00
|
|
|
|
2016-07-08 17:54:18 -04:00
|
|
|
for _, d := range cl {
|
2016-07-26 11:44:46 -04:00
|
|
|
var (
|
|
|
|
info swarm.Info
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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) {
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err = d.SwarmInfo()
|
2016-07-26 11:44:46 -04:00
|
|
|
return err, check.Commentf("cluster not ready in time")
|
|
|
|
}
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, checkInfo, checker.IsNil)
|
2016-07-08 17:54:18 -04:00
|
|
|
if !info.ControlAvailable {
|
|
|
|
totalWCount++
|
|
|
|
continue
|
|
|
|
}
|
2016-07-26 11:44:46 -04:00
|
|
|
|
2016-07-08 17:54:18 -04:00
|
|
|
var leaderFound bool
|
|
|
|
totalMCount++
|
|
|
|
var mCount, wCount int
|
2016-07-26 11:44:46 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
for _, n := range d.ListNodes(c) {
|
2016-07-26 11:44:46 -04:00
|
|
|
waitReady := func(c *check.C) (interface{}, check.CommentInterface) {
|
|
|
|
if n.Status.State == swarm.NodeStateReady {
|
|
|
|
return true, nil
|
|
|
|
}
|
2016-12-09 04:17:53 -05:00
|
|
|
nn := d.GetNode(c, n.ID)
|
2016-07-26 11:44:46 -04:00
|
|
|
n = *nn
|
|
|
|
return n.Status.State == swarm.NodeStateReady, check.Commentf("state of node %s, reported by %s", n.ID, d.Info.NodeID)
|
|
|
|
}
|
|
|
|
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 04:17:53 -05:00
|
|
|
nn := d.GetNode(c, n.ID)
|
2016-07-26 11:44:46 -04:00
|
|
|
n = *nn
|
|
|
|
return n.Spec.Availability == swarm.NodeAvailabilityActive, check.Commentf("availability of node %s, reported by %s", n.ID, d.Info.NodeID)
|
|
|
|
}
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, waitActive, checker.True)
|
|
|
|
|
2016-07-08 17:54:18 -04:00
|
|
|
if n.Spec.Role == swarm.NodeRoleManager {
|
|
|
|
c.Assert(n.ManagerStatus, checker.NotNil, check.Commentf("manager status of node %s (manager), reported by %s", n.ID, d.Info.NodeID))
|
|
|
|
if n.ManagerStatus.Leader {
|
|
|
|
leaderFound = true
|
|
|
|
}
|
|
|
|
mCount++
|
|
|
|
} else {
|
|
|
|
c.Assert(n.ManagerStatus, checker.IsNil, check.Commentf("manager status of node %s (worker), reported by %s", n.ID, d.Info.NodeID))
|
|
|
|
wCount++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.Assert(leaderFound, checker.True, check.Commentf("lack of leader reported by node %s", info.NodeID))
|
|
|
|
c.Assert(mCount, checker.Equals, managerCount, check.Commentf("managers count reported by node %s", info.NodeID))
|
|
|
|
c.Assert(wCount, checker.Equals, workerCount, check.Commentf("workers count reported by node %s", info.NodeID))
|
|
|
|
}
|
|
|
|
c.Assert(totalMCount, checker.Equals, managerCount)
|
|
|
|
c.Assert(totalWCount, checker.Equals, workerCount)
|
|
|
|
}
|
|
|
|
|
[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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmRestartCluster(c *check.C) {
|
2016-07-08 17:54:18 -04:00
|
|
|
mCount, wCount := 5, 1
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
var nodes []*daemon.Swarm
|
2016-07-08 17:54:18 -04:00
|
|
|
for i := 0; i < mCount; i++ {
|
|
|
|
manager := s.AddDaemon(c, true, true)
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err := manager.SwarmInfo()
|
2016-07-08 17:54:18 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.ControlAvailable, checker.True)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
|
|
|
|
nodes = append(nodes, manager)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < wCount; i++ {
|
|
|
|
worker := s.AddDaemon(c, true, false)
|
2016-12-09 04:17:53 -05:00
|
|
|
info, err := worker.SwarmInfo()
|
2016-07-08 17:54:18 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(info.ControlAvailable, checker.False)
|
|
|
|
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
|
|
|
|
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 {
|
2016-12-09 04:17:53 -05:00
|
|
|
go func(daemon *daemon.Swarm) {
|
2016-07-08 17:54:18 -04:00
|
|
|
defer wg.Done()
|
|
|
|
if err := daemon.Stop(); err != nil {
|
|
|
|
errs <- err
|
|
|
|
}
|
2016-12-09 04:17:53 -05:00
|
|
|
// FIXME(vdemeester) This is duplicated…
|
2016-07-08 17:54:18 -04:00
|
|
|
if root := os.Getenv("DOCKER_REMAP_ROOT"); root != "" {
|
2016-12-09 04:17:53 -05:00
|
|
|
daemon.Root = filepath.Dir(daemon.Root)
|
2016-07-08 17:54:18 -04:00
|
|
|
}
|
|
|
|
}(d)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
close(errs)
|
|
|
|
for err := range errs {
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// start whole cluster
|
|
|
|
{
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(len(nodes))
|
|
|
|
errs := make(chan error, len(nodes))
|
|
|
|
|
|
|
|
for _, d := range nodes {
|
2016-12-09 04:17:53 -05:00
|
|
|
go func(daemon *daemon.Swarm) {
|
2016-07-08 17:54:18 -04:00
|
|
|
defer wg.Done()
|
|
|
|
if err := daemon.Start("--iptables=false"); err != nil {
|
|
|
|
errs <- err
|
|
|
|
}
|
|
|
|
}(d)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
close(errs)
|
|
|
|
for err := range errs {
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkClusterHealth(c, nodes, mCount, wCount)
|
|
|
|
}
|
2016-08-29 00:15:03 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateWithName(c *check.C) {
|
2016-08-29 00:15:03 -04:00
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
instances := 2
|
2016-12-09 04:17:53 -05:00
|
|
|
id := d.CreateService(c, simpleTestService, setInstances(instances))
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
2016-08-29 00:15:03 -04:00
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
service := d.GetService(c, id)
|
2016-08-29 00:15:03 -04:00
|
|
|
instances = 5
|
|
|
|
|
|
|
|
setInstances(instances)(service)
|
|
|
|
url := fmt.Sprintf("/services/%s/update?version=%d", service.Spec.Name, service.Version.Index)
|
|
|
|
status, out, err := d.SockRequest("POST", url, service.Spec)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
|
2016-12-09 04:17:53 -05:00
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
|
2016-08-29 00:15:03 -04:00
|
|
|
}
|
2016-10-26 16:30:53 -04:00
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmSecretsEmptyList(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
secrets := d.ListSecrets(c)
|
2016-10-26 16:30:53 -04:00
|
|
|
c.Assert(secrets, checker.NotNil)
|
|
|
|
c.Assert(len(secrets), checker.Equals, 0, check.Commentf("secrets: %#v", secrets))
|
|
|
|
}
|
2016-10-27 22:49:23 -04:00
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmSecretsCreate(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
testName := "test_secret"
|
2016-12-09 04:17:53 -05:00
|
|
|
id := d.CreateSecret(c, swarm.SecretSpec{
|
2016-10-27 22:49:23 -04:00
|
|
|
swarm.Annotations{
|
|
|
|
Name: testName,
|
|
|
|
},
|
|
|
|
[]byte("TESTINGDATA"),
|
|
|
|
})
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
secrets := d.ListSecrets(c)
|
2016-10-27 22:49:23 -04:00
|
|
|
c.Assert(len(secrets), checker.Equals, 1, check.Commentf("secrets: %#v", secrets))
|
|
|
|
name := secrets[0].Spec.Annotations.Name
|
|
|
|
c.Assert(name, checker.Equals, testName, check.Commentf("secret: %s", name))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmSecretsDelete(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
testName := "test_secret"
|
2016-12-09 04:17:53 -05:00
|
|
|
id := d.CreateSecret(c, swarm.SecretSpec{
|
2016-10-27 22:49:23 -04:00
|
|
|
swarm.Annotations{
|
|
|
|
Name: testName,
|
|
|
|
},
|
|
|
|
[]byte("TESTINGDATA"),
|
|
|
|
})
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
secret := d.GetSecret(c, id)
|
2016-10-27 22:49:23 -04:00
|
|
|
c.Assert(secret.ID, checker.Equals, id, check.Commentf("secret: %v", secret))
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
d.DeleteSecret(c, secret.ID)
|
2016-10-27 22:49:23 -04:00
|
|
|
status, out, err := d.SockRequest("GET", "/secrets/"+id, nil)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusNotFound, check.Commentf("secret delete: %s", string(out)))
|
|
|
|
}
|