integration-cli/docker_cli_plugins_test.go
a2d48c9e
 package main
 
 import (
7d62e40f
 	"context"
3d86b0c7
 	"fmt"
662d4569
 	"io/ioutil"
0e8e8f0f
 	"net/http"
5690730a
 	"os"
15a538a6
 	"path"
5690730a
 	"path/filepath"
6dca1e6d
 	"strings"
e25352a4
 	"testing"
15a538a6
 	"time"
303b1d20
 
15a538a6
 	"github.com/docker/docker/api/types"
b0ba39d4
 	"github.com/docker/docker/integration-cli/cli"
0e8e8f0f
 	"github.com/docker/docker/integration-cli/daemon"
5f56503f
 	"github.com/docker/docker/internal/test/fixtures/plugin"
6345208b
 	"gotest.tools/assert"
6dca1e6d
 )
 
 var (
c54b717c
 	pluginProcessName = "sample-volume-plugin"
f4798b98
 	pName             = "tiborvass/sample-volume-plugin"
 	npName            = "tiborvass/test-docker-netplugin"
a08ffa0e
 	pTag              = "latest"
 	pNameWithTag      = pName + ":" + pTag
fc2c0e62
 	npNameWithTag     = npName + ":" + pTag
a2d48c9e
 )
 
64a928a3
 func (ps *DockerPluginSuite) TestPluginBasicOps(c *testing.T) {
15a538a6
 	plugin := ps.getPluginRepoWithTag()
 	_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", plugin)
6345208b
 	assert.NilError(c, err)
a2d48c9e
 
 	out, _, err := dockerCmdWithError("plugin", "ls")
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, plugin))
 	assert.Assert(c, strings.Contains(out, "true"))
15a538a6
 	id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", plugin)
586b7cc1
 	id = strings.TrimSpace(id)
6345208b
 	assert.NilError(c, err)
a2d48c9e
 
15a538a6
 	out, _, err = dockerCmdWithError("plugin", "remove", plugin)
6345208b
 	assert.ErrorContains(c, err, "")
ed9449a4
 	assert.Assert(c, strings.Contains(out, "is enabled"))
15a538a6
 	_, _, err = dockerCmdWithError("plugin", "disable", plugin)
6345208b
 	assert.NilError(c, err)
a2d48c9e
 
15a538a6
 	out, _, err = dockerCmdWithError("plugin", "remove", plugin)
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, plugin))
142b1f8b
 	_, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id))
5690730a
 	if !os.IsNotExist(err) {
 		c.Fatal(err)
 	}
a2d48c9e
 }
22e781e8
 
64a928a3
 func (ps *DockerPluginSuite) TestPluginForceRemove(c *testing.T) {
15a538a6
 	pNameWithTag := ps.getPluginRepoWithTag()
 
ddd8a657
 	_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
6345208b
 	assert.NilError(c, err)
0016b331
 
ddd8a657
 	out, _, _ := dockerCmdWithError("plugin", "remove", pNameWithTag)
ed9449a4
 	assert.Assert(c, strings.Contains(out, "is enabled"))
0016b331
 	out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag)
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, pNameWithTag))
b22d07f5
 }
 
64a928a3
 func (s *DockerSuite) TestPluginActive(c *testing.T) {
ebff8c79
 	testRequires(c, DaemonIsLinux, IsAmd64, Network)
15a538a6
 
8cb2229c
 	_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
6345208b
 	assert.NilError(c, err)
b22d07f5
 
8cb2229c
 	_, _, err = dockerCmdWithError("volume", "create", "-d", pNameWithTag, "--name", "testvol1")
6345208b
 	assert.NilError(c, err)
b22d07f5
 
ddd8a657
 	out, _, _ := dockerCmdWithError("plugin", "disable", pNameWithTag)
ed9449a4
 	assert.Assert(c, strings.Contains(out, "in use"))
8cb2229c
 	_, _, err = dockerCmdWithError("volume", "rm", "testvol1")
6345208b
 	assert.NilError(c, err)
b22d07f5
 
 	_, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
6345208b
 	assert.NilError(c, err)
b22d07f5
 
 	out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, pNameWithTag))
