Browse code

Merge pull request #31340 from anusha-ragunathan/plugin_nw_filter

Add network plugin filter test

Tibor Vass authored on 2017/03/07 08:31:59
Showing 1 changed files
... ...
@@ -5,6 +5,7 @@ package main
5 5
 import (
6 6
 	"encoding/json"
7 7
 	"strings"
8
+	"time"
8 9
 
9 10
 	"github.com/docker/docker/api/types/swarm"
10 11
 	"github.com/docker/docker/integration-cli/checker"
... ...
@@ -50,3 +51,53 @@ func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *check.C) {
50 50
 	c.Assert(mounts[0].Name, checker.Equals, "my-volume")
51 51
 	c.Assert(mounts[0].Driver, checker.Equals, "customvolumedriver")
52 52
 }
53
+
54
+// Test network plugin filter in swarm
55
+func (s *DockerSwarmSuite) TestSwarmNetworkPluginV2(c *check.C) {
56
+	d1 := s.AddDaemon(c, true, true)
57
+	d2 := s.AddDaemon(c, true, false)
58
+
59
+	// install plugin on d1 and d2
60
+	pluginName := "aragunathan/global-net-plugin:latest"
61
+
62
+	_, err := d1.Cmd("plugin", "install", pluginName, "--grant-all-permissions")
63
+	c.Assert(err, checker.IsNil)
64
+
65
+	_, err = d2.Cmd("plugin", "install", pluginName, "--grant-all-permissions")
66
+	c.Assert(err, checker.IsNil)
67
+
68
+	// create network
69
+	networkName := "globalnet"
70
+	_, err = d1.Cmd("network", "create", "--driver", pluginName, networkName)
71
+	c.Assert(err, checker.IsNil)
72
+
73
+	// create a global service to ensure that both nodes will have an instance
74
+	serviceName := "my-service"
75
+	_, err = d1.Cmd("service", "create", "--name", serviceName, "--mode=global", "--network", networkName, "busybox", "top")
76
+	c.Assert(err, checker.IsNil)
77
+
78
+	// wait for tasks ready
79
+	waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, 2)
80
+
81
+	// remove service
82
+	_, err = d1.Cmd("service", "rm", serviceName)
83
+	c.Assert(err, checker.IsNil)
84
+
85
+	// wait to ensure all containers have exited before removing the plugin. Else there's a
86
+	// possibility of container exits erroring out due to plugins being unavailable.
87
+	waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, 0)
88
+
89
+	// disable plugin on worker
90
+	_, err = d2.Cmd("plugin", "disable", "-f", pluginName)
91
+	c.Assert(err, checker.IsNil)
92
+
93
+	time.Sleep(20 * time.Second)
94
+
95
+	image := "busybox"
96
+	// create a new global service again.
97
+	_, err = d1.Cmd("service", "create", "--name", serviceName, "--mode=global", "--network", networkName, image, "top")
98
+	c.Assert(err, checker.IsNil)
99
+
100
+	waitAndAssert(c, defaultReconciliationTimeout, d1.CheckRunningTaskImages, checker.DeepEquals,
101
+		map[string]int{image: 1})
102
+}