Merge pull request #1995 from allencloud/validate-overcommitRatio-not-to-be-negative

validate swarm.overcommit and add integration test for cluster options
This commit is contained in:
Victor Vieux 2016-04-06 18:26:19 -07:00
commit 75b3569594
2 changed files with 24 additions and 2 deletions

View File

@ -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
}

View File

@ -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"* ]]
}