docker_cli_plugins_test.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. package main
  2. import (
  3. "github.com/docker/docker/pkg/integration/checker"
  4. "github.com/go-check/check"
  5. "io/ioutil"
  6. "os"
  7. "path/filepath"
  8. "strings"
  9. )
  10. var (
  11. pluginProcessName = "sample-volume-plugin"
  12. pName = "tiborvass/sample-volume-plugin"
  13. pTag = "latest"
  14. pNameWithTag = pName + ":" + pTag
  15. )
  16. func (s *DockerSuite) TestPluginBasicOps(c *check.C) {
  17. testRequires(c, DaemonIsLinux, Network)
  18. _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
  19. c.Assert(err, checker.IsNil)
  20. out, _, err := dockerCmdWithError("plugin", "ls")
  21. c.Assert(err, checker.IsNil)
  22. c.Assert(out, checker.Contains, pName)
  23. c.Assert(out, checker.Contains, pTag)
  24. c.Assert(out, checker.Contains, "true")
  25. id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
  26. id = strings.TrimSpace(id)
  27. c.Assert(err, checker.IsNil)
  28. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  29. c.Assert(err, checker.NotNil)
  30. c.Assert(out, checker.Contains, "is enabled")
  31. _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
  32. c.Assert(err, checker.IsNil)
  33. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  34. c.Assert(err, checker.IsNil)
  35. c.Assert(out, checker.Contains, pNameWithTag)
  36. _, err = os.Stat(filepath.Join(dockerBasePath, "plugins", id))
  37. if !os.IsNotExist(err) {
  38. c.Fatal(err)
  39. }
  40. }
  41. func (s *DockerSuite) TestPluginForceRemove(c *check.C) {
  42. testRequires(c, DaemonIsLinux, Network)
  43. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
  44. c.Assert(err, checker.IsNil)
  45. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  46. c.Assert(out, checker.Contains, "is enabled")
  47. out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag)
  48. c.Assert(err, checker.IsNil)
  49. c.Assert(out, checker.Contains, pNameWithTag)
  50. }
  51. func (s *DockerSuite) TestPluginActive(c *check.C) {
  52. testRequires(c, DaemonIsLinux, Network, IsAmd64)
  53. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
  54. c.Assert(err, checker.IsNil)
  55. out, _, err = dockerCmdWithError("volume", "create", "-d", pNameWithTag)
  56. c.Assert(err, checker.IsNil)
  57. vID := strings.TrimSpace(out)
  58. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  59. c.Assert(out, checker.Contains, "is in use")
  60. _, _, err = dockerCmdWithError("volume", "rm", vID)
  61. c.Assert(err, checker.IsNil)
  62. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  63. c.Assert(out, checker.Contains, "is enabled")
  64. _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
  65. c.Assert(err, checker.IsNil)
  66. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  67. c.Assert(err, checker.IsNil)
  68. c.Assert(out, checker.Contains, pNameWithTag)
  69. }
  70. func (s *DockerSuite) TestPluginInstallDisable(c *check.C) {
  71. testRequires(c, DaemonIsLinux, Network)
  72. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
  73. c.Assert(err, checker.IsNil)
  74. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  75. out, _, err = dockerCmdWithError("plugin", "ls")
  76. c.Assert(err, checker.IsNil)
  77. c.Assert(out, checker.Contains, "false")
  78. out, _, err = dockerCmdWithError("plugin", "enable", pName)
  79. c.Assert(err, checker.IsNil)
  80. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  81. out, _, err = dockerCmdWithError("plugin", "disable", pName)
  82. c.Assert(err, checker.IsNil)
  83. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  84. out, _, err = dockerCmdWithError("plugin", "remove", pName)
  85. c.Assert(err, checker.IsNil)
  86. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  87. }
  88. func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *check.C) {
  89. testRequires(c, DaemonIsLinux, Network)
  90. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
  91. c.Assert(err, checker.IsNil)
  92. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  93. dockerCmd(c, "volume", "ls")
  94. }
  95. func (s *DockerSuite) TestPluginSet(c *check.C) {
  96. testRequires(c, DaemonIsLinux, Network)
  97. out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName)
  98. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  99. env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
  100. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
  101. dockerCmd(c, "plugin", "set", pName, "DEBUG=1")
  102. env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
  103. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
  104. }
  105. func (s *DockerSuite) TestPluginInstallArgs(c *check.C) {
  106. testRequires(c, DaemonIsLinux, Network)
  107. out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1")
  108. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  109. env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
  110. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
  111. }
  112. func (s *DockerSuite) TestPluginInstallImage(c *check.C) {
  113. testRequires(c, DaemonIsLinux, Network)
  114. out, _, err := dockerCmdWithError("plugin", "install", "redis")
  115. c.Assert(err, checker.NotNil)
  116. c.Assert(out, checker.Contains, "content is not a plugin")
  117. }
  118. func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) {
  119. testRequires(c, DaemonIsLinux, Network)
  120. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName)
  121. c.Assert(err, checker.IsNil)
  122. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  123. out, _, err = dockerCmdWithError("plugin", "enable", pName)
  124. c.Assert(err, checker.NotNil)
  125. c.Assert(strings.TrimSpace(out), checker.Contains, "already enabled")
  126. _, _, err = dockerCmdWithError("plugin", "disable", pName)
  127. c.Assert(err, checker.IsNil)
  128. out, _, err = dockerCmdWithError("plugin", "disable", pName)
  129. c.Assert(err, checker.NotNil)
  130. c.Assert(strings.TrimSpace(out), checker.Contains, "already disabled")
  131. _, _, err = dockerCmdWithError("plugin", "remove", pName)
  132. c.Assert(err, checker.IsNil)
  133. }
  134. func (s *DockerSuite) TestPluginCreate(c *check.C) {
  135. testRequires(c, DaemonIsLinux, Network)
  136. name := "foo/bar-driver"
  137. temp, err := ioutil.TempDir("", "foo")
  138. c.Assert(err, checker.IsNil)
  139. defer os.RemoveAll(temp)
  140. data := `{"description": "foo plugin"}`
  141. err = ioutil.WriteFile(filepath.Join(temp, "config.json"), []byte(data), 0644)
  142. c.Assert(err, checker.IsNil)
  143. out, _, err := dockerCmdWithError("plugin", "create", name, temp)
  144. c.Assert(err, checker.IsNil)
  145. c.Assert(out, checker.Contains, name)
  146. out, _, err = dockerCmdWithError("plugin", "ls")
  147. c.Assert(err, checker.IsNil)
  148. c.Assert(out, checker.Contains, name)
  149. out, _, err = dockerCmdWithError("plugin", "create", name, temp)
  150. c.Assert(err, checker.NotNil)
  151. c.Assert(out, checker.Contains, "already exist")
  152. out, _, err = dockerCmdWithError("plugin", "ls")
  153. c.Assert(err, checker.IsNil)
  154. c.Assert(out, checker.Contains, name)
  155. // The output will consists of one HEADER line and one line of foo/bar-driver
  156. c.Assert(len(strings.Split(strings.TrimSpace(out), "\n")), checker.Equals, 2)
  157. }
  158. func (s *DockerSuite) TestPluginInspect(c *check.C) {
  159. testRequires(c, DaemonIsLinux, Network)
  160. _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
  161. c.Assert(err, checker.IsNil)
  162. out, _, err := dockerCmdWithError("plugin", "ls")
  163. c.Assert(err, checker.IsNil)
  164. c.Assert(out, checker.Contains, pName)
  165. c.Assert(out, checker.Contains, pTag)
  166. c.Assert(out, checker.Contains, "true")
  167. // Find the ID first
  168. out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
  169. c.Assert(err, checker.IsNil)
  170. id := strings.TrimSpace(out)
  171. c.Assert(id, checker.Not(checker.Equals), "")
  172. // Long form
  173. out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id)
  174. c.Assert(err, checker.IsNil)
  175. c.Assert(strings.TrimSpace(out), checker.Equals, id)
  176. // Short form
  177. out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
  178. c.Assert(err, checker.IsNil)
  179. c.Assert(strings.TrimSpace(out), checker.Equals, id)
  180. // Name with tag form
  181. out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
  182. c.Assert(err, checker.IsNil)
  183. c.Assert(strings.TrimSpace(out), checker.Equals, id)
  184. // Name without tag form
  185. out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pName)
  186. c.Assert(err, checker.IsNil)
  187. c.Assert(strings.TrimSpace(out), checker.Equals, id)
  188. _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
  189. c.Assert(err, checker.IsNil)
  190. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  191. c.Assert(err, checker.IsNil)
  192. c.Assert(out, checker.Contains, pNameWithTag)
  193. // After remove nothing should be found
  194. _, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
  195. c.Assert(err, checker.NotNil)
  196. }