0016b331
 }
 
64a928a3
 func (s *DockerSuite) TestPluginActiveNetwork(c *testing.T) {
fc2c0e62
 	testRequires(c, DaemonIsLinux, IsAmd64, Network)
ddd8a657
 	_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", npNameWithTag)
6345208b
 	assert.NilError(c, err)
fc2c0e62
 
ddd8a657
 	out, _, err := dockerCmdWithError("network", "create", "-d", npNameWithTag, "test")
6345208b
 	assert.NilError(c, err)
fc2c0e62
 
 	nID := strings.TrimSpace(out)
 
ddd8a657
 	out, _, _ = dockerCmdWithError("plugin", "remove", npNameWithTag)
ed9449a4
 	assert.Assert(c, strings.Contains(out, "is in use"))
fc2c0e62
 	_, _, err = dockerCmdWithError("network", "rm", nID)
6345208b
 	assert.NilError(c, err)
fc2c0e62
 
ddd8a657
 	out, _, _ = dockerCmdWithError("plugin", "remove", npNameWithTag)
ed9449a4
 	assert.Assert(c, strings.Contains(out, "is enabled"))
fc2c0e62
 	_, _, err = dockerCmdWithError("plugin", "disable", npNameWithTag)
6345208b
 	assert.NilError(c, err)
fc2c0e62
 
 	out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag)
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, npNameWithTag))
fc2c0e62
 }
 
64a928a3
 func (ps *DockerPluginSuite) TestPluginInstallDisable(c *testing.T) {
15a538a6
 	pName := ps.getPluginRepoWithTag()
 
6dca1e6d
 	out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
6dca1e6d
 	out, _, err = dockerCmdWithError("plugin", "ls")
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, "false"))
6dca1e6d
 	out, _, err = dockerCmdWithError("plugin", "enable", pName)
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
6dca1e6d
 	out, _, err = dockerCmdWithError("plugin", "disable", pName)
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
6dca1e6d
 	out, _, err = dockerCmdWithError("plugin", "remove", pName)
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
22e781e8
 }
d32df6d9
 
64a928a3
 func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *testing.T) {
ebff8c79
 	testRequires(c, DaemonIsLinux, IsAmd64, Network)
7236e420
 	out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
7236e420
 	dockerCmd(c, "volume", "ls")
 }
 
64a928a3
 func (ps *DockerPluginSuite) TestPluginSet(c *testing.T) {
0a91ba2d
 	client := testEnv.APIClient()
efbed450
 
15a538a6
 	name := "test"
 	ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
 	defer cancel()
 
 	initialValue := "0"
6572e27d
 	mntSrc := "foo"
 	devPath := "/dev/bar"
 
0a91ba2d
 	// Create a new plugin with extra settings
 	err := plugin.Create(ctx, client, name, func(cfg *plugin.Config) {
15a538a6
 		cfg.Env = []types.PluginEnv{{Name: "DEBUG", Value: &initialValue, Settable: []string{"value"}}}
6572e27d
 		cfg.Mounts = []types.PluginMount{
 			{Name: "pmount1", Settable: []string{"source"}, Type: "none", Source: &mntSrc},
 			{Name: "pmount2", Settable: []string{"source"}, Type: "none"}, // Mount without source is invalid.
 		}
 		cfg.Linux.Devices = []types.PluginDevice{
 			{Name: "pdev1", Path: &devPath, Settable: []string{"path"}},
 			{Name: "pdev2", Settable: []string{"path"}}, // Device without Path is invalid.
 		}
15a538a6
 	})
2f069fa3
 	assert.Assert(c, err == nil, "failed to create test plugin")
15a538a6
 
 	env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", name)
6dc7846d
 	assert.Equal(c, strings.TrimSpace(env), "[DEBUG=0]")
efbed450
 
15a538a6
 	dockerCmd(c, "plugin", "set", name, "DEBUG=1")
efbed450
 
15a538a6
 	env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", name)
6dc7846d
 	assert.Equal(c, strings.TrimSpace(env), "[DEBUG=1]")
6572e27d
 
 	env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{with $mount := index .Settings.Mounts 0}}{{$mount.Source}}{{end}}", name)
