Skip to content

Commit

Permalink
Merge pull request docker-archive#1995 from allencloud/validate-overc…
Browse files Browse the repository at this point in the history
…ommitRatio-not-to-be-negative

validate swarm.overcommit and add integration test for cluster options
  • Loading branch information
vieux committed Apr 7, 2016
2 parents 335b2ed + d403254 commit 75b3569
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cluster/swarm/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,19 @@ func NewCluster(scheduler *scheduler.Scheduler, TLSConfig *tls.Config, discovery
}

if val, ok := options.Float("swarm.overcommit", ""); ok {
cluster.overcommitRatio = val
if val <= float64(-1) {
log.Fatalf("swarm.overcommit should be larger than -1, %f is invalid", val)
} else if val < float64(0) {
log.Warn("-1 < swarm.overcommit < 0 will make swarm take less resource than docker engine offers")
cluster.overcommitRatio = val
} else {
cluster.overcommitRatio = val
}
}

if val, ok := options.Int("swarm.createretry", ""); ok {
if val < 0 {
log.Fatalf("swarm.createretry=%d is invalid", val)
log.Fatalf("swarm.createretry can not be negative, %d is invalid", val)
}
cluster.createRetry = val
}
Expand Down
15 changes: 15 additions & 0 deletions test/integration/nodemanagement/cluster_options.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bats

load ../helpers

@test "cluster options" {
# cluster option swarm.overcommit
run swarm manage --cluster-opt swarm.overcommit=-2 nodes://192.168.56.22:4444
[ "$status" -ne 0 ]
[[ "${output}" == *"swarm.overcommit should be larger than -1, -2.000000 is invalid"* ]]

# cluster option swarm.createretry
run swarm manage --cluster-opt swarm.createretry=-1 nodes://192.168.56.22:4444
[ "$status" -ne 0 ]
[[ "${output}" == *"swarm.createretry can not be negative, -1 is invalid"* ]]
}

0 comments on commit 75b3569

Please sign in to comment.