1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

In DockerSwarmSuite.TestSwarmJoinPromoteLocked, actually wait for the node to

finish being demoted before restarting it and ensuring it isn't locked anymore
to reduce test flakiness.

Signed-off-by: cyli <cyli@twistedmatrix.com>
This commit is contained in:
cyli 2016-12-02 16:28:27 -08:00
parent 1c96879f1e
commit e831a7cdb7

View file

@ -1042,20 +1042,32 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *check.C) {
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive) c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
} }
// get d3's cert
d3cert, err := ioutil.ReadFile(filepath.Join(d3.folder, "root", "swarm", "certificates", "swarm-node.crt"))
c.Assert(err, checker.IsNil)
// demote manager back to worker - workers are not locked // demote manager back to worker - workers are not locked
outs, err = d1.Cmd("node", "demote", d3.Info.NodeID) outs, err = d1.Cmd("node", "demote", d3.Info.NodeID)
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
c.Assert(outs, checker.Contains, "demoted in the swarm") c.Assert(outs, checker.Contains, "demoted in the swarm")
// verify that it's been demoted // Wait for it to actually be demoted, for the key and cert to be replaced.
out, err := d1.Cmd("node", "ls", "--filter", "id="+d3.Info.NodeID) // Then restart and assert that the node is not locked. If we don't wait for the cert
c.Assert(err, checker.IsNil) // to be replaced, then the node still has the manager TLS key which is still locked
lines := strings.Split(strings.TrimSpace(out), "\n") // (because we never want a manager TLS key to be on disk unencrypted if the cluster
c.Assert(len(lines), checker.GreaterThan, 0) // is set to autolock)
columns := strings.Fields(lines[len(lines)-1]) waitAndAssert(c, defaultReconciliationTimeout, d3.checkControlAvailable, checker.False)
c.Assert(columns, checker.HasLen, 4) // if it was a manager it'd have a manager status field waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
cert, err := ioutil.ReadFile(filepath.Join(d3.folder, "root", "swarm", "certificates", "swarm-node.crt"))
if err != nil {
return "", check.Commentf("error: %v", err)
}
return string(cert), check.Commentf("cert: %v", string(cert))
}, checker.Not(checker.Equals), string(d3cert))
checkSwarmLockedToUnlocked(c, d3, unlockKey) // by now, it should *never* be locked on restart
c.Assert(d3.Restart(), checker.IsNil)
c.Assert(getNodeStatus(c, d3), checker.Equals, swarm.LocalNodeStateActive)
} }
func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *check.C) { func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *check.C) {