|
@@ -5,14 +5,20 @@ import (
|
|
|
"io/ioutil"
|
|
|
"net/http"
|
|
|
"os"
|
|
|
+ "path"
|
|
|
"path/filepath"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
|
|
|
+ "github.com/docker/docker/api/types"
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
|
|
"github.com/docker/docker/integration-cli/cli"
|
|
|
"github.com/docker/docker/integration-cli/daemon"
|
|
|
+ "github.com/docker/docker/integration-cli/fixtures/plugin"
|
|
|
+ "github.com/docker/docker/integration-cli/request"
|
|
|
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
|
|
"github.com/go-check/check"
|
|
|
+ "golang.org/x/net/context"
|
|
|
)
|
|
|
|
|
|
var (
|
|
@@ -24,31 +30,30 @@ var (
|
|
|
npNameWithTag = npName + ":" + pTag
|
|
|
)
|
|
|
|
|
|
-func (s *DockerSuite) TestPluginBasicOps(c *check.C) {
|
|
|
- testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
|
- _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
|
|
+func (ps *DockerPluginSuite) TestPluginBasicOps(c *check.C) {
|
|
|
+ plugin := ps.getPluginRepoWithTag()
|
|
|
+ _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", plugin)
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
out, _, err := dockerCmdWithError("plugin", "ls")
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
- c.Assert(out, checker.Contains, pName)
|
|
|
- c.Assert(out, checker.Contains, pTag)
|
|
|
+ c.Assert(out, checker.Contains, plugin)
|
|
|
c.Assert(out, checker.Contains, "true")
|
|
|
|
|
|
- id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
|
|
|
+ id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", plugin)
|
|
|
id = strings.TrimSpace(id)
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
- out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
|
|
+ out, _, err = dockerCmdWithError("plugin", "remove", plugin)
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
c.Assert(out, checker.Contains, "is enabled")
|
|
|
|
|
|
- _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
|
|
|
+ _, _, err = dockerCmdWithError("plugin", "disable", plugin)
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
- out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
|
|
+ out, _, err = dockerCmdWithError("plugin", "remove", plugin)
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
- c.Assert(out, checker.Contains, pNameWithTag)
|
|
|
+ c.Assert(out, checker.Contains, plugin)
|
|
|
|
|
|
_, err = os.Stat(filepath.Join(testEnv.DockerBasePath(), "plugins", id))
|
|
|
if !os.IsNotExist(err) {
|
|
@@ -56,8 +61,9 @@ func (s *DockerSuite) TestPluginBasicOps(c *check.C) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (s *DockerSuite) TestPluginForceRemove(c *check.C) {
|
|
|
- testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
|
+func (ps *DockerPluginSuite) TestPluginForceRemove(c *check.C) {
|
|
|
+ pNameWithTag := ps.getPluginRepoWithTag()
|
|
|
+
|
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
@@ -71,6 +77,7 @@ func (s *DockerSuite) TestPluginForceRemove(c *check.C) {
|
|
|
|
|
|
func (s *DockerSuite) TestPluginActive(c *check.C) {
|
|
|
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
|
+
|
|
|
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
@@ -118,8 +125,9 @@ func (s *DockerSuite) TestPluginActiveNetwork(c *check.C) {
|
|
|
c.Assert(out, checker.Contains, npNameWithTag)
|
|
|
}
|
|
|
|
|
|
-func (s *DockerSuite) TestPluginInstallDisable(c *check.C) {
|
|
|
- testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
|
+func (ps *DockerPluginSuite) TestPluginInstallDisable(c *check.C) {
|
|
|
+ pName := ps.getPluginRepoWithTag()
|
|
|
+
|
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
@@ -150,22 +158,39 @@ func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *check.C) {
|
|
|
dockerCmd(c, "volume", "ls")
|
|
|
}
|
|
|
|
|
|
-func (s *DockerSuite) TestPluginSet(c *check.C) {
|
|
|
- testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
|
- out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName)
|
|
|
- c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
|
+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"))
|
|
|
|
|
|
- env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
|
|
|
+ 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)
|
|
|
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
|
|
|
|
|
|
- dockerCmd(c, "plugin", "set", pName, "DEBUG=1")
|
|
|
+ dockerCmd(c, "plugin", "set", name, "DEBUG=1")
|
|
|
|
|
|
- env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
|
|
|
+ env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", name)
|
|
|
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
|
|
|
}
|
|
|
|
|
|
-func (s *DockerSuite) TestPluginInstallArgs(c *check.C) {
|
|
|
- testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
|
+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"}}}
|
|
|
+ })
|
|
|
+
|
|
|
out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1")
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
|
|
|
@@ -173,8 +198,8 @@ func (s *DockerSuite) TestPluginInstallArgs(c *check.C) {
|
|
|
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
|
|
|
}
|
|
|
|
|
|
-func (s *DockerRegistrySuite) TestPluginInstallImage(c *check.C) {
|
|
|
- testRequires(c, DaemonIsLinux, IsAmd64)
|
|
|
+func (ps *DockerPluginSuite) TestPluginInstallImage(c *check.C) {
|
|
|
+ testRequires(c, IsAmd64)
|
|
|
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
// tag the image to upload it to the private registry
|
|
@@ -187,8 +212,9 @@ func (s *DockerRegistrySuite) TestPluginInstallImage(c *check.C) {
|
|
|
c.Assert(out, checker.Contains, `Encountered remote "application/vnd.docker.container.image.v1+json"(image) when fetching`)
|
|
|
}
|
|
|
|
|
|
-func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) {
|
|
|
- testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
|
+func (ps *DockerPluginSuite) TestPluginEnableDisableNegative(c *check.C) {
|
|
|
+ pName := ps.getPluginRepoWithTag()
|
|
|
+
|
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName)
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
@@ -208,9 +234,7 @@ func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) {
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
}
|
|
|
|
|
|
-func (s *DockerSuite) TestPluginCreate(c *check.C) {
|
|
|
- testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
|
-
|
|
|
+func (ps *DockerPluginSuite) TestPluginCreate(c *check.C) {
|
|
|
name := "foo/bar-driver"
|
|
|
temp, err := ioutil.TempDir("", "foo")
|
|
|
c.Assert(err, checker.IsNil)
|
|
@@ -242,15 +266,15 @@ func (s *DockerSuite) TestPluginCreate(c *check.C) {
|
|
|
c.Assert(len(strings.Split(strings.TrimSpace(out), "\n")), checker.Equals, 2)
|
|
|
}
|
|
|
|
|
|
-func (s *DockerSuite) TestPluginInspect(c *check.C) {
|
|
|
- testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
|
+func (ps *DockerPluginSuite) TestPluginInspect(c *check.C) {
|
|
|
+ pNameWithTag := ps.getPluginRepoWithTag()
|
|
|
+
|
|
|
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
out, _, err := dockerCmdWithError("plugin", "ls")
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
- c.Assert(out, checker.Contains, pName)
|
|
|
- c.Assert(out, checker.Contains, pTag)
|
|
|
+ c.Assert(out, checker.Contains, pNameWithTag)
|
|
|
c.Assert(out, checker.Contains, "true")
|
|
|
|
|
|
// Find the ID first
|
|
@@ -275,7 +299,7 @@ func (s *DockerSuite) TestPluginInspect(c *check.C) {
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, id)
|
|
|
|
|
|
// Name without tag form
|
|
|
- out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pName)
|
|
|
+ out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", ps.getPluginRepo())
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, id)
|
|
|
|
|
@@ -347,21 +371,29 @@ func (s *DockerTrustSuite) TestPluginUntrustedInstall(c *check.C) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func (s *DockerSuite) TestPluginIDPrefix(c *check.C) {
|
|
|
- testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
|
- _, _, err := dockerCmdWithError("plugin", "install", "--disable", "--grant-all-permissions", pNameWithTag)
|
|
|
- c.Assert(err, checker.IsNil)
|
|
|
+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"))
|
|
|
|
|
|
// Find ID first
|
|
|
- id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
|
|
|
+ id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", name)
|
|
|
id = strings.TrimSpace(id)
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
// List current state
|
|
|
out, _, err := dockerCmdWithError("plugin", "ls")
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
- c.Assert(out, checker.Contains, pName)
|
|
|
- c.Assert(out, checker.Contains, pTag)
|
|
|
+ c.Assert(out, checker.Contains, name)
|
|
|
c.Assert(out, checker.Contains, "false")
|
|
|
|
|
|
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5])
|
|
@@ -377,8 +409,7 @@ func (s *DockerSuite) TestPluginIDPrefix(c *check.C) {
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
- c.Assert(out, checker.Contains, pName)
|
|
|
- c.Assert(out, checker.Contains, pTag)
|
|
|
+ c.Assert(out, checker.Contains, name)
|
|
|
c.Assert(out, checker.Contains, "true")
|
|
|
|
|
|
// Disable
|
|
@@ -386,8 +417,7 @@ func (s *DockerSuite) TestPluginIDPrefix(c *check.C) {
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
- c.Assert(out, checker.Contains, pName)
|
|
|
- c.Assert(out, checker.Contains, pTag)
|
|
|
+ c.Assert(out, checker.Contains, name)
|
|
|
c.Assert(out, checker.Contains, "false")
|
|
|
|
|
|
// Remove
|
|
@@ -396,13 +426,10 @@ func (s *DockerSuite) TestPluginIDPrefix(c *check.C) {
|
|
|
// List returns none
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
- c.Assert(out, checker.Not(checker.Contains), pName)
|
|
|
- c.Assert(out, checker.Not(checker.Contains), pTag)
|
|
|
+ c.Assert(out, checker.Not(checker.Contains), name)
|
|
|
}
|
|
|
|
|
|
-func (s *DockerSuite) TestPluginListDefaultFormat(c *check.C) {
|
|
|
- testRequires(c, DaemonIsLinux, Network, IsAmd64)
|
|
|
-
|
|
|
+func (ps *DockerPluginSuite) TestPluginListDefaultFormat(c *check.C) {
|
|
|
config, err := ioutil.TempDir("", "config-file-")
|
|
|
c.Assert(err, check.IsNil)
|
|
|
defer os.RemoveAll(config)
|
|
@@ -410,17 +437,25 @@ func (s *DockerSuite) TestPluginListDefaultFormat(c *check.C) {
|
|
|
err = ioutil.WriteFile(filepath.Join(config, "config.json"), []byte(`{"pluginsFormat": "raw"}`), 0644)
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
- out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", pName)
|
|
|
- c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
|
+ 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"))
|
|
|
|
|
|
- out, _ = dockerCmd(c, "plugin", "inspect", "--format", "{{.ID}}", pNameWithTag)
|
|
|
+ out, _ := dockerCmd(c, "plugin", "inspect", "--format", "{{.ID}}", name)
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
// We expect the format to be in `raw + --no-trunc`
|
|
|
expectedOutput := fmt.Sprintf(`plugin_id: %s
|
|
|
name: %s
|
|
|
-description: A sample volume plugin for Docker
|
|
|
-enabled: true`, id, pNameWithTag)
|
|
|
+description: test plugin
|
|
|
+enabled: false`, id, name)
|
|
|
|
|
|
out, _ = dockerCmd(c, "--config", config, "plugin", "ls", "--no-trunc")
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, expectedOutput)
|