mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
662d456928
This fix tries to fix the issue raised in 28684: 1. Duplicate plugin create with the same name will override the old plugin reference 2. In case an error happens in the middle of the plugin creation, plugin directories in `/var/lib/docker/plugins` are not cleaned up. This fix update the plugin store so that `Add()` will return an error if a plugin with the same name already exist. This fix also will clean up the directory in `/var/lib/docker/plugins` in case an error happens in the middle of the plugin creation. This fix fixes 28684. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
203 lines
6.9 KiB
Go
203 lines
6.9 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/docker/docker/pkg/integration/checker"
|
|
"github.com/go-check/check"
|
|
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
pluginProcessName = "no-remove"
|
|
pName = "tiborvass/no-remove"
|
|
pTag = "latest"
|
|
pNameWithTag = pName + ":" + pTag
|
|
)
|
|
|
|
func (s *DockerSuite) TestPluginBasicOps(c *check.C) {
|
|
testRequires(c, DaemonIsLinux, Network)
|
|
_, _, 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, "true")
|
|
|
|
id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
|
|
id = strings.TrimSpace(id)
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
|
c.Assert(out, checker.Contains, "is enabled")
|
|
|
|
_, _, 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)
|
|
|
|
_, err = os.Stat(filepath.Join(dockerBasePath, "plugins", id))
|
|
if !os.IsNotExist(err) {
|
|
c.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func (s *DockerSuite) TestPluginForceRemove(c *check.C) {
|
|
testRequires(c, DaemonIsLinux, Network)
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
|
c.Assert(out, checker.Contains, "is enabled")
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag)
|
|
c.Assert(err, checker.IsNil)
|
|
c.Assert(out, checker.Contains, pNameWithTag)
|
|
}
|
|
|
|
func (s *DockerSuite) TestPluginActive(c *check.C) {
|
|
testRequires(c, DaemonIsLinux, Network, IsAmd64)
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
out, _, err = dockerCmdWithError("volume", "create", "-d", pNameWithTag)
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
vID := strings.TrimSpace(out)
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
|
c.Assert(out, checker.Contains, "is in use")
|
|
|
|
_, _, err = dockerCmdWithError("volume", "rm", vID)
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
|
c.Assert(out, checker.Contains, "is enabled")
|
|
|
|
_, _, 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)
|
|
}
|
|
|
|
func (s *DockerSuite) TestPluginInstallDisable(c *check.C) {
|
|
testRequires(c, DaemonIsLinux, Network)
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
|
|
c.Assert(err, checker.IsNil)
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
|
c.Assert(err, checker.IsNil)
|
|
c.Assert(out, checker.Contains, "false")
|
|
|
|
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)
|
|
c.Assert(err, checker.IsNil)
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
}
|
|
|
|
func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *check.C) {
|
|
testRequires(c, DaemonIsLinux, Network)
|
|
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")
|
|
}
|
|
|
|
func (s *DockerSuite) TestPluginSet(c *check.C) {
|
|
testRequires(c, DaemonIsLinux, Network)
|
|
out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName)
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
|
|
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
|
|
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
|
|
|
|
dockerCmd(c, "plugin", "set", pName, "DEBUG=1")
|
|
|
|
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
|
|
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
|
|
}
|
|
|
|
func (s *DockerSuite) TestPluginInstallArgs(c *check.C) {
|
|
testRequires(c, DaemonIsLinux, Network)
|
|
out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1")
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
|
|
|
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
|
|
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
|
|
}
|
|
|
|
func (s *DockerSuite) TestPluginInstallImage(c *check.C) {
|
|
testRequires(c, DaemonIsLinux, Network)
|
|
out, _, err := dockerCmdWithError("plugin", "install", "redis")
|
|
c.Assert(err, checker.NotNil)
|
|
c.Assert(out, checker.Contains, "content is not a plugin")
|
|
}
|
|
|
|
func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) {
|
|
testRequires(c, DaemonIsLinux, Network)
|
|
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)
|
|
}
|
|
|
|
func (s *DockerSuite) TestPluginCreate(c *check.C) {
|
|
testRequires(c, DaemonIsLinux, Network)
|
|
|
|
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)
|
|
|
|
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)
|
|
}
|