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