1.validate cluster option swarm.overcommit

2.change swarm.createretry's error info and add its integration test
Signed-off-by: Sun Hongliang <allen.sun@daocloud.io>
This commit is contained in:
Sun Hongliang 2016-03-18 23:46:29 +08:00
parent 335b2edda3
commit d403254ed2
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"* ]]
}