Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
fix tests and keep swarm id
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Vieux <[email protected]>
  • Loading branch information
vieux committed Jan 4, 2016
1 parent 36b4aa5 commit 58f3171
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
9 changes: 6 additions & 3 deletions cluster/swarm/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,12 @@ func (c *Cluster) createContainer(config *cluster.ContainerConfig, name string,
return nil, fmt.Errorf("Conflict: The name %s is already assigned. You have to delete (or rename) that container to be able to assign %s to a container again.", name, name)
}

// Associate a Swarm ID to the container we are creating.
swarmID := c.generateUniqueID()
config.SetSwarmID(swarmID)
swarmID := config.SwarmID()
if swarmID == "" {
// Associate a Swarm ID to the container we are creating.
swarmID = c.generateUniqueID()
config.SetSwarmID(swarmID)
}

configTemp := config
if withSoftImageAffinity {
Expand Down
17 changes: 13 additions & 4 deletions test/integration/rescheduling.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function teardown() {

@test "rescheduling" {
start_docker_with_busybox 2
swarm_manage --engine-refresh-min-interval=1s --engine-refresh-max-interval=1s --engine-refresh-retry=1 ${HOSTS[0]},${HOSTS[1]}
swarm_manage --engine-refresh-min-interval=1s --engine-refresh-max-interval=1s --engine-failure-retry=1 ${HOSTS[0]},${HOSTS[1]}

# c1 on node-0 with reschedule=on-node-failure
run docker_swarm run -dit --name c1 -e constraint:node==~node-0 --label com.docker.swarm.reschedule-policy=on-node-failure busybox sh
Expand All @@ -35,6 +35,9 @@ function teardown() {
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-1"'* ]]

# Get c1 swarm id
swarm_id=$(docker_swarm inspect -f '{{ index .Config.Labels "com.docker.swarm.id" }}' c1)

# Stop node-0
docker_host stop ${DOCKER_CONTAINERS[0]}

Expand All @@ -46,6 +49,13 @@ function teardown() {
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-1"'* ]]

# Check swarm id didn't change for c1
[[ "$swarm_id" == $(docker_swarm inspect -f '{{ index .Config.Labels "com.docker.swarm.id" }}' c1) ]]

run docker_swarm inspect "$swarm_id"
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-1"'* ]]

# c2 should still be on node-0 since the rescheduling policy was off.
run docker_swarm inspect c2
[ "$status" -eq 1 ]
Expand All @@ -58,7 +68,7 @@ function teardown() {

@test "rescheduling with constraints" {
start_docker_with_busybox 2
swarm_manage --engine-refresh-min-interval=1s --engine-refresh-max-interval=1s --engine-refresh-retry=1 ${HOSTS[0]},${HOSTS[1]}
swarm_manage --engine-refresh-min-interval=1s --engine-refresh-max-interval=1s --engine-failure-retry=1 ${HOSTS[0]},${HOSTS[1]}

# c1 on node-0 with reschedule=on-node-failure
run docker_swarm run -dit --name c1 -e constraint:node==~node-0 -e reschedule:on-node-failure busybox sh
Expand Down Expand Up @@ -111,13 +121,12 @@ function teardown() {

run docker_swarm run -dit -e reschedule:on-node-failure --label com.docker.swarm.reschedule-policy=off busybox sh
[ "$status" -eq 1 ]
echo ${output}
[[ "${output}" == *"conflicting reschedule policies"* ]]
}

@test "rescheduling pending" {
start_docker_with_busybox 2
swarm_manage --engine-refresh-min-interval=1s --engine-refresh-max-interval=1s --engine-refresh-retry=1 ${HOSTS[0]},${HOSTS[1]}
swarm_manage --engine-refresh-min-interval=1s --engine-refresh-max-interval=1s --engine-failure-retry=1 ${HOSTS[0]},${HOSTS[1]}

# c1 on node-0 with reschedule=on-node-failure
run docker_swarm run -dit --name c1 -e affinity:container!=c* -e constraint:node==~node-0 -e reschedule:on-node-failure busybox sh
Expand Down

0 comments on commit 58f3171

Please sign in to comment.