2016-10-06 10:09:54 -04:00
|
|
|
// +build linux
|
2016-03-18 14:50:19 -04:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-07-08 13:37:52 -04:00
|
|
|
"strings"
|
2019-09-09 17:06:12 -04:00
|
|
|
"testing"
|
2016-07-08 13:37:52 -04:00
|
|
|
|
2017-05-23 10:22:32 -04:00
|
|
|
"golang.org/x/sys/unix"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
"gotest.tools/v3/icmd"
|
2016-03-18 14:50:19 -04:00
|
|
|
)
|
|
|
|
|
2016-06-17 11:21:03 -04:00
|
|
|
// TestDaemonRestartWithPluginEnabled tests state restore for an enabled plugin
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonRestartWithPluginEnabled(c *testing.T) {
|
2016-12-12 15:46:36 -05:00
|
|
|
testRequires(c, IsAmd64, Network)
|
2016-10-06 10:09:54 -04:00
|
|
|
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Start(c)
|
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-12-09 17:20:14 -05:00
|
|
|
s.d.Restart(c)
|
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
|
|
|
}
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, pName))
|
|
|
|
assert.Assert(c, strings.Contains(out, "true"))
|
2016-06-17 11:21:03 -04:00
|
|
|
}
|
2016-03-18 14:50:19 -04:00
|
|
|
|
2016-08-11 18:59:35 -04:00
|
|
|
// TestDaemonRestartWithPluginDisabled tests state restore for a disabled plugin
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonRestartWithPluginDisabled(c *testing.T) {
|
2016-12-12 15:46:36 -05:00
|
|
|
testRequires(c, IsAmd64, Network)
|
2016-10-06 10:09:54 -04:00
|
|
|
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Start(c)
|
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-12-09 17:20:14 -05:00
|
|
|
s.d.Restart(c)
|
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
|
|
|
}
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, pName))
|
|
|
|
assert.Assert(c, strings.Contains(out, "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.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonKillLiveRestoreWithPlugins(c *testing.T) {
|
2016-12-12 15:46:36 -05:00
|
|
|
testRequires(c, IsAmd64, Network)
|
2016-10-06 10:09:54 -04:00
|
|
|
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Start(c, "--live-restore")
|
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() {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Restart(c, "--live-restore")
|
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
|
|
|
}
|
|
|
|
|
2017-01-05 06:38:34 -05:00
|
|
|
icmd.RunCommand("pgrep", "-f", pluginProcessName).Assert(c, icmd.Success)
|
2016-07-22 11:53:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestDaemonShutdownLiveRestoreWithPlugins SIGTERMs daemon started with --live-restore.
|
|
|
|
// Plugins should continue to run.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonShutdownLiveRestoreWithPlugins(c *testing.T) {
|
2016-12-12 15:46:36 -05:00
|
|
|
testRequires(c, IsAmd64, Network)
|
2016-10-06 10:09:54 -04:00
|
|
|
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Start(c, "--live-restore")
|
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() {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Restart(c, "--live-restore")
|
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)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
if err := s.d.Interrupt(); err != nil {
|
2016-07-22 11:53:26 -04:00
|
|
|
c.Fatalf("Could not kill daemon: %v", err)
|
2016-07-01 14:36:11 -04:00
|
|
|
}
|
|
|
|
|
2017-01-05 06:38:34 -05:00
|
|
|
icmd.RunCommand("pgrep", "-f", pluginProcessName).Assert(c, icmd.Success)
|
2016-07-01 14:36:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestDaemonShutdownWithPlugins shuts down running plugins.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonShutdownWithPlugins(c *testing.T) {
|
2019-07-19 04:53:42 -04:00
|
|
|
testRequires(c, IsAmd64, Network)
|
2016-10-06 10:09:54 -04:00
|
|
|
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Start(c)
|
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() {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Restart(c)
|
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)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2016-12-09 04:17:53 -05:00
|
|
|
if err := s.d.Interrupt(); err != nil {
|
2016-07-01 14:36:11 -04:00
|
|
|
c.Fatalf("Could not kill daemon: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-07-11 11:55:39 -04:00
|
|
|
for {
|
2017-05-23 10:22:32 -04:00
|
|
|
if err := unix.Kill(s.d.Pid(), 0); err == unix.ESRCH {
|
2016-07-11 11:55:39 -04:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2016-07-01 14:36:11 -04:00
|
|
|
|
2017-01-05 06:38:34 -05:00
|
|
|
icmd.RunCommand("pgrep", "-f", pluginProcessName).Assert(c, icmd.Expected{
|
|
|
|
ExitCode: 1,
|
2017-01-05 13:08:24 -05:00
|
|
|
Error: "exit status 1",
|
2017-01-05 06:38:34 -05:00
|
|
|
})
|
2016-12-09 12:53:10 -05:00
|
|
|
|
2017-03-22 17:37:16 -04:00
|
|
|
s.d.Start(c)
|
|
|
|
icmd.RunCommand("pgrep", "-f", pluginProcessName).Assert(c, icmd.Success)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestDaemonKillWithPlugins leaves plugins running.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerDaemonSuite) TestDaemonKillWithPlugins(c *testing.T) {
|
2019-07-19 04:53:42 -04:00
|
|
|
testRequires(c, IsAmd64, Network)
|
2017-03-22 17:37:16 -04:00
|
|
|
|
|
|
|
s.d.Start(c)
|
|
|
|
if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pName); err != nil {
|
|
|
|
c.Fatalf("Could not install plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
s.d.Restart(c)
|
|
|
|
if out, err := s.d.Cmd("plugin", "disable", pName); err != nil {
|
|
|
|
c.Fatalf("Could not disable plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
if out, err := s.d.Cmd("plugin", "remove", pName); err != nil {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
// assert that plugins are running.
|
2017-01-05 06:38:34 -05:00
|
|
|
icmd.RunCommand("pgrep", "-f", pluginProcessName).Assert(c, icmd.Success)
|
2016-07-01 14:36:11 -04:00
|
|
|
}
|
2016-07-08 13:37:52 -04:00
|
|
|
|
|
|
|
// TestVolumePlugin tests volume creation using a plugin.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerDaemonSuite) TestVolumePlugin(c *testing.T) {
|
2016-12-12 15:46:36 -05:00
|
|
|
testRequires(c, IsAmd64, Network)
|
2016-10-06 10:09:54 -04:00
|
|
|
|
2016-07-08 13:37:52 -04:00
|
|
|
volName := "plugin-volume"
|
|
|
|
destDir := "/tmp/data/"
|
|
|
|
destFile := "foo"
|
|
|
|
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Start(c)
|
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-22 14:21:34 -05:00
|
|
|
|
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)
|
|
|
|
}
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, volName))
|
|
|
|
assert.Assert(c, strings.Contains(out, pName))
|
2016-08-16 18:53:43 -04:00
|
|
|
|
2016-07-08 13:37:52 -04:00
|
|
|
out, err = s.d.Cmd("run", "--rm", "-v", volName+":"+destDir, "busybox", "touch", destDir+destFile)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-07-08 13:37:52 -04:00
|
|
|
|
2018-02-20 16:57:20 -05:00
|
|
|
out, err = s.d.Cmd("run", "--rm", "-v", volName+":"+destDir, "busybox", "ls", destDir+destFile)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-22 14:21:34 -05:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerDaemonSuite) TestPluginVolumeRemoveOnRestart(c *testing.T) {
|
2019-07-19 04:53:42 -04:00
|
|
|
testRequires(c, IsAmd64, Network)
|
2016-12-01 17:17:07 -05:00
|
|
|
|
|
|
|
s.d.Start(c, "--live-restore=true")
|
|
|
|
|
|
|
|
out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.Contains(out, pName))
|
2016-12-01 17:17:07 -05:00
|
|
|
|
|
|
|
out, err = s.d.Cmd("volume", "create", "--driver", pName, "test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-12-01 17:17:07 -05:00
|
|
|
|
|
|
|
s.d.Restart(c, "--live-restore=true")
|
|
|
|
|
|
|
|
out, err = s.d.Cmd("plugin", "disable", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "", out)
|
|
|
|
assert.Assert(c, strings.Contains(out, "in use"))
|
2016-12-20 11:26:58 -05:00
|
|
|
|
|
|
|
out, err = s.d.Cmd("volume", "rm", "test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-12-20 11:26:58 -05:00
|
|
|
|
|
|
|
out, err = s.d.Cmd("plugin", "disable", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-12-20 11:26:58 -05:00
|
|
|
|
|
|
|
out, err = s.d.Cmd("plugin", "rm", pName)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-12-01 17:17:07 -05:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerDaemonSuite) TestPluginListFilterEnabled(c *testing.T) {
|
2017-02-28 16:50:39 -05:00
|
|
|
testRequires(c, IsAmd64, Network)
|
2016-11-23 07:58:15 -05:00
|
|
|
|
|
|
|
s.d.Start(c)
|
|
|
|
|
|
|
|
out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pNameWithTag, "--disable")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-23 07:58:15 -05:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if out, err := s.d.Cmd("plugin", "remove", pNameWithTag); err != nil {
|
|
|
|
c.Fatalf("Could not remove plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
out, err = s.d.Cmd("plugin", "ls", "--filter", "enabled=true")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, !strings.Contains(out, pName))
|
2016-11-23 07:58:15 -05:00
|
|
|
|
|
|
|
out, err = s.d.Cmd("plugin", "ls", "--filter", "enabled=false")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.Contains(out, pName))
|
|
|
|
assert.Assert(c, strings.Contains(out, "false"))
|
2016-11-23 07:58:15 -05:00
|
|
|
|
|
|
|
out, err = s.d.Cmd("plugin", "ls")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.Contains(out, pName))
|
2016-11-23 07:58:15 -05:00
|
|
|
}
|
2016-11-23 08:27:09 -05:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerDaemonSuite) TestPluginListFilterCapability(c *testing.T) {
|
2017-02-28 16:50:39 -05:00
|
|
|
testRequires(c, IsAmd64, Network)
|
2016-11-23 08:27:09 -05:00
|
|
|
|
|
|
|
s.d.Start(c)
|
|
|
|
|
|
|
|
out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pNameWithTag, "--disable")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-23 08:27:09 -05:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if out, err := s.d.Cmd("plugin", "remove", pNameWithTag); err != nil {
|
|
|
|
c.Fatalf("Could not remove plugin: %v %s", err, out)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
out, err = s.d.Cmd("plugin", "ls", "--filter", "capability=volumedriver")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.Contains(out, pName))
|
2016-11-23 08:27:09 -05:00
|
|
|
|
|
|
|
out, err = s.d.Cmd("plugin", "ls", "--filter", "capability=authz")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, !strings.Contains(out, pName))
|
2016-11-23 08:27:09 -05:00
|
|
|
|
|
|
|
out, err = s.d.Cmd("plugin", "ls")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.Contains(out, pName))
|
2016-11-23 08:27:09 -05:00
|
|
|
}
|