Browse code

Add integration test for parsing swarm update options

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit a933ac3c27ac88cf69a2bc2bc16ce076486c0206)

Tonis Tiigi authored on 2016/06/17 09:04:56
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,76 @@
0
+// +build !windows
1
+
2
+package main
3
+
4
+import (
5
+	"encoding/json"
6
+	"time"
7
+
8
+	"github.com/docker/docker/pkg/integration/checker"
9
+	"github.com/docker/engine-api/types/swarm"
10
+	"github.com/go-check/check"
11
+)
12
+
13
+func (s *DockerSwarmSuite) TestSwarmUpdate(c *check.C) {
14
+	d := s.AddDaemon(c, true, true)
15
+
16
+	getSpec := func() swarm.Spec {
17
+		out, err := d.Cmd("swarm", "inspect")
18
+		c.Assert(err, checker.IsNil)
19
+		var sw []swarm.Swarm
20
+		c.Assert(json.Unmarshal([]byte(out), &sw), checker.IsNil)
21
+		c.Assert(len(sw), checker.Equals, 1)
22
+		return sw[0].Spec
23
+	}
24
+
25
+	out, err := d.Cmd("swarm", "update", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s", "--auto-accept", "manager", "--auto-accept", "worker", "--secret", "foo")
26
+	c.Assert(err, checker.IsNil, check.Commentf("out: %v", out))
27
+
28
+	spec := getSpec()
29
+	c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour)
30
+	c.Assert(spec.Dispatcher.HeartbeatPeriod, checker.Equals, uint64(11*time.Second))
31
+
32
+	c.Assert(spec.AcceptancePolicy.Policies, checker.HasLen, 2)
33
+
34
+	for _, p := range spec.AcceptancePolicy.Policies {
35
+		c.Assert(p.Autoaccept, checker.Equals, true)
36
+		c.Assert(p.Secret, checker.NotNil)
37
+		c.Assert(*p.Secret, checker.Not(checker.Equals), "")
38
+	}
39
+
40
+	out, err = d.Cmd("swarm", "update", "--auto-accept", "none")
41
+	c.Assert(err, checker.IsNil, check.Commentf("out: %v", out))
42
+
43
+	spec = getSpec()
44
+	c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour)
45
+	c.Assert(spec.Dispatcher.HeartbeatPeriod, checker.Equals, uint64(11*time.Second))
46
+
47
+	c.Assert(spec.AcceptancePolicy.Policies, checker.HasLen, 2)
48
+
49
+	for _, p := range spec.AcceptancePolicy.Policies {
50
+		c.Assert(p.Autoaccept, checker.Equals, false)
51
+		// secret is still set
52
+		c.Assert(p.Secret, checker.NotNil)
53
+		c.Assert(*p.Secret, checker.Not(checker.Equals), "")
54
+	}
55
+
56
+	out, err = d.Cmd("swarm", "update", "--auto-accept", "manager", "--secret", "")
57
+	c.Assert(err, checker.IsNil, check.Commentf("out: %v", out))
58
+
59
+	spec = getSpec()
60
+
61
+	c.Assert(spec.AcceptancePolicy.Policies, checker.HasLen, 2)
62
+
63
+	for _, p := range spec.AcceptancePolicy.Policies {
64
+		c.Assert(p.Autoaccept, checker.Equals, p.Role == swarm.NodeRoleManager)
65
+		// secret has been removed
66
+		c.Assert(p.Secret, checker.IsNil)
67
+	}
68
+
69
+	// setting anything under 30m for cert-expiry is not allowed
70
+	out, err = d.Cmd("swarm", "update", "--cert-expiry", "15m")
71
+	c.Assert(err, checker.NotNil)
72
+	c.Assert(out, checker.Contains, "minimum certificate expiry time")
73
+	spec = getSpec()
74
+	c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour)
75
+}