docker_cli_plugins_test.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "net/http"
  6. "os"
  7. "path"
  8. "path/filepath"
  9. "strings"
  10. "time"
  11. "github.com/docker/docker/api/types"
  12. "github.com/docker/docker/integration-cli/checker"
  13. "github.com/docker/docker/integration-cli/cli"
  14. "github.com/docker/docker/integration-cli/daemon"
  15. "github.com/docker/docker/integration-cli/fixtures/plugin"
  16. "github.com/go-check/check"
  17. "github.com/gotestyourself/gotestyourself/icmd"
  18. "golang.org/x/net/context"
  19. )
  20. var (
  21. pluginProcessName = "sample-volume-plugin"
  22. pName = "tiborvass/sample-volume-plugin"
  23. npName = "tiborvass/test-docker-netplugin"
  24. pTag = "latest"
  25. pNameWithTag = pName + ":" + pTag
  26. npNameWithTag = npName + ":" + pTag
  27. )
  28. func (ps *DockerPluginSuite) TestPluginBasicOps(c *check.C) {
  29. plugin := ps.getPluginRepoWithTag()
  30. _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", plugin)
  31. c.Assert(err, checker.IsNil)
  32. out, _, err := dockerCmdWithError("plugin", "ls")
  33. c.Assert(err, checker.IsNil)
  34. c.Assert(out, checker.Contains, plugin)
  35. c.Assert(out, checker.Contains, "true")
  36. id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", plugin)
  37. id = strings.TrimSpace(id)
  38. c.Assert(err, checker.IsNil)
  39. out, _, err = dockerCmdWithError("plugin", "remove", plugin)
  40. c.Assert(err, checker.NotNil)
  41. c.Assert(out, checker.Contains, "is enabled")
  42. _, _, err = dockerCmdWithError("plugin", "disable", plugin)
  43. c.Assert(err, checker.IsNil)
  44. out, _, err = dockerCmdWithError("plugin", "remove", plugin)
  45. c.Assert(err, checker.IsNil)
  46. c.Assert(out, checker.Contains, plugin)
  47. _, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id))
  48. if !os.IsNotExist(err) {
  49. c.Fatal(err)
  50. }
  51. }
  52. func (ps *DockerPluginSuite) TestPluginForceRemove(c *check.C) {
  53. pNameWithTag := ps.getPluginRepoWithTag()
  54. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
  55. c.Assert(err, checker.IsNil)
  56. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  57. c.Assert(out, checker.Contains, "is enabled")
  58. out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag)
  59. c.Assert(err, checker.IsNil)
  60. c.Assert(out, checker.Contains, pNameWithTag)
  61. }
  62. func (s *DockerSuite) TestPluginActive(c *check.C) {
  63. testRequires(c, DaemonIsLinux, IsAmd64, Network)
  64. _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
  65. c.Assert(err, checker.IsNil)
  66. _, _, err = dockerCmdWithError("volume", "create", "-d", pNameWithTag, "--name", "testvol1")
  67. c.Assert(err, checker.IsNil)
  68. out, _, err := dockerCmdWithError("plugin", "disable", pNameWithTag)
  69. c.Assert(out, checker.Contains, "in use")
  70. _, _, err = dockerCmdWithError("volume", "rm", "testvol1")
  71. c.Assert(err, checker.IsNil)
  72. _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
  73. c.Assert(err, checker.IsNil)
  74. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  75. c.Assert(err, checker.IsNil)
  76. c.Assert(out, checker.Contains, pNameWithTag)
  77. }
  78. func (s *DockerSuite) TestPluginActiveNetwork(c *check.C) {
  79. testRequires(c, DaemonIsLinux, IsAmd64, Network)
  80. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", npNameWithTag)
  81. c.Assert(err, checker.IsNil)
  82. out, _, err = dockerCmdWithError("network", "create", "-d", npNameWithTag, "test")
  83. c.Assert(err, checker.IsNil)
  84. nID := strings.TrimSpace(out)
  85. out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag)
  86. c.Assert(out, checker.Contains, "is in use")
  87. _, _, err = dockerCmdWithError("network", "rm", nID)
  88. c.Assert(err, checker.IsNil)
  89. out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag)
  90. c.Assert(out, checker.Contains, "is enabled")
  91. _, _, err = dockerCmdWithError("plugin", "disable", npNameWithTag)
  92. c.Assert(err, checker.IsNil)
  93. out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag)
  94. c.Assert(err, checker.IsNil)
  95. c.Assert(out, checker.Contains, npNameWithTag)
  96. }
  97. func (ps *DockerPluginSuite) TestPluginInstallDisable(c *check.C) {
  98. pName := ps.getPluginRepoWithTag()
  99. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
  100. c.Assert(err, checker.IsNil)
  101. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  102. out, _, err = dockerCmdWithError("plugin", "ls")
  103. c.Assert(err, checker.IsNil)
  104. c.Assert(out, checker.Contains, "false")
  105. out, _, err = dockerCmdWithError("plugin", "enable", pName)
  106. c.Assert(err, checker.IsNil)
  107. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  108. out, _, err = dockerCmdWithError("plugin", "disable", pName)
  109. c.Assert(err, checker.IsNil)
  110. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  111. out, _, err = dockerCmdWithError("plugin", "remove", pName)
  112. c.Assert(err, checker.IsNil)
  113. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  114. }
  115. func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *check.C) {
  116. testRequires(c, DaemonIsLinux, IsAmd64, Network)
  117. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
  118. c.Assert(err, checker.IsNil)
  119. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  120. dockerCmd(c, "volume", "ls")
  121. }
  122. func (ps *DockerPluginSuite) TestPluginSet(c *check.C) {
  123. client := testEnv.APIClient()
  124. name := "test"
  125. ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
  126. defer cancel()
  127. initialValue := "0"
  128. mntSrc := "foo"
  129. devPath := "/dev/bar"
  130. // Create a new plugin with extra settings
  131. err := plugin.Create(ctx, client, name, func(cfg *plugin.Config) {
  132. cfg.Env = []types.PluginEnv{{Name: "DEBUG", Value: &initialValue, Settable: []string{"value"}}}
  133. cfg.Mounts = []types.PluginMount{
  134. {Name: "pmount1", Settable: []string{"source"}, Type: "none", Source: &mntSrc},
  135. {Name: "pmount2", Settable: []string{"source"}, Type: "none"}, // Mount without source is invalid.
  136. }
  137. cfg.Linux.Devices = []types.PluginDevice{
  138. {Name: "pdev1", Path: &devPath, Settable: []string{"path"}},
  139. {Name: "pdev2", Settable: []string{"path"}}, // Device without Path is invalid.
  140. }
  141. })
  142. c.Assert(err, checker.IsNil, check.Commentf("failed to create test plugin"))
  143. env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", name)
  144. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
  145. dockerCmd(c, "plugin", "set", name, "DEBUG=1")
  146. env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", name)
  147. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
  148. env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{with $mount := index .Settings.Mounts 0}}{{$mount.Source}}{{end}}", name)
  149. c.Assert(strings.TrimSpace(env), checker.Contains, mntSrc)
  150. dockerCmd(c, "plugin", "set", name, "pmount1.source=bar")
  151. env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{with $mount := index .Settings.Mounts 0}}{{$mount.Source}}{{end}}", name)
  152. c.Assert(strings.TrimSpace(env), checker.Contains, "bar")
  153. out, _, err := dockerCmdWithError("plugin", "set", name, "pmount2.source=bar2")
  154. c.Assert(err, checker.NotNil)
  155. c.Assert(out, checker.Contains, "Plugin config has no mount source")
  156. out, _, err = dockerCmdWithError("plugin", "set", name, "pdev2.path=/dev/bar2")
  157. c.Assert(err, checker.NotNil)
  158. c.Assert(out, checker.Contains, "Plugin config has no device path")
  159. }
  160. func (ps *DockerPluginSuite) TestPluginInstallArgs(c *check.C) {
  161. pName := path.Join(ps.registryHost(), "plugin", "testplugininstallwithargs")
  162. ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
  163. defer cancel()
  164. plugin.CreateInRegistry(ctx, pName, nil, func(cfg *plugin.Config) {
  165. cfg.Env = []types.PluginEnv{{Name: "DEBUG", Settable: []string{"value"}}}
  166. })
  167. out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1")
  168. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  169. env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
  170. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
  171. }
  172. func (ps *DockerPluginSuite) TestPluginInstallImage(c *check.C) {
  173. testRequires(c, IsAmd64)
  174. repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
  175. // tag the image to upload it to the private registry
  176. dockerCmd(c, "tag", "busybox", repoName)
  177. // push the image to the registry
  178. dockerCmd(c, "push", repoName)
  179. out, _, err := dockerCmdWithError("plugin", "install", repoName)
  180. c.Assert(err, checker.NotNil)
  181. c.Assert(out, checker.Contains, `Encountered remote "application/vnd.docker.container.image.v1+json"(image) when fetching`)
  182. }
  183. func (ps *DockerPluginSuite) TestPluginEnableDisableNegative(c *check.C) {
  184. pName := ps.getPluginRepoWithTag()
  185. out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName)
  186. c.Assert(err, checker.IsNil)
  187. c.Assert(strings.TrimSpace(out), checker.Contains, pName)
  188. out, _, err = dockerCmdWithError("plugin", "enable", pName)
  189. c.Assert(err, checker.NotNil)
  190. c.Assert(strings.TrimSpace(out), checker.Contains, "already enabled")
  191. _, _, err = dockerCmdWithError("plugin", "disable", pName)
  192. c.Assert(err, checker.IsNil)
  193. out, _, err = dockerCmdWithError("plugin", "disable", pName)
  194. c.Assert(err, checker.NotNil)
  195. c.Assert(strings.TrimSpace(out), checker.Contains, "already disabled")
  196. _, _, err = dockerCmdWithError("plugin", "remove", pName)
  197. c.Assert(err, checker.IsNil)
  198. }
  199. func (ps *DockerPluginSuite) TestPluginCreate(c *check.C) {
  200. name := "foo/bar-driver"
  201. temp, err := ioutil.TempDir("", "foo")
  202. c.Assert(err, checker.IsNil)
  203. defer os.RemoveAll(temp)
  204. data := `{"description": "foo plugin"}`
  205. err = ioutil.WriteFile(filepath.Join(temp, "config.json"), []byte(data), 0644)
  206. c.Assert(err, checker.IsNil)
  207. err = os.MkdirAll(filepath.Join(temp, "rootfs"), 0700)
  208. c.Assert(err, checker.IsNil)
  209. out, _, err := dockerCmdWithError("plugin", "create", name, temp)
  210. c.Assert(err, checker.IsNil)
  211. c.Assert(out, checker.Contains, name)
  212. out, _, err = dockerCmdWithError("plugin", "ls")
  213. c.Assert(err, checker.IsNil)
  214. c.Assert(out, checker.Contains, name)
  215. out, _, err = dockerCmdWithError("plugin", "create", name, temp)
  216. c.Assert(err, checker.NotNil)
  217. c.Assert(out, checker.Contains, "already exist")
  218. out, _, err = dockerCmdWithError("plugin", "ls")
  219. c.Assert(err, checker.IsNil)
  220. c.Assert(out, checker.Contains, name)
  221. // The output will consists of one HEADER line and one line of foo/bar-driver
  222. c.Assert(len(strings.Split(strings.TrimSpace(out), "\n")), checker.Equals, 2)
  223. }
  224. func (ps *DockerPluginSuite) TestPluginInspect(c *check.C) {
  225. pNameWithTag := ps.getPluginRepoWithTag()
  226. _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
  227. c.Assert(err, checker.IsNil)
  228. out, _, err := dockerCmdWithError("plugin", "ls")
  229. c.Assert(err, checker.IsNil)
  230. c.Assert(out, checker.Contains, pNameWithTag)
  231. c.Assert(out, checker.Contains, "true")
  232. // Find the ID first
  233. out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
  234. c.Assert(err, checker.IsNil)
  235. id := strings.TrimSpace(out)
  236. c.Assert(id, checker.Not(checker.Equals), "")
  237. // Long form
  238. out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id)
  239. c.Assert(err, checker.IsNil)
  240. c.Assert(strings.TrimSpace(out), checker.Equals, id)
  241. // Short form
  242. out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
  243. c.Assert(err, checker.IsNil)
  244. c.Assert(strings.TrimSpace(out), checker.Equals, id)
  245. // Name with tag form
  246. out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
  247. c.Assert(err, checker.IsNil)
  248. c.Assert(strings.TrimSpace(out), checker.Equals, id)
  249. // Name without tag form
  250. out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", ps.getPluginRepo())
  251. c.Assert(err, checker.IsNil)
  252. c.Assert(strings.TrimSpace(out), checker.Equals, id)
  253. _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
  254. c.Assert(err, checker.IsNil)
  255. out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
  256. c.Assert(err, checker.IsNil)
  257. c.Assert(out, checker.Contains, pNameWithTag)
  258. // After remove nothing should be found
  259. _, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
  260. c.Assert(err, checker.NotNil)
  261. }
  262. // Test case for https://github.com/docker/docker/pull/29186#discussion_r91277345
  263. func (s *DockerSuite) TestPluginInspectOnWindows(c *check.C) {
  264. // This test should work on Windows only
  265. testRequires(c, DaemonIsWindows)
  266. out, _, err := dockerCmdWithError("plugin", "inspect", "foobar")
  267. c.Assert(err, checker.NotNil)
  268. c.Assert(out, checker.Contains, "plugins are not supported on this platform")
  269. c.Assert(err.Error(), checker.Contains, "plugins are not supported on this platform")
  270. }
  271. func (s *DockerTrustSuite) TestPluginTrustedInstall(c *check.C) {
  272. testRequires(c, DaemonIsLinux, IsAmd64, Network)
  273. trustedName := s.setupTrustedplugin(c, pNameWithTag, "trusted-plugin-install")
  274. cli.Docker(cli.Args("plugin", "install", "--grant-all-permissions", trustedName), trustedCmd).Assert(c, icmd.Expected{
  275. Out: trustedName,
  276. })
  277. out := cli.DockerCmd(c, "plugin", "ls").Combined()
  278. c.Assert(out, checker.Contains, "true")
  279. out = cli.DockerCmd(c, "plugin", "disable", trustedName).Combined()
  280. c.Assert(strings.TrimSpace(out), checker.Contains, trustedName)
  281. out = cli.DockerCmd(c, "plugin", "enable", trustedName).Combined()
  282. c.Assert(strings.TrimSpace(out), checker.Contains, trustedName)
  283. out = cli.DockerCmd(c, "plugin", "rm", "-f", trustedName).Combined()
  284. c.Assert(strings.TrimSpace(out), checker.Contains, trustedName)
  285. // Try untrusted pull to ensure we pushed the tag to the registry
  286. cli.Docker(cli.Args("plugin", "install", "--disable-content-trust=true", "--grant-all-permissions", trustedName), trustedCmd).Assert(c, SuccessDownloaded)
  287. out = cli.DockerCmd(c, "plugin", "ls").Combined()
  288. c.Assert(out, checker.Contains, "true")
  289. }
  290. func (s *DockerTrustSuite) TestPluginUntrustedInstall(c *check.C) {
  291. testRequires(c, DaemonIsLinux, IsAmd64, Network)
  292. pluginName := fmt.Sprintf("%v/dockercliuntrusted/plugintest:latest", privateRegistryURL)
  293. // install locally and push to private registry
  294. cli.DockerCmd(c, "plugin", "install", "--grant-all-permissions", "--alias", pluginName, pNameWithTag)
  295. cli.DockerCmd(c, "plugin", "push", pluginName)
  296. cli.DockerCmd(c, "plugin", "rm", "-f", pluginName)
  297. // Try trusted install on untrusted plugin
  298. cli.Docker(cli.Args("plugin", "install", "--grant-all-permissions", pluginName), trustedCmd).Assert(c, icmd.Expected{
  299. ExitCode: 1,
  300. Err: "Error: remote trust data does not exist",
  301. })
  302. }
  303. func (ps *DockerPluginSuite) TestPluginIDPrefix(c *check.C) {
  304. name := "test"
  305. client := testEnv.APIClient()
  306. ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
  307. initialValue := "0"
  308. err := plugin.Create(ctx, client, name, func(cfg *plugin.Config) {
  309. cfg.Env = []types.PluginEnv{{Name: "DEBUG", Value: &initialValue, Settable: []string{"value"}}}
  310. })
  311. cancel()
  312. c.Assert(err, checker.IsNil, check.Commentf("failed to create test plugin"))
  313. // Find ID first
  314. id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", name)
  315. id = strings.TrimSpace(id)
  316. c.Assert(err, checker.IsNil)
  317. // List current state
  318. out, _, err := dockerCmdWithError("plugin", "ls")
  319. c.Assert(err, checker.IsNil)
  320. c.Assert(out, checker.Contains, name)
  321. c.Assert(out, checker.Contains, "false")
  322. env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5])
  323. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
  324. dockerCmd(c, "plugin", "set", id[:5], "DEBUG=1")
  325. env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5])
  326. c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
  327. // Enable
  328. _, _, err = dockerCmdWithError("plugin", "enable", id[:5])
  329. c.Assert(err, checker.IsNil)
  330. out, _, err = dockerCmdWithError("plugin", "ls")
  331. c.Assert(err, checker.IsNil)
  332. c.Assert(out, checker.Contains, name)
  333. c.Assert(out, checker.Contains, "true")
  334. // Disable
  335. _, _, err = dockerCmdWithError("plugin", "disable", id[:5])
  336. c.Assert(err, checker.IsNil)
  337. out, _, err = dockerCmdWithError("plugin", "ls")
  338. c.Assert(err, checker.IsNil)
  339. c.Assert(out, checker.Contains, name)
  340. c.Assert(out, checker.Contains, "false")
  341. // Remove
  342. out, _, err = dockerCmdWithError("plugin", "remove", id[:5])
  343. c.Assert(err, checker.IsNil)
  344. // List returns none
  345. out, _, err = dockerCmdWithError("plugin", "ls")
  346. c.Assert(err, checker.IsNil)
  347. c.Assert(out, checker.Not(checker.Contains), name)
  348. }
  349. func (ps *DockerPluginSuite) TestPluginListDefaultFormat(c *check.C) {
  350. config, err := ioutil.TempDir("", "config-file-")
  351. c.Assert(err, check.IsNil)
  352. defer os.RemoveAll(config)
  353. err = ioutil.WriteFile(filepath.Join(config, "config.json"), []byte(`{"pluginsFormat": "raw"}`), 0644)
  354. c.Assert(err, check.IsNil)
  355. name := "test:latest"
  356. client := testEnv.APIClient()
  357. ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
  358. defer cancel()
  359. err = plugin.Create(ctx, client, name, func(cfg *plugin.Config) {
  360. cfg.Description = "test plugin"
  361. })
  362. c.Assert(err, checker.IsNil, check.Commentf("failed to create test plugin"))
  363. out, _ := dockerCmd(c, "plugin", "inspect", "--format", "{{.ID}}", name)
  364. id := strings.TrimSpace(out)
  365. // We expect the format to be in `raw + --no-trunc`
  366. expectedOutput := fmt.Sprintf(`plugin_id: %s
  367. name: %s
  368. description: test plugin
  369. enabled: false`, id, name)
  370. out, _ = dockerCmd(c, "--config", config, "plugin", "ls", "--no-trunc")
  371. c.Assert(strings.TrimSpace(out), checker.Contains, expectedOutput)
  372. }
  373. func (s *DockerSuite) TestPluginUpgrade(c *check.C) {
  374. testRequires(c, DaemonIsLinux, Network, SameHostDaemon, IsAmd64, NotUserNamespace)
  375. plugin := "cpuguy83/docker-volume-driver-plugin-local:latest"
  376. pluginV2 := "cpuguy83/docker-volume-driver-plugin-local:v2"
  377. dockerCmd(c, "plugin", "install", "--grant-all-permissions", plugin)
  378. dockerCmd(c, "volume", "create", "--driver", plugin, "bananas")
  379. dockerCmd(c, "run", "--rm", "-v", "bananas:/apple", "busybox", "sh", "-c", "touch /apple/core")
  380. out, _, err := dockerCmdWithError("plugin", "upgrade", "--grant-all-permissions", plugin, pluginV2)
  381. c.Assert(err, checker.NotNil, check.Commentf(out))
  382. c.Assert(out, checker.Contains, "disabled before upgrading")
  383. out, _ = dockerCmd(c, "plugin", "inspect", "--format={{.ID}}", plugin)
  384. id := strings.TrimSpace(out)
  385. // make sure "v2" does not exists
  386. _, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id, "rootfs", "v2"))
  387. c.Assert(os.IsNotExist(err), checker.True, check.Commentf(out))
  388. dockerCmd(c, "plugin", "disable", "-f", plugin)
  389. dockerCmd(c, "plugin", "upgrade", "--grant-all-permissions", "--skip-remote-check", plugin, pluginV2)
  390. // make sure "v2" file exists
  391. _, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id, "rootfs", "v2"))
  392. c.Assert(err, checker.IsNil)
  393. dockerCmd(c, "plugin", "enable", plugin)
  394. dockerCmd(c, "volume", "inspect", "bananas")
  395. dockerCmd(c, "run", "--rm", "-v", "bananas:/apple", "busybox", "sh", "-c", "ls -lh /apple/core")
  396. }
  397. func (s *DockerSuite) TestPluginMetricsCollector(c *check.C) {
  398. testRequires(c, DaemonIsLinux, Network, SameHostDaemon, IsAmd64)
  399. d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{})
  400. d.Start(c)
  401. defer d.Stop(c)
  402. name := "cpuguy83/docker-metrics-plugin-test:latest"
  403. r := cli.Docker(cli.Args("plugin", "install", "--grant-all-permissions", name), cli.Daemon(d))
  404. c.Assert(r.Error, checker.IsNil, check.Commentf(r.Combined()))
  405. // plugin lisens on localhost:19393 and proxies the metrics
  406. resp, err := http.Get("http://localhost:19393/metrics")
  407. c.Assert(err, checker.IsNil)
  408. defer resp.Body.Close()
  409. b, err := ioutil.ReadAll(resp.Body)
  410. c.Assert(err, checker.IsNil)
  411. // check that a known metric is there... don't expect this metric to change over time.. probably safe
  412. c.Assert(string(b), checker.Contains, "container_actions")
  413. }