Browse code

integration-cli: allow temporary no-leader error

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2019/07/17 06:07:26
Showing 1 changed files
... ...
@@ -1303,9 +1303,21 @@ func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *check.C) {
1303 1303
 
1304 1304
 		c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
1305 1305
 
1306
-		outs, err = d.Cmd("node", "ls")
1307
-		assert.NilError(c, err)
1308
-		c.Assert(outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked")
1306
+		retry := 0
1307
+		for {
1308
+			// an issue sometimes prevents leader to be available right away
1309
+			outs, err = d.Cmd("node", "ls")
1310
+			if err != nil && retry < 5 {
1311
+				if strings.Contains(err.Error(), "swarm does not have a leader") {
1312
+					retry++
1313
+					time.Sleep(3 * time.Second)
1314
+					continue
1315
+				}
1316
+			}
1317
+			assert.NilError(c, err)
1318
+			c.Assert(outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked")
1319
+			break
1320
+		}
1309 1321
 
1310 1322
 		unlockKey = newUnlockKey
1311 1323
 	}
... ...
@@ -1383,9 +1395,21 @@ func (s *DockerSwarmSuite) TestSwarmClusterRotateUnlockKey(c *check.C) {
1383 1383
 
1384 1384
 			c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
1385 1385
 
1386
-			outs, err = d.Cmd("node", "ls")
1387
-			c.Assert(err, checker.IsNil, check.Commentf("%s", outs))
1388
-			c.Assert(outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked")
1386
+			retry := 0
1387
+			for {
1388
+				// an issue sometimes prevents leader to be available right away
1389
+				outs, err = d.Cmd("node", "ls")
1390
+				if err != nil && retry < 5 {
1391
+					if strings.Contains(err.Error(), "swarm does not have a leader") {
1392
+						retry++
1393
+						time.Sleep(3 * time.Second)
1394
+						continue
1395
+					}
1396
+				}
1397
+				c.Assert(err, checker.IsNil, check.Commentf("%s", outs))
1398
+				c.Assert(outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked")
1399
+				break
1400
+			}
1389 1401
 		}
1390 1402
 
1391 1403
 		unlockKey = newUnlockKey