github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/integration-cli/docker_cli_swarm_unix_test.go (about) 1 // +build !windows 2 3 package main 4 5 import ( 6 "encoding/json" 7 "strings" 8 "time" 9 10 "github.com/docker/docker/api/types/swarm" 11 "github.com/docker/docker/integration-cli/checker" 12 "github.com/go-check/check" 13 ) 14 15 func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *check.C) { 16 d := s.AddDaemon(c, true, true) 17 18 out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--mount", "type=volume,source=my-volume,destination=/foo,volume-driver=customvolumedriver", "--name", "top", "busybox", "top") 19 c.Assert(err, checker.IsNil, check.Commentf("%s", out)) 20 21 // Make sure task stays pending before plugin is available 22 waitAndAssert(c, defaultReconciliationTimeout, d.CheckServiceTasksInStateWithError("top", swarm.TaskStatePending, "missing plugin on 1 node"), checker.Equals, 1) 23 24 plugin := newVolumePlugin(c, "customvolumedriver") 25 defer plugin.Close() 26 27 // create a dummy volume to trigger lazy loading of the plugin 28 out, err = d.Cmd("volume", "create", "-d", "customvolumedriver", "hello") 29 c.Assert(err, checker.IsNil, check.Commentf("%s", out)) 30 31 // TODO(aaronl): It will take about 15 seconds for swarm to realize the 32 // plugin was loaded. Switching the test over to plugin v2 would avoid 33 // this long delay. 34 35 // make sure task has been deployed. 36 waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) 37 38 out, err = d.Cmd("ps", "-q") 39 c.Assert(err, checker.IsNil) 40 containerID := strings.TrimSpace(out) 41 42 out, err = d.Cmd("inspect", "-f", "{{json .Mounts}}", containerID) 43 c.Assert(err, checker.IsNil) 44 45 var mounts []struct { 46 Name string 47 Driver string 48 } 49 50 c.Assert(json.NewDecoder(strings.NewReader(out)).Decode(&mounts), checker.IsNil) 51 c.Assert(len(mounts), checker.Equals, 1, check.Commentf("%s", out)) 52 c.Assert(mounts[0].Name, checker.Equals, "my-volume") 53 c.Assert(mounts[0].Driver, checker.Equals, "customvolumedriver") 54 } 55 56 // Test network plugin filter in swarm 57 func (s *DockerSwarmSuite) TestSwarmNetworkPluginV2(c *check.C) { 58 testRequires(c, IsAmd64) 59 d1 := s.AddDaemon(c, true, true) 60 d2 := s.AddDaemon(c, true, false) 61 62 // install plugin on d1 and d2 63 pluginName := "aragunathan/global-net-plugin:latest" 64 65 _, err := d1.Cmd("plugin", "install", pluginName, "--grant-all-permissions") 66 c.Assert(err, checker.IsNil) 67 68 _, err = d2.Cmd("plugin", "install", pluginName, "--grant-all-permissions") 69 c.Assert(err, checker.IsNil) 70 71 // create network 72 networkName := "globalnet" 73 _, err = d1.Cmd("network", "create", "--driver", pluginName, networkName) 74 c.Assert(err, checker.IsNil) 75 76 // create a global service to ensure that both nodes will have an instance 77 serviceName := "my-service" 78 _, err = d1.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--mode=global", "--network", networkName, "busybox", "top") 79 c.Assert(err, checker.IsNil) 80 81 // wait for tasks ready 82 waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, 2) 83 84 // remove service 85 _, err = d1.Cmd("service", "rm", serviceName) 86 c.Assert(err, checker.IsNil) 87 88 // wait to ensure all containers have exited before removing the plugin. Else there's a 89 // possibility of container exits erroring out due to plugins being unavailable. 90 waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.CheckActiveContainerCount, d2.CheckActiveContainerCount), checker.Equals, 0) 91 92 // disable plugin on worker 93 _, err = d2.Cmd("plugin", "disable", "-f", pluginName) 94 c.Assert(err, checker.IsNil) 95 96 time.Sleep(20 * time.Second) 97 98 image := "busybox:latest" 99 // create a new global service again. 100 _, err = d1.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--mode=global", "--network", networkName, image, "top") 101 c.Assert(err, checker.IsNil) 102 103 waitAndAssert(c, defaultReconciliationTimeout, d1.CheckRunningTaskImages, checker.DeepEquals, 104 map[string]int{image: 1}) 105 }