ed9449a4
 	assert.Assert(c, strings.Contains(strings.TrimSpace(env), mntSrc))
6572e27d
 	dockerCmd(c, "plugin", "set", name, "pmount1.source=bar")
 
 	env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{with $mount := index .Settings.Mounts 0}}{{$mount.Source}}{{end}}", name)
ed9449a4
 	assert.Assert(c, strings.Contains(strings.TrimSpace(env), "bar"))
6572e27d
 	out, _, err := dockerCmdWithError("plugin", "set", name, "pmount2.source=bar2")
6345208b
 	assert.ErrorContains(c, err, "")
ed9449a4
 	assert.Assert(c, strings.Contains(out, "Plugin config has no mount source"))
6572e27d
 	out, _, err = dockerCmdWithError("plugin", "set", name, "pdev2.path=/dev/bar2")
6345208b
 	assert.ErrorContains(c, err, "")
ed9449a4
 	assert.Assert(c, strings.Contains(out, "Plugin config has no device path"))
efbed450
 }
 
64a928a3
 func (ps *DockerPluginSuite) TestPluginInstallArgs(c *testing.T) {
15a538a6
 	pName := path.Join(ps.registryHost(), "plugin", "testplugininstallwithargs")
 	ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
 	defer cancel()
 
 	plugin.CreateInRegistry(ctx, pName, nil, func(cfg *plugin.Config) {
 		cfg.Env = []types.PluginEnv{{Name: "DEBUG", Settable: []string{"value"}}}
 	})
 
69276fdd
 	out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1")
ed9449a4
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
49ca91fb
 	env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
6dc7846d
 	assert.Equal(c, strings.TrimSpace(env), "[DEBUG=1]")
69276fdd
 }
 
64a928a3
 func (ps *DockerPluginSuite) TestPluginInstallImage(c *testing.T) {
15a538a6
 	testRequires(c, IsAmd64)
3d86b0c7
 
 	repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
 	// tag the image to upload it to the private registry
 	dockerCmd(c, "tag", "busybox", repoName)
 	// push the image to the registry
 	dockerCmd(c, "push", repoName)
 
 	out, _, err := dockerCmdWithError("plugin", "install", repoName)
6345208b
 	assert.ErrorContains(c, err, "")
ed9449a4
 	assert.Assert(c, strings.Contains(out, `Encountered remote "application/vnd.docker.container.image.v1+json"(image) when fetching`))
d32df6d9
 }
b867f6c6
 
64a928a3
 func (ps *DockerPluginSuite) TestPluginEnableDisableNegative(c *testing.T) {
15a538a6
 	pName := ps.getPluginRepoWithTag()
 
b867f6c6
 	out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName)
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
b867f6c6
 	out, _, err = dockerCmdWithError("plugin", "enable", pName)
6345208b
 	assert.ErrorContains(c, err, "")
ed9449a4
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), "already enabled"))
b867f6c6
 	_, _, err = dockerCmdWithError("plugin", "disable", pName)
6345208b
 	assert.NilError(c, err)
b867f6c6
 
 	out, _, err = dockerCmdWithError("plugin", "disable", pName)
6345208b
 	assert.ErrorContains(c, err, "")
ed9449a4
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), "already disabled"))
b867f6c6
 	_, _, err = dockerCmdWithError("plugin", "remove", pName)
