2015-05-19 16:05:25 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2015-10-19 15:53:52 -04:00
|
|
|
"io"
|
2015-05-19 16:05:25 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"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"
|
2015-08-28 14:16:18 -04:00
|
|
|
"time"
|
2015-05-19 16:05:25 -04:00
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-05-19 16:05:25 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2015-05-22 13:37:00 -04:00
|
|
|
check.Suite(&DockerExternalVolumeSuite{
|
2015-05-19 16:05:25 -04:00
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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
|
2015-05-22 13:37:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type DockerExternalVolumeSuite struct {
|
2015-05-19 16:05:25 -04:00
|
|
|
server *httptest.Server
|
|
|
|
ds *DockerSuite
|
2015-05-22 13:37:00 -04:00
|
|
|
d *Daemon
|
|
|
|
ec *eventCounter
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2015-05-22 13:37:00 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) SetUpTest(c *check.C) {
|
|
|
|
s.d = NewDaemon(c)
|
|
|
|
s.ec = &eventCounter{}
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2015-05-22 13:37:00 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TearDownTest(c *check.C) {
|
|
|
|
s.d.Stop()
|
2015-05-19 16:05:25 -04:00
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
|
|
|
|
2015-05-22 13:37:00 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) SetUpSuite(c *check.C) {
|
2015-05-19 16:05:25 -04:00
|
|
|
mux := http.NewServeMux()
|
|
|
|
s.server = httptest.NewServer(mux)
|
|
|
|
|
|
|
|
type pluginRequest struct {
|
2015-10-19 15:53:52 -04:00
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
type pluginResp struct {
|
|
|
|
Mountpoint string `json:",omitempty"`
|
|
|
|
Err string `json:",omitempty"`
|
|
|
|
}
|
|
|
|
|
2015-09-23 16:29:14 -04:00
|
|
|
type vol struct {
|
|
|
|
Name string
|
|
|
|
Mountpoint string
|
|
|
|
}
|
|
|
|
var volList []vol
|
|
|
|
|
2015-10-19 15:53:52 -04:00
|
|
|
read := func(b io.ReadCloser) (pluginRequest, error) {
|
|
|
|
defer b.Close()
|
|
|
|
var pr pluginRequest
|
|
|
|
if err := json.NewDecoder(b).Decode(&pr); err != nil {
|
|
|
|
return pr, err
|
|
|
|
}
|
|
|
|
return pr, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
volList = append(volList, vol{Name: pr.Name})
|
|
|
|
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++
|
|
|
|
send(w, map[string][]vol{"Volumes": volList})
|
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-09-23 16:29:14 -04:00
|
|
|
for _, v := range volList {
|
|
|
|
if v.Name == pr.Name {
|
|
|
|
v.Mountpoint = hostVolumePath(pr.Name)
|
|
|
|
send(w, map[string]vol{"Volume": v})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
send(w, `{"Err": "no such volume"}`)
|
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
|
|
|
|
2015-10-19 15:53:52 -04:00
|
|
|
if err := os.RemoveAll(hostVolumePath(pr.Name)); err != nil {
|
|
|
|
send(w, &pluginResp{Err: err.Error()})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-09-23 16:29:14 -04:00
|
|
|
for i, v := range volList {
|
|
|
|
if v.Name == pr.Name {
|
|
|
|
if err := os.RemoveAll(hostVolumePath(v.Name)); err != nil {
|
|
|
|
send(w, fmt.Sprintf(`{"Err": "%v"}`, err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
volList = append(volList[:i], volList[i+1:]...)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if err := ioutil.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
|
|
|
}
|
|
|
|
|
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
|
|
|
})
|
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
err := os.MkdirAll("/etc/docker/plugins", 0755)
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-19 16:05:25 -04:00
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
err = ioutil.WriteFile("/etc/docker/plugins/test-external-volume-driver.spec", []byte(s.server.URL), 0644)
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2015-05-22 13:37:00 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TearDownSuite(c *check.C) {
|
2015-05-19 16:05:25 -04:00
|
|
|
s.server.Close()
|
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
err := os.RemoveAll("/etc/docker/plugins")
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2015-10-19 15:53:52 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverNamed(c *check.C) {
|
2015-10-15 07:12:56 -04:00
|
|
|
err := s.d.StartWithBusybox()
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
|
|
|
out, err := s.d.Cmd("run", "--rm", "--name", "test-data", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", "test-external-volume-driver", "busybox:latest", "cat", "/tmp/external-volume-test/test")
|
2015-10-19 15:53:52 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(out, checker.Contains, s.server.URL)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
|
|
|
p := hostVolumePath("external-volume-test")
|
|
|
|
_, err = os.Lstat(p)
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(err, checker.NotNil)
|
2015-10-19 15:53:52 -04:00
|
|
|
c.Assert(os.IsNotExist(err), checker.True, check.Commentf("Expected volume path in host to not exist: %s, %v\n", p, err))
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(s.ec.activations, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.creations, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.removals, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.mounts, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.unmounts, checker.Equals, 1)
|
2015-05-22 13:37:00 -04:00
|
|
|
}
|
|
|
|
|
2015-10-19 15:53:52 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnnamed(c *check.C) {
|
2015-10-15 07:12:56 -04:00
|
|
|
err := s.d.StartWithBusybox()
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
|
|
|
out, err := s.d.Cmd("run", "--rm", "--name", "test-data", "-v", "/tmp/external-volume-test", "--volume-driver", "test-external-volume-driver", "busybox:latest", "cat", "/tmp/external-volume-test/test")
|
2015-10-19 15:53:52 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(out, checker.Contains, s.server.URL)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(s.ec.activations, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.creations, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.removals, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.mounts, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.unmounts, checker.Equals, 1)
|
2015-05-22 13:37:00 -04:00
|
|
|
}
|
|
|
|
|
2015-10-19 15:53:52 -04:00
|
|
|
func (s DockerExternalVolumeSuite) TestExternalVolumeDriverVolumesFrom(c *check.C) {
|
2015-10-15 07:12:56 -04:00
|
|
|
err := s.d.StartWithBusybox()
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2015-06-12 09:25:32 -04:00
|
|
|
out, err := s.d.Cmd("run", "-d", "--name", "vol-test1", "-v", "/foo", "--volume-driver", "test-external-volume-driver", "busybox:latest")
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(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")
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(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")
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(s.ec.activations, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.creations, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.removals, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.mounts, checker.Equals, 2)
|
|
|
|
c.Assert(s.ec.unmounts, checker.Equals, 2)
|
2015-05-22 13:37:00 -04:00
|
|
|
}
|
|
|
|
|
2015-10-19 15:53:52 -04:00
|
|
|
func (s DockerExternalVolumeSuite) TestExternalVolumeDriverDeleteContainer(c *check.C) {
|
2015-10-15 07:12:56 -04:00
|
|
|
err := s.d.StartWithBusybox()
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
out, err := s.d.Cmd("run", "-d", "--name", "vol-test1", "-v", "/foo", "--volume-driver", "test-external-volume-driver", "busybox:latest")
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(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")
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(s.ec.activations, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.creations, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.removals, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.mounts, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.unmounts, checker.Equals, 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-10-19 15:53:52 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverNamedCheckBindLocalVolume(c *check.C) {
|
2015-10-15 07:12:56 -04:00
|
|
|
err := s.d.StartWithBusybox()
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-11 22:27:33 -04:00
|
|
|
|
|
|
|
expected := s.server.URL
|
|
|
|
dockerfile := fmt.Sprintf(`FROM busybox:latest
|
|
|
|
RUN mkdir /nobindthenlocalvol
|
|
|
|
RUN echo %s > /nobindthenlocalvol/test
|
|
|
|
VOLUME ["/nobindthenlocalvol"]`, expected)
|
|
|
|
|
|
|
|
img := "test-checkbindlocalvolume"
|
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
_, err = buildImageWithOutInDamon(s.d.sock(), img, dockerfile, true)
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-11 22:27:33 -04:00
|
|
|
|
|
|
|
out, err := s.d.Cmd("run", "--rm", "--name", "test-data-nobind", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", "test-external-volume-driver", img, "cat", "/nobindthenlocalvol/test")
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-11 22:27:33 -04:00
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(out, checker.Contains, expected)
|
2015-08-11 22:27:33 -04:00
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(s.ec.activations, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.creations, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.removals, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.mounts, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.unmounts, checker.Equals, 1)
|
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
|
2015-10-19 15:53:52 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c *check.C) {
|
2015-08-28 14:16:18 -04:00
|
|
|
specPath := "/etc/docker/plugins/down-driver.spec"
|
2015-09-23 16:29:14 -04:00
|
|
|
err := ioutil.WriteFile(specPath, []byte("tcp://127.0.0.7:9999"), 0644)
|
|
|
|
c.Assert(err, check.IsNil)
|
2015-08-28 14:16:18 -04:00
|
|
|
defer os.RemoveAll(specPath)
|
|
|
|
|
|
|
|
chCmd1 := make(chan struct{})
|
|
|
|
chCmd2 := make(chan error)
|
|
|
|
cmd1 := exec.Command(dockerBinary, "volume", "create", "-d", "down-driver")
|
|
|
|
cmd2 := exec.Command(dockerBinary, "volume", "create")
|
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(cmd1.Start(), checker.IsNil)
|
2015-08-28 14:16:18 -04:00
|
|
|
defer cmd1.Process.Kill()
|
|
|
|
time.Sleep(100 * time.Millisecond) // ensure API has been called
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(cmd2.Start(), checker.IsNil)
|
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:
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
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
|
|
|
|
2015-10-19 15:53:52 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverRetryNotImmediatelyExists(c *check.C) {
|
2015-10-15 07:12:56 -04:00
|
|
|
err := s.d.StartWithBusybox()
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-28 14:55:05 -04:00
|
|
|
|
|
|
|
specPath := "/etc/docker/plugins/test-external-volume-driver-retry.spec"
|
|
|
|
os.RemoveAll(specPath)
|
|
|
|
defer os.RemoveAll(specPath)
|
|
|
|
|
|
|
|
errchan := make(chan error)
|
|
|
|
go func() {
|
|
|
|
if out, err := s.d.Cmd("run", "--rm", "--name", "test-data-retry", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", "test-external-volume-driver-retry", "busybox:latest"); err != nil {
|
|
|
|
errchan <- fmt.Errorf("%v:\n%s", err, out)
|
|
|
|
}
|
|
|
|
close(errchan)
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
// wait for a retry to occur, then create spec to allow plugin to register
|
|
|
|
time.Sleep(2000 * time.Millisecond)
|
2015-10-19 15:53:52 -04:00
|
|
|
// no need to check for an error here since it will get picked up by the timeout later
|
|
|
|
ioutil.WriteFile(specPath, []byte(s.server.URL), 0644)
|
2015-08-28 14:55:05 -04:00
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case err := <-errchan:
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-28 14:55:05 -04:00
|
|
|
case <-time.After(8 * time.Second):
|
|
|
|
c.Fatal("volume creates fail when plugin not immediately available")
|
|
|
|
}
|
|
|
|
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(s.ec.activations, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.creations, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.removals, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.mounts, checker.Equals, 1)
|
|
|
|
c.Assert(s.ec.unmounts, checker.Equals, 1)
|
2015-08-28 14:55:05 -04:00
|
|
|
}
|
2015-09-01 20:13:38 -04:00
|
|
|
|
2015-10-19 15:53:52 -04:00
|
|
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverBindExternalVolume(c *check.C) {
|
2015-09-01 20:13:38 -04:00
|
|
|
dockerCmd(c, "volume", "create", "-d", "test-external-volume-driver", "--name", "foo")
|
|
|
|
dockerCmd(c, "run", "-d", "--name", "testing", "-v", "foo:/bar", "busybox", "top")
|
|
|
|
|
|
|
|
var mounts []struct {
|
|
|
|
Name string
|
|
|
|
Driver string
|
|
|
|
}
|
|
|
|
out, err := inspectFieldJSON("testing", "Mounts")
|
2015-10-15 07:12:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(json.NewDecoder(strings.NewReader(out)).Decode(&mounts), checker.IsNil)
|
|
|
|
c.Assert(len(mounts), checker.Equals, 1, check.Commentf(out))
|
|
|
|
c.Assert(mounts[0].Name, checker.Equals, "foo")
|
|
|
|
c.Assert(mounts[0].Driver, checker.Equals, "test-external-volume-driver")
|
2015-09-01 20:13:38 -04:00
|
|
|
}
|
2015-09-23 16:29:14 -04:00
|
|
|
|
|
|
|
func (s *DockerExternalVolumeSuite) TestStartExternalVolumeDriverList(c *check.C) {
|
|
|
|
dockerCmd(c, "volume", "create", "-d", "test-external-volume-driver", "--name", "abc")
|
|
|
|
out, _ := dockerCmd(c, "volume", "ls")
|
|
|
|
ls := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
c.Assert(len(ls), check.Equals, 2, check.Commentf("\n%s", out))
|
|
|
|
|
|
|
|
vol := strings.Fields(ls[len(ls)-1])
|
|
|
|
c.Assert(len(vol), check.Equals, 2, check.Commentf("%v", vol))
|
|
|
|
c.Assert(vol[0], check.Equals, "test-external-volume-driver")
|
|
|
|
c.Assert(vol[1], check.Equals, "abc")
|
|
|
|
|
|
|
|
c.Assert(s.ec.lists, check.Equals, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerExternalVolumeSuite) TestStartExternalVolumeDriverGet(c *check.C) {
|
|
|
|
out, _, err := dockerCmdWithError("volume", "inspect", "dummy")
|
|
|
|
c.Assert(err, check.NotNil, check.Commentf(out))
|
|
|
|
c.Assert(s.ec.gets, check.Equals, 1)
|
|
|
|
c.Assert(out, checker.Contains, "No such volume")
|
|
|
|
}
|