mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix volume driver API compatibility mode (a little)
Signed-off-by: Stephen Rust <srust@blockbridge.com>
This commit is contained in:
parent
2b56501480
commit
c3985bdf79
3 changed files with 46 additions and 17 deletions
|
@ -24,11 +24,18 @@ func init() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type vol struct {
|
||||||
|
Name string
|
||||||
|
Mountpoint string
|
||||||
|
Opts map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
type DockerExternalVolumeSuiteCompatV1_1 struct {
|
type DockerExternalVolumeSuiteCompatV1_1 struct {
|
||||||
server *httptest.Server
|
server *httptest.Server
|
||||||
ds *DockerSuite
|
ds *DockerSuite
|
||||||
d *Daemon
|
d *Daemon
|
||||||
ec *eventCounter
|
ec *eventCounter
|
||||||
|
volList []vol
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerExternalVolumeSuiteCompatV1_1) SetUpTest(c *check.C) {
|
func (s *DockerExternalVolumeSuiteCompatV1_1) SetUpTest(c *check.C) {
|
||||||
|
@ -47,6 +54,7 @@ func (s *DockerExternalVolumeSuiteCompatV1_1) SetUpSuite(c *check.C) {
|
||||||
|
|
||||||
type pluginRequest struct {
|
type pluginRequest struct {
|
||||||
Name string
|
Name string
|
||||||
|
Opts map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type pluginResp struct {
|
type pluginResp struct {
|
||||||
|
@ -54,12 +62,6 @@ func (s *DockerExternalVolumeSuiteCompatV1_1) SetUpSuite(c *check.C) {
|
||||||
Err string `json:",omitempty"`
|
Err string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type vol struct {
|
|
||||||
Name string
|
|
||||||
Mountpoint string
|
|
||||||
}
|
|
||||||
var volList []vol
|
|
||||||
|
|
||||||
read := func(b io.ReadCloser) (pluginRequest, error) {
|
read := func(b io.ReadCloser) (pluginRequest, error) {
|
||||||
defer b.Close()
|
defer b.Close()
|
||||||
var pr pluginRequest
|
var pr pluginRequest
|
||||||
|
@ -94,7 +96,7 @@ func (s *DockerExternalVolumeSuiteCompatV1_1) SetUpSuite(c *check.C) {
|
||||||
send(w, err)
|
send(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
volList = append(volList, vol{Name: pr.Name})
|
s.volList = append(s.volList, vol{Name: pr.Name, Opts: pr.Opts})
|
||||||
send(w, nil)
|
send(w, nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -111,13 +113,13 @@ func (s *DockerExternalVolumeSuiteCompatV1_1) SetUpSuite(c *check.C) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, v := range volList {
|
for i, v := range s.volList {
|
||||||
if v.Name == pr.Name {
|
if v.Name == pr.Name {
|
||||||
if err := os.RemoveAll(hostVolumePath(v.Name)); err != nil {
|
if err := os.RemoveAll(hostVolumePath(v.Name)); err != nil {
|
||||||
send(w, fmt.Sprintf(`{"Err": "%v"}`, err))
|
send(w, fmt.Sprintf(`{"Err": "%v"}`, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
volList = append(volList[:i], volList[i+1:]...)
|
s.volList = append(s.volList[:i], s.volList[i+1:]...)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,3 +215,20 @@ func (s *DockerExternalVolumeSuiteCompatV1_1) TestExternalVolumeDriverCompatV1_1
|
||||||
out, err = s.d.Cmd("volume", "rm", "foo")
|
out, err = s.d.Cmd("volume", "rm", "foo")
|
||||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerExternalVolumeSuiteCompatV1_1) TestExternalVolumeDriverCompatOptionsV1_1(c *check.C) {
|
||||||
|
err := s.d.StartWithBusybox()
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
|
out, err := s.d.Cmd("volume", "create", "--name", "optvol", "--driver", "test-external-volume-driver", "--opt", "opt1=opt1val", "--opt", "opt2=opt2val")
|
||||||
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||||
|
|
||||||
|
out, err = s.d.Cmd("volume", "inspect", "optvol")
|
||||||
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||||
|
|
||||||
|
c.Assert(s.volList[0].Opts["opt1"], checker.Equals, "opt1val")
|
||||||
|
c.Assert(s.volList[0].Opts["opt2"], checker.Equals, "opt2val")
|
||||||
|
|
||||||
|
out, err = s.d.Cmd("volume", "rm", "optvol")
|
||||||
|
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||||
|
}
|
||||||
|
|
|
@ -15,7 +15,20 @@ func (a *volumeDriverAdapter) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *volumeDriverAdapter) Create(name string, opts map[string]string) (volume.Volume, error) {
|
func (a *volumeDriverAdapter) Create(name string, opts map[string]string) (volume.Volume, error) {
|
||||||
err := a.proxy.Create(name, opts)
|
// First try a Get. For drivers that support Get this will return any
|
||||||
|
// existing volume.
|
||||||
|
v, err := a.proxy.Get(name)
|
||||||
|
if v != nil {
|
||||||
|
return &volumeAdapter{
|
||||||
|
proxy: a.proxy,
|
||||||
|
name: v.Name,
|
||||||
|
driverName: a.Name(),
|
||||||
|
eMount: v.Mountpoint,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Driver didn't support Get or volume didn't exist. Perform Create.
|
||||||
|
err = a.proxy.Create(name, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,9 +192,6 @@ func (s *VolumeStore) create(name, driverName string, opts map[string]string) (v
|
||||||
return nil, &OpErr{Op: "create", Name: name, Err: err}
|
return nil, &OpErr{Op: "create", Name: name, Err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, err := vd.Get(name); err == nil {
|
|
||||||
return v, nil
|
|
||||||
}
|
|
||||||
return vd.Create(name, opts)
|
return vd.Create(name, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue