2016-05-07 06:05:26 -04:00
// This file will be removed when we completely drop support for
// passing HostConfig to container start API.
package main
import (
"net/http"
"strings"
2016-12-30 12:23:00 -05:00
"github.com/docker/docker/integration-cli/checker"
2016-12-30 04:49:36 -05:00
"github.com/docker/docker/integration-cli/request"
2016-05-07 06:05:26 -04:00
"github.com/go-check/check"
)
func formatV123StartAPIURL ( url string ) string {
return "/v1.23" + url
}
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
func ( s * DockerSuite ) TestDeprecatedContainerAPIStartHostConfig ( c * check . C ) {
2016-05-07 06:05:26 -04:00
name := "test-deprecated-api-124"
dockerCmd ( c , "create" , "--name" , name , "busybox" )
config := map [ string ] interface { } {
"Binds" : [ ] string { "/aa:/bb" } ,
}
2017-05-23 23:56:26 -04:00
res , body , err := request . Post ( "/containers/" + name + "/start" , request . JSONBody ( config ) )
2016-05-07 06:05:26 -04:00
c . Assert ( err , checker . IsNil )
2017-05-23 23:56:26 -04:00
buf , err := request . ReadBody ( body )
c . Assert ( err , checker . IsNil )
c . Assert ( res . StatusCode , checker . Equals , http . StatusBadRequest )
c . Assert ( string ( buf ) , checker . Contains , "was deprecated since API v1.22" )
2016-05-07 06:05:26 -04:00
}
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
func ( s * DockerSuite ) TestDeprecatedContainerAPIStartVolumeBinds ( c * check . C ) {
2016-05-07 06:05:26 -04:00
// TODO Windows CI: Investigate further why this fails on Windows to Windows CI.
testRequires ( c , DaemonIsLinux )
path := "/foo"
2017-01-13 11:23:28 -05:00
if testEnv . DaemonPlatform ( ) == "windows" {
2016-05-07 06:05:26 -04:00
path = ` c:\foo `
}
name := "testing"
config := map [ string ] interface { } {
"Image" : "busybox" ,
"Volumes" : map [ string ] struct { } { path : { } } ,
}
2017-05-23 23:56:26 -04:00
res , _ , err := request . Post ( formatV123StartAPIURL ( "/containers/create?name=" + name ) , request . JSONBody ( config ) )
2016-05-07 06:05:26 -04:00
c . Assert ( err , checker . IsNil )
2017-05-23 23:56:26 -04:00
c . Assert ( res . StatusCode , checker . Equals , http . StatusCreated )
2016-05-07 06:05:26 -04:00
2017-08-22 16:08:42 -04:00
bindPath := RandomTmpDirPath ( "test" , testEnv . DaemonPlatform ( ) )
2016-05-07 06:05:26 -04:00
config = map [ string ] interface { } {
"Binds" : [ ] string { bindPath + ":" + path } ,
}
2017-05-23 23:56:26 -04:00
res , _ , err = request . Post ( formatV123StartAPIURL ( "/containers/" + name + "/start" ) , request . JSONBody ( config ) )
2016-05-07 06:05:26 -04:00
c . Assert ( err , checker . IsNil )
2017-05-23 23:56:26 -04:00
c . Assert ( res . StatusCode , checker . Equals , http . StatusNoContent )
2016-05-07 06:05:26 -04:00
pth , err := inspectMountSourceField ( name , path )
c . Assert ( err , checker . IsNil )
c . Assert ( pth , checker . Equals , bindPath , check . Commentf ( "expected volume host path to be %s, got %s" , bindPath , pth ) )
}
// Test for GH#10618
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
func ( s * DockerSuite ) TestDeprecatedContainerAPIStartDupVolumeBinds ( c * check . C ) {
2016-05-07 06:05:26 -04:00
// TODO Windows to Windows CI - Port this
testRequires ( c , DaemonIsLinux )
name := "testdups"
config := map [ string ] interface { } {
"Image" : "busybox" ,
"Volumes" : map [ string ] struct { } { "/tmp" : { } } ,
}
2017-05-23 23:56:26 -04:00
res , _ , err := request . Post ( formatV123StartAPIURL ( "/containers/create?name=" + name ) , request . JSONBody ( config ) )
2016-05-07 06:05:26 -04:00
c . Assert ( err , checker . IsNil )
2017-05-23 23:56:26 -04:00
c . Assert ( res . StatusCode , checker . Equals , http . StatusCreated )
2016-05-07 06:05:26 -04:00
2017-08-22 16:08:42 -04:00
bindPath1 := RandomTmpDirPath ( "test1" , testEnv . DaemonPlatform ( ) )
bindPath2 := RandomTmpDirPath ( "test2" , testEnv . DaemonPlatform ( ) )
2016-05-07 06:05:26 -04:00
config = map [ string ] interface { } {
"Binds" : [ ] string { bindPath1 + ":/tmp" , bindPath2 + ":/tmp" } ,
}
2017-05-23 23:56:26 -04:00
res , body , err := request . Post ( formatV123StartAPIURL ( "/containers/" + name + "/start" ) , request . JSONBody ( config ) )
2016-05-07 06:05:26 -04:00
c . Assert ( err , checker . IsNil )
2017-05-23 23:56:26 -04:00
buf , err := request . ReadBody ( body )
c . Assert ( err , checker . IsNil )
c . Assert ( res . StatusCode , checker . Equals , http . StatusBadRequest )
c . Assert ( string ( buf ) , checker . Contains , "Duplicate mount point" , check . Commentf ( "Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v" , string ( buf ) , err ) )
2016-05-07 06:05:26 -04:00
}
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
func ( s * DockerSuite ) TestDeprecatedContainerAPIStartVolumesFrom ( c * check . C ) {
2016-05-07 06:05:26 -04:00
// TODO Windows to Windows CI - Port this
testRequires ( c , DaemonIsLinux )
volName := "voltst"
volPath := "/tmp"
dockerCmd ( c , "run" , "--name" , volName , "-v" , volPath , "busybox" )
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
name := "TestContainerAPIStartVolumesFrom"
2016-05-07 06:05:26 -04:00
config := map [ string ] interface { } {
"Image" : "busybox" ,
"Volumes" : map [ string ] struct { } { volPath : { } } ,
}
2017-05-23 23:56:26 -04:00
res , _ , err := request . Post ( formatV123StartAPIURL ( "/containers/create?name=" + name ) , request . JSONBody ( config ) )
2016-05-07 06:05:26 -04:00
c . Assert ( err , checker . IsNil )
2017-05-23 23:56:26 -04:00
c . Assert ( res . StatusCode , checker . Equals , http . StatusCreated )
2016-05-07 06:05:26 -04:00
config = map [ string ] interface { } {
"VolumesFrom" : [ ] string { volName } ,
}
2017-05-23 23:56:26 -04:00
res , _ , err = request . Post ( formatV123StartAPIURL ( "/containers/" + name + "/start" ) , request . JSONBody ( config ) )
2016-05-07 06:05:26 -04:00
c . Assert ( err , checker . IsNil )
2017-05-23 23:56:26 -04:00
c . Assert ( res . StatusCode , checker . Equals , http . StatusNoContent )
2016-05-07 06:05:26 -04:00
pth , err := inspectMountSourceField ( name , volPath )
c . Assert ( err , checker . IsNil )
pth2 , err := inspectMountSourceField ( volName , volPath )
c . Assert ( err , checker . IsNil )
c . Assert ( pth , checker . Equals , pth2 , check . Commentf ( "expected volume host path to be %s, got %s" , pth , pth2 ) )
}
// #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
func ( s * DockerSuite ) TestDeprecatedPostContainerBindNormalVolume ( c * check . C ) {
// TODO Windows to Windows CI - Port this
testRequires ( c , DaemonIsLinux )
dockerCmd ( c , "create" , "-v" , "/foo" , "--name=one" , "busybox" )
fooDir , err := inspectMountSourceField ( "one" , "/foo" )
c . Assert ( err , checker . IsNil )
dockerCmd ( c , "create" , "-v" , "/foo" , "--name=two" , "busybox" )
bindSpec := map [ string ] [ ] string { "Binds" : { fooDir + ":/foo" } }
2017-05-23 23:56:26 -04:00
res , _ , err := request . Post ( formatV123StartAPIURL ( "/containers/two/start" ) , request . JSONBody ( bindSpec ) )
2016-05-07 06:05:26 -04:00
c . Assert ( err , checker . IsNil )
2017-05-23 23:56:26 -04:00
c . Assert ( res . StatusCode , checker . Equals , http . StatusNoContent )
2016-05-07 06:05:26 -04:00
fooDir2 , err := inspectMountSourceField ( "two" , "/foo" )
c . Assert ( err , checker . IsNil )
c . Assert ( fooDir2 , checker . Equals , fooDir , check . Commentf ( "expected volume path to be %s, got: %s" , fooDir , fooDir2 ) )
}
func ( s * DockerSuite ) TestDeprecatedStartWithTooLowMemoryLimit ( c * check . C ) {
// TODO Windows: Port once memory is supported
testRequires ( c , DaemonIsLinux )
out , _ := dockerCmd ( c , "create" , "busybox" )
containerID := strings . TrimSpace ( out )
config := ` {
"CpuShares" : 100 ,
"Memory" : 524287
} `
2017-03-06 10:35:27 -05:00
res , body , err := request . Post ( formatV123StartAPIURL ( "/containers/" + containerID + "/start" ) , request . RawString ( config ) , request . JSON )
2016-05-07 06:05:26 -04:00
c . Assert ( err , checker . IsNil )
2017-08-21 18:50:40 -04:00
b , err2 := request . ReadBody ( body )
2016-05-07 06:05:26 -04:00
c . Assert ( err2 , checker . IsNil )
2017-07-19 10:20:13 -04:00
c . Assert ( res . StatusCode , checker . Equals , http . StatusBadRequest )
2016-05-07 06:05:26 -04:00
c . Assert ( string ( b ) , checker . Contains , "Minimum memory limit allowed is 4MB" )
}
// #14640
func ( s * DockerSuite ) TestDeprecatedPostContainersStartWithoutLinksInHostConfig ( c * check . C ) {
// TODO Windows: Windows doesn't support supplying a hostconfig on start.
// An alternate test could be written to validate the negative testing aspect of this
testRequires ( c , DaemonIsLinux )
name := "test-host-config-links"
2016-08-17 18:46:28 -04:00
dockerCmd ( c , append ( [ ] string { "create" , "--name" , name , "busybox" } , sleepCommandForDaemonPlatform ( ) ... ) ... )
2016-05-07 06:05:26 -04:00
hc := inspectFieldJSON ( c , name , "HostConfig" )
config := ` { "HostConfig": ` + hc + ` } `
2017-03-06 10:35:27 -05:00
res , b , err := request . Post ( formatV123StartAPIURL ( "/containers/" + name + "/start" ) , request . RawString ( config ) , request . JSON )
2016-05-07 06:05:26 -04:00
c . Assert ( err , checker . IsNil )
c . Assert ( res . StatusCode , checker . Equals , http . StatusNoContent )
b . Close ( )
}
// #14640
func ( s * DockerSuite ) TestDeprecatedPostContainersStartWithLinksInHostConfig ( c * check . C ) {
// TODO Windows: Windows doesn't support supplying a hostconfig on start.
// An alternate test could be written to validate the negative testing aspect of this
testRequires ( c , DaemonIsLinux )
name := "test-host-config-links"
dockerCmd ( c , "run" , "--name" , "foo" , "-d" , "busybox" , "top" )
dockerCmd ( c , "create" , "--name" , name , "--link" , "foo:bar" , "busybox" , "top" )
hc := inspectFieldJSON ( c , name , "HostConfig" )
config := ` { "HostConfig": ` + hc + ` } `
2017-03-06 10:35:27 -05:00
res , b , err := request . Post ( formatV123StartAPIURL ( "/containers/" + name + "/start" ) , request . RawString ( config ) , request . JSON )
2016-05-07 06:05:26 -04:00
c . Assert ( err , checker . IsNil )
c . Assert ( res . StatusCode , checker . Equals , http . StatusNoContent )
b . Close ( )
}
// #14640
func ( s * DockerSuite ) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLinked ( c * check . C ) {
// Windows does not support links
testRequires ( c , DaemonIsLinux )
name := "test-host-config-links"
out , _ := dockerCmd ( c , "run" , "--name" , "link0" , "-d" , "busybox" , "top" )
2017-09-22 09:52:41 -04:00
defer dockerCmd ( c , "stop" , "link0" )
2016-05-07 06:05:26 -04:00
id := strings . TrimSpace ( out )
dockerCmd ( c , "create" , "--name" , name , "--link" , id , "busybox" , "top" )
2017-09-22 09:52:41 -04:00
defer dockerCmd ( c , "stop" , name )
2016-05-07 06:05:26 -04:00
hc := inspectFieldJSON ( c , name , "HostConfig" )
config := ` { "HostConfig": ` + hc + ` } `
2017-03-06 10:35:27 -05:00
res , b , err := request . Post ( formatV123StartAPIURL ( "/containers/" + name + "/start" ) , request . RawString ( config ) , request . JSON )
2016-05-07 06:05:26 -04:00
c . Assert ( err , checker . IsNil )
c . Assert ( res . StatusCode , checker . Equals , http . StatusNoContent )
b . Close ( )
}
func ( s * DockerSuite ) TestDeprecatedStartWithNilDNS ( c * check . C ) {
// TODO Windows: Add once DNS is supported
testRequires ( c , DaemonIsLinux )
out , _ := dockerCmd ( c , "create" , "busybox" )
containerID := strings . TrimSpace ( out )
config := ` { "HostConfig": { "Dns": null}} `
2017-03-06 10:35:27 -05:00
res , b , err := request . Post ( formatV123StartAPIURL ( "/containers/" + containerID + "/start" ) , request . RawString ( config ) , request . JSON )
2016-05-07 06:05:26 -04:00
c . Assert ( err , checker . IsNil )
c . Assert ( res . StatusCode , checker . Equals , http . StatusNoContent )
b . Close ( )
dns := inspectFieldJSON ( c , containerID , "HostConfig.Dns" )
c . Assert ( dns , checker . Equals , "[]" )
}