daemon_unix_test.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // +build !windows
  2. package main
  3. import (
  4. "testing"
  5. "github.com/docker/docker/daemon"
  6. "github.com/docker/docker/pkg/testutil/assert"
  7. "github.com/docker/docker/pkg/testutil/tempfile"
  8. )
  9. func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
  10. content := `{"log-opts": {"max-size": "1k"}}`
  11. tempFile := tempfile.NewTempFile(t, "config", content)
  12. defer tempFile.Remove()
  13. opts := defaultOptions(tempFile.Name())
  14. opts.common.Debug = true
  15. opts.common.LogLevel = "info"
  16. assert.NilError(t, opts.flags.Set("selinux-enabled", "true"))
  17. loadedConfig, err := loadDaemonCliConfig(opts)
  18. assert.NilError(t, err)
  19. assert.NotNil(t, loadedConfig)
  20. assert.Equal(t, loadedConfig.Debug, true)
  21. assert.Equal(t, loadedConfig.LogLevel, "info")
  22. assert.Equal(t, loadedConfig.EnableSelinuxSupport, true)
  23. assert.Equal(t, loadedConfig.LogConfig.Type, "json-file")
  24. assert.Equal(t, loadedConfig.LogConfig.Config["max-size"], "1k")
  25. }
  26. func TestLoadDaemonConfigWithNetwork(t *testing.T) {
  27. content := `{"bip": "127.0.0.2", "ip": "127.0.0.1"}`
  28. tempFile := tempfile.NewTempFile(t, "config", content)
  29. defer tempFile.Remove()
  30. opts := defaultOptions(tempFile.Name())
  31. loadedConfig, err := loadDaemonCliConfig(opts)
  32. assert.NilError(t, err)
  33. assert.NotNil(t, loadedConfig)
  34. assert.Equal(t, loadedConfig.IP, "127.0.0.2")
  35. assert.Equal(t, loadedConfig.DefaultIP.String(), "127.0.0.1")
  36. }
  37. func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
  38. content := `{
  39. "cluster-store-opts": {"kv.cacertfile": "/var/lib/docker/discovery_certs/ca.pem"},
  40. "log-opts": {"tag": "test"}
  41. }`
  42. tempFile := tempfile.NewTempFile(t, "config", content)
  43. defer tempFile.Remove()
  44. opts := defaultOptions(tempFile.Name())
  45. loadedConfig, err := loadDaemonCliConfig(opts)
  46. assert.NilError(t, err)
  47. assert.NotNil(t, loadedConfig)
  48. assert.NotNil(t, loadedConfig.ClusterOpts)
  49. expectedPath := "/var/lib/docker/discovery_certs/ca.pem"
  50. assert.Equal(t, loadedConfig.ClusterOpts["kv.cacertfile"], expectedPath)
  51. assert.NotNil(t, loadedConfig.LogConfig.Config)
  52. assert.Equal(t, loadedConfig.LogConfig.Config["tag"], "test")
  53. }
  54. func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
  55. content := `{ "userland-proxy": false }`
  56. tempFile := tempfile.NewTempFile(t, "config", content)
  57. defer tempFile.Remove()
  58. opts := defaultOptions(tempFile.Name())
  59. loadedConfig, err := loadDaemonCliConfig(opts)
  60. assert.NilError(t, err)
  61. assert.NotNil(t, loadedConfig)
  62. assert.NotNil(t, loadedConfig.ClusterOpts)
  63. assert.Equal(t, loadedConfig.EnableUserlandProxy, false)
  64. // make sure reloading doesn't generate configuration
  65. // conflicts after normalizing boolean values.
  66. reload := func(reloadedConfig *daemon.Config) {
  67. assert.Equal(t, reloadedConfig.EnableUserlandProxy, false)
  68. }
  69. assert.NilError(t, daemon.ReloadConfiguration(opts.configFile, opts.flags, reload))
  70. }
  71. func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
  72. tempFile := tempfile.NewTempFile(t, "config", `{}`)
  73. defer tempFile.Remove()
  74. opts := defaultOptions(tempFile.Name())
  75. loadedConfig, err := loadDaemonCliConfig(opts)
  76. assert.NilError(t, err)
  77. assert.NotNil(t, loadedConfig)
  78. assert.NotNil(t, loadedConfig.ClusterOpts)
  79. assert.Equal(t, loadedConfig.EnableUserlandProxy, true)
  80. }
  81. func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
  82. content := `{"disable-legacy-registry": true}`
  83. tempFile := tempfile.NewTempFile(t, "config", content)
  84. defer tempFile.Remove()
  85. opts := defaultOptions(tempFile.Name())
  86. loadedConfig, err := loadDaemonCliConfig(opts)
  87. assert.NilError(t, err)
  88. assert.NotNil(t, loadedConfig)
  89. assert.Equal(t, loadedConfig.V2Only, true)
  90. }