2015-05-19 16:05:25 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2015-10-19 15:53:52 -04:00
|
|
|
"io"
|
2015-05-19 16:05:25 -04:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"os"
|
2015-08-28 14:16:18 -04:00
|
|
|
"os/exec"
|
2015-05-19 16:05:25 -04:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2019-09-09 17:06:12 -04:00
|
|
|
"testing"
|
2015-08-28 14:16:18 -04:00
|
|
|
"time"
|
2015-05-19 16:05:25 -04:00
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2022-03-18 11:33:43 -04:00
|
|
|
volumetypes "github.com/docker/docker/api/types/volume"
|
2016-12-09 04:17:53 -05:00
|
|
|
"github.com/docker/docker/integration-cli/daemon"
|
2016-10-05 14:39:45 -04:00
|
|
|
"github.com/docker/docker/pkg/stringid"
|
2019-08-29 16:52:40 -04:00
|
|
|
testdaemon "github.com/docker/docker/testutil/daemon"
|
2016-04-11 11:17:52 -04:00
|
|
|
"github.com/docker/docker/volume"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2015-05-19 16:05:25 -04:00
|
|
|
)
|
|
|
|
|
2016-10-05 14:39:45 -04:00
|
|
|
const volumePluginName = "test-external-volume-driver"
|
|
|
|
|
2015-05-22 13:37:00 -04:00
|
|
|
type eventCounter struct {
|
|
|
|
activations int
|
|
|
|
creations int
|
|
|
|
removals int
|
|
|
|
mounts int
|
|
|
|
unmounts int
|
|
|
|
paths int
|
2015-09-23 16:29:14 -04:00
|
|
|
lists int
|
|
|
|
gets int
|
2016-04-11 11:17:52 -04:00
|
|
|
caps int
|
2015-05-22 13:37:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type DockerExternalVolumeSuite struct {
|
2016-10-05 14:39:45 -04:00
|
|
|
ds *DockerSuite
|
2016-12-09 04:17:53 -05:00
|
|
|
d *daemon.Daemon
|
2016-10-05 14:39:45 -04:00
|
|
|
*volumePlugin
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) SetUpTest(c *testing.T) {
|
2018-12-24 07:25:53 -05:00
|
|
|
testRequires(c, testEnv.IsLocalDaemon)
|
2018-04-13 11:02:56 -04:00
|
|
|
s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
|
2015-05-22 13:37:00 -04:00
|
|
|
s.ec = &eventCounter{}
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TearDownTest(c *testing.T) {
|
2016-11-21 12:37:13 -05:00
|
|
|
if s.d != nil {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Stop(c)
|
2016-11-21 12:37:13 -05:00
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) SetUpSuite(c *testing.T) {
|
2016-10-05 14:39:45 -04:00
|
|
|
s.volumePlugin = newVolumePlugin(c, volumePluginName)
|
|
|
|
}
|
|
|
|
|
|
|
|
type volumePlugin struct {
|
|
|
|
ec *eventCounter
|
|
|
|
*httptest.Server
|
|
|
|
vols map[string]vol
|
|
|
|
}
|
|
|
|
|
|
|
|
type vol struct {
|
|
|
|
Name string
|
|
|
|
Mountpoint string
|
|
|
|
Ninja bool // hack used to trigger a null volume return on `Get`
|
|
|
|
Status map[string]interface{}
|
2016-10-03 13:53:06 -04:00
|
|
|
Options map[string]string
|
2016-10-05 14:39:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *volumePlugin) Close() {
|
|
|
|
p.Server.Close()
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func newVolumePlugin(c *testing.T, name string) *volumePlugin {
|
2015-05-19 16:05:25 -04:00
|
|
|
mux := http.NewServeMux()
|
2016-10-05 14:39:45 -04:00
|
|
|
s := &volumePlugin{Server: httptest.NewServer(mux), ec: &eventCounter{}, vols: make(map[string]vol)}
|
2015-05-19 16:05:25 -04:00
|
|
|
|
|
|
|
type pluginRequest struct {
|
2015-10-19 15:53:52 -04:00
|
|
|
Name string
|
2016-02-24 20:45:38 -05:00
|
|
|
Opts map[string]string
|
2016-03-07 21:41:44 -05:00
|
|
|
ID string
|
2015-10-19 15:53:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type pluginResp struct {
|
|
|
|
Mountpoint string `json:",omitempty"`
|
|
|
|
Err string `json:",omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
read := func(b io.ReadCloser) (pluginRequest, error) {
|
|
|
|
defer b.Close()
|
|
|
|
var pr pluginRequest
|
2016-12-14 16:16:12 -05:00
|
|
|
err := json.NewDecoder(b).Decode(&pr)
|
|
|
|
return pr, err
|
2015-10-19 15:53:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
send := func(w http.ResponseWriter, data interface{}) {
|
|
|
|
switch t := data.(type) {
|
|
|
|
case error:
|
|
|
|
http.Error(w, t.Error(), 500)
|
|
|
|
case string:
|
|
|
|
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json")
|
|
|
|
fmt.Fprintln(w, t)
|
|
|
|
default:
|
|
|
|
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json")
|
|
|
|
json.NewEncoder(w).Encode(&data)
|
|
|
|
}
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/Plugin.Activate", func(w http.ResponseWriter, r *http.Request) {
|
2015-05-22 13:37:00 -04:00
|
|
|
s.ec.activations++
|
2015-10-19 15:53:52 -04:00
|
|
|
send(w, `{"Implements": ["VolumeDriver"]}`)
|
2015-05-19 16:05:25 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc("/VolumeDriver.Create", func(w http.ResponseWriter, r *http.Request) {
|
2015-05-22 13:37:00 -04:00
|
|
|
s.ec.creations++
|
2015-09-23 16:29:14 -04:00
|
|
|
pr, err := read(r.Body)
|
|
|
|
if err != nil {
|
|
|
|
send(w, err)
|
|
|
|
return
|
|
|
|
}
|
2016-02-24 20:45:38 -05:00
|
|
|
_, isNinja := pr.Opts["ninja"]
|
2016-03-07 15:44:43 -05:00
|
|
|
status := map[string]interface{}{"Hello": "world"}
|
2016-10-03 13:53:06 -04:00
|
|
|
s.vols[pr.Name] = vol{Name: pr.Name, Ninja: isNinja, Status: status, Options: pr.Opts}
|
2015-09-23 16:29:14 -04:00
|
|
|
send(w, nil)
|
|
|
|
})
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2015-09-23 16:29:14 -04:00
|
|
|
mux.HandleFunc("/VolumeDriver.List", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
s.ec.lists++
|
2016-10-05 14:39:45 -04:00
|
|
|
vols := make([]vol, 0, len(s.vols))
|
|
|
|
for _, v := range s.vols {
|
2016-03-03 05:51:59 -05:00
|
|
|
if v.Ninja {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
vols = append(vols, v)
|
|
|
|
}
|
|
|
|
send(w, map[string][]vol{"Volumes": vols})
|
2015-09-23 16:29:14 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc("/VolumeDriver.Get", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
s.ec.gets++
|
|
|
|
pr, err := read(r.Body)
|
2015-10-19 15:53:52 -04:00
|
|
|
if err != nil {
|
|
|
|
send(w, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:39:45 -04:00
|
|
|
v, exists := s.vols[pr.Name]
|
|
|
|
if !exists {
|
|
|
|
send(w, `{"Err": "no such volume"}`)
|
|
|
|
}
|
2016-03-07 15:44:43 -05:00
|
|
|
|
2016-10-05 14:39:45 -04:00
|
|
|
if v.Ninja {
|
|
|
|
send(w, map[string]vol{})
|
|
|
|
return
|
2015-09-23 16:29:14 -04:00
|
|
|
}
|
2016-10-05 14:39:45 -04:00
|
|
|
|
|
|
|
v.Mountpoint = hostVolumePath(pr.Name)
|
|
|
|
send(w, map[string]vol{"Volume": v})
|
2015-05-19 16:05:25 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc("/VolumeDriver.Remove", func(w http.ResponseWriter, r *http.Request) {
|
2015-05-22 13:37:00 -04:00
|
|
|
s.ec.removals++
|
2015-10-19 15:53:52 -04:00
|
|
|
pr, err := read(r.Body)
|
|
|
|
if err != nil {
|
|
|
|
send(w, err)
|
|
|
|
return
|
|
|
|
}
|
2015-09-23 16:29:14 -04:00
|
|
|
|
2016-10-05 14:39:45 -04:00
|
|
|
v, ok := s.vols[pr.Name]
|
|
|
|
if !ok {
|
|
|
|
send(w, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.RemoveAll(hostVolumePath(v.Name)); err != nil {
|
|
|
|
send(w, &pluginResp{Err: err.Error()})
|
|
|
|
return
|
2015-09-23 16:29:14 -04:00
|
|
|
}
|
2016-10-05 14:39:45 -04:00
|
|
|
delete(s.vols, v.Name)
|
2015-10-19 15:53:52 -04:00
|
|
|
send(w, nil)
|
2015-05-19 16:05:25 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc("/VolumeDriver.Path", func(w http.ResponseWriter, r *http.Request) {
|
2015-05-22 13:37:00 -04:00
|
|
|
s.ec.paths++
|
|
|
|
|
2015-10-19 15:53:52 -04:00
|
|
|
pr, err := read(r.Body)
|
|
|
|
if err != nil {
|
|
|
|
send(w, err)
|
|
|
|
return
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
2015-10-19 15:53:52 -04:00
|
|
|
p := hostVolumePath(pr.Name)
|
2015-09-23 16:29:14 -04:00
|
|
|
send(w, &pluginResp{Mountpoint: p})
|
2015-05-19 16:05:25 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
mux.HandleFunc("/VolumeDriver.Mount", func(w http.ResponseWriter, r *http.Request) {
|
2015-05-22 13:37:00 -04:00
|
|
|
s.ec.mounts++
|
|
|
|
|
2015-10-19 15:53:52 -04:00
|
|
|
pr, err := read(r.Body)
|
|
|
|
if err != nil {
|
|
|
|
send(w, err)
|
|
|
|
return
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2016-10-03 13:53:06 -04:00
|
|
|
if v, exists := s.vols[pr.Name]; exists {
|
|
|
|
// Use this to simulate a mount failure
|
|
|
|
if _, exists := v.Options["invalidOption"]; exists {
|
|
|
|
send(w, fmt.Errorf("invalid argument"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-19 15:53:52 -04:00
|
|
|
p := hostVolumePath(pr.Name)
|
2015-05-19 16:05:25 -04:00
|
|
|
if err := os.MkdirAll(p, 0755); err != nil {
|
2015-10-19 15:53:52 -04:00
|
|
|
send(w, &pluginResp{Err: err.Error()})
|
|
|
|
return
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
if err := os.WriteFile(filepath.Join(p, "test"), []byte(s.Server.URL), 0644); err != nil {
|
2015-10-19 15:53:52 -04:00
|
|
|
send(w, err)
|
|
|
|
return
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
if err := os.WriteFile(filepath.Join(p, "mountID"), []byte(pr.ID), 0644); err != nil {
|
2016-03-07 21:41:44 -05:00
|
|
|
send(w, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-10-19 15:53:52 -04:00
|
|
|
send(w, &pluginResp{Mountpoint: p})
|
2015-05-19 16:05:25 -04:00
|
|
|
})
|
|
|
|
|
2015-05-22 13:37:00 -04:00
|
|
|
mux.HandleFunc("/VolumeDriver.Unmount", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
s.ec.unmounts++
|
|
|
|
|
2015-10-19 15:53:52 -04:00
|
|
|
_, err := read(r.Body)
|
|
|
|
if err != nil {
|
|
|
|
send(w, err)
|
|
|
|
return
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2015-09-23 16:29:14 -04:00
|
|
|
send(w, nil)
|
2015-05-19 16:05:25 -04:00
|
|
|
})
|
|
|
|
|
2016-04-11 11:17:52 -04:00
|
|
|
mux.HandleFunc("/VolumeDriver.Capabilities", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
s.ec.caps++
|
|
|
|
|
|
|
|
_, err := read(r.Body)
|
|
|
|
if err != nil {
|
|
|
|
send(w, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
send(w, `{"Capabilities": { "Scope": "global" }}`)
|
|
|
|
})
|
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
err := os.MkdirAll("/etc/docker/plugins", 0755)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2015-05-19 16:05:25 -04:00
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
err = os.WriteFile("/etc/docker/plugins/"+name+".spec", []byte(s.Server.URL), 0644)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-10-05 14:39:45 -04:00
|
|
|
return s
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TearDownSuite(c *testing.T) {
|
2016-10-05 14:39:45 -04:00
|
|
|
s.volumePlugin.Close()
|
2015-05-19 16:05:25 -04:00
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
err := os.RemoveAll("/etc/docker/plugins")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestVolumeCLICreateOptionConflict(c *testing.T) {
|
2016-12-13 20:20:52 -05:00
|
|
|
dockerCmd(c, "volume", "create", "test")
|
|
|
|
|
|
|
|
out, _, err := dockerCmdWithError("volume", "create", "test", "--driver", volumePluginName)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, err != nil, "volume create exception name already in use with another driver")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "must be unique"))
|
2016-12-13 20:20:52 -05:00
|
|
|
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Driver }}", "test")
|
|
|
|
_, _, err = dockerCmdWithError("volume", "create", "test", "--driver", strings.TrimSpace(out))
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-12-13 20:20:52 -05:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverNamed(c *testing.T) {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.StartWithBusybox(c)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2016-10-05 14:39:45 -04:00
|
|
|
out, err := s.d.Cmd("run", "--rm", "--name", "test-data", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", volumePluginName, "busybox:latest", "cat", "/tmp/external-volume-test/test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, s.Server.URL))
|
2016-01-21 21:57:53 -05:00
|
|
|
_, err = s.d.Cmd("volume", "rm", "external-volume-test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-01-21 21:57:53 -05:00
|
|
|
|
2015-05-22 13:37:00 -04:00
|
|
|
p := hostVolumePath("external-volume-test")
|
|
|
|
_, err = os.Lstat(p)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-09-11 06:57:29 -04:00
|
|
|
assert.Assert(c, os.IsNotExist(err), "Expected volume path in host to not exist: %s, %v\n", p, err)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, s.ec.activations, 1)
|
|
|
|
assert.Equal(c, s.ec.creations, 1)
|
|
|
|
assert.Equal(c, s.ec.removals, 1)
|
|
|
|
assert.Equal(c, s.ec.mounts, 1)
|
|
|
|
assert.Equal(c, s.ec.unmounts, 1)
|
2015-05-22 13:37:00 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnnamed(c *testing.T) {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.StartWithBusybox(c)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2016-10-05 14:39:45 -04:00
|
|
|
out, err := s.d.Cmd("run", "--rm", "--name", "test-data", "-v", "/tmp/external-volume-test", "--volume-driver", volumePluginName, "busybox:latest", "cat", "/tmp/external-volume-test/test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, s.Server.URL))
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, s.ec.activations, 1)
|
|
|
|
assert.Equal(c, s.ec.creations, 1)
|
|
|
|
assert.Equal(c, s.ec.removals, 1)
|
|
|
|
assert.Equal(c, s.ec.mounts, 1)
|
|
|
|
assert.Equal(c, s.ec.unmounts, 1)
|
2015-05-22 13:37:00 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverVolumesFrom(c *testing.T) {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.StartWithBusybox(c)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2016-10-05 14:39:45 -04:00
|
|
|
out, err := s.d.Cmd("run", "--name", "vol-test1", "-v", "/foo", "--volume-driver", volumePluginName, "busybox:latest")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2015-06-12 09:25:32 -04:00
|
|
|
out, err = s.d.Cmd("run", "--rm", "--volumes-from", "vol-test1", "--name", "vol-test2", "busybox", "ls", "/tmp")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2015-06-12 09:25:32 -04:00
|
|
|
out, err = s.d.Cmd("rm", "-fv", "vol-test1")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, s.ec.activations, 1)
|
|
|
|
assert.Equal(c, s.ec.creations, 1)
|
|
|
|
assert.Equal(c, s.ec.removals, 1)
|
|
|
|
assert.Equal(c, s.ec.mounts, 2)
|
|
|
|
assert.Equal(c, s.ec.unmounts, 2)
|
2015-05-22 13:37:00 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverDeleteContainer(c *testing.T) {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.StartWithBusybox(c)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2016-10-05 14:39:45 -04:00
|
|
|
out, err := s.d.Cmd("run", "--name", "vol-test1", "-v", "/foo", "--volume-driver", volumePluginName, "busybox:latest")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
out, err = s.d.Cmd("rm", "-fv", "vol-test1")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, s.ec.activations, 1)
|
|
|
|
assert.Equal(c, s.ec.creations, 1)
|
|
|
|
assert.Equal(c, s.ec.removals, 1)
|
|
|
|
assert.Equal(c, s.ec.mounts, 1)
|
|
|
|
assert.Equal(c, s.ec.unmounts, 1)
|
2015-05-22 13:37:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func hostVolumePath(name string) string {
|
|
|
|
return fmt.Sprintf("/var/lib/docker/volumes/%s", name)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
2015-08-11 22:27:33 -04:00
|
|
|
|
2015-08-28 14:16:18 -04:00
|
|
|
// Make sure a request to use a down driver doesn't block other requests
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c *testing.T) {
|
2015-08-28 14:16:18 -04:00
|
|
|
specPath := "/etc/docker/plugins/down-driver.spec"
|
2021-08-24 06:10:50 -04:00
|
|
|
err := os.WriteFile(specPath, []byte("tcp://127.0.0.7:9999"), 0644)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2015-08-28 14:16:18 -04:00
|
|
|
defer os.RemoveAll(specPath)
|
|
|
|
|
|
|
|
chCmd1 := make(chan struct{})
|
2020-02-25 17:13:25 -05:00
|
|
|
chCmd2 := make(chan error, 1)
|
2015-08-28 14:16:18 -04:00
|
|
|
cmd1 := exec.Command(dockerBinary, "volume", "create", "-d", "down-driver")
|
|
|
|
cmd2 := exec.Command(dockerBinary, "volume", "create")
|
|
|
|
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Assert(c, cmd1.Start() == nil)
|
2015-08-28 14:16:18 -04:00
|
|
|
defer cmd1.Process.Kill()
|
|
|
|
time.Sleep(100 * time.Millisecond) // ensure API has been called
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Assert(c, cmd2.Start() == nil)
|
2015-08-28 14:16:18 -04:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
cmd1.Wait()
|
|
|
|
close(chCmd1)
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
chCmd2 <- cmd2.Wait()
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-chCmd1:
|
|
|
|
cmd2.Process.Kill()
|
|
|
|
c.Fatalf("volume create with down driver finished unexpectedly")
|
|
|
|
case err := <-chCmd2:
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2015-08-28 14:16:18 -04:00
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
cmd2.Process.Kill()
|
2015-09-23 16:29:14 -04:00
|
|
|
c.Fatal("volume creates are blocked by previous create requests when previous driver is down")
|
2015-08-28 14:16:18 -04:00
|
|
|
}
|
|
|
|
}
|
2015-09-23 16:29:14 -04:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverRetryNotImmediatelyExists(c *testing.T) {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.StartWithBusybox(c)
|
2017-01-04 15:04:29 -05:00
|
|
|
driverName := "test-external-volume-driver-retry"
|
2015-08-28 14:55:05 -04:00
|
|
|
|
2020-02-25 17:13:25 -05:00
|
|
|
errchan := make(chan error, 1)
|
2017-01-04 15:04:29 -05:00
|
|
|
started := make(chan struct{})
|
2015-08-28 14:55:05 -04:00
|
|
|
go func() {
|
2017-01-04 15:04:29 -05:00
|
|
|
close(started)
|
|
|
|
if out, err := s.d.Cmd("run", "--rm", "--name", "test-data-retry", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", driverName, "busybox:latest"); err != nil {
|
2015-08-28 14:55:05 -04:00
|
|
|
errchan <- fmt.Errorf("%v:\n%s", err, out)
|
|
|
|
}
|
|
|
|
close(errchan)
|
|
|
|
}()
|
2017-01-04 15:04:29 -05:00
|
|
|
|
|
|
|
<-started
|
|
|
|
// wait for a retry to occur, then create spec to allow plugin to register
|
2017-02-10 11:27:07 -05:00
|
|
|
time.Sleep(2 * time.Second)
|
2017-01-04 15:04:29 -05:00
|
|
|
p := newVolumePlugin(c, driverName)
|
|
|
|
defer p.Close()
|
2015-08-28 14:55:05 -04:00
|
|
|
|
|
|
|
select {
|
|
|
|
case err := <-errchan:
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2015-08-28 14:55:05 -04:00
|
|
|
case <-time.After(8 * time.Second):
|
|
|
|
c.Fatal("volume creates fail when plugin not immediately available")
|
|
|
|
}
|
|
|
|
|
2016-12-09 17:20:14 -05:00
|
|
|
_, err := s.d.Cmd("volume", "rm", "external-volume-test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-01-21 21:57:53 -05:00
|
|
|
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, p.ec.activations, 1)
|
|
|
|
assert.Equal(c, p.ec.creations, 1)
|
|
|
|
assert.Equal(c, p.ec.removals, 1)
|
|
|
|
assert.Equal(c, p.ec.mounts, 1)
|
|
|
|
assert.Equal(c, p.ec.unmounts, 1)
|
2015-08-28 14:55:05 -04:00
|
|
|
}
|
2015-09-01 20:13:38 -04:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverBindExternalVolume(c *testing.T) {
|
2016-10-05 14:39:45 -04:00
|
|
|
dockerCmd(c, "volume", "create", "-d", volumePluginName, "foo")
|
2015-09-01 20:13:38 -04:00
|
|
|
dockerCmd(c, "run", "-d", "--name", "testing", "-v", "foo:/bar", "busybox", "top")
|
|
|
|
|
|
|
|
var mounts []struct {
|
|
|
|
Name string
|
|
|
|
Driver string
|
|
|
|
}
|
2016-01-28 09:19:25 -05:00
|
|
|
out := inspectFieldJSON(c, "testing", "Mounts")
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Assert(c, json.NewDecoder(strings.NewReader(out)).Decode(&mounts) == nil)
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 06:36:00 -04:00
|
|
|
assert.Equal(c, len(mounts), 1, out)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, mounts[0].Name, "foo")
|
|
|
|
assert.Equal(c, mounts[0].Driver, volumePluginName)
|
2015-09-01 20:13:38 -04:00
|
|
|
}
|
2015-09-23 16:29:14 -04:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverList(c *testing.T) {
|
2016-10-05 14:39:45 -04:00
|
|
|
dockerCmd(c, "volume", "create", "-d", volumePluginName, "abc3")
|
2015-09-23 16:29:14 -04:00
|
|
|
out, _ := dockerCmd(c, "volume", "ls")
|
|
|
|
ls := strings.Split(strings.TrimSpace(out), "\n")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Equal(c, len(ls), 2, fmt.Sprintf("\n%s", out))
|
2015-09-23 16:29:14 -04:00
|
|
|
|
|
|
|
vol := strings.Fields(ls[len(ls)-1])
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Equal(c, len(vol), 2, fmt.Sprintf("%v", vol))
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, vol[0], volumePluginName)
|
|
|
|
assert.Equal(c, vol[1], "abc3")
|
2015-09-23 16:29:14 -04:00
|
|
|
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, s.ec.lists, 1)
|
2015-09-23 16:29:14 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGet(c *testing.T) {
|
2015-09-23 16:29:14 -04:00
|
|
|
out, _, err := dockerCmdWithError("volume", "inspect", "dummy")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "", out)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "No such volume"))
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, s.ec.gets, 1)
|
2016-03-07 15:44:43 -05:00
|
|
|
|
2016-10-05 14:39:45 -04:00
|
|
|
dockerCmd(c, "volume", "create", "test", "-d", volumePluginName)
|
2016-03-07 15:44:43 -05:00
|
|
|
out, _ = dockerCmd(c, "volume", "inspect", "test")
|
|
|
|
|
|
|
|
type vol struct {
|
|
|
|
Status map[string]string
|
|
|
|
}
|
|
|
|
var st []vol
|
|
|
|
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Assert(c, json.Unmarshal([]byte(out), &st) == nil)
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Equal(c, len(st), 1)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Equal(c, len(st[0].Status), 1, fmt.Sprintf("%v", st[0]))
|
|
|
|
assert.Equal(c, st[0].Status["Hello"], "world", fmt.Sprintf("%v", st[0].Status))
|
2015-09-23 16:29:14 -04:00
|
|
|
}
|
2016-02-10 12:02:52 -05:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverWithDaemonRestart(c *testing.T) {
|
2016-10-05 14:39:45 -04:00
|
|
|
dockerCmd(c, "volume", "create", "-d", volumePluginName, "abc1")
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Restart(c)
|
2016-02-10 12:02:52 -05:00
|
|
|
|
2016-03-03 05:51:59 -05:00
|
|
|
dockerCmd(c, "run", "--name=test", "-v", "abc1:/foo", "busybox", "true")
|
2016-02-10 12:02:52 -05:00
|
|
|
var mounts []types.MountPoint
|
2017-01-10 13:16:25 -05:00
|
|
|
inspectFieldAndUnmarshall(c, "test", "Mounts", &mounts)
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Equal(c, len(mounts), 1)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, mounts[0].Driver, volumePluginName)
|
2016-02-10 12:02:52 -05:00
|
|
|
}
|
2016-02-24 20:45:38 -05:00
|
|
|
|
|
|
|
// Ensures that the daemon handles when the plugin responds to a `Get` request with a null volume and a null error.
|
|
|
|
// Prior the daemon would panic in this scenario.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGetEmptyResponse(c *testing.T) {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Start(c)
|
2016-06-28 13:36:10 -04:00
|
|
|
|
2016-10-05 14:39:45 -04:00
|
|
|
out, err := s.d.Cmd("volume", "create", "-d", volumePluginName, "abc2", "--opt", "ninja=1")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-06-28 13:36:10 -04:00
|
|
|
|
|
|
|
out, err = s.d.Cmd("volume", "inspect", "abc2")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "", out)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "No such volume"))
|
2016-02-24 20:45:38 -05:00
|
|
|
}
|
2016-04-12 17:09:55 -04:00
|
|
|
|
|
|
|
// Ensure only cached paths are used in volume list to prevent N+1 calls to `VolumeDriver.Path`
|
2018-03-22 17:11:03 -04:00
|
|
|
//
|
|
|
|
// TODO(@cpuguy83): This test is testing internal implementation. In all the cases here, there may not even be a path
|
|
|
|
// available because the volume is not even mounted. Consider removing this test.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverPathCalls(c *testing.T) {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Start(c)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, s.ec.paths, 0)
|
2016-04-12 17:09:55 -04:00
|
|
|
|
2016-06-14 18:42:30 -04:00
|
|
|
out, err := s.d.Cmd("volume", "create", "test", "--driver=test-external-volume-driver")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, s.ec.paths, 0)
|
2016-04-12 17:09:55 -04:00
|
|
|
|
|
|
|
out, err = s.d.Cmd("volume", "ls")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, s.ec.paths, 0)
|
2016-04-12 17:09:55 -04:00
|
|
|
}
|
2016-03-07 21:41:44 -05:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverMountID(c *testing.T) {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.StartWithBusybox(c)
|
2016-03-07 21:41:44 -05:00
|
|
|
|
2016-10-05 14:39:45 -04:00
|
|
|
out, err := s.d.Cmd("run", "--rm", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", volumePluginName, "busybox:latest", "cat", "/tmp/external-volume-test/test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
|
|
|
assert.Assert(c, strings.TrimSpace(out) != "")
|
2016-03-07 21:41:44 -05:00
|
|
|
}
|
2016-04-11 11:17:52 -04:00
|
|
|
|
|
|
|
// Check that VolumeDriver.Capabilities gets called, and only called once
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverCapabilities(c *testing.T) {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.Start(c)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, s.ec.caps, 0)
|
2016-04-11 11:17:52 -04:00
|
|
|
|
|
|
|
for i := 0; i < 3; i++ {
|
2016-10-05 14:39:45 -04:00
|
|
|
out, err := s.d.Cmd("volume", "create", "-d", volumePluginName, fmt.Sprintf("test%d", i))
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, s.ec.caps, 1)
|
2016-04-11 11:17:52 -04:00
|
|
|
out, err = s.d.Cmd("volume", "inspect", "--format={{.Scope}}", fmt.Sprintf("test%d", i))
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), volume.GlobalScope)
|
2016-04-11 11:17:52 -04:00
|
|
|
}
|
|
|
|
}
|
2016-10-05 14:39:45 -04:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *testing.T) {
|
2019-06-07 06:21:18 -04:00
|
|
|
driverName := stringid.GenerateRandomID()
|
2016-10-05 14:39:45 -04:00
|
|
|
p := newVolumePlugin(c, driverName)
|
|
|
|
defer p.Close()
|
|
|
|
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.StartWithBusybox(c)
|
2016-10-05 14:39:45 -04:00
|
|
|
|
|
|
|
out, err := s.d.Cmd("volume", "create", "-d", driverName, "--name", "test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-10-05 14:39:45 -04:00
|
|
|
|
|
|
|
out, err = s.d.Cmd("volume", "create", "-d", "local", "--name", "test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "", out)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "must be unique"))
|
2016-10-05 14:39:45 -04:00
|
|
|
// simulate out of band volume deletion on plugin level
|
|
|
|
delete(p.vols, "test")
|
|
|
|
|
2016-11-30 11:11:50 -05:00
|
|
|
// test re-create with same driver
|
|
|
|
out, err = s.d.Cmd("volume", "create", "-d", driverName, "--opt", "foo=bar", "--name", "test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-30 11:11:50 -05:00
|
|
|
out, err = s.d.Cmd("volume", "inspect", "test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-30 11:11:50 -05:00
|
|
|
|
2022-03-18 11:33:43 -04:00
|
|
|
var vs []volumetypes.Volume
|
2016-11-30 11:11:50 -05:00
|
|
|
err = json.Unmarshal([]byte(out), &vs)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Equal(c, len(vs), 1)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, vs[0].Driver, driverName)
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Assert(c, vs[0].Options != nil)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, vs[0].Options["foo"], "bar")
|
|
|
|
assert.Equal(c, vs[0].Driver, driverName)
|
2016-11-30 11:11:50 -05:00
|
|
|
|
|
|
|
// simulate out of band volume deletion on plugin level
|
|
|
|
delete(p.vols, "test")
|
|
|
|
|
|
|
|
// test create with different driver
|
2016-10-05 14:39:45 -04:00
|
|
|
out, err = s.d.Cmd("volume", "create", "-d", "local", "--name", "test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-30 11:11:50 -05:00
|
|
|
|
|
|
|
out, err = s.d.Cmd("volume", "inspect", "test")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, out)
|
2016-11-30 11:11:50 -05:00
|
|
|
vs = nil
|
|
|
|
err = json.Unmarshal([]byte(out), &vs)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Equal(c, len(vs), 1)
|
|
|
|
assert.Equal(c, len(vs[0].Options), 0)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, vs[0].Driver, "local")
|
2016-10-05 14:39:45 -04:00
|
|
|
}
|
2016-10-03 13:53:06 -04:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnmountOnMountFail(c *testing.T) {
|
2016-12-09 17:20:14 -05:00
|
|
|
s.d.StartWithBusybox(c)
|
2016-10-03 13:53:06 -04:00
|
|
|
s.d.Cmd("volume", "create", "-d", "test-external-volume-driver", "--opt=invalidOption=1", "--name=testumount")
|
|
|
|
|
|
|
|
out, _ := s.d.Cmd("run", "-v", "testumount:/foo", "busybox", "true")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 06:36:00 -04:00
|
|
|
assert.Equal(c, s.ec.unmounts, 0, out)
|
2016-10-03 13:53:06 -04:00
|
|
|
out, _ = s.d.Cmd("run", "-w", "/foo", "-v", "testumount:/foo", "busybox", "true")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 06:36:00 -04:00
|
|
|
assert.Equal(c, s.ec.unmounts, 0, out)
|
2016-10-03 13:53:06 -04:00
|
|
|
}
|
2017-04-27 23:33:33 -04:00
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnmountOnCp(c *testing.T) {
|
2017-04-27 23:33:33 -04:00
|
|
|
s.d.StartWithBusybox(c)
|
|
|
|
s.d.Cmd("volume", "create", "-d", "test-external-volume-driver", "--name=test")
|
|
|
|
|
|
|
|
out, _ := s.d.Cmd("run", "-d", "--name=test", "-v", "test:/foo", "busybox", "/bin/sh", "-c", "touch /test && top")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 06:36:00 -04:00
|
|
|
assert.Equal(c, s.ec.mounts, 1, out)
|
2017-04-27 23:33:33 -04:00
|
|
|
|
|
|
|
out, _ = s.d.Cmd("cp", "test:/test", "/tmp/test")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 06:36:00 -04:00
|
|
|
assert.Equal(c, s.ec.mounts, 2, out)
|
|
|
|
assert.Equal(c, s.ec.unmounts, 1, out)
|
2017-04-27 23:33:33 -04:00
|
|
|
|
|
|
|
out, _ = s.d.Cmd("kill", "test")
|
integration-cli: S1025: the argument is already a string (gosimple)
```
integration-cli/docker_cli_daemon_test.go:1753:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1783:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_daemon_test.go:1893:92: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:444:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:600:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:602:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:610:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:613:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:614:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_external_volume_driver_test.go:617:36: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_plugins_test.go:431:39: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:174:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1046:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1071:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1074:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1079:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1087:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1102:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1108:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1128:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1323:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1329:32: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1388:34: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
integration-cli/docker_cli_swarm_test.go:1985:31: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-11 06:36:00 -04:00
|
|
|
assert.Equal(c, s.ec.unmounts, 2, out)
|
2017-04-27 23:33:33 -04:00
|
|
|
}
|