docker_cli_plugins_test.go 19 KB

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