Merge pull request #15798 from calavera/volume_driver_host_config

Move VolumeDriver to HostConfig to make containers portable.
Upstream-commit: 9ca4aa479788867cd2dce161efa1e43ea5dfc14f
Component: engine
This commit is contained in:
Brian Goff
2015-09-08 22:05:40 -04:00
22 changed files with 181 additions and 78 deletions
@@ -49,3 +49,65 @@ func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) {
}
}
}
func (s *DockerSuite) TestInspectApiContainerVolumeDriverLegacy(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
cleanedContainerID := strings.TrimSpace(out)
cases := []string{"1.19", "1.20"}
for _, version := range cases {
endpoint := fmt.Sprintf("/v%s/containers/%s/json", version, cleanedContainerID)
status, body, err := sockRequest("GET", endpoint, nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
var inspectJSON map[string]interface{}
if err = json.Unmarshal(body, &inspectJSON); err != nil {
c.Fatalf("unable to unmarshal body for version %s: %v", version, err)
}
config, ok := inspectJSON["Config"]
if !ok {
c.Fatal("Unable to find 'Config'")
}
cfg := config.(map[string]interface{})
if _, ok := cfg["VolumeDriver"]; !ok {
c.Fatalf("Api version %s expected to include VolumeDriver in 'Config'", version)
}
}
}
func (s *DockerSuite) TestInspectApiContainerVolumeDriver(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
cleanedContainerID := strings.TrimSpace(out)
endpoint := fmt.Sprintf("/v1.21/containers/%s/json", cleanedContainerID)
status, body, err := sockRequest("GET", endpoint, nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
var inspectJSON map[string]interface{}
if err = json.Unmarshal(body, &inspectJSON); err != nil {
c.Fatalf("unable to unmarshal body for version 1.21: %v", err)
}
config, ok := inspectJSON["Config"]
if !ok {
c.Fatal("Unable to find 'Config'")
}
cfg := config.(map[string]interface{})
if _, ok := cfg["VolumeDriver"]; ok {
c.Fatal("Api version 1.21 expected to not include VolumeDriver in 'Config'")
}
config, ok = inspectJSON["HostConfig"]
if !ok {
c.Fatal("Unable to find 'HostConfig'")
}
cfg = config.(map[string]interface{})
if _, ok := cfg["VolumeDriver"]; !ok {
c.Fatal("Api version 1.21 expected to include VolumeDriver in 'HostConfig'")
}
}
@@ -253,15 +253,11 @@ func (s *DockerExternalVolumeSuite) TestStartExternalNamedVolumeDriverCheckBindL
img := "test-checkbindlocalvolume"
args := []string{"--host", s.d.sock()}
buildOut, err := buildImageArgs(args, img, dockerfile, true)
fmt.Println(buildOut)
_, err := buildImageWithOutInDamon(s.d.sock(), img, dockerfile, true)
c.Assert(err, check.IsNil)
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")
if err != nil {
fmt.Println(out)
c.Fatal(err)
}
c.Assert(err, check.IsNil)
if !strings.Contains(out, expected) {
c.Fatalf("External volume mount failed. Output: %s\n", out)
@@ -1382,22 +1382,14 @@ func createTmpFile(c *check.C, content string) string {
return filename
}
func buildImageArgs(args []string, name, dockerfile string, useCache bool) (string, error) {
id, _, err := buildImageWithOutArgs(args, name, dockerfile, useCache)
return id, err
}
func buildImageWithOutArgs(args []string, name, dockerfile string, useCache bool) (string, string, error) {
func buildImageWithOutInDamon(socket string, name, dockerfile string, useCache bool) (string, error) {
args := []string{"--host", socket}
buildCmd := buildImageCmdArgs(args, name, dockerfile, useCache)
out, exitCode, err := runCommandWithOutput(buildCmd)
if err != nil || exitCode != 0 {
return "", out, fmt.Errorf("failed to build the image: %s", out)
return out, fmt.Errorf("failed to build the image: %s, error: %v", out, err)
}
id, err := getIDByName(name)
if err != nil {
return "", out, err
}
return id, out, nil
return out, nil
}
func buildImageCmdArgs(args []string, name, dockerfile string, useCache bool) *exec.Cmd {