mirror of
https://github.com/clearlinux/docker.git
synced 2026-11-20 04:42:56 +00:00
Merge pull request #13828 from calavera/plugin_fixes
Fix volume plugin serialization.
This commit is contained in:
@@ -61,21 +61,21 @@ func (s *DockerExternalVolumeSuite) SetUpSuite(c *check.C) {
|
|||||||
mux.HandleFunc("/Plugin.Activate", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/Plugin.Activate", func(w http.ResponseWriter, r *http.Request) {
|
||||||
s.ec.activations++
|
s.ec.activations++
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "appplication/vnd.docker.plugins.v1+json")
|
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json")
|
||||||
fmt.Fprintln(w, `{"Implements": ["VolumeDriver"]}`)
|
fmt.Fprintln(w, `{"Implements": ["VolumeDriver"]}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
mux.HandleFunc("/VolumeDriver.Create", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/VolumeDriver.Create", func(w http.ResponseWriter, r *http.Request) {
|
||||||
s.ec.creations++
|
s.ec.creations++
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "appplication/vnd.docker.plugins.v1+json")
|
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json")
|
||||||
fmt.Fprintln(w, `{}`)
|
fmt.Fprintln(w, `{}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
mux.HandleFunc("/VolumeDriver.Remove", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/VolumeDriver.Remove", func(w http.ResponseWriter, r *http.Request) {
|
||||||
s.ec.removals++
|
s.ec.removals++
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "appplication/vnd.docker.plugins.v1+json")
|
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json")
|
||||||
fmt.Fprintln(w, `{}`)
|
fmt.Fprintln(w, `{}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ func (s *DockerExternalVolumeSuite) SetUpSuite(c *check.C) {
|
|||||||
|
|
||||||
p := hostVolumePath(pr.name)
|
p := hostVolumePath(pr.name)
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "appplication/vnd.docker.plugins.v1+json")
|
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json")
|
||||||
fmt.Fprintln(w, fmt.Sprintf("{\"Mountpoint\": \"%s\"}", p))
|
fmt.Fprintln(w, fmt.Sprintf("{\"Mountpoint\": \"%s\"}", p))
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ func (s *DockerExternalVolumeSuite) SetUpSuite(c *check.C) {
|
|||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "appplication/vnd.docker.plugins.v1+json")
|
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json")
|
||||||
fmt.Fprintln(w, fmt.Sprintf("{\"Mountpoint\": \"%s\"}", p))
|
fmt.Fprintln(w, fmt.Sprintf("{\"Mountpoint\": \"%s\"}", p))
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ func (s *DockerExternalVolumeSuite) SetUpSuite(c *check.C) {
|
|||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "appplication/vnd.docker.plugins.v1+json")
|
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json")
|
||||||
fmt.Fprintln(w, `{}`)
|
fmt.Fprintln(w, `{}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ type volumeDriverRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type volumeDriverResponse struct {
|
type volumeDriverResponse struct {
|
||||||
Mountpoint string `json:",ommitempty"`
|
Mountpoint string `json:",omitempty"`
|
||||||
Err error `json:",ommitempty"`
|
Err string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type volumeDriverProxy struct {
|
type volumeDriverProxy struct {
|
||||||
@@ -23,7 +23,7 @@ func (pp *volumeDriverProxy) Create(name string) error {
|
|||||||
var ret volumeDriverResponse
|
var ret volumeDriverResponse
|
||||||
err := pp.c.Call("VolumeDriver.Create", args, &ret)
|
err := pp.c.Call("VolumeDriver.Create", args, &ret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pp.fmtError(name, err)
|
return pp.fmtError(name, err.Error())
|
||||||
}
|
}
|
||||||
return pp.fmtError(name, ret.Err)
|
return pp.fmtError(name, ret.Err)
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ func (pp *volumeDriverProxy) Remove(name string) error {
|
|||||||
var ret volumeDriverResponse
|
var ret volumeDriverResponse
|
||||||
err := pp.c.Call("VolumeDriver.Remove", args, &ret)
|
err := pp.c.Call("VolumeDriver.Remove", args, &ret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pp.fmtError(name, err)
|
return pp.fmtError(name, err.Error())
|
||||||
}
|
}
|
||||||
return pp.fmtError(name, ret.Err)
|
return pp.fmtError(name, ret.Err)
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ func (pp *volumeDriverProxy) Path(name string) (string, error) {
|
|||||||
args := volumeDriverRequest{name}
|
args := volumeDriverRequest{name}
|
||||||
var ret volumeDriverResponse
|
var ret volumeDriverResponse
|
||||||
if err := pp.c.Call("VolumeDriver.Path", args, &ret); err != nil {
|
if err := pp.c.Call("VolumeDriver.Path", args, &ret); err != nil {
|
||||||
return "", pp.fmtError(name, err)
|
return "", pp.fmtError(name, err.Error())
|
||||||
}
|
}
|
||||||
return ret.Mountpoint, pp.fmtError(name, ret.Err)
|
return ret.Mountpoint, pp.fmtError(name, ret.Err)
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ func (pp *volumeDriverProxy) Mount(name string) (string, error) {
|
|||||||
args := volumeDriverRequest{name}
|
args := volumeDriverRequest{name}
|
||||||
var ret volumeDriverResponse
|
var ret volumeDriverResponse
|
||||||
if err := pp.c.Call("VolumeDriver.Mount", args, &ret); err != nil {
|
if err := pp.c.Call("VolumeDriver.Mount", args, &ret); err != nil {
|
||||||
return "", pp.fmtError(name, err)
|
return "", pp.fmtError(name, err.Error())
|
||||||
}
|
}
|
||||||
return ret.Mountpoint, pp.fmtError(name, ret.Err)
|
return ret.Mountpoint, pp.fmtError(name, ret.Err)
|
||||||
}
|
}
|
||||||
@@ -61,13 +61,13 @@ func (pp *volumeDriverProxy) Unmount(name string) error {
|
|||||||
var ret volumeDriverResponse
|
var ret volumeDriverResponse
|
||||||
err := pp.c.Call("VolumeDriver.Unmount", args, &ret)
|
err := pp.c.Call("VolumeDriver.Unmount", args, &ret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pp.fmtError(name, err)
|
return pp.fmtError(name, err.Error())
|
||||||
}
|
}
|
||||||
return pp.fmtError(name, ret.Err)
|
return pp.fmtError(name, ret.Err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pp *volumeDriverProxy) fmtError(name string, err error) error {
|
func (pp *volumeDriverProxy) fmtError(name string, err string) error {
|
||||||
if err == nil {
|
if len(err) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("External volume driver request failed for %s: %v", name, err)
|
return fmt.Errorf("External volume driver request failed for %s: %v", name, err)
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package volumedrivers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/plugins"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestVolumeRequestError(t *testing.T) {
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
server := httptest.NewServer(mux)
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
mux.HandleFunc("/VolumeDriver.Create", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json")
|
||||||
|
fmt.Fprintln(w, `{"Err": "Cannot create volume"}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.HandleFunc("/VolumeDriver.Remove", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json")
|
||||||
|
fmt.Fprintln(w, `{"Err": "Cannot remove volume"}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.HandleFunc("/VolumeDriver.Mount", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json")
|
||||||
|
fmt.Fprintln(w, `{"Err": "Cannot mount volume"}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.HandleFunc("/VolumeDriver.Unmount", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json")
|
||||||
|
fmt.Fprintln(w, `{"Err": "Cannot unmount volume"}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.HandleFunc("/VolumeDriver.Path", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json")
|
||||||
|
fmt.Fprintln(w, `{"Err": "Unknown volume"}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
u, _ := url.Parse(server.URL)
|
||||||
|
client := plugins.NewClient("tcp://" + u.Host)
|
||||||
|
driver := volumeDriverProxy{client}
|
||||||
|
|
||||||
|
err := driver.Create("volume")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Expected error, was nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(err.Error(), "Cannot create volume") {
|
||||||
|
t.Fatalf("Unexpected error: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = driver.Mount("volume")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Expected error, was nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(err.Error(), "Cannot mount volume") {
|
||||||
|
t.Fatalf("Unexpected error: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = driver.Unmount("volume")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Expected error, was nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(err.Error(), "Cannot unmount volume") {
|
||||||
|
t.Fatalf("Unexpected error: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = driver.Remove("volume")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Expected error, was nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(err.Error(), "Cannot remove volume") {
|
||||||
|
t.Fatalf("Unexpected error: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = driver.Path("volume")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Expected error, was nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(err.Error(), "Unknown volume") {
|
||||||
|
t.Fatalf("Unexpected error: %v\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user