docker_cli_swarm_unix_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // +build !windows
  2. package main
  3. import (
  4. "encoding/json"
  5. "strings"
  6. "github.com/docker/docker/api/types/swarm"
  7. "github.com/docker/docker/pkg/integration/checker"
  8. "github.com/go-check/check"
  9. )
  10. func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *check.C) {
  11. d := s.AddDaemon(c, true, true)
  12. out, err := d.Cmd("service", "create", "--mount", "type=volume,source=my-volume,destination=/foo,volume-driver=customvolumedriver", "--name", "top", "busybox", "top")
  13. c.Assert(err, checker.IsNil, check.Commentf(out))
  14. // Make sure task stays pending before plugin is available
  15. waitAndAssert(c, defaultReconciliationTimeout, d.checkServiceTasksInState("top", swarm.TaskStatePending, "missing plugin on 1 node"), checker.Equals, 1)
  16. plugin := newVolumePlugin(c, "customvolumedriver")
  17. defer plugin.Close()
  18. // create a dummy volume to trigger lazy loading of the plugin
  19. out, err = d.Cmd("volume", "create", "-d", "customvolumedriver", "hello")
  20. // TODO(aaronl): It will take about 15 seconds for swarm to realize the
  21. // plugin was loaded. Switching the test over to plugin v2 would avoid
  22. // this long delay.
  23. // make sure task has been deployed.
  24. waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1)
  25. out, err = d.Cmd("ps", "-q")
  26. c.Assert(err, checker.IsNil)
  27. containerID := strings.TrimSpace(out)
  28. out, err = d.Cmd("inspect", "-f", "{{json .Mounts}}", containerID)
  29. c.Assert(err, checker.IsNil)
  30. var mounts []struct {
  31. Name string
  32. Driver string
  33. }
  34. c.Assert(json.NewDecoder(strings.NewReader(out)).Decode(&mounts), checker.IsNil)
  35. c.Assert(len(mounts), checker.Equals, 1, check.Commentf(out))
  36. c.Assert(mounts[0].Name, checker.Equals, "my-volume")
  37. c.Assert(mounts[0].Driver, checker.Equals, "customvolumedriver")
  38. }