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