2016-06-15 17:18:55 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
|
|
|
"github.com/go-check/check"
|
2016-07-15 17:37:17 +00:00
|
|
|
|
2016-07-27 20:38:13 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2016-07-15 17:37:17 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
pName = "tiborvass/no-remove"
|
|
|
|
pTag = "latest"
|
|
|
|
pNameWithTag = pName + ":" + pTag
|
2016-06-15 17:18:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestPluginBasicOps(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux, ExperimentalDaemon)
|
2016-07-15 17:37:17 +00:00
|
|
|
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
2016-06-15 17:18:55 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, _, err := dockerCmdWithError("plugin", "ls")
|
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-15 17:37:17 +00:00
|
|
|
c.Assert(out, checker.Contains, pName)
|
|
|
|
c.Assert(out, checker.Contains, pTag)
|
2016-06-15 17:18:55 +00:00
|
|
|
c.Assert(out, checker.Contains, "true")
|
|
|
|
|
2016-07-15 17:37:17 +00:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "inspect", pNameWithTag)
|
2016-06-15 17:18:55 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-27 20:38:13 +00:00
|
|
|
tmpFile, err := ioutil.TempFile("", "inspect.json")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer tmpFile.Close()
|
|
|
|
|
|
|
|
if _, err := tmpFile.Write([]byte(out)); err != nil {
|
|
|
|
c.Fatal(err)
|
|
|
|
}
|
|
|
|
// FIXME: When `docker plugin inspect` takes a format as input, jq can be replaced.
|
|
|
|
id, err := exec.Command("jq", ".Id", "--raw-output", tmpFile.Name()).CombinedOutput()
|
|
|
|
c.Assert(err, checker.IsNil)
|
2016-06-15 17:18:55 +00:00
|
|
|
|
2016-07-15 17:37:17 +00:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
2016-06-15 17:18:55 +00:00
|
|
|
c.Assert(out, checker.Contains, "is active")
|
|
|
|
|
2016-07-15 17:37:17 +00:00
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
|
2016-06-15 17:18:55 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
2016-07-15 17:37:17 +00:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
2016-06-15 17:18:55 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-15 17:37:17 +00:00
|
|
|
c.Assert(out, checker.Contains, pNameWithTag)
|
2016-07-27 20:38:13 +00:00
|
|
|
|
|
|
|
_, err = os.Stat(filepath.Join(dockerBasePath, "plugins", string(id)))
|
|
|
|
if !os.IsNotExist(err) {
|
|
|
|
c.Fatal(err)
|
|
|
|
}
|
2016-06-15 17:18:55 +00:00
|
|
|
}
|
2016-06-17 14:44:57 +00:00
|
|
|
|
2016-07-22 15:24:54 +00:00
|
|
|
func (s *DockerSuite) TestPluginForceRemove(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux, ExperimentalDaemon)
|
|
|
|
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 active")
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, pNameWithTag)
|
|
|
|
}
|
|
|
|
|
2016-06-17 14:44:57 +00:00
|
|
|
func (s *DockerSuite) TestPluginInstallDisable(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux, ExperimentalDaemon)
|
2016-07-15 17:37:17 +00:00
|
|
|
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
|
2016-06-17 14:44:57 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-15 17:37:17 +00:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
2016-06-17 14:44:57 +00:00
|
|
|
|
2016-07-15 17:37:17 +00:00
|
|
|
out, _, err = dockerCmdWithError("plugin", "ls")
|
2016-06-17 14:44:57 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, "false")
|
|
|
|
|
2016-07-15 17:37:17 +00: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 14:44:57 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-07-15 17:37:17 +00:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
2016-06-17 14:44:57 +00:00
|
|
|
}
|
2016-07-06 19:16:14 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestPluginInstallImage(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux, ExperimentalDaemon)
|
|
|
|
out, _, err := dockerCmdWithError("plugin", "install", "redis")
|
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
c.Assert(out, checker.Contains, "content is not a plugin")
|
|
|
|
}
|
2016-07-25 21:06:27 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux, ExperimentalDaemon)
|
|
|
|
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)
|
|
|
|
}
|