github.com/noxiouz/docker@v0.7.3-0.20160629055221-3d231c78e8c5/integration-cli/docker_deprecated_api_v124_test.go (about) 1 // This file will be removed when we completely drop support for 2 // passing HostConfig to container start API. 3 4 package main 5 6 import ( 7 "net/http" 8 "strings" 9 10 "github.com/docker/docker/pkg/integration/checker" 11 "github.com/go-check/check" 12 ) 13 14 func formatV123StartAPIURL(url string) string { 15 return "/v1.23" + url 16 } 17 18 func (s *DockerSuite) TestDeprecatedContainerApiStartHostConfig(c *check.C) { 19 name := "test-deprecated-api-124" 20 dockerCmd(c, "create", "--name", name, "busybox") 21 config := map[string]interface{}{ 22 "Binds": []string{"/aa:/bb"}, 23 } 24 status, body, err := sockRequest("POST", "/containers/"+name+"/start", config) 25 c.Assert(err, checker.IsNil) 26 c.Assert(status, checker.Equals, http.StatusBadRequest) 27 c.Assert(string(body), checker.Contains, "was deprecated since v1.10") 28 } 29 30 func (s *DockerSuite) TestDeprecatedContainerApiStartVolumeBinds(c *check.C) { 31 // TODO Windows CI: Investigate further why this fails on Windows to Windows CI. 32 testRequires(c, DaemonIsLinux) 33 path := "/foo" 34 if daemonPlatform == "windows" { 35 path = `c:\foo` 36 } 37 name := "testing" 38 config := map[string]interface{}{ 39 "Image": "busybox", 40 "Volumes": map[string]struct{}{path: {}}, 41 } 42 43 status, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config) 44 c.Assert(err, checker.IsNil) 45 c.Assert(status, checker.Equals, http.StatusCreated) 46 47 bindPath := randomTmpDirPath("test", daemonPlatform) 48 config = map[string]interface{}{ 49 "Binds": []string{bindPath + ":" + path}, 50 } 51 status, _, err = sockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config) 52 c.Assert(err, checker.IsNil) 53 c.Assert(status, checker.Equals, http.StatusNoContent) 54 55 pth, err := inspectMountSourceField(name, path) 56 c.Assert(err, checker.IsNil) 57 c.Assert(pth, checker.Equals, bindPath, check.Commentf("expected volume host path to be %s, got %s", bindPath, pth)) 58 } 59 60 // Test for GH#10618 61 func (s *DockerSuite) TestDeprecatedContainerApiStartDupVolumeBinds(c *check.C) { 62 // TODO Windows to Windows CI - Port this 63 testRequires(c, DaemonIsLinux) 64 name := "testdups" 65 config := map[string]interface{}{ 66 "Image": "busybox", 67 "Volumes": map[string]struct{}{"/tmp": {}}, 68 } 69 70 status, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config) 71 c.Assert(err, checker.IsNil) 72 c.Assert(status, checker.Equals, http.StatusCreated) 73 74 bindPath1 := randomTmpDirPath("test1", daemonPlatform) 75 bindPath2 := randomTmpDirPath("test2", daemonPlatform) 76 77 config = map[string]interface{}{ 78 "Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"}, 79 } 80 status, body, err := sockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config) 81 c.Assert(err, checker.IsNil) 82 c.Assert(status, checker.Equals, http.StatusInternalServerError) 83 c.Assert(string(body), checker.Contains, "Duplicate mount point", check.Commentf("Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(body), err)) 84 } 85 86 func (s *DockerSuite) TestDeprecatedContainerApiStartVolumesFrom(c *check.C) { 87 // TODO Windows to Windows CI - Port this 88 testRequires(c, DaemonIsLinux) 89 volName := "voltst" 90 volPath := "/tmp" 91 92 dockerCmd(c, "run", "--name", volName, "-v", volPath, "busybox") 93 94 name := "TestContainerApiStartVolumesFrom" 95 config := map[string]interface{}{ 96 "Image": "busybox", 97 "Volumes": map[string]struct{}{volPath: {}}, 98 } 99 100 status, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config) 101 c.Assert(err, checker.IsNil) 102 c.Assert(status, checker.Equals, http.StatusCreated) 103 104 config = map[string]interface{}{ 105 "VolumesFrom": []string{volName}, 106 } 107 status, _, err = sockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config) 108 c.Assert(err, checker.IsNil) 109 c.Assert(status, checker.Equals, http.StatusNoContent) 110 111 pth, err := inspectMountSourceField(name, volPath) 112 c.Assert(err, checker.IsNil) 113 pth2, err := inspectMountSourceField(volName, volPath) 114 c.Assert(err, checker.IsNil) 115 c.Assert(pth, checker.Equals, pth2, check.Commentf("expected volume host path to be %s, got %s", pth, pth2)) 116 } 117 118 // #9981 - Allow a docker created volume (ie, one in /var/lib/docker/volumes) to be used to overwrite (via passing in Binds on api start) an existing volume 119 func (s *DockerSuite) TestDeprecatedPostContainerBindNormalVolume(c *check.C) { 120 // TODO Windows to Windows CI - Port this 121 testRequires(c, DaemonIsLinux) 122 dockerCmd(c, "create", "-v", "/foo", "--name=one", "busybox") 123 124 fooDir, err := inspectMountSourceField("one", "/foo") 125 c.Assert(err, checker.IsNil) 126 127 dockerCmd(c, "create", "-v", "/foo", "--name=two", "busybox") 128 129 bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}} 130 status, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/two/start"), bindSpec) 131 c.Assert(err, checker.IsNil) 132 c.Assert(status, checker.Equals, http.StatusNoContent) 133 134 fooDir2, err := inspectMountSourceField("two", "/foo") 135 c.Assert(err, checker.IsNil) 136 c.Assert(fooDir2, checker.Equals, fooDir, check.Commentf("expected volume path to be %s, got: %s", fooDir, fooDir2)) 137 } 138 139 func (s *DockerSuite) TestDeprecatedStartWithTooLowMemoryLimit(c *check.C) { 140 // TODO Windows: Port once memory is supported 141 testRequires(c, DaemonIsLinux) 142 out, _ := dockerCmd(c, "create", "busybox") 143 144 containerID := strings.TrimSpace(out) 145 146 config := `{ 147 "CpuShares": 100, 148 "Memory": 524287 149 }` 150 151 res, body, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+containerID+"/start"), strings.NewReader(config), "application/json") 152 c.Assert(err, checker.IsNil) 153 b, err2 := readBody(body) 154 c.Assert(err2, checker.IsNil) 155 c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) 156 c.Assert(string(b), checker.Contains, "Minimum memory limit allowed is 4MB") 157 } 158 159 // #14640 160 func (s *DockerSuite) TestDeprecatedPostContainersStartWithoutLinksInHostConfig(c *check.C) { 161 // TODO Windows: Windows doesn't support supplying a hostconfig on start. 162 // An alternate test could be written to validate the negative testing aspect of this 163 testRequires(c, DaemonIsLinux) 164 name := "test-host-config-links" 165 dockerCmd(c, append([]string{"create", "--name", name, "busybox"}, defaultSleepCommand...)...) 166 167 hc := inspectFieldJSON(c, name, "HostConfig") 168 config := `{"HostConfig":` + hc + `}` 169 170 res, b, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+name+"/start"), strings.NewReader(config), "application/json") 171 c.Assert(err, checker.IsNil) 172 c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent) 173 b.Close() 174 } 175 176 // #14640 177 func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(c *check.C) { 178 // TODO Windows: Windows doesn't support supplying a hostconfig on start. 179 // An alternate test could be written to validate the negative testing aspect of this 180 testRequires(c, DaemonIsLinux) 181 name := "test-host-config-links" 182 dockerCmd(c, "run", "--name", "foo", "-d", "busybox", "top") 183 dockerCmd(c, "create", "--name", name, "--link", "foo:bar", "busybox", "top") 184 185 hc := inspectFieldJSON(c, name, "HostConfig") 186 config := `{"HostConfig":` + hc + `}` 187 188 res, b, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+name+"/start"), strings.NewReader(config), "application/json") 189 c.Assert(err, checker.IsNil) 190 c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent) 191 b.Close() 192 } 193 194 // #14640 195 func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLinked(c *check.C) { 196 // Windows does not support links 197 testRequires(c, DaemonIsLinux) 198 name := "test-host-config-links" 199 out, _ := dockerCmd(c, "run", "--name", "link0", "-d", "busybox", "top") 200 id := strings.TrimSpace(out) 201 dockerCmd(c, "create", "--name", name, "--link", id, "busybox", "top") 202 203 hc := inspectFieldJSON(c, name, "HostConfig") 204 config := `{"HostConfig":` + hc + `}` 205 206 res, b, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+name+"/start"), strings.NewReader(config), "application/json") 207 c.Assert(err, checker.IsNil) 208 c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent) 209 b.Close() 210 } 211 212 func (s *DockerSuite) TestDeprecatedStartWithNilDNS(c *check.C) { 213 // TODO Windows: Add once DNS is supported 214 testRequires(c, DaemonIsLinux) 215 out, _ := dockerCmd(c, "create", "busybox") 216 containerID := strings.TrimSpace(out) 217 218 config := `{"HostConfig": {"Dns": null}}` 219 220 res, b, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+containerID+"/start"), strings.NewReader(config), "application/json") 221 c.Assert(err, checker.IsNil) 222 c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent) 223 b.Close() 224 225 dns := inspectFieldJSON(c, containerID, "HostConfig.Dns") 226 c.Assert(dns, checker.Equals, "[]") 227 }