2017-11-01 23:37:53 +00:00
|
|
|
// +build !windows
|
2016-01-25 21:30:33 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-01-23 11:23:07 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/daemon/config"
|
2018-06-11 13:32:11 +00:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
|
|
|
"gotest.tools/fs"
|
2016-01-25 21:30:33 +00:00
|
|
|
)
|
|
|
|
|
2016-03-12 03:31:08 +00:00
|
|
|
func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
|
2016-06-22 22:36:51 +00:00
|
|
|
content := `{"log-opts": {"max-size": "1k"}}`
|
2017-08-23 21:25:00 +00:00
|
|
|
tempFile := fs.NewFile(t, "config", fs.WithContent(content))
|
2016-06-22 22:36:51 +00:00
|
|
|
defer tempFile.Remove()
|
|
|
|
|
2018-10-15 07:52:53 +00:00
|
|
|
opts := defaultOptions(t, tempFile.Path())
|
2017-06-01 20:34:31 +00:00
|
|
|
opts.Debug = true
|
|
|
|
opts.LogLevel = "info"
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Check(t, opts.flags.Set("selinux-enabled", "true"))
|
2016-06-22 22:36:51 +00:00
|
|
|
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, loadedConfig != nil)
|
|
|
|
|
|
|
|
assert.Check(t, loadedConfig.Debug)
|
|
|
|
assert.Check(t, is.Equal("info", loadedConfig.LogLevel))
|
|
|
|
assert.Check(t, loadedConfig.EnableSelinuxSupport)
|
|
|
|
assert.Check(t, is.Equal("json-file", loadedConfig.LogConfig.Type))
|
|
|
|
assert.Check(t, is.Equal("1k", loadedConfig.LogConfig.Config["max-size"]))
|
2016-03-12 03:31:08 +00:00
|
|
|
}
|
|
|
|
|
2016-01-25 21:30:33 +00:00
|
|
|
func TestLoadDaemonConfigWithNetwork(t *testing.T) {
|
2016-06-22 22:36:51 +00:00
|
|
|
content := `{"bip": "127.0.0.2", "ip": "127.0.0.1"}`
|
2017-08-23 21:25:00 +00:00
|
|
|
tempFile := fs.NewFile(t, "config", fs.WithContent(content))
|
2016-06-22 22:36:51 +00:00
|
|
|
defer tempFile.Remove()
|
2016-01-25 21:30:33 +00:00
|
|
|
|
2018-10-15 07:52:53 +00:00
|
|
|
opts := defaultOptions(t, tempFile.Path())
|
2016-06-22 22:36:51 +00:00
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, loadedConfig != nil)
|
2016-01-25 21:30:33 +00:00
|
|
|
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Check(t, is.Equal("127.0.0.2", loadedConfig.IP))
|
|
|
|
assert.Check(t, is.Equal("127.0.0.1", loadedConfig.DefaultIP.String()))
|
2016-01-25 21:30:33 +00:00
|
|
|
}
|
2016-03-01 01:50:16 +00:00
|
|
|
|
|
|
|
func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
|
2016-06-22 22:36:51 +00:00
|
|
|
content := `{
|
2016-03-01 01:50:16 +00:00
|
|
|
"cluster-store-opts": {"kv.cacertfile": "/var/lib/docker/discovery_certs/ca.pem"},
|
|
|
|
"log-opts": {"tag": "test"}
|
2016-06-22 22:36:51 +00:00
|
|
|
}`
|
2017-08-23 21:25:00 +00:00
|
|
|
tempFile := fs.NewFile(t, "config", fs.WithContent(content))
|
2016-06-22 22:36:51 +00:00
|
|
|
defer tempFile.Remove()
|
2016-03-01 01:50:16 +00:00
|
|
|
|
2018-10-15 07:52:53 +00:00
|
|
|
opts := defaultOptions(t, tempFile.Path())
|
2016-06-22 22:36:51 +00:00
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, loadedConfig != nil)
|
|
|
|
assert.Check(t, loadedConfig.ClusterOpts != nil)
|
2016-03-01 01:50:16 +00:00
|
|
|
|
|
|
|
expectedPath := "/var/lib/docker/discovery_certs/ca.pem"
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Check(t, is.Equal(expectedPath, loadedConfig.ClusterOpts["kv.cacertfile"]))
|
|
|
|
assert.Check(t, loadedConfig.LogConfig.Config != nil)
|
|
|
|
assert.Check(t, is.Equal("test", loadedConfig.LogConfig.Config["tag"]))
|
2016-03-01 01:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
|
2016-06-22 22:36:51 +00:00
|
|
|
content := `{ "userland-proxy": false }`
|
2017-08-23 21:25:00 +00:00
|
|
|
tempFile := fs.NewFile(t, "config", fs.WithContent(content))
|
2016-06-22 22:36:51 +00:00
|
|
|
defer tempFile.Remove()
|
2016-03-01 01:50:16 +00:00
|
|
|
|
2018-10-15 07:52:53 +00:00
|
|
|
opts := defaultOptions(t, tempFile.Path())
|
2016-06-22 22:36:51 +00:00
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, loadedConfig != nil)
|
2016-03-01 01:50:16 +00:00
|
|
|
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Check(t, !loadedConfig.EnableUserlandProxy)
|
2016-03-01 01:50:16 +00:00
|
|
|
|
|
|
|
// make sure reloading doesn't generate configuration
|
|
|
|
// conflicts after normalizing boolean values.
|
2017-01-23 11:23:07 +00:00
|
|
|
reload := func(reloadedConfig *config.Config) {
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Check(t, !reloadedConfig.EnableUserlandProxy)
|
2016-03-01 01:50:16 +00:00
|
|
|
}
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Check(t, config.Reload(opts.configFile, opts.flags, reload))
|
2016-03-01 01:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
|
2017-08-23 21:25:00 +00:00
|
|
|
tempFile := fs.NewFile(t, "config", fs.WithContent(`{}`))
|
2016-06-22 22:36:51 +00:00
|
|
|
defer tempFile.Remove()
|
2016-03-01 01:50:16 +00:00
|
|
|
|
2018-10-15 07:52:53 +00:00
|
|
|
opts := defaultOptions(t, tempFile.Path())
|
2016-06-22 22:36:51 +00:00
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, loadedConfig != nil)
|
2016-03-01 01:50:16 +00:00
|
|
|
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.Check(t, loadedConfig.EnableUserlandProxy)
|
2016-03-01 01:50:16 +00:00
|
|
|
}
|