6345208b
 	assert.NilError(c, err)
b867f6c6
 }
662d4569
 
64a928a3
 func (ps *DockerPluginSuite) TestPluginCreate(c *testing.T) {
662d4569
 	name := "foo/bar-driver"
 	temp, err := ioutil.TempDir("", "foo")
6345208b
 	assert.NilError(c, err)
662d4569
 	defer os.RemoveAll(temp)
 
 	data := `{"description": "foo plugin"}`
 	err = ioutil.WriteFile(filepath.Join(temp, "config.json"), []byte(data), 0644)
6345208b
 	assert.NilError(c, err)
662d4569
 
3d86b0c7
 	err = os.MkdirAll(filepath.Join(temp, "rootfs"), 0700)
6345208b
 	assert.NilError(c, err)
3d86b0c7
 
662d4569
 	out, _, err := dockerCmdWithError("plugin", "create", name, temp)
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, name))
662d4569
 	out, _, err = dockerCmdWithError("plugin", "ls")
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, name))
662d4569
 	out, _, err = dockerCmdWithError("plugin", "create", name, temp)
6345208b
 	assert.ErrorContains(c, err, "")
ed9449a4
 	assert.Assert(c, strings.Contains(out, "already exist"))
662d4569
 	out, _, err = dockerCmdWithError("plugin", "ls")
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, name))
662d4569
 	// The output will consists of one HEADER line and one line of foo/bar-driver
6dc7846d
 	assert.Equal(c, len(strings.Split(strings.TrimSpace(out), "\n")), 2)
662d4569
 }
0ce6e070
 
64a928a3
 func (ps *DockerPluginSuite) TestPluginInspect(c *testing.T) {
15a538a6
 	pNameWithTag := ps.getPluginRepoWithTag()
 
0ce6e070
 	_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
6345208b
 	assert.NilError(c, err)
0ce6e070
 
 	out, _, err := dockerCmdWithError("plugin", "ls")
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, pNameWithTag))
 	assert.Assert(c, strings.Contains(out, "true"))
0ce6e070
 	// Find the ID first
 	out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
6345208b
 	assert.NilError(c, err)
0ce6e070
 	id := strings.TrimSpace(out)
6345208b
 	assert.Assert(c, id != "")
0ce6e070
 
 	// Long form
 	out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id)
6345208b
 	assert.NilError(c, err)
 	assert.Equal(c, strings.TrimSpace(out), id)
0ce6e070
 
 	// Short form
 	out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
6345208b
 	assert.NilError(c, err)
 	assert.Equal(c, strings.TrimSpace(out), id)
0ce6e070
 
 	// Name with tag form
 	out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
6345208b
 	assert.NilError(c, err)
 	assert.Equal(c, strings.TrimSpace(out), id)
0ce6e070
 
 	// Name without tag form
15a538a6
 	out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", ps.getPluginRepo())
6345208b
 	assert.NilError(c, err)
 	assert.Equal(c, strings.TrimSpace(out), id)
0ce6e070
 
 	_, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
6345208b
 	assert.NilError(c, err)
0ce6e070
 
 	out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, pNameWithTag))
0ce6e070
 	// After remove nothing should be found
 	_, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
6345208b
 	assert.ErrorContains(c, err, "")
0ce6e070
 }
0b3c10ac
 
 // Test case for https://github.com/docker/docker/pull/29186#discussion_r91277345
64a928a3
 func (s *DockerSuite) TestPluginInspectOnWindows(c *testing.T) {
0b3c10ac
 	// This test should work on Windows only
 	testRequires(c, DaemonIsWindows)
 
 	out, _, err := dockerCmdWithError("plugin", "inspect", "foobar")
6345208b
 	assert.ErrorContains(c, err, "")
ed9449a4
 	assert.Assert(c, strings.Contains(out, "plugins are not supported on this platform"))
6345208b
 	assert.ErrorContains(c, err, "plugins are not supported on this platform")
0b3c10ac
 }
