2016-06-15 13:18:55 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-12-12 18:05:53 -05:00
|
|
|
"fmt"
|
2016-11-22 12:42:58 -05:00
|
|
|
"io/ioutil"
|
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"
|
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-01-05 13:08:24 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
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"
|
2017-07-12 16:31:13 -04:00
|
|
|
"github.com/docker/docker/integration-cli/fixtures/plugin"
|
|
|
|
"github.com/docker/docker/integration-cli/request"
|
2017-01-05 13:08:24 -05:00
|
|
|
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
|
|
|
"github.com/go-check/check"
|
2017-07-12 16:31:13 -04:00
|
|
|
"golang.org/x/net/context"
|
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
|
|
|
)
|
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginBasicOps(c *check.C) {
|
|
|
|
plugin := ps.getPluginRepoWithTag()
|
|
|
|
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", plugin)
|
2016-06-15 13:18:55 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, _, err := dockerCmdWithError("plugin", "ls")
|
|
|
|
c.Assert(err, checker.IsNil)
|
2017-07-12 16:31:13 -04:00
|
|
|
c.Assert(out, checker.Contains, plugin)
|
2016-06-15 13:18:55 -04:00
|
|
|
c.Assert(out, checker.Contains, "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)
|
2016-07-27 16:38:13 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-06-15 13:18:55 -04:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", plugin)
|
2016-11-22 14:21:34 -05:00
|
|
|
c.Assert(err, checker.NotNil)
|
2016-08-04 19:19:46 -04:00
|
|
|
c.Assert(out, checker.Contains, "is enabled")
|
2016-06-15 13:18:55 -04:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", plugin)
|
2016-06-15 13:18:55 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", plugin)
|
2016-06-15 13:18:55 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2017-07-12 16:31:13 -04:00
|
|
|
c.Assert(out, checker.Contains, plugin)
|
2016-07-27 16:38:13 -04:00
|
|
|
|
2017-01-13 11:23:28 -05:00
|
|
|
_, err = os.Stat(filepath.Join(testEnv.DockerBasePath(), "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
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginForceRemove(c *check.C) {
|
|
|
|
pNameWithTag := ps.getPluginRepoWithTag()
|
|
|
|
|
2016-07-22 11:24:54 -04:00
|
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
2016-08-04 19:19:46 -04:00
|
|
|
c.Assert(out, checker.Contains, "is enabled")
|
2016-07-22 11:24:54 -04:00
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag)
|
2016-09-07 09:59:15 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, pNameWithTag)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestPluginActive(c *check.C) {
|
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)
|
2016-09-07 09:59:15 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
2016-12-20 11:26:58 -05:00
|
|
|
_, _, err = dockerCmdWithError("volume", "create", "-d", pNameWithTag, "--name", "testvol1")
|
2016-09-07 09:59:15 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
2016-12-20 11:26:58 -05:00
|
|
|
out, _, err := dockerCmdWithError("plugin", "disable", pNameWithTag)
|
|
|
|
c.Assert(out, checker.Contains, "in use")
|
2016-09-07 09:59:15 -04:00
|
|
|
|
2016-12-20 11:26:58 -05:00
|
|
|
_, _, err = dockerCmdWithError("volume", "rm", "testvol1")
|
2016-09-07 09:59:15 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
2016-07-22 11:24:54 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, pNameWithTag)
|
|
|
|
}
|
|
|
|
|
2016-12-16 15:53:22 -05:00
|
|
|
func (s *DockerSuite) TestPluginActiveNetwork(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", npNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("network", "create", "-d", npNameWithTag, "test")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
nID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag)
|
|
|
|
c.Assert(out, checker.Contains, "is in use")
|
|
|
|
|
|
|
|
_, _, err = dockerCmdWithError("network", "rm", nID)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag)
|
|
|
|
c.Assert(out, checker.Contains, "is enabled")
|
|
|
|
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", npNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, npNameWithTag)
|
|
|
|
}
|
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginInstallDisable(c *check.C) {
|
|
|
|
pName := ps.getPluginRepoWithTag()
|
|
|
|
|
2016-07-15 13:37:17 -04:00
|
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
|
2016-06-17 10:44:57 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-15 13:37:17 -04:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
2016-06-17 10:44:57 -04:00
|
|
|
|
2016-07-15 13:37:17 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
2016-06-17 10:44:57 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, "false")
|
|
|
|
|
2016-07-15 13:37:17 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "enable", pName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "disable", pName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pName)
|
2016-06-17 10:44:57 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-15 13:37:17 -04:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
2016-06-17 10:44:57 -04:00
|
|
|
}
|
2016-07-06 15:16:14 -04:00
|
|
|
|
2016-11-01 18:03:14 -04:00
|
|
|
func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *check.C) {
|
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)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
|
|
|
|
|
|
dockerCmd(c, "volume", "ls")
|
|
|
|
}
|
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginSet(c *check.C) {
|
|
|
|
// Create a new plugin with extra settings
|
|
|
|
client, err := request.NewClient()
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to create test client"))
|
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"
|
|
|
|
err = plugin.Create(ctx, client, name, func(cfg *plugin.Config) {
|
|
|
|
cfg.Env = []types.PluginEnv{{Name: "DEBUG", Value: &initialValue, Settable: []string{"value"}}}
|
|
|
|
})
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to create test plugin"))
|
|
|
|
|
|
|
|
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", name)
|
2016-10-31 20:07:05 -04:00
|
|
|
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
|
|
|
|
|
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)
|
2016-10-31 20:07:05 -04:00
|
|
|
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
|
|
|
|
}
|
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginInstallArgs(c *check.C) {
|
|
|
|
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")
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
|
|
|
2016-11-07 21:51:47 -05:00
|
|
|
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
|
2016-11-07 20:43:11 -05:00
|
|
|
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
|
|
|
|
}
|
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginInstallImage(c *check.C) {
|
|
|
|
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)
|
2016-07-06 15:16:14 -04:00
|
|
|
c.Assert(err, checker.NotNil)
|
2017-01-10 22:27:55 -05:00
|
|
|
c.Assert(out, checker.Contains, `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
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginEnableDisableNegative(c *check.C) {
|
|
|
|
pName := ps.getPluginRepoWithTag()
|
|
|
|
|
2016-07-25 17:06:27 -04:00
|
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "enable", pName)
|
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, "already enabled")
|
|
|
|
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", pName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "disable", pName)
|
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, "already disabled")
|
|
|
|
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "remove", pName)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
}
|
2016-11-22 12:42:58 -05:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginCreate(c *check.C) {
|
2016-11-22 12:42:58 -05:00
|
|
|
name := "foo/bar-driver"
|
|
|
|
temp, err := ioutil.TempDir("", "foo")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer os.RemoveAll(temp)
|
|
|
|
|
|
|
|
data := `{"description": "foo plugin"}`
|
|
|
|
err = ioutil.WriteFile(filepath.Join(temp, "config.json"), []byte(data), 0644)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
2016-12-12 18:05:53 -05:00
|
|
|
err = os.MkdirAll(filepath.Join(temp, "rootfs"), 0700)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
2016-11-22 12:42:58 -05:00
|
|
|
out, _, err := dockerCmdWithError("plugin", "create", name, temp)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, name)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, name)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "create", name, temp)
|
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
c.Assert(out, checker.Contains, "already exist")
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, name)
|
|
|
|
// The output will consists of one HEADER line and one line of foo/bar-driver
|
|
|
|
c.Assert(len(strings.Split(strings.TrimSpace(out), "\n")), checker.Equals, 2)
|
|
|
|
}
|
2016-11-23 23:04:44 -05:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginInspect(c *check.C) {
|
|
|
|
pNameWithTag := ps.getPluginRepoWithTag()
|
|
|
|
|
2016-11-23 23:04:44 -05:00
|
|
|
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, _, err := dockerCmdWithError("plugin", "ls")
|
|
|
|
c.Assert(err, checker.IsNil)
|
2017-07-12 16:31:13 -04:00
|
|
|
c.Assert(out, checker.Contains, pNameWithTag)
|
2016-11-23 23:04:44 -05:00
|
|
|
c.Assert(out, checker.Contains, "true")
|
|
|
|
|
|
|
|
// Find the ID first
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
c.Assert(id, checker.Not(checker.Equals), "")
|
|
|
|
|
|
|
|
// Long form
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, id)
|
|
|
|
|
|
|
|
// Short form
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, id)
|
|
|
|
|
|
|
|
// Name with tag form
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, id)
|
|
|
|
|
|
|
|
// Name without tag form
|
2017-07-12 16:31:13 -04:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", ps.getPluginRepo())
|
2016-11-23 23:04:44 -05:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, id)
|
|
|
|
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, pNameWithTag)
|
|
|
|
|
|
|
|
// After remove nothing should be found
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
|
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
}
|
2016-12-07 10:38:18 -05:00
|
|
|
|
|
|
|
// Test case for https://github.com/docker/docker/pull/29186#discussion_r91277345
|
|
|
|
func (s *DockerSuite) TestPluginInspectOnWindows(c *check.C) {
|
|
|
|
// This test should work on Windows only
|
|
|
|
testRequires(c, DaemonIsWindows)
|
|
|
|
|
|
|
|
out, _, err := dockerCmdWithError("plugin", "inspect", "foobar")
|
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
c.Assert(out, checker.Contains, "plugins are not supported on this platform")
|
|
|
|
c.Assert(err.Error(), checker.Contains, "plugins are not supported on this platform")
|
|
|
|
}
|
2016-12-27 15:51:00 -05:00
|
|
|
|
|
|
|
func (s *DockerTrustSuite) TestPluginTrustedInstall(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
|
|
|
|
|
|
trustedName := s.setupTrustedplugin(c, pNameWithTag, "trusted-plugin-install")
|
|
|
|
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.Docker(cli.Args("plugin", "install", "--grant-all-permissions", trustedName), trustedCmd).Assert(c, icmd.Expected{
|
2017-01-05 13:08:24 -05:00
|
|
|
Out: trustedName,
|
|
|
|
})
|
2016-12-27 15:51:00 -05:00
|
|
|
|
2017-04-19 08:04:39 -04:00
|
|
|
out := cli.DockerCmd(c, "plugin", "ls").Combined()
|
2016-12-27 15:51:00 -05:00
|
|
|
c.Assert(out, checker.Contains, "true")
|
|
|
|
|
2017-04-19 08:04:39 -04:00
|
|
|
out = cli.DockerCmd(c, "plugin", "disable", trustedName).Combined()
|
2016-12-27 15:51:00 -05:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, trustedName)
|
|
|
|
|
2017-04-19 08:04:39 -04:00
|
|
|
out = cli.DockerCmd(c, "plugin", "enable", trustedName).Combined()
|
2016-12-27 15:51:00 -05:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, trustedName)
|
|
|
|
|
2017-04-19 08:04:39 -04:00
|
|
|
out = cli.DockerCmd(c, "plugin", "rm", "-f", trustedName).Combined()
|
2016-12-27 15:51:00 -05:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, trustedName)
|
|
|
|
|
|
|
|
// Try untrusted pull to ensure we pushed the tag to the registry
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.Docker(cli.Args("plugin", "install", "--disable-content-trust=true", "--grant-all-permissions", trustedName), trustedCmd).Assert(c, SuccessDownloaded)
|
2016-12-27 15:51:00 -05:00
|
|
|
|
2017-04-19 08:04:39 -04:00
|
|
|
out = cli.DockerCmd(c, "plugin", "ls").Combined()
|
2016-12-27 15:51:00 -05:00
|
|
|
c.Assert(out, checker.Contains, "true")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerTrustSuite) TestPluginUntrustedInstall(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
|
|
|
|
|
|
pluginName := fmt.Sprintf("%v/dockercliuntrusted/plugintest:latest", privateRegistryURL)
|
|
|
|
// install locally and push to private registry
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.DockerCmd(c, "plugin", "install", "--grant-all-permissions", "--alias", pluginName, pNameWithTag)
|
|
|
|
cli.DockerCmd(c, "plugin", "push", pluginName)
|
|
|
|
cli.DockerCmd(c, "plugin", "rm", "-f", pluginName)
|
2016-12-27 15:51:00 -05:00
|
|
|
|
|
|
|
// Try trusted install on untrusted plugin
|
2017-04-19 08:04:39 -04:00
|
|
|
cli.Docker(cli.Args("plugin", "install", "--grant-all-permissions", pluginName), trustedCmd).Assert(c, icmd.Expected{
|
2017-01-05 13:08:24 -05:00
|
|
|
ExitCode: 1,
|
|
|
|
Err: "Error: remote trust data does not exist",
|
|
|
|
})
|
2016-12-27 15:51:00 -05:00
|
|
|
}
|
2016-12-22 18:41:53 -05:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginIDPrefix(c *check.C) {
|
|
|
|
name := "test"
|
|
|
|
client, err := request.NewClient()
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("error creating test client"))
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
|
|
|
initialValue := "0"
|
|
|
|
err = plugin.Create(ctx, client, name, func(cfg *plugin.Config) {
|
|
|
|
cfg.Env = []types.PluginEnv{{Name: "DEBUG", Value: &initialValue, Settable: []string{"value"}}}
|
|
|
|
})
|
|
|
|
cancel()
|
|
|
|
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("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)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
// List current state
|
|
|
|
out, _, err := dockerCmdWithError("plugin", "ls")
|
|
|
|
c.Assert(err, checker.IsNil)
|
2017-07-12 16:31:13 -04:00
|
|
|
c.Assert(out, checker.Contains, name)
|
2016-12-22 18:41:53 -05:00
|
|
|
c.Assert(out, checker.Contains, "false")
|
|
|
|
|
|
|
|
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5])
|
|
|
|
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
|
|
|
|
|
|
|
|
dockerCmd(c, "plugin", "set", id[:5], "DEBUG=1")
|
|
|
|
|
|
|
|
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5])
|
|
|
|
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
|
|
|
|
|
|
|
|
// Enable
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "enable", id[:5])
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
|
|
|
c.Assert(err, checker.IsNil)
|
2017-07-12 16:31:13 -04:00
|
|
|
c.Assert(out, checker.Contains, name)
|
2016-12-22 18:41:53 -05:00
|
|
|
c.Assert(out, checker.Contains, "true")
|
|
|
|
|
|
|
|
// Disable
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", id[:5])
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
|
|
|
c.Assert(err, checker.IsNil)
|
2017-07-12 16:31:13 -04:00
|
|
|
c.Assert(out, checker.Contains, name)
|
2016-12-22 18:41:53 -05:00
|
|
|
c.Assert(out, checker.Contains, "false")
|
|
|
|
|
|
|
|
// Remove
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", id[:5])
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
// List returns none
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
|
|
|
c.Assert(err, checker.IsNil)
|
2017-07-12 16:31:13 -04:00
|
|
|
c.Assert(out, checker.Not(checker.Contains), name)
|
2016-12-22 18:41:53 -05:00
|
|
|
}
|
2016-11-22 19:23:21 -05:00
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
func (ps *DockerPluginSuite) TestPluginListDefaultFormat(c *check.C) {
|
2016-11-22 19:23:21 -05:00
|
|
|
config, err := ioutil.TempDir("", "config-file-")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
defer os.RemoveAll(config)
|
|
|
|
|
|
|
|
err = ioutil.WriteFile(filepath.Join(config, "config.json"), []byte(`{"pluginsFormat": "raw"}`), 0644)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2017-07-12 16:31:13 -04:00
|
|
|
name := "test:latest"
|
|
|
|
client, err := request.NewClient()
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("error creating test client"))
|
|
|
|
|
|
|
|
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"
|
|
|
|
})
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("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")
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, expectedOutput)
|
|
|
|
}
|
2017-01-28 19:54:32 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestPluginUpgrade(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux, Network, SameHostDaemon, IsAmd64)
|
|
|
|
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)
|
|
|
|
c.Assert(err, checker.NotNil, check.Commentf(out))
|
|
|
|
c.Assert(out, checker.Contains, "disabled before upgrading")
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "plugin", "inspect", "--format={{.ID}}", plugin)
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
// make sure "v2" does not exists
|
|
|
|
_, err = os.Stat(filepath.Join(testEnv.DockerBasePath(), "plugins", id, "rootfs", "v2"))
|
|
|
|
c.Assert(os.IsNotExist(err), checker.True, check.Commentf(out))
|
|
|
|
|
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
|
|
|
|
_, err = os.Stat(filepath.Join(testEnv.DockerBasePath(), "plugins", id, "rootfs", "v2"))
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
func (s *DockerSuite) TestPluginMetricsCollector(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux, Network, SameHostDaemon, IsAmd64)
|
|
|
|
d := daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{})
|
|
|
|
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))
|
|
|
|
c.Assert(r.Error, checker.IsNil, check.Commentf(r.Combined()))
|
|
|
|
|
|
|
|
// plugin lisens on localhost:19393 and proxies the metrics
|
|
|
|
resp, err := http.Get("http://localhost:19393/metrics")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
b, err := ioutil.ReadAll(resp.Body)
|
|
|
|
c.Assert(err, checker.IsNil)
|
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
|
2017-04-13 21:56:50 -04:00
|
|
|
c.Assert(string(b), checker.Contains, "container_actions")
|
|
|
|
}
|