2018-03-27 14:03:23 -04:00
|
|
|
package volumes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2019-08-29 16:52:40 -04:00
|
|
|
"github.com/docker/docker/testutil/daemon"
|
|
|
|
"github.com/docker/docker/testutil/fixtures/plugin"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
"gotest.tools/v3/skip"
|
2018-03-27 14:03:23 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestPluginWithDevMounts tests very specific regression caused by mounts ordering
|
|
|
|
// (sorted in the daemon). See #36698
|
|
|
|
func TestPluginWithDevMounts(t *testing.T) {
|
2018-04-25 05:03:43 -04:00
|
|
|
skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
|
2020-03-13 09:37:09 -04:00
|
|
|
skip.If(t, testEnv.IsRootless)
|
2018-03-27 14:03:23 -04:00
|
|
|
t.Parallel()
|
|
|
|
|
2018-04-10 10:29:48 -04:00
|
|
|
d := daemon.New(t)
|
2018-03-27 14:03:23 -04:00
|
|
|
d.Start(t, "--iptables=false")
|
|
|
|
defer d.Stop(t)
|
|
|
|
|
2018-12-22 09:53:02 -05:00
|
|
|
c := d.NewClientT(t)
|
2018-03-27 14:03:23 -04:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
testDir, err := os.MkdirTemp("", "test-dir")
|
2019-01-21 07:16:02 -05:00
|
|
|
assert.NilError(t, err)
|
2018-03-27 14:03:23 -04:00
|
|
|
defer os.RemoveAll(testDir)
|
|
|
|
|
2018-12-22 09:53:02 -05:00
|
|
|
createPlugin(t, c, "test", "dummy", asVolumeDriver, func(c *plugin.Config) {
|
2018-03-27 14:03:23 -04:00
|
|
|
root := "/"
|
|
|
|
dev := "/dev"
|
|
|
|
mounts := []types.PluginMount{
|
|
|
|
{Type: "bind", Source: &root, Destination: "/host", Options: []string{"rbind"}},
|
|
|
|
{Type: "bind", Source: &dev, Destination: "/dev", Options: []string{"rbind"}},
|
|
|
|
{Type: "bind", Source: &testDir, Destination: "/etc/foo", Options: []string{"rbind"}},
|
|
|
|
}
|
|
|
|
c.PluginConfig.Mounts = append(c.PluginConfig.Mounts, mounts...)
|
|
|
|
c.PropagatedMount = "/propagated"
|
|
|
|
c.Network = types.PluginConfigNetwork{Type: "host"}
|
|
|
|
c.IpcHost = true
|
|
|
|
})
|
|
|
|
|
2018-12-22 09:53:02 -05:00
|
|
|
err = c.PluginEnable(ctx, "test", types.PluginEnableOptions{Timeout: 30})
|
2019-01-21 07:16:02 -05:00
|
|
|
assert.NilError(t, err)
|
2018-03-27 14:03:23 -04:00
|
|
|
defer func() {
|
2018-12-22 09:53:02 -05:00
|
|
|
err := c.PluginRemove(ctx, "test", types.PluginRemoveOptions{Force: true})
|
2018-03-27 14:03:23 -04:00
|
|
|
assert.Check(t, err)
|
|
|
|
}()
|
|
|
|
|
2018-12-22 09:53:02 -05:00
|
|
|
p, _, err := c.PluginInspectWithRaw(ctx, "test")
|
2019-01-21 07:16:02 -05:00
|
|
|
assert.NilError(t, err)
|
2018-03-27 14:03:23 -04:00
|
|
|
assert.Assert(t, p.Enabled)
|
|
|
|
}
|