14e8bba4
 
64a928a3
 func (ps *DockerPluginSuite) TestPluginIDPrefix(c *testing.T) {
15a538a6
 	name := "test"
0a91ba2d
 	client := testEnv.APIClient()
15a538a6
 
 	ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
 	initialValue := "0"
0a91ba2d
 	err := plugin.Create(ctx, client, name, func(cfg *plugin.Config) {
15a538a6
 		cfg.Env = []types.PluginEnv{{Name: "DEBUG", Value: &initialValue, Settable: []string{"value"}}}
 	})
 	cancel()
 
2f069fa3
 	assert.Assert(c, err == nil, "failed to create test plugin")
c80e74e8
 
 	// Find ID first
15a538a6
 	id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", name)
c80e74e8
 	id = strings.TrimSpace(id)
6345208b
 	assert.NilError(c, err)
c80e74e8
 
 	// List current state
 	out, _, err := dockerCmdWithError("plugin", "ls")
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, name))
 	assert.Assert(c, strings.Contains(out, "false"))
c80e74e8
 	env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5])
6dc7846d
 	assert.Equal(c, strings.TrimSpace(env), "[DEBUG=0]")
c80e74e8
 
 	dockerCmd(c, "plugin", "set", id[:5], "DEBUG=1")
 
 	env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5])
6dc7846d
 	assert.Equal(c, strings.TrimSpace(env), "[DEBUG=1]")
c80e74e8
 
 	// Enable
 	_, _, err = dockerCmdWithError("plugin", "enable", id[:5])
6345208b
 	assert.NilError(c, err)
c80e74e8
 	out, _, err = dockerCmdWithError("plugin", "ls")
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, name))
 	assert.Assert(c, strings.Contains(out, "true"))
c80e74e8
 	// Disable
 	_, _, err = dockerCmdWithError("plugin", "disable", id[:5])
6345208b
 	assert.NilError(c, err)
c80e74e8
 	out, _, err = dockerCmdWithError("plugin", "ls")
6345208b
 	assert.NilError(c, err)
ed9449a4
 	assert.Assert(c, strings.Contains(out, name))
 	assert.Assert(c, strings.Contains(out, "false"))
c80e74e8
 	// Remove
ddd8a657
 	_, _, err = dockerCmdWithError("plugin", "remove", id[:5])
6345208b
 	assert.NilError(c, err)
c80e74e8
 	// List returns none
 	out, _, err = dockerCmdWithError("plugin", "ls")
6345208b
 	assert.NilError(c, err)
07b24365
 	assert.Assert(c, !strings.Contains(out, name))
c80e74e8
 }
1c0d37fa
 
64a928a3
 func (ps *DockerPluginSuite) TestPluginListDefaultFormat(c *testing.T) {
1c0d37fa
 	config, err := ioutil.TempDir("", "config-file-")
6345208b
 	assert.NilError(c, err)
1c0d37fa
 	defer os.RemoveAll(config)
 
 	err = ioutil.WriteFile(filepath.Join(config, "config.json"), []byte(`{"pluginsFormat": "raw"}`), 0644)
6345208b
 	assert.NilError(c, err)
1c0d37fa
 
15a538a6
 	name := "test:latest"
0a91ba2d
 	client := testEnv.APIClient()
15a538a6
 
 	ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
 	defer cancel()
 	err = plugin.Create(ctx, client, name, func(cfg *plugin.Config) {
 		cfg.Description = "test plugin"
 	})
2f069fa3
 	assert.Assert(c, err == nil, "failed to create test plugin")
1c0d37fa
 
15a538a6
 	out, _ := dockerCmd(c, "plugin", "inspect", "--format", "{{.ID}}", name)
1c0d37fa
 	id := strings.TrimSpace(out)
 
 	// We expect the format to be in `raw + --no-trunc`
 	expectedOutput := fmt.Sprintf(`plugin_id: %s
 name: %s
15a538a6
 description: test plugin
 enabled: false`, id, name)
1c0d37fa
 
 	out, _ = dockerCmd(c, "--config", config, "plugin", "ls", "--no-trunc")
ed9449a4
 	assert.Assert(c, strings.Contains(strings.TrimSpace(out), expectedOutput))
1c0d37fa
 }
