docker_cli_plugins_test.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package main
  2. import (
  3. "github.com/docker/docker/pkg/integration/checker"
  4. "github.com/go-check/check"
  5. "os"
  6. "path/filepath"
  7. "strings"
  8. )
  9. var (
  10. pluginProcessName = "no-remove"
  11. pName = "tiborvass/no-remove"
  12. pTag = "latest"
  13. pNameWithTag = pName + ":" + pTag
  14. )
  15. func (s *DockerSuite) TestPluginBasicOps(c *check.C) {
  16. testRequires(c, DaemonIsLinux, Network)
  17. _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
  18. c.Assert(err, checker.IsNil)
  19. out, _, err := dockerCmdWithError("plugin", "ls")
  20. c.Assert(err, checker.IsNil)
  21. c.Assert(out, checker.Contains, pName)
  22. c.Assert(out, checker.Contains, pTag)
  23. c.Assert(out, checker.Contains, "true")
  24. id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
  25. id = strings.TrimSpace(id)
  26. c.Assert(err, checker.IsNil)
  27. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  28. c.Assert(out, checker.Contains, "is enabled")
  29. _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
  30. c.Assert(err, checker.IsNil)
  31. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  32. c.Assert(err, checker.IsNil)
  33. c.Assert(out, checker.Contains, pNameWithTag)
  34. _, err = os.Stat(filepath.Join(dockerBasePath, "plugins", id))
  35. if !os.IsNotExist(err) {
  36. c.Fatal(err)
  37. }
  38. }
  39. func (s *DockerSuite) TestPluginForceRemove(c *check.C) {
  40. testRequires(c, DaemonIsLinux, Network)
  41. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
  42. c.Assert(err, checker.IsNil)
  43. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  44. c.Assert(out, checker.Contains, "is enabled")
  45. out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag)
  46. c.Assert(err, checker.IsNil)
  47. c.Assert(out, checker.Contains, pNameWithTag)
  48. }
  49. func (s *DockerSuite) TestPluginActive(c *check.C) {
  50. testRequires(c, DaemonIsLinux, Network, IsAmd64)
  51. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
  52. c.Assert(err, checker.IsNil)
  53. out, _, err = dockerCmdWithError("volume", "create", "-d", pNameWithTag)
  54. c.Assert(err, checker.IsNil)
  55. vID := strings.TrimSpace(out)
  56. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  57. c.Assert(out, checker.Contains, "is in use")
  58. _, _, err = dockerCmdWithError("volume", "rm", vID)
  59. c.Assert(err, checker.IsNil)
  60. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  61. c.Assert(out, checker.Contains, "is enabled")
  62. _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
  63. c.Assert(err, checker.IsNil)
  64. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  65. c.Assert(err, checker.IsNil)
  66. c.Assert(out, checker.Contains, pNameWithTag)
  67. }
  68. func (s *DockerSuite) TestPluginInstallDisable(c *check.C) {
  69. testRequires(c, DaemonIsLinux, Network)
  70. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
  71. c.Assert(err, checker.IsNil)
  72. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  73. out, _, err = dockerCmdWithError("plugin", "ls")
  74. c.Assert(err, checker.IsNil)
  75. c.Assert(out, checker.Contains, "false")
  76. out, _, err = dockerCmdWithError("plugin", "enable", pName)
  77. c.Assert(err, checker.IsNil)
  78. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  79. out, _, err = dockerCmdWithError("plugin", "disable", pName)
  80. c.Assert(err, checker.IsNil)
  81. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  82. out, _, err = dockerCmdWithError("plugin", "remove", pName)
  83. c.Assert(err, checker.IsNil)
  84. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  85. }
  86. func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *check.C) {
  87. testRequires(c, DaemonIsLinux, Network)
  88. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
  89. c.Assert(err, checker.IsNil)
  90. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  91. dockerCmd(c, "volume", "ls")
  92. }
  93. func (s *DockerSuite) TestPluginSet(c *check.C) {
  94. testRequires(c, DaemonIsLinux, Network)
  95. out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName)
  96. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  97. env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
  98. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
  99. dockerCmd(c, "plugin", "set", pName, "DEBUG=1")
  100. env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
  101. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
  102. }
  103. func (s *DockerSuite) TestPluginInstallArgs(c *check.C) {
  104. testRequires(c, DaemonIsLinux, Network)
  105. out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1")
  106. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  107. env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
  108. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
  109. }
  110. func (s *DockerSuite) TestPluginInstallImage(c *check.C) {
  111. testRequires(c, DaemonIsLinux)
  112. out, _, err := dockerCmdWithError("plugin", "install", "redis")
  113. c.Assert(err, checker.NotNil)
  114. c.Assert(out, checker.Contains, "content is not a plugin")
  115. }
  116. func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) {
  117. testRequires(c, DaemonIsLinux, Network)
  118. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName)
  119. c.Assert(err, checker.IsNil)
  120. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  121. out, _, err = dockerCmdWithError("plugin", "enable", pName)
  122. c.Assert(err, checker.NotNil)
  123. c.Assert(strings.TrimSpace(out), checker.Contains, "already enabled")
  124. _, _, err = dockerCmdWithError("plugin", "disable", pName)
  125. c.Assert(err, checker.IsNil)
  126. out, _, err = dockerCmdWithError("plugin", "disable", pName)
  127. c.Assert(err, checker.NotNil)
  128. c.Assert(strings.TrimSpace(out), checker.Contains, "already disabled")
  129. _, _, err = dockerCmdWithError("plugin", "remove", pName)
  130. c.Assert(err, checker.IsNil)
  131. }