docker_cli_plugins_test.go 8.7 KB

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