Browse code

Fix Config.Cpuset from API < 1.20

Signed-off-by: Antonio Murdaca <amurdaca@redhat.com>

Antonio Murdaca authored on 2015/10/13 16:09:05
Showing 4 changed files
... ...
@@ -24,5 +24,5 @@ type ContainerConfig struct {
24 24
 	Memory       int64
25 25
 	MemorySwap   int64
26 26
 	CPUShares    int64  `json:"CpuShares"`
27
-	CPUSet       string `json:"CpuSet"`
27
+	CPUSet       string `json:"Cpuset"`
28 28
 }
... ...
@@ -16,7 +16,8 @@ type ContainerJSON struct {
16 16
 // ContainerConfig is a backcompatibility struct used in ContainerJSON for the API 1.20
17 17
 type ContainerConfig struct {
18 18
 	*runconfig.Config
19
-	// backward compatibility, it lives now in HostConfig
19
+
20
+	// backward compatibility, they now live in HostConfig
20 21
 	VolumeDriver string
21 22
 }
22 23
 
23 24
new file mode 100644
... ...
@@ -0,0 +1,38 @@
0
+// +build !windows
1
+
2
+package main
3
+
4
+import (
5
+	"encoding/json"
6
+	"fmt"
7
+	"net/http"
8
+
9
+	"github.com/go-check/check"
10
+)
11
+
12
+// #16665
13
+func (s *DockerSuite) TestInspectApiCpusetInConfigPre120(c *check.C) {
14
+	testRequires(c, DaemonIsLinux)
15
+	testRequires(c, cgroupCpuset)
16
+
17
+	name := "cpusetinconfig-pre120"
18
+	dockerCmd(c, "run", "--name", name, "--cpuset", "0-1", "busybox", "true")
19
+
20
+	status, body, err := sockRequest("GET", fmt.Sprintf("/v1.19/containers/%s/json", name), nil)
21
+	c.Assert(status, check.Equals, http.StatusOK)
22
+	c.Assert(err, check.IsNil)
23
+
24
+	var inspectJSON map[string]interface{}
25
+	if err = json.Unmarshal(body, &inspectJSON); err != nil {
26
+		c.Fatalf("unable to unmarshal body for version 1.19: %v", err)
27
+	}
28
+
29
+	config, ok := inspectJSON["Config"]
30
+	if !ok {
31
+		c.Fatal("Unable to find 'Config'")
32
+	}
33
+	cfg := config.(map[string]interface{})
34
+	if _, ok := cfg["Cpuset"]; !ok {
35
+		c.Fatal("Api version 1.19 expected to include Cpuset in 'Config'")
36
+	}
37
+}
... ...
@@ -95,7 +95,7 @@ func (s *DockerSuite) TestKillWithInvalidSignal(c *check.C) {
95 95
 	}
96 96
 }
97 97
 
98
-func (s *DockerSuite) TestKillofStoppedContainerAPIPre120(c *check.C) {
98
+func (s *DockerSuite) TestKillStoppedContainerAPIPre120(c *check.C) {
99 99
 	testRequires(c, DaemonIsLinux)
100 100
 	dockerCmd(c, "run", "--name", "docker-kill-test-api", "-d", "busybox", "top")
101 101
 	dockerCmd(c, "stop", "docker-kill-test-api")