Browse code

fix config load error with ulimits Signed-off-by: allencloud <allen.sun@daocloud.io>

allencloud authored on 2016/08/10 19:52:06
Showing 4 changed files
... ...
@@ -45,6 +45,7 @@ var flatOptions = map[string]bool{
45 45
 	"cluster-store-opts": true,
46 46
 	"log-opts":           true,
47 47
 	"runtimes":           true,
48
+	"default-ulimits":    true,
48 49
 }
49 50
 
50 51
 // LogConfig represents the default log configuration.
... ...
@@ -11,41 +11,6 @@ import (
11 11
 	"github.com/spf13/pflag"
12 12
 )
13 13
 
14
-func TestDaemonConfigurationMerge(t *testing.T) {
15
-	f, err := ioutil.TempFile("", "docker-config-")
16
-	if err != nil {
17
-		t.Fatal(err)
18
-	}
19
-
20
-	configFile := f.Name()
21
-	f.Write([]byte(`{"debug": true}`))
22
-	f.Close()
23
-
24
-	c := &Config{
25
-		CommonConfig: CommonConfig{
26
-			AutoRestart: true,
27
-			LogConfig: LogConfig{
28
-				Type:   "syslog",
29
-				Config: map[string]string{"tag": "test"},
30
-			},
31
-		},
32
-	}
33
-
34
-	cc, err := MergeDaemonConfigurations(c, nil, configFile)
35
-	if err != nil {
36
-		t.Fatal(err)
37
-	}
38
-	if !cc.Debug {
39
-		t.Fatalf("expected %v, got %v\n", true, cc.Debug)
40
-	}
41
-	if !cc.AutoRestart {
42
-		t.Fatalf("expected %v, got %v\n", true, cc.AutoRestart)
43
-	}
44
-	if cc.LogConfig.Type != "syslog" {
45
-		t.Fatalf("expected syslog config, got %q\n", cc.LogConfig)
46
-	}
47
-}
48
-
49 14
 func TestDaemonConfigurationNotFound(t *testing.T) {
50 15
 	_, err := MergeDaemonConfigurations(&Config{}, nil, "/tmp/foo-bar-baz-docker")
51 16
 	if err == nil || !os.IsNotExist(err) {
52 17
new file mode 100644
... ...
@@ -0,0 +1,80 @@
0
+// +build !windows
1
+
2
+package daemon
3
+
4
+import (
5
+	"io/ioutil"
6
+	"testing"
7
+)
8
+
9
+func TestDaemonConfigurationMerge(t *testing.T) {
10
+	f, err := ioutil.TempFile("", "docker-config-")
11
+	if err != nil {
12
+		t.Fatal(err)
13
+	}
14
+
15
+	configFile := f.Name()
16
+
17
+	f.Write([]byte(`
18
+		{
19
+			"debug": true,
20
+			"default-ulimits": {
21
+				"nofile": {
22
+					"Name": "nofile",
23
+					"Hard": 2048,
24
+					"Soft": 1024
25
+				}
26
+			},
27
+			"log-opts": {
28
+				"tag": "test_tag"
29
+			}
30
+		}`))
31
+
32
+	f.Close()
33
+
34
+	c := &Config{
35
+		CommonConfig: CommonConfig{
36
+			AutoRestart: true,
37
+			LogConfig: LogConfig{
38
+				Type:   "syslog",
39
+				Config: map[string]string{"tag": "test"},
40
+			},
41
+		},
42
+	}
43
+
44
+	cc, err := MergeDaemonConfigurations(c, nil, configFile)
45
+	if err != nil {
46
+		t.Fatal(err)
47
+	}
48
+	if !cc.Debug {
49
+		t.Fatalf("expected %v, got %v\n", true, cc.Debug)
50
+	}
51
+	if !cc.AutoRestart {
52
+		t.Fatalf("expected %v, got %v\n", true, cc.AutoRestart)
53
+	}
54
+	if cc.LogConfig.Type != "syslog" {
55
+		t.Fatalf("expected syslog config, got %q\n", cc.LogConfig)
56
+	}
57
+
58
+	if configValue, OK := cc.LogConfig.Config["tag"]; !OK {
59
+		t.Fatal("expected syslog config attributes, got nil\n")
60
+	} else {
61
+		if configValue != "test_tag" {
62
+			t.Fatalf("expected syslog config attributes 'tag=test_tag', got 'tag=%s'\n", configValue)
63
+		}
64
+	}
65
+
66
+	if cc.Ulimits == nil {
67
+		t.Fatal("expected default ulimit config, got nil\n")
68
+	} else {
69
+		if _, OK := cc.Ulimits["nofile"]; OK {
70
+			if cc.Ulimits["nofile"].Name != "nofile" ||
71
+				cc.Ulimits["nofile"].Hard != 2048 ||
72
+				cc.Ulimits["nofile"].Soft != 1024 {
73
+				t.Fatalf("expected default ulimit name, hard and soft are nofile, 2048, 1024, got %s, %d, %d\n", cc.Ulimits["nofile"].Name, cc.Ulimits["nofile"].Hard, cc.Ulimits["nofile"].Soft)
74
+			}
75
+		} else {
76
+			t.Fatal("expected default ulimit name nofile, got nil\n")
77
+		}
78
+	}
79
+}
0 80
new file mode 100644
... ...
@@ -0,0 +1,59 @@
0
+// +build windows
1
+
2
+package daemon
3
+
4
+import (
5
+	"io/ioutil"
6
+	"testing"
7
+)
8
+
9
+func TestDaemonConfigurationMerge(t *testing.T) {
10
+	f, err := ioutil.TempFile("", "docker-config-")
11
+	if err != nil {
12
+		t.Fatal(err)
13
+	}
14
+
15
+	configFile := f.Name()
16
+
17
+	f.Write([]byte(`
18
+		{
19
+			"debug": true,
20
+			"log-opts": {
21
+				"tag": "test_tag"
22
+			}
23
+		}`))
24
+
25
+	f.Close()
26
+
27
+	c := &Config{
28
+		CommonConfig: CommonConfig{
29
+			AutoRestart: true,
30
+			LogConfig: LogConfig{
31
+				Type:   "syslog",
32
+				Config: map[string]string{"tag": "test"},
33
+			},
34
+		},
35
+	}
36
+
37
+	cc, err := MergeDaemonConfigurations(c, nil, configFile)
38
+	if err != nil {
39
+		t.Fatal(err)
40
+	}
41
+	if !cc.Debug {
42
+		t.Fatalf("expected %v, got %v\n", true, cc.Debug)
43
+	}
44
+	if !cc.AutoRestart {
45
+		t.Fatalf("expected %v, got %v\n", true, cc.AutoRestart)
46
+	}
47
+	if cc.LogConfig.Type != "syslog" {
48
+		t.Fatalf("expected syslog config, got %q\n", cc.LogConfig)
49
+	}
50
+
51
+	if configValue, OK := cc.LogConfig.Config["tag"]; !OK {
52
+		t.Fatal("expected syslog config attributes, got nil\n")
53
+	} else {
54
+		if configValue != "test_tag" {
55
+			t.Fatalf("expected syslog config attributes 'tag=test_tag', got 'tag=%s'\n", configValue)
56
+		}
57
+	}
58
+}