Browse code

integration-cli: Have TestSwarmJoinPromoteLocked wait for the role to change in the certificate

Since the certificate may be renewed multiple times, this check is
necessary.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>

Aaron Lehmann authored on 2017/04/17 04:40:11
Showing 1 changed files
... ...
@@ -15,6 +15,7 @@ import (
15 15
 	"strings"
16 16
 	"time"
17 17
 
18
+	"github.com/cloudflare/cfssl/helpers"
18 19
 	"github.com/docker/docker/api/types"
19 20
 	"github.com/docker/docker/api/types/swarm"
20 21
 	"github.com/docker/docker/integration-cli/checker"
... ...
@@ -1221,10 +1222,6 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *check.C) {
1221 1221
 		c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
1222 1222
 	}
1223 1223
 
1224
-	// get d3's cert
1225
-	d3cert, err := ioutil.ReadFile(filepath.Join(d3.Folder, "root", "swarm", "certificates", "swarm-node.crt"))
1226
-	c.Assert(err, checker.IsNil)
1227
-
1228 1224
 	// demote manager back to worker - workers are not locked
1229 1225
 	outs, err = d1.Cmd("node", "demote", d3.Info.NodeID)
1230 1226
 	c.Assert(err, checker.IsNil)
... ...
@@ -1237,12 +1234,16 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *check.C) {
1237 1237
 	// is set to autolock)
1238 1238
 	waitAndAssert(c, defaultReconciliationTimeout, d3.CheckControlAvailable, checker.False)
1239 1239
 	waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
1240
-		cert, err := ioutil.ReadFile(filepath.Join(d3.Folder, "root", "swarm", "certificates", "swarm-node.crt"))
1240
+		certBytes, err := ioutil.ReadFile(filepath.Join(d3.Folder, "root", "swarm", "certificates", "swarm-node.crt"))
1241 1241
 		if err != nil {
1242 1242
 			return "", check.Commentf("error: %v", err)
1243 1243
 		}
1244
-		return string(cert), check.Commentf("cert: %v", string(cert))
1245
-	}, checker.Not(checker.Equals), string(d3cert))
1244
+		certs, err := helpers.ParseCertificatesPEM(certBytes)
1245
+		if err == nil && len(certs) > 0 && len(certs[0].Subject.OrganizationalUnit) > 0 {
1246
+			return certs[0].Subject.OrganizationalUnit[0], nil
1247
+		}
1248
+		return "", check.Commentf("could not get organizational unit from certificate")
1249
+	}, checker.Equals, "swarm-worker")
1246 1250
 
1247 1251
 	// by now, it should *never* be locked on restart
1248 1252
 	d3.Restart(c)