2016-10-06 10:09:54 -04:00
|
|
|
// +build linux
|
2016-03-18 14:50:19 -04:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-07-01 14:36:11 -04:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
2016-07-08 13:37:52 -04:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2016-07-11 11:55:39 -04:00
|
|
|
"syscall"
|
2016-07-08 13:37:52 -04:00
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
|
|
|
"github.com/go-check/check"
|
2016-03-18 14:50:19 -04:00
|
|
|
)
|
|
|
|
|
2016-06-17 11:21:03 -04:00
|
|
|
// TestDaemonRestartWithPluginEnabled tests state restore for an enabled plugin
|
|
|
|
func (s *DockerDaemonSuite) TestDaemonRestartWithPluginEnabled(c *check.C) {
|
2016-11-09 20:49:09 -05:00
|
|
|
testRequires(c, Network)
|
2016-10-06 10:09:54 -04:00
|
|
|
|
2016-03-18 14:50:19 -04:00
|
|
|
if err := s.d.Start(); err != nil {
|
2016-06-17 11:21:03 -04:00
|
|
|
c.Fatalf("Could not start daemon: %v", err)
|
2016-03-04 17:41:53 -05:00
|
|
|
}
|
|
|
|
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pName); err != nil {
|
2016-06-17 11:21:03 -04:00
|
|
|
c.Fatalf("Could not install plugin: %v %s", err, out)
|
2016-03-04 17:41:53 -05:00
|
|
|
}
|
|
|
|
|
2016-06-27 23:32:03 -04:00
|
|
|
defer func() {
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "disable", pName); err != nil {
|
2016-06-27 23:32:03 -04:00
|
|
|
c.Fatalf("Could not disable plugin: %v %s", err, out)
|
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "remove", pName); err != nil {
|
2016-06-27 23:32:03 -04:00
|
|
|
c.Fatalf("Could not remove plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2016-06-17 11:21:03 -04:00
|
|
|
if err := s.d.Restart(); err != nil {
|
|
|
|
c.Fatalf("Could not restart daemon: %v", err)
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
|
|
|
|
2016-06-17 11:21:03 -04:00
|
|
|
out, err := s.d.Cmd("plugin", "ls")
|
2016-03-18 14:50:19 -04:00
|
|
|
if err != nil {
|
2016-06-17 11:21:03 -04:00
|
|
|
c.Fatalf("Could not list plugins: %v %s", err, out)
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
c.Assert(out, checker.Contains, pName)
|
2016-06-17 11:21:03 -04:00
|
|
|
c.Assert(out, checker.Contains, "true")
|
|
|
|
}
|
2016-03-18 14:50:19 -04:00
|
|
|
|
2016-08-11 18:59:35 -04:00
|
|
|
// TestDaemonRestartWithPluginDisabled tests state restore for a disabled plugin
|
2016-06-17 11:21:03 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonRestartWithPluginDisabled(c *check.C) {
|
2016-11-09 20:49:09 -05:00
|
|
|
testRequires(c, Network)
|
2016-10-06 10:09:54 -04:00
|
|
|
|
2016-06-17 11:21:03 -04:00
|
|
|
if err := s.d.Start(); err != nil {
|
|
|
|
c.Fatalf("Could not start daemon: %v", err)
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
|
|
|
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pName, "--disable"); err != nil {
|
2016-06-17 11:21:03 -04:00
|
|
|
c.Fatalf("Could not install plugin: %v %s", err, out)
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
|
|
|
|
2016-06-27 23:32:03 -04:00
|
|
|
defer func() {
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "remove", pName); err != nil {
|
2016-06-27 23:32:03 -04:00
|
|
|
c.Fatalf("Could not remove plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2016-06-17 11:21:03 -04:00
|
|
|
if err := s.d.Restart(); err != nil {
|
|
|
|
c.Fatalf("Could not restart daemon: %v", err)
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
|
|
|
|
2016-06-17 11:21:03 -04:00
|
|
|
out, err := s.d.Cmd("plugin", "ls")
|
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("Could not list plugins: %v %s", err, out)
|
2016-06-14 14:06:11 -04:00
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
c.Assert(out, checker.Contains, pName)
|
2016-06-17 11:21:03 -04:00
|
|
|
c.Assert(out, checker.Contains, "false")
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
2016-07-01 14:36:11 -04:00
|
|
|
|
2016-07-22 11:53:26 -04:00
|
|
|
// TestDaemonKillLiveRestoreWithPlugins SIGKILLs daemon started with --live-restore.
|
|
|
|
// Plugins should continue to run.
|
|
|
|
func (s *DockerDaemonSuite) TestDaemonKillLiveRestoreWithPlugins(c *check.C) {
|
2016-11-11 12:50:43 -05:00
|
|
|
testRequires(c, Network, IsAmd64)
|
2016-10-06 10:09:54 -04:00
|
|
|
|
2016-07-01 14:36:11 -04:00
|
|
|
if err := s.d.Start("--live-restore"); err != nil {
|
|
|
|
c.Fatalf("Could not start daemon: %v", err)
|
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pName); err != nil {
|
2016-07-01 14:36:11 -04:00
|
|
|
c.Fatalf("Could not install plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err := s.d.Restart("--live-restore"); err != nil {
|
|
|
|
c.Fatalf("Could not restart daemon: %v", err)
|
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "disable", pName); err != nil {
|
2016-07-01 14:36:11 -04:00
|
|
|
c.Fatalf("Could not disable plugin: %v %s", err, out)
|
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "remove", pName); err != nil {
|
2016-07-01 14:36:11 -04:00
|
|
|
c.Fatalf("Could not remove plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if err := s.d.Kill(); err != nil {
|
|
|
|
c.Fatalf("Could not kill daemon: %v", err)
|
2016-07-22 11:53:26 -04:00
|
|
|
}
|
|
|
|
|
2016-11-10 16:07:53 -05:00
|
|
|
cmd := exec.Command("pgrep", "-f", pluginProcessName)
|
2016-07-22 11:53:26 -04:00
|
|
|
if out, ec, err := runCommandWithOutput(cmd); ec != 0 {
|
|
|
|
c.Fatalf("Expected exit code '0', got %d err: %v output: %s ", ec, err, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestDaemonShutdownLiveRestoreWithPlugins SIGTERMs daemon started with --live-restore.
|
|
|
|
// Plugins should continue to run.
|
|
|
|
func (s *DockerDaemonSuite) TestDaemonShutdownLiveRestoreWithPlugins(c *check.C) {
|
2016-11-11 12:50:43 -05:00
|
|
|
testRequires(c, Network, IsAmd64)
|
2016-10-06 10:09:54 -04:00
|
|
|
|
2016-07-22 11:53:26 -04:00
|
|
|
if err := s.d.Start("--live-restore"); err != nil {
|
|
|
|
c.Fatalf("Could not start daemon: %v", err)
|
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pName); err != nil {
|
2016-07-22 11:53:26 -04:00
|
|
|
c.Fatalf("Could not install plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err := s.d.Restart("--live-restore"); err != nil {
|
|
|
|
c.Fatalf("Could not restart daemon: %v", err)
|
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "disable", pName); err != nil {
|
2016-07-22 11:53:26 -04:00
|
|
|
c.Fatalf("Could not disable plugin: %v %s", err, out)
|
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "remove", pName); err != nil {
|
2016-07-22 11:53:26 -04:00
|
|
|
c.Fatalf("Could not remove plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if err := s.d.cmd.Process.Signal(os.Interrupt); err != nil {
|
|
|
|
c.Fatalf("Could not kill daemon: %v", err)
|
2016-07-01 14:36:11 -04:00
|
|
|
}
|
|
|
|
|
2016-11-10 16:07:53 -05:00
|
|
|
cmd := exec.Command("pgrep", "-f", pluginProcessName)
|
2016-07-01 14:36:11 -04:00
|
|
|
if out, ec, err := runCommandWithOutput(cmd); ec != 0 {
|
|
|
|
c.Fatalf("Expected exit code '0', got %d err: %v output: %s ", ec, err, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestDaemonShutdownWithPlugins shuts down running plugins.
|
|
|
|
func (s *DockerDaemonSuite) TestDaemonShutdownWithPlugins(c *check.C) {
|
2016-11-09 20:49:09 -05:00
|
|
|
testRequires(c, Network)
|
2016-10-06 10:09:54 -04:00
|
|
|
|
2016-07-01 14:36:11 -04:00
|
|
|
if err := s.d.Start(); err != nil {
|
|
|
|
c.Fatalf("Could not start daemon: %v", err)
|
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pName); err != nil {
|
2016-07-01 14:36:11 -04:00
|
|
|
c.Fatalf("Could not install plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if err := s.d.Restart(); err != nil {
|
|
|
|
c.Fatalf("Could not restart daemon: %v", err)
|
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "disable", pName); err != nil {
|
2016-07-01 14:36:11 -04:00
|
|
|
c.Fatalf("Could not disable plugin: %v %s", err, out)
|
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "remove", pName); err != nil {
|
2016-07-01 14:36:11 -04:00
|
|
|
c.Fatalf("Could not remove plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if err := s.d.cmd.Process.Signal(os.Interrupt); err != nil {
|
|
|
|
c.Fatalf("Could not kill daemon: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-07-11 11:55:39 -04:00
|
|
|
for {
|
|
|
|
if err := syscall.Kill(s.d.cmd.Process.Pid, 0); err == syscall.ESRCH {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2016-07-01 14:36:11 -04:00
|
|
|
|
2016-11-10 16:07:53 -05:00
|
|
|
cmd := exec.Command("pgrep", "-f", pluginProcessName)
|
2016-07-01 14:36:11 -04:00
|
|
|
if out, ec, err := runCommandWithOutput(cmd); ec != 1 {
|
|
|
|
c.Fatalf("Expected exit code '1', got %d err: %v output: %s ", ec, err, out)
|
|
|
|
}
|
|
|
|
}
|
2016-07-08 13:37:52 -04:00
|
|
|
|
|
|
|
// TestVolumePlugin tests volume creation using a plugin.
|
|
|
|
func (s *DockerDaemonSuite) TestVolumePlugin(c *check.C) {
|
2016-11-11 12:50:43 -05:00
|
|
|
testRequires(c, Network, IsAmd64)
|
2016-10-06 10:09:54 -04:00
|
|
|
|
2016-07-08 13:37:52 -04:00
|
|
|
volName := "plugin-volume"
|
|
|
|
volRoot := "/data"
|
|
|
|
destDir := "/tmp/data/"
|
|
|
|
destFile := "foo"
|
|
|
|
|
|
|
|
if err := s.d.Start(); err != nil {
|
|
|
|
c.Fatalf("Could not start daemon: %v", err)
|
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
out, err := s.d.Cmd("plugin", "install", pName, "--grant-all-permissions")
|
2016-07-08 13:37:52 -04:00
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("Could not install plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
defer func() {
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "disable", pName); err != nil {
|
2016-07-08 13:37:52 -04:00
|
|
|
c.Fatalf("Could not disable plugin: %v %s", err, out)
|
|
|
|
}
|
2016-11-10 16:07:53 -05:00
|
|
|
if out, err := s.d.Cmd("plugin", "remove", pName); err != nil {
|
2016-07-08 13:37:52 -04:00
|
|
|
c.Fatalf("Could not remove plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2016-11-10 16:07:53 -05:00
|
|
|
out, err = s.d.Cmd("volume", "create", "-d", pName, volName)
|
2016-07-08 13:37:52 -04:00
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("Could not create volume: %v %s", err, out)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if out, err := s.d.Cmd("volume", "remove", volName); err != nil {
|
|
|
|
c.Fatalf("Could not remove volume: %v %s", err, out)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2016-08-16 18:53:43 -04:00
|
|
|
out, err = s.d.Cmd("volume", "ls")
|
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("Could not list volume: %v %s", err, out)
|
|
|
|
}
|
|
|
|
c.Assert(out, checker.Contains, volName)
|
2016-11-10 16:07:53 -05:00
|
|
|
c.Assert(out, checker.Contains, pName)
|
2016-08-16 18:53:43 -04:00
|
|
|
|
2016-07-08 13:37:52 -04:00
|
|
|
mountPoint, err := s.d.Cmd("volume", "inspect", volName, "--format", "{{.Mountpoint}}")
|
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("Could not inspect volume: %v %s", err, mountPoint)
|
|
|
|
}
|
|
|
|
mountPoint = strings.TrimSpace(mountPoint)
|
|
|
|
|
|
|
|
out, err = s.d.Cmd("run", "--rm", "-v", volName+":"+destDir, "busybox", "touch", destDir+destFile)
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
|
|
path := filepath.Join(mountPoint, destFile)
|
|
|
|
_, err = os.Lstat(path)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
// tiborvass/no-remove is a volume plugin that persists data on disk at /data,
|
|
|
|
// even after the volume is removed. So perform an explicit filesystem cleanup.
|
|
|
|
os.RemoveAll(volRoot)
|
|
|
|
}
|