2016-06-15 13:18:55 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-04-19 18:30:59 -04:00
|
|
|
"context"
|
2016-12-12 18:05:53 -05:00
|
|
|
"fmt"
|
2021-08-24 06:10:50 -04:00
|
|
|
"io"
|
2017-04-13 21:56:50 -04:00
|
|
|
"net/http"
|
2016-07-27 16:38:13 -04:00
|
|
|
"os"
|
2017-07-12 16:31:13 -04:00
|
|
|
"path"
|
2016-07-27 16:38:13 -04:00
|
|
|
"path/filepath"
|
2016-07-15 13:37:17 -04:00
|
|
|
"strings"
|
2019-09-09 17:06:12 -04:00
|
|
|
"testing"
|
2017-07-12 16:31:13 -04:00
|
|
|
"time"
|
2017-01-05 13:08:24 -05:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2017-04-19 08:04:39 -04:00
|
|
|
"github.com/docker/docker/integration-cli/cli"
|
2017-04-13 21:56:50 -04:00
|
|
|
"github.com/docker/docker/integration-cli/daemon"
|
2019-08-29 16:52:40 -04:00
|
|
|
"github.com/docker/docker/testutil/fixtures/plugin"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2016-07-15 13:37:17 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-11-22 14:21:34 -05:00
|
|
|
pluginProcessName = "sample-volume-plugin"
|
2017-01-05 16:55:43 -05:00
|
|
|
pName = "tiborvass/sample-volume-plugin"
|
|
|
|
npName = "tiborvass/test-docker-netplugin"
|
2016-11-10 16:07:53 -05:00
|
|
|
pTag = "latest"
|
|
|
|
pNameWithTag = pName + ":" + pTag
|
2016-12-16 15:53:22 -05:00
|
|
|
npNameWithTag = npName + ":" + pTag
|
2016-06-15 13:18:55 -04:00
|
|
|
)
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginBasicOps(c *testing.T) {
|
2017-07-12 16:31:13 -04:00
|
|
|
plugin := ps.getPluginRepoWithTag()
|
|
|
|
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", plugin)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-06-15 13:18:55 -04:00
|
|
|
|
|
|
|
out, _, err := dockerCmdWithError("plugin", "ls")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, plugin))
|
|
|
|
assert.Assert(c, strings.Contains(out, "true"))
|
2017-07-12 16:31:13 -04:00
|
|
|
id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", plugin)
|
2016-11-04 20:37:41 -04:00
|
|
|
id = strings.TrimSpace(id)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-06-15 13:18:55 -04:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", plugin)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "is enabled"))
|
2017-07-12 16:31:13 -04:00
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", plugin)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-06-15 13:18:55 -04:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", plugin)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, plugin))
|
2018-01-15 09:28:10 -05:00
|
|
|
_, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id))
|
2016-07-27 16:38:13 -04:00
|
|
|
if !os.IsNotExist(err) {
|
|
|
|
c.Fatal(err)
|
|
|
|
}
|
2016-06-15 13:18:55 -04:00
|
|
|
}
|
2016-06-17 10:44:57 -04:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginForceRemove(c *testing.T) {
|
2017-07-12 16:31:13 -04:00
|
|
|
pNameWithTag := ps.getPluginRepoWithTag()
|
|
|
|
|
2018-07-09 13:40:34 -04:00
|
|
|
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-07-22 11:24:54 -04:00
|
|
|
|
2018-07-09 13:40:34 -04:00
|
|
|
out, _, _ := dockerCmdWithError("plugin", "remove", pNameWithTag)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "is enabled"))
|
2016-07-22 11:24:54 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, pNameWithTag))
|
2016-09-07 09:59:15 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestPluginActive(c *testing.T) {
|
2016-12-12 15:46:36 -05:00
|
|
|
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
2017-07-12 16:31:13 -04:00
|
|
|
|
2016-12-20 11:26:58 -05:00
|
|
|
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-09-07 09:59:15 -04:00
|
|
|
|
2016-12-20 11:26:58 -05:00
|
|
|
_, _, err = dockerCmdWithError("volume", "create", "-d", pNameWithTag, "--name", "testvol1")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-09-07 09:59:15 -04:00
|
|
|
|
2018-07-09 13:40:34 -04:00
|
|
|
out, _, _ := dockerCmdWithError("plugin", "disable", pNameWithTag)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "in use"))
|
2016-12-20 11:26:58 -05:00
|
|
|
_, _, err = dockerCmdWithError("volume", "rm", "testvol1")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-09-07 09:59:15 -04:00
|
|
|
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-09-07 09:59:15 -04:00
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, pNameWithTag))
|
2016-07-22 11:24:54 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestPluginActiveNetwork(c *testing.T) {
|
2016-12-16 15:53:22 -05:00
|
|
|
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
2018-07-09 13:40:34 -04:00
|
|
|
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", npNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-12-16 15:53:22 -05:00
|
|
|
|
2018-07-09 13:40:34 -04:00
|
|
|
out, _, err := dockerCmdWithError("network", "create", "-d", npNameWithTag, "test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-12-16 15:53:22 -05:00
|
|
|
|
|
|
|
nID := strings.TrimSpace(out)
|
|
|
|
|
2018-07-09 13:40:34 -04:00
|
|
|
out, _, _ = dockerCmdWithError("plugin", "remove", npNameWithTag)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "is in use"))
|
2016-12-16 15:53:22 -05:00
|
|
|
_, _, err = dockerCmdWithError("network", "rm", nID)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-12-16 15:53:22 -05:00
|
|
|
|
2018-07-09 13:40:34 -04:00
|
|
|
out, _, _ = dockerCmdWithError("plugin", "remove", npNameWithTag)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "is enabled"))
|
2016-12-16 15:53:22 -05:00
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", npNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-12-16 15:53:22 -05:00
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, npNameWithTag))
|
2016-12-16 15:53:22 -05:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginInstallDisable(c *testing.T) {
|
2017-07-12 16:31:13 -04:00
|
|
|
pName := ps.getPluginRepoWithTag()
|
|
|
|
|
2016-07-15 13:37:17 -04:00
|
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
2016-07-15 13:37:17 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "false"))
|
2016-07-15 13:37:17 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "enable", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
2016-07-15 13:37:17 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "disable", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
2016-07-15 13:37:17 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
2016-06-17 10:44:57 -04:00
|
|
|
}
|
2016-07-06 15:16:14 -04:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *testing.T) {
|
2016-12-12 15:46:36 -05:00
|
|
|
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
2016-11-01 18:03:14 -04:00
|
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
2016-11-01 18:03:14 -04:00
|
|
|
dockerCmd(c, "volume", "ls")
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginSet(c *testing.T) {
|
2017-09-19 16:12:29 -04:00
|
|
|
client := testEnv.APIClient()
|
2016-10-31 20:07:05 -04:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
name := "test"
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
initialValue := "0"
|
2017-11-28 16:04:13 -05:00
|
|
|
mntSrc := "foo"
|
|
|
|
devPath := "/dev/bar"
|
|
|
|
|
2017-09-19 16:12:29 -04:00
|
|
|
// Create a new plugin with extra settings
|
|
|
|
err := plugin.Create(ctx, client, name, func(cfg *plugin.Config) {
|
2017-07-12 16:31:13 -04:00
|
|
|
cfg.Env = []types.PluginEnv{{Name: "DEBUG", Value: &initialValue, Settable: []string{"value"}}}
|
2017-11-28 16:04:13 -05:00
|
|
|
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.
|
|
|
|
}
|
2017-07-12 16:31:13 -04:00
|
|
|
})
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, err == nil, "failed to create test plugin")
|
2017-07-12 16:31:13 -04:00
|
|
|
|
|
|
|
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", name)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, strings.TrimSpace(env), "[DEBUG=0]")
|
2016-10-31 20:07:05 -04:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
dockerCmd(c, "plugin", "set", name, "DEBUG=1")
|
2016-10-31 20:07:05 -04:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", name)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, strings.TrimSpace(env), "[DEBUG=1]")
|
2017-11-28 16:04:13 -05:00
|
|
|
|
|
|
|
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{with $mount := index .Settings.Mounts 0}}{{$mount.Source}}{{end}}", name)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(env), mntSrc))
|
2017-11-28 16:04:13 -05:00
|
|
|
dockerCmd(c, "plugin", "set", name, "pmount1.source=bar")
|
|
|
|
|
|
|
|
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{with $mount := index .Settings.Mounts 0}}{{$mount.Source}}{{end}}", name)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(env), "bar"))
|
2017-11-28 16:04:13 -05:00
|
|
|
out, _, err := dockerCmdWithError("plugin", "set", name, "pmount2.source=bar2")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "Plugin config has no mount source"))
|
2017-11-28 16:04:13 -05:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "set", name, "pdev2.path=/dev/bar2")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "Plugin config has no device path"))
|
2016-10-31 20:07:05 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginInstallArgs(c *testing.T) {
|
2017-07-12 16:31:13 -04:00
|
|
|
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"}}}
|
|
|
|
})
|
|
|
|
|
2016-11-07 20:43:11 -05:00
|
|
|
out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
2016-11-07 21:51:47 -05:00
|
|
|
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, strings.TrimSpace(env), "[DEBUG=1]")
|
2016-11-07 20:43:11 -05:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginInstallImage(c *testing.T) {
|
2017-07-12 16:31:13 -04:00
|
|
|
testRequires(c, IsAmd64)
|
2016-12-12 18:05:53 -05:00
|
|
|
|
|
|
|
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)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, `Encountered remote "application/vnd.docker.container.image.v1+json"(image) when fetching`))
|
2016-07-06 15:16:14 -04:00
|
|
|
}
|
2016-07-25 17:06:27 -04:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginEnableDisableNegative(c *testing.T) {
|
2017-07-12 16:31:13 -04:00
|
|
|
pName := ps.getPluginRepoWithTag()
|
|
|
|
|
2016-07-25 17:06:27 -04:00
|
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), pName))
|
2016-07-25 17:06:27 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "enable", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "already enabled"))
|
2016-07-25 17:06:27 -04:00
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-07-25 17:06:27 -04:00
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "disable", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), "already disabled"))
|
2016-07-25 17:06:27 -04:00
|
|
|
_, _, err = dockerCmdWithError("plugin", "remove", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-07-25 17:06:27 -04:00
|
|
|
}
|
2016-11-22 12:42:58 -05:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginCreate(c *testing.T) {
|
2016-11-22 12:42:58 -05:00
|
|
|
name := "foo/bar-driver"
|
2021-08-24 06:10:50 -04:00
|
|
|
temp, err := os.MkdirTemp("", "foo")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-11-22 12:42:58 -05:00
|
|
|
defer os.RemoveAll(temp)
|
|
|
|
|
|
|
|
data := `{"description": "foo plugin"}`
|
2021-08-24 06:10:50 -04:00
|
|
|
err = os.WriteFile(filepath.Join(temp, "config.json"), []byte(data), 0644)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-11-22 12:42:58 -05:00
|
|
|
|
2016-12-12 18:05:53 -05:00
|
|
|
err = os.MkdirAll(filepath.Join(temp, "rootfs"), 0700)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-12-12 18:05:53 -05:00
|
|
|
|
2016-11-22 12:42:58 -05:00
|
|
|
out, _, err := dockerCmdWithError("plugin", "create", name, temp)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, name))
|
2016-11-22 12:42:58 -05:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, name))
|
2016-11-22 12:42:58 -05:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "create", name, temp)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "already exist"))
|
2016-11-22 12:42:58 -05:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, name))
|
2016-11-22 12:42:58 -05:00
|
|
|
// The output will consists of one HEADER line and one line of foo/bar-driver
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, len(strings.Split(strings.TrimSpace(out), "\n")), 2)
|
2016-11-22 12:42:58 -05:00
|
|
|
}
|
2016-11-23 23:04:44 -05:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginInspect(c *testing.T) {
|
2017-07-12 16:31:13 -04:00
|
|
|
pNameWithTag := ps.getPluginRepoWithTag()
|
|
|
|
|
2016-11-23 23:04:44 -05:00
|
|
|
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-11-23 23:04:44 -05:00
|
|
|
|
|
|
|
out, _, err := dockerCmdWithError("plugin", "ls")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, pNameWithTag))
|
|
|
|
assert.Assert(c, strings.Contains(out, "true"))
|
2016-11-23 23:04:44 -05:00
|
|
|
// Find the ID first
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-11-23 23:04:44 -05:00
|
|
|
id := strings.TrimSpace(out)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Assert(c, id != "")
|
2016-11-23 23:04:44 -05:00
|
|
|
|
|
|
|
// Long form
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), id)
|
2016-11-23 23:04:44 -05:00
|
|
|
|
|
|
|
// Short form
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), id)
|
2016-11-23 23:04:44 -05:00
|
|
|
|
|
|
|
// Name with tag form
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), id)
|
2016-11-23 23:04:44 -05:00
|
|
|
|
|
|
|
// Name without tag form
|
2017-07-12 16:31:13 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", ps.getPluginRepo())
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), id)
|
2016-11-23 23:04:44 -05:00
|
|
|
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-11-23 23:04:44 -05:00
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, pNameWithTag))
|
2016-11-23 23:04:44 -05:00
|
|
|
// After remove nothing should be found
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2016-11-23 23:04:44 -05:00
|
|
|
}
|
2016-12-07 10:38:18 -05:00
|
|
|
|
|
|
|
// Test case for https://github.com/docker/docker/pull/29186#discussion_r91277345
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestPluginInspectOnWindows(c *testing.T) {
|
2016-12-07 10:38:18 -05:00
|
|
|
// This test should work on Windows only
|
|
|
|
testRequires(c, DaemonIsWindows)
|
|
|
|
|
|
|
|
out, _, err := dockerCmdWithError("plugin", "inspect", "foobar")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "plugins are not supported on this platform"))
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "plugins are not supported on this platform")
|
2016-12-07 10:38:18 -05:00
|
|
|
}
|
2016-12-27 15:51:00 -05:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginIDPrefix(c *testing.T) {
|
2017-07-12 16:31:13 -04:00
|
|
|
name := "test"
|
2017-09-19 16:12:29 -04:00
|
|
|
client := testEnv.APIClient()
|
2017-07-12 16:31:13 -04:00
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
|
|
|
initialValue := "0"
|
2017-09-19 16:12:29 -04:00
|
|
|
err := plugin.Create(ctx, client, name, func(cfg *plugin.Config) {
|
2017-07-12 16:31:13 -04:00
|
|
|
cfg.Env = []types.PluginEnv{{Name: "DEBUG", Value: &initialValue, Settable: []string{"value"}}}
|
|
|
|
})
|
|
|
|
cancel()
|
|
|
|
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, err == nil, "failed to create test plugin")
|
2016-12-22 18:41:53 -05:00
|
|
|
|
|
|
|
// Find ID first
|
2017-07-12 16:31:13 -04:00
|
|
|
id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", name)
|
2016-12-22 18:41:53 -05:00
|
|
|
id = strings.TrimSpace(id)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-12-22 18:41:53 -05:00
|
|
|
|
|
|
|
// List current state
|
|
|
|
out, _, err := dockerCmdWithError("plugin", "ls")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, name))
|
|
|
|
assert.Assert(c, strings.Contains(out, "false"))
|
2016-12-22 18:41:53 -05:00
|
|
|
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5])
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, strings.TrimSpace(env), "[DEBUG=0]")
|
2016-12-22 18:41:53 -05:00
|
|
|
|
|
|
|
dockerCmd(c, "plugin", "set", id[:5], "DEBUG=1")
|
|
|
|
|
|
|
|
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5])
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, strings.TrimSpace(env), "[DEBUG=1]")
|
2016-12-22 18:41:53 -05:00
|
|
|
|
|
|
|
// Enable
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "enable", id[:5])
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-12-22 18:41:53 -05:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, name))
|
|
|
|
assert.Assert(c, strings.Contains(out, "true"))
|
2016-12-22 18:41:53 -05:00
|
|
|
// Disable
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", id[:5])
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-12-22 18:41:53 -05:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, name))
|
|
|
|
assert.Assert(c, strings.Contains(out, "false"))
|
2016-12-22 18:41:53 -05:00
|
|
|
// Remove
|
2018-07-09 13:40:34 -04:00
|
|
|
_, _, err = dockerCmdWithError("plugin", "remove", id[:5])
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-12-22 18:41:53 -05:00
|
|
|
// List returns none
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:07:46 -04:00
|
|
|
assert.Assert(c, !strings.Contains(out, name))
|
2016-12-22 18:41:53 -05:00
|
|
|
}
|
2016-11-22 19:23:21 -05:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginListDefaultFormat(c *testing.T) {
|
2021-08-24 06:10:50 -04:00
|
|
|
config, err := os.MkdirTemp("", "config-file-")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-11-22 19:23:21 -05:00
|
|
|
defer os.RemoveAll(config)
|
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
err = os.WriteFile(filepath.Join(config, "config.json"), []byte(`{"pluginsFormat": "raw"}`), 0644)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-11-22 19:23:21 -05:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
name := "test:latest"
|
2017-09-19 16:12:29 -04:00
|
|
|
client := testEnv.APIClient()
|
2017-07-12 16:31:13 -04:00
|
|
|
|
|
|
|
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"
|
|
|
|
})
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, err == nil, "failed to create test plugin")
|
2016-11-22 19:23:21 -05:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
out, _ := dockerCmd(c, "plugin", "inspect", "--format", "{{.ID}}", name)
|
2016-11-22 19:23:21 -05:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
// We expect the format to be in `raw + --no-trunc`
|
|
|
|
expectedOutput := fmt.Sprintf(`plugin_id: %s
|
|
|
|
name: %s
|
2017-07-12 16:31:13 -04:00
|
|
|
description: test plugin
|
|
|
|
enabled: false`, id, name)
|
2016-11-22 19:23:21 -05:00
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "--config", config, "plugin", "ls", "--no-trunc")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(strings.TrimSpace(out), expectedOutput))
|
2016-11-22 19:23:21 -05:00
|
|
|
}
|
2017-01-28 19:54:32 -05:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestPluginUpgrade(c *testing.T) {
|
2018-12-24 07:25:53 -05:00
|
|
|
testRequires(c, DaemonIsLinux, Network, testEnv.IsLocalDaemon, IsAmd64, NotUserNamespace)
|
2017-01-28 19:54:32 -05:00
|
|
|
plugin := "cpuguy83/docker-volume-driver-plugin-local:latest"
|
|
|
|
pluginV2 := "cpuguy83/docker-volume-driver-plugin-local:v2"
|
|
|
|
|
|
|
|
dockerCmd(c, "plugin", "install", "--grant-all-permissions", plugin)
|
2017-02-02 23:08:35 -05:00
|
|
|
dockerCmd(c, "volume", "create", "--driver", plugin, "bananas")
|
|
|
|
dockerCmd(c, "run", "--rm", "-v", "bananas:/apple", "busybox", "sh", "-c", "touch /apple/core")
|
|
|
|
|
2017-01-28 19:54:32 -05:00
|
|
|
out, _, err := dockerCmdWithError("plugin", "upgrade", "--grant-all-permissions", plugin, pluginV2)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "", out)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "disabled before upgrading"))
|
2017-01-28 19:54:32 -05:00
|
|
|
out, _ = dockerCmd(c, "plugin", "inspect", "--format={{.ID}}", plugin)
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
// make sure "v2" does not exists
|
2018-01-15 09:28:10 -05:00
|
|
|
_, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id, "rootfs", "v2"))
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 06:36:00 -04:00
|
|
|
assert.Assert(c, os.IsNotExist(err), out)
|
2017-01-28 19:54:32 -05:00
|
|
|
|
2017-02-02 23:08:35 -05:00
|
|
|
dockerCmd(c, "plugin", "disable", "-f", plugin)
|
2017-01-28 19:54:32 -05:00
|
|
|
dockerCmd(c, "plugin", "upgrade", "--grant-all-permissions", "--skip-remote-check", plugin, pluginV2)
|
|
|
|
|
|
|
|
// make sure "v2" file exists
|
2018-01-15 09:28:10 -05:00
|
|
|
_, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id, "rootfs", "v2"))
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2017-01-28 19:54:32 -05:00
|
|
|
|
|
|
|
dockerCmd(c, "plugin", "enable", plugin)
|
2017-02-02 23:08:35 -05:00
|
|
|
dockerCmd(c, "volume", "inspect", "bananas")
|
|
|
|
dockerCmd(c, "run", "--rm", "-v", "bananas:/apple", "busybox", "sh", "-c", "ls -lh /apple/core")
|
2017-01-28 19:54:32 -05:00
|
|
|
}
|
2017-04-13 21:56:50 -04:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSuite) TestPluginMetricsCollector(c *testing.T) {
|
2018-12-24 07:25:53 -05:00
|
|
|
testRequires(c, DaemonIsLinux, Network, testEnv.IsLocalDaemon, IsAmd64)
|
2018-04-13 11:02:56 -04:00
|
|
|
d := daemon.New(c, dockerBinary, dockerdBinary)
|
2017-04-13 21:56:50 -04:00
|
|
|
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))
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, r.Error == nil, r.Combined())
|
2017-04-13 21:56:50 -04:00
|
|
|
|
|
|
|
// plugin lisens on localhost:19393 and proxies the metrics
|
|
|
|
resp, err := http.Get("http://localhost:19393/metrics")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2017-04-13 21:56:50 -04:00
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
b, err := io.ReadAll(resp.Body)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2017-05-21 19:24:07 -04:00
|
|
|
// check that a known metric is there... don't expect this metric to change over time.. probably safe
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(string(b), "container_actions"))
|
2017-04-13 21:56:50 -04:00
|
|
|
}
|