03c69497
 
64a928a3
 func (s *DockerSuite) TestPluginUpgrade(c *testing.T) {
43b15e92
 	testRequires(c, DaemonIsLinux, Network, testEnv.IsLocalDaemon, IsAmd64, NotUserNamespace)
03c69497
 	plugin := "cpuguy83/docker-volume-driver-plugin-local:latest"
 	pluginV2 := "cpuguy83/docker-volume-driver-plugin-local:v2"
 
 	dockerCmd(c, "plugin", "install", "--grant-all-permissions", plugin)
e8307b86
 	dockerCmd(c, "volume", "create", "--driver", plugin, "bananas")
 	dockerCmd(c, "run", "--rm", "-v", "bananas:/apple", "busybox", "sh", "-c", "touch /apple/core")
 
03c69497
 	out, _, err := dockerCmdWithError("plugin", "upgrade", "--grant-all-permissions", plugin, pluginV2)
6345208b
 	assert.ErrorContains(c, err, "", out)
ed9449a4
 	assert.Assert(c, strings.Contains(out, "disabled before upgrading"))
03c69497
 	out, _ = dockerCmd(c, "plugin", "inspect", "--format={{.ID}}", plugin)
 	id := strings.TrimSpace(out)
 
 	// make sure "v2" does not exists
142b1f8b
 	_, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id, "rootfs", "v2"))
4cf69b99
 	assert.Assert(c, os.IsNotExist(err), "%s", out)
03c69497
 
e8307b86
 	dockerCmd(c, "plugin", "disable", "-f", plugin)
03c69497
 	dockerCmd(c, "plugin", "upgrade", "--grant-all-permissions", "--skip-remote-check", plugin, pluginV2)
 
 	// make sure "v2" file exists
142b1f8b
 	_, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id, "rootfs", "v2"))
6345208b
 	assert.NilError(c, err)
03c69497
 
 	dockerCmd(c, "plugin", "enable", plugin)
e8307b86
 	dockerCmd(c, "volume", "inspect", "bananas")
 	dockerCmd(c, "run", "--rm", "-v", "bananas:/apple", "busybox", "sh", "-c", "ls -lh /apple/core")
03c69497
 }
0e8e8f0f
 
64a928a3
 func (s *DockerSuite) TestPluginMetricsCollector(c *testing.T) {
43b15e92
 	testRequires(c, DaemonIsLinux, Network, testEnv.IsLocalDaemon, IsAmd64)
239a8a51
 	d := daemon.New(c, dockerBinary, dockerdBinary)
0e8e8f0f
 	d.Start(c)
 	defer d.Stop(c)
 
 	name := "cpuguy83/docker-metrics-plugin-test:latest"
 	r := cli.Docker(cli.Args("plugin", "install", "--grant-all-permissions", name), cli.Daemon(d))
be28c059
 	assert.Assert(c, r.Error == nil, r.Combined())
0e8e8f0f
 
 	// plugin lisens on localhost:19393 and proxies the metrics
 	resp, err := http.Get("http://localhost:19393/metrics")
6345208b
 	assert.NilError(c, err)
0e8e8f0f
 	defer resp.Body.Close()
 
 	b, err := ioutil.ReadAll(resp.Body)
6345208b
 	assert.NilError(c, err)
39bcaee4
 	// check that a known metric is there... don't expect this metric to change over time.. probably safe
ed9449a4
 	assert.Assert(c, strings.Contains(string(b), "container_actions"))
0e8e8f0f
 }