2017-02-09 04:25:17 -05:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
|
|
|
"github.com/docker/docker/integration-cli/daemon"
|
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmListNodes(c *check.C) {
|
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, false)
|
|
|
|
d3 := s.AddDaemon(c, true, false)
|
|
|
|
|
|
|
|
nodes := d1.ListNodes(c)
|
|
|
|
c.Assert(len(nodes), checker.Equals, 3, check.Commentf("nodes: %#v", nodes))
|
|
|
|
|
|
|
|
loop0:
|
|
|
|
for _, n := range nodes {
|
2018-04-11 06:10:17 -04:00
|
|
|
for _, d := range []*daemon.Daemon{d1, d2, d3} {
|
|
|
|
if n.ID == d.NodeID() {
|
2017-02-09 04:25:17 -05:00
|
|
|
continue loop0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.Errorf("unknown nodeID %v", n.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmNodeUpdate(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
nodes := d.ListNodes(c)
|
|
|
|
|
|
|
|
d.UpdateNode(c, nodes[0].ID, func(n *swarm.Node) {
|
|
|
|
n.Spec.Availability = swarm.NodeAvailabilityPause
|
|
|
|
})
|
|
|
|
|
|
|
|
n := d.GetNode(c, nodes[0].ID)
|
|
|
|
c.Assert(n.Spec.Availability, checker.Equals, swarm.NodeAvailabilityPause)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *check.C) {
|
|
|
|
testRequires(c, Network)
|
|
|
|
d1 := s.AddDaemon(c, true, true)
|
|
|
|
d2 := s.AddDaemon(c, true, false)
|
|
|
|
_ = s.AddDaemon(c, true, false)
|
|
|
|
|
|
|
|
nodes := d1.ListNodes(c)
|
|
|
|
c.Assert(len(nodes), checker.Equals, 3, check.Commentf("nodes: %#v", nodes))
|
|
|
|
|
|
|
|
// Getting the info so we can take the NodeID
|
2018-04-11 06:10:17 -04:00
|
|
|
d2Info := d2.SwarmInfo(c)
|
2017-02-09 04:25:17 -05:00
|
|
|
|
|
|
|
// forceful removal of d2 should work
|
|
|
|
d1.RemoveNode(c, d2Info.NodeID, true)
|
|
|
|
|
|
|
|
nodes = d1.ListNodes(c)
|
|
|
|
c.Assert(len(nodes), checker.Equals, 2, check.Commentf("nodes: %#v", nodes))
|
|
|
|
|
|
|
|
// Restart the node that was removed
|
2018-10-25 14:47:56 -04:00
|
|
|
d2.RestartNode(c)
|
2017-02-09 04:25:17 -05:00
|
|
|
|
|
|
|
// Give some time for the node to rejoin
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
|
|
|
// Make sure the node didn't rejoin
|
|
|
|
nodes = d1.ListNodes(c)
|
|
|
|
c.Assert(len(nodes), checker.Equals, 2, check.Commentf("nodes: %#v", nodes))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *check.C) {
|
|
|
|
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
|
|
|
|
id := d1.CreateService(c, simpleTestService, setInstances(instances))
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
// drain d2, all containers should move to d1
|
2018-04-11 06:10:17 -04:00
|
|
|
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
2017-02-09 04:25:17 -05:00
|
|
|
n.Spec.Availability = swarm.NodeAvailabilityDrain
|
|
|
|
})
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, 0)
|
|
|
|
|
|
|
|
// set d2 back to active
|
2018-04-11 06:10:17 -04:00
|
|
|
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
2017-02-09 04:25:17 -05:00
|
|
|
n.Spec.Availability = swarm.NodeAvailabilityActive
|
|
|
|
})
|
|
|
|
|
|
|
|
instances = 1
|
|
|
|
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
|
|
|
|
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout*2, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, instances)
|
|
|
|
|
|
|
|
instances = 8
|
|
|
|
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
|
|
|
|
|
|
|
|
// drained node first so we don't get any old containers
|
|
|
|
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)
|
|
|
|
|
2018-04-11 09:52:13 -04:00
|
|
|
d2ContainerCount := len(d2.ActiveContainers(c))
|
2017-02-09 04:25:17 -05:00
|
|
|
|
|
|
|
// set d2 to paused, scale service up, only d1 gets new tasks
|
2018-04-11 06:10:17 -04:00
|
|
|
d1.UpdateNode(c, d2.NodeID(), func(n *swarm.Node) {
|
2017-02-09 04:25:17 -05:00
|
|
|
n.Spec.Availability = swarm.NodeAvailabilityPause
|
|
|
|
})
|
|
|
|
|
|
|
|
instances = 14
|
|
|
|
d1.UpdateService(c, d1.GetService(c, id), setInstances(instances))
|
|
|
|
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d1.CheckActiveContainerCount, checker.Equals, instances-d2ContainerCount)
|
|
|
|
waitAndAssert(c, defaultReconciliationTimeout, d2.CheckActiveContainerCount, checker.Equals, d2ContainerCount)
|
|
|
|
|
|
|
|
}
|