docker_cli_swarm_unix_test.go 3.8 KB

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