From b3385caa4e0ca760279fc976bf1fb488bb2ba626 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 14 Jul 2015 14:47:47 -0700 Subject: [PATCH 1/2] add env support in mesos Signed-off-by: Victor Vieux --- cluster/mesos/task.go | 4 ++++ test/integration/api/inspect.bats | 3 ++- test/integration/mesos/api/inspect.bats | 32 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/integration/mesos/api/inspect.bats diff --git a/cluster/mesos/task.go b/cluster/mesos/task.go index 951d322cd5..da14ea46a3 100644 --- a/cluster/mesos/task.go +++ b/cluster/mesos/task.go @@ -104,6 +104,10 @@ func (t *task) build(slaveID string) { t.Container.Docker.Parameters = append(t.Container.Docker.Parameters, &mesosproto.Parameter{Key: proto.String("label"), Value: proto.String(fmt.Sprintf("%s=%s", key, value))}) } + for _, value := range t.config.Env { + t.Container.Docker.Parameters = append(t.Container.Docker.Parameters, &mesosproto.Parameter{Key: proto.String("env"), Value: proto.String(value)}) + } + t.SlaveId = &mesosproto.SlaveID{Value: &slaveID} } diff --git a/test/integration/api/inspect.bats b/test/integration/api/inspect.bats index 2e3d3adbd1..200732dea6 100644 --- a/test/integration/api/inspect.bats +++ b/test/integration/api/inspect.bats @@ -11,7 +11,7 @@ function teardown() { start_docker_with_busybox 2 swarm_manage # run container - docker_swarm run -d --name test_container busybox sleep 500 + docker_swarm run -d -e TEST=true --name test_container busybox sleep 500 # make sure container exsists run docker_swarm ps -l @@ -22,6 +22,7 @@ function teardown() { run docker_swarm inspect test_container [ "$status" -eq 0 ] [[ "${output}" == *"NetworkSettings"* ]] + [[ "${output}" == *"TEST=true"* ]] # the specific information of swarm node [[ "${output}" == *'"Node": {'* ]] [[ "${output}" == *'"Name": "node-'* ]] diff --git a/test/integration/mesos/api/inspect.bats b/test/integration/mesos/api/inspect.bats new file mode 100644 index 0000000000..08b4c60ede --- /dev/null +++ b/test/integration/mesos/api/inspect.bats @@ -0,0 +1,32 @@ +#!/usr/bin/env bats + +load ../mesos_helpers + +function teardown() { + swarm_manage_cleanup + stop_mesos + stop_docker +} + +@test "docker inspect" { + start_docker_with_busybox 2 + start_mesos + swarm_manage_mesos + # run container + docker_swarm run -d -m 20m -e TEST=true --name test_container busybox sleep 500 + + # make sure container exsists + run docker_swarm ps -l + [ "${#lines[@]}" -eq 2 ] + [[ "${lines[1]}" == *"test_container"* ]] + + # inspect and verify + run docker_swarm inspect test_container + [ "$status" -eq 0 ] + [[ "${output}" == *"NetworkSettings"* ]] + [[ "${output}" == *"TEST=true"* ]] + # the specific information of swarm node + [[ "${output}" == *'"Node": {'* ]] + [[ "${output}" == *'"Name": "node-'* ]] +} + From 248370469f8b9b0b691e1d44e1e70d4f2e6d791b Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 14 Jul 2015 15:07:33 -0700 Subject: [PATCH 2/2] add hostname support Signed-off-by: Victor Vieux --- cluster/mesos/task.go | 7 +++++++ test/integration/api/inspect.bats | 4 +++- test/integration/mesos/api/events.bats | 2 +- test/integration/mesos/api/inspect.bats | 6 ++++-- test/integration/test_runner.sh | 2 +- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cluster/mesos/task.go b/cluster/mesos/task.go index da14ea46a3..6f9242138d 100644 --- a/cluster/mesos/task.go +++ b/cluster/mesos/task.go @@ -44,6 +44,13 @@ func (t *task) build(slaveID string) { }, } + if t.config.Hostname != "" { + t.Container.Hostname = proto.String(t.config.Hostname) + if t.config.Domainname != "" { + t.Container.Hostname = proto.String(t.config.Hostname + "." + t.config.Domainname) + } + } + switch t.config.HostConfig.NetworkMode { case "none": t.Container.Docker.Network = mesosproto.ContainerInfo_DockerInfo_NONE.Enum() diff --git a/test/integration/api/inspect.bats b/test/integration/api/inspect.bats index 200732dea6..e8dfbc334e 100644 --- a/test/integration/api/inspect.bats +++ b/test/integration/api/inspect.bats @@ -11,7 +11,7 @@ function teardown() { start_docker_with_busybox 2 swarm_manage # run container - docker_swarm run -d -e TEST=true --name test_container busybox sleep 500 + docker_swarm run -d -e TEST=true -h hostname.test --name test_container busybox sleep 500 # make sure container exsists run docker_swarm ps -l @@ -23,6 +23,8 @@ function teardown() { [ "$status" -eq 0 ] [[ "${output}" == *"NetworkSettings"* ]] [[ "${output}" == *"TEST=true"* ]] + [[ "${output}" == *'"Hostname": "hostname"'* ]] + [[ "${output}" == *'"Domainname": "test"'* ]] # the specific information of swarm node [[ "${output}" == *'"Node": {'* ]] [[ "${output}" == *'"Name": "node-'* ]] diff --git a/test/integration/mesos/api/events.bats b/test/integration/mesos/api/events.bats index 3f2671a426..3e8ad6aa45 100644 --- a/test/integration/mesos/api/events.bats +++ b/test/integration/mesos/api/events.bats @@ -8,7 +8,7 @@ function teardown() { stop_docker } -@test "docker events" { +@test "mesos - docker events" { start_docker_with_busybox 2 start_mesos swarm_manage_mesos diff --git a/test/integration/mesos/api/inspect.bats b/test/integration/mesos/api/inspect.bats index 08b4c60ede..9c72589067 100644 --- a/test/integration/mesos/api/inspect.bats +++ b/test/integration/mesos/api/inspect.bats @@ -8,12 +8,12 @@ function teardown() { stop_docker } -@test "docker inspect" { +@test "mesos - docker inspect" { start_docker_with_busybox 2 start_mesos swarm_manage_mesos # run container - docker_swarm run -d -m 20m -e TEST=true --name test_container busybox sleep 500 + docker_swarm run -d -m 20m -e TEST=true -h hostname.test --name test_container busybox sleep 500 # make sure container exsists run docker_swarm ps -l @@ -25,6 +25,8 @@ function teardown() { [ "$status" -eq 0 ] [[ "${output}" == *"NetworkSettings"* ]] [[ "${output}" == *"TEST=true"* ]] + [[ "${output}" == *'"Hostname": "hostname"'* ]] + [[ "${output}" == *'"Domainname": "test"'* ]] # the specific information of swarm node [[ "${output}" == *'"Node": {'* ]] [[ "${output}" == *'"Name": "node-'* ]] diff --git a/test/integration/test_runner.sh b/test/integration/test_runner.sh index ebae66e481..faedb97a89 100755 --- a/test/integration/test_runner.sh +++ b/test/integration/test_runner.sh @@ -12,7 +12,7 @@ function execute() { } # Tests to run. Defaults to all. -TESTS=${@:-. discovery api mesos} +TESTS=${@:-. discovery api mesos/api} # Generate a temporary binary for the tests. export SWARM_BINARY=`mktemp`