2016-06-07 03:45:21 -04:00
|
|
|
// +build !windows,!solaris
|
|
|
|
|
|
|
|
// TODO: Create new file for Solaris which tests config parameters
|
|
|
|
// as described in daemon/config_solaris.go
|
2016-01-25 16:30:33 -05:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/daemon"
|
2016-06-22 18:36:51 -04:00
|
|
|
"github.com/docker/docker/pkg/testutil/assert"
|
|
|
|
"github.com/docker/docker/pkg/testutil/tempfile"
|
2016-06-07 03:45:21 -04:00
|
|
|
"testing"
|
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"}}`
|
|
|
|
tempFile := tempfile.NewTempFile(t, "config", content)
|
|
|
|
defer tempFile.Remove()
|
|
|
|
|
|
|
|
opts := defaultOptions(tempFile.Name())
|
|
|
|
opts.common.Debug = true
|
|
|
|
opts.common.LogLevel = "info"
|
|
|
|
assert.NilError(t, opts.flags.Set("selinux-enabled", "true"))
|
|
|
|
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.NotNil(t, loadedConfig)
|
|
|
|
|
|
|
|
assert.Equal(t, loadedConfig.Debug, true)
|
|
|
|
assert.Equal(t, loadedConfig.LogLevel, "info")
|
|
|
|
assert.Equal(t, loadedConfig.EnableSelinuxSupport, true)
|
|
|
|
assert.Equal(t, loadedConfig.LogConfig.Type, "json-file")
|
|
|
|
assert.Equal(t, loadedConfig.LogConfig.Config["max-size"], "1k")
|
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"}`
|
|
|
|
tempFile := tempfile.NewTempFile(t, "config", content)
|
|
|
|
defer tempFile.Remove()
|
2016-01-25 16:30:33 -05:00
|
|
|
|
2016-06-22 18:36:51 -04:00
|
|
|
opts := defaultOptions(tempFile.Name())
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.NotNil(t, loadedConfig)
|
2016-01-25 16:30:33 -05:00
|
|
|
|
2016-06-22 18:36:51 -04:00
|
|
|
assert.Equal(t, loadedConfig.IP, "127.0.0.2")
|
|
|
|
assert.Equal(t, loadedConfig.DefaultIP.String(), "127.0.0.1")
|
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
|
|
|
}`
|
|
|
|
tempFile := tempfile.NewTempFile(t, "config", content)
|
|
|
|
defer tempFile.Remove()
|
2016-02-29 20:50:16 -05:00
|
|
|
|
2016-06-22 18:36:51 -04:00
|
|
|
opts := defaultOptions(tempFile.Name())
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.NotNil(t, loadedConfig)
|
|
|
|
assert.NotNil(t, loadedConfig.ClusterOpts)
|
2016-02-29 20:50:16 -05:00
|
|
|
|
|
|
|
expectedPath := "/var/lib/docker/discovery_certs/ca.pem"
|
2016-06-22 18:36:51 -04:00
|
|
|
assert.Equal(t, loadedConfig.ClusterOpts["kv.cacertfile"], expectedPath)
|
|
|
|
assert.NotNil(t, loadedConfig.LogConfig.Config)
|
|
|
|
assert.Equal(t, loadedConfig.LogConfig.Config["tag"], "test")
|
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 }`
|
|
|
|
tempFile := tempfile.NewTempFile(t, "config", content)
|
|
|
|
defer tempFile.Remove()
|
2016-02-29 20:50:16 -05:00
|
|
|
|
2016-06-22 18:36:51 -04:00
|
|
|
opts := defaultOptions(tempFile.Name())
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.NotNil(t, loadedConfig)
|
|
|
|
assert.NotNil(t, loadedConfig.ClusterOpts)
|
2016-02-29 20:50:16 -05:00
|
|
|
|
2016-06-22 18:36:51 -04:00
|
|
|
assert.Equal(t, loadedConfig.EnableUserlandProxy, false)
|
2016-02-29 20:50:16 -05:00
|
|
|
|
|
|
|
// make sure reloading doesn't generate configuration
|
|
|
|
// conflicts after normalizing boolean values.
|
2016-06-22 18:36:51 -04:00
|
|
|
reload := func(reloadedConfig *daemon.Config) {
|
|
|
|
assert.Equal(t, reloadedConfig.EnableUserlandProxy, false)
|
2016-02-29 20:50:16 -05:00
|
|
|
}
|
2016-06-22 18:36:51 -04:00
|
|
|
assert.NilError(t, daemon.ReloadConfiguration(opts.configFile, opts.flags, reload))
|
2016-02-29 20:50:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
|
2016-06-22 18:36:51 -04:00
|
|
|
tempFile := tempfile.NewTempFile(t, "config", `{}`)
|
|
|
|
defer tempFile.Remove()
|
2016-02-29 20:50:16 -05:00
|
|
|
|
2016-06-22 18:36:51 -04:00
|
|
|
opts := defaultOptions(tempFile.Name())
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.NotNil(t, loadedConfig)
|
|
|
|
assert.NotNil(t, loadedConfig.ClusterOpts)
|
2016-02-29 20:50:16 -05:00
|
|
|
|
2016-06-22 18:36:51 -04:00
|
|
|
assert.Equal(t, loadedConfig.EnableUserlandProxy, true)
|
2016-02-29 20:50:16 -05:00
|
|
|
}
|
2016-07-18 17:48:26 -04:00
|
|
|
|
|
|
|
func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
|
2016-06-23 11:25:51 -04:00
|
|
|
content := `{"disable-legacy-registry": true}`
|
|
|
|
tempFile := tempfile.NewTempFile(t, "config", content)
|
|
|
|
defer tempFile.Remove()
|
2016-07-18 17:48:26 -04:00
|
|
|
|
2016-06-23 11:25:51 -04:00
|
|
|
opts := defaultOptions(tempFile.Name())
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.NotNil(t, loadedConfig)
|
|
|
|
assert.Equal(t, loadedConfig.V2Only, true)
|
2016-07-18 17:48:26 -04:00
|
|
|
}
|