mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix issue caused by duplicate docker plugin create
with same names
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>
(cherry picked from commit 662d456928
)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
parent
4a0b7b215e
commit
d0fb24d853
4 changed files with 69 additions and 4 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/go-check/check"
|
||||
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -169,3 +170,34 @@ func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) {
|
|||
_, _, 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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue