mirror of https://github.com/docker/docs.git
add a reschedule test with compose
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
c363c31608
commit
d97c06207d
|
@ -47,3 +47,54 @@ function teardown() {
|
||||||
# check memory-swappiness
|
# check memory-swappiness
|
||||||
[[ "${output}" == *"->80/tcp"* ]]
|
[[ "${output}" == *"->80/tcp"* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function containerRunning() {
|
||||||
|
local container="$1"
|
||||||
|
local node="$2"
|
||||||
|
run docker_swarm inspect "$container"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "${output}" == *"\"Name\": \"$node\""* ]]
|
||||||
|
[[ "${output}" == *"\"Status\": \"running\""* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "docker-compose up - reschedule" {
|
||||||
|
start_docker_with_busybox 2
|
||||||
|
swarm_manage --engine-refresh-min-interval=1s --engine-refresh-max-interval=1s --engine-failure-retry=1 ${HOSTS[0]},${HOSTS[1]}
|
||||||
|
FILE=$TESTDATA/compose/reschedule.yml
|
||||||
|
|
||||||
|
docker-compose_swarm -f $FILE up -d
|
||||||
|
|
||||||
|
run docker_swarm ps -q
|
||||||
|
[ "${#lines[@]}" -eq 2 ]
|
||||||
|
|
||||||
|
# Make sure containers are running where they should.
|
||||||
|
containerRunning "compose_service1_1" "node-0"
|
||||||
|
containerRunning "compose_service2_1" "node-0"
|
||||||
|
|
||||||
|
# Get service1 swarm id
|
||||||
|
swarm_id=$(docker_swarm inspect -f '{{ index .Config.Labels "com.docker.swarm.id" }}' compose_service1_1)
|
||||||
|
|
||||||
|
# Stop node-0
|
||||||
|
docker_host kill ${DOCKER_CONTAINERS[0]}
|
||||||
|
|
||||||
|
# Wait for Swarm to detect the node failure.
|
||||||
|
retry 5 1 eval "docker_swarm info | grep -q 'Unhealthy'"
|
||||||
|
|
||||||
|
# Wait for the container to be rescheduled
|
||||||
|
# service1 should have been rescheduled from node-0 to node-1
|
||||||
|
retry 5 1 containerRunning "compose_service1_1" "node-1"
|
||||||
|
|
||||||
|
# Check swarm id didn't change for service1
|
||||||
|
[[ "$swarm_id" == $(docker_swarm inspect -f '{{ index .Config.Labels "com.docker.swarm.id" }}' compose_service1_1) ]]
|
||||||
|
|
||||||
|
run docker_swarm inspect "$swarm_id"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "${output}" == *'"Name": "node-1"'* ]]
|
||||||
|
|
||||||
|
# service_2 should still be on node-0 since the rescheduling policy was off.
|
||||||
|
run docker_swarm inspect compose_service2_1
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
|
||||||
|
run docker_swarm ps -q
|
||||||
|
[ "${#lines[@]}" -eq 1 ]
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
service1:
|
||||||
|
image: busybox
|
||||||
|
ports:
|
||||||
|
- "80"
|
||||||
|
command: sleep 100
|
||||||
|
labels:
|
||||||
|
com.docker.swarm.constraints: '["node==~node-0"]'
|
||||||
|
com.docker.swarm.reschedule-policies: '["on-node-failure"]'
|
||||||
|
|
||||||
|
service2:
|
||||||
|
image: busybox
|
||||||
|
command: sleep 100
|
||||||
|
labels:
|
||||||
|
com.docker.swarm.constraints: '["node==~node-0"]'
|
Loading…
Reference in New Issue