Browse code

Check integration test requirements using daemon

When running against a remote daemon, we cannot use the local
filesystem to determine configuration.

Signed-off-by: Christopher Crone <christopher.crone@docker.com>

Christopher Crone authored on 2017/09/11 23:23:59
Showing 4 changed files
... ...
@@ -677,7 +677,7 @@ func (s *DockerSuite) TestRunWithSwappinessInvalid(c *check.C) {
677 677
 }
678 678
 
679 679
 func (s *DockerSuite) TestRunWithMemoryReservation(c *check.C) {
680
-	testRequires(c, memoryReservationSupport)
680
+	testRequires(c, SameHostDaemon, memoryReservationSupport)
681 681
 
682 682
 	file := "/sys/fs/cgroup/memory/memory.soft_limit_in_bytes"
683 683
 	out, _ := dockerCmd(c, "run", "--memory-reservation", "200M", "--name", "test", "busybox", "cat", file)
... ...
@@ -689,7 +689,7 @@ func (s *DockerSuite) TestRunWithMemoryReservation(c *check.C) {
689 689
 
690 690
 func (s *DockerSuite) TestRunWithMemoryReservationInvalid(c *check.C) {
691 691
 	testRequires(c, memoryLimitSupport)
692
-	testRequires(c, memoryReservationSupport)
692
+	testRequires(c, SameHostDaemon, memoryReservationSupport)
693 693
 	out, _, err := dockerCmdWithError("run", "-m", "500M", "--memory-reservation", "800M", "busybox", "true")
694 694
 	c.Assert(err, check.NotNil)
695 695
 	expected := "Minimum memory limit can not be less than memory reservation limit"
... ...
@@ -1401,7 +1401,7 @@ func (s *DockerSuite) TestRunDeviceSymlink(c *check.C) {
1401 1401
 
1402 1402
 // TestRunPIDsLimit makes sure the pids cgroup is set with --pids-limit
1403 1403
 func (s *DockerSuite) TestRunPIDsLimit(c *check.C) {
1404
-	testRequires(c, pidsLimit)
1404
+	testRequires(c, SameHostDaemon, pidsLimit)
1405 1405
 
1406 1406
 	file := "/sys/fs/cgroup/pids/pids.max"
1407 1407
 	out, _ := dockerCmd(c, "run", "--name", "skittles", "--pids-limit", "4", "busybox", "cat", file)
... ...
@@ -14,7 +14,6 @@ import (
14 14
 	"github.com/docker/docker/client"
15 15
 	"github.com/docker/docker/integration-cli/checker"
16 16
 	"github.com/docker/docker/integration-cli/request"
17
-	"github.com/docker/docker/pkg/parsers/kernel"
18 17
 	"github.com/go-check/check"
19 18
 	"github.com/kr/pty"
20 19
 )
... ...
@@ -139,7 +138,7 @@ func (s *DockerSuite) TestUpdateKernelMemory(c *check.C) {
139 139
 func (s *DockerSuite) TestUpdateKernelMemoryUninitialized(c *check.C) {
140 140
 	testRequires(c, DaemonIsLinux, kernelMemorySupport)
141 141
 
142
-	isNewKernel := kernel.CheckKernelVersion(4, 6, 0)
142
+	isNewKernel := CheckKernelVersion(4, 6, 0)
143 143
 	name := "test-update-container"
144 144
 	dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
145 145
 	_, _, err := dockerCmdWithError("update", "--kernel-memory", "100M", name)
... ...
@@ -18,19 +18,19 @@ var (
18 18
 )
19 19
 
20 20
 func cpuCfsPeriod() bool {
21
-	return SysInfo.CPUCfsPeriod
21
+	return testEnv.DaemonInfo.CPUCfsPeriod
22 22
 }
23 23
 
24 24
 func cpuCfsQuota() bool {
25
-	return SysInfo.CPUCfsQuota
25
+	return testEnv.DaemonInfo.CPUCfsQuota
26 26
 }
27 27
 
28 28
 func cpuShare() bool {
29
-	return SysInfo.CPUShares
29
+	return testEnv.DaemonInfo.CPUShares
30 30
 }
31 31
 
32 32
 func oomControl() bool {
33
-	return SysInfo.OomKillDisable
33
+	return testEnv.DaemonInfo.OomKillDisable
34 34
 }
35 35
 
36 36
 func pidsLimit() bool {
... ...
@@ -38,11 +38,11 @@ func pidsLimit() bool {
38 38
 }
39 39
 
40 40
 func kernelMemorySupport() bool {
41
-	return SysInfo.KernelMemory
41
+	return testEnv.DaemonInfo.KernelMemory
42 42
 }
43 43
 
44 44
 func memoryLimitSupport() bool {
45
-	return SysInfo.MemoryLimit
45
+	return testEnv.DaemonInfo.MemoryLimit
46 46
 }
47 47
 
48 48
 func memoryReservationSupport() bool {
... ...
@@ -50,19 +50,19 @@ func memoryReservationSupport() bool {
50 50
 }
51 51
 
52 52
 func swapMemorySupport() bool {
53
-	return SysInfo.SwapLimit
53
+	return testEnv.DaemonInfo.SwapLimit
54 54
 }
55 55
 
56 56
 func memorySwappinessSupport() bool {
57
-	return SysInfo.MemorySwappiness
57
+	return SameHostDaemon() && SysInfo.MemorySwappiness
58 58
 }
59 59
 
60 60
 func blkioWeight() bool {
61
-	return SysInfo.BlkioWeight
61
+	return SameHostDaemon() && SysInfo.BlkioWeight
62 62
 }
63 63
 
64 64
 func cgroupCpuset() bool {
65
-	return SysInfo.Cpuset
65
+	return testEnv.DaemonInfo.CPUSet
66 66
 }
67 67
 
68 68
 func seccompEnabled() bool {
... ...
@@ -111,5 +111,7 @@ func overlay2Supported() bool {
111 111
 }
112 112
 
113 113
 func init() {
114
-	SysInfo = sysinfo.New(true)
114
+	if SameHostDaemon() {
115
+		SysInfo = sysinfo.New(true)
116
+	}
115 117
 }
... ...
@@ -9,6 +9,7 @@ import (
9 9
 
10 10
 	"github.com/docker/docker/api/types"
11 11
 	"github.com/docker/docker/client"
12
+	"github.com/docker/docker/pkg/parsers/kernel"
12 13
 	"github.com/docker/docker/pkg/stringutils"
13 14
 	"github.com/go-check/check"
14 15
 	"github.com/gotestyourself/gotestyourself/icmd"
... ...
@@ -194,3 +195,19 @@ func NewEnvClientWithVersion(version string) (*client.Client, error) {
194 194
 	cli.NegotiateAPIVersionPing(types.Ping{APIVersion: version})
195 195
 	return cli, nil
196 196
 }
197
+
198
+// GetKernelVersion gets the current kernel version.
199
+func GetKernelVersion() *kernel.VersionInfo {
200
+	v, _ := kernel.ParseRelease(testEnv.DaemonInfo.KernelVersion)
201
+	return v
202
+}
203
+
204
+// CheckKernelVersion checks if current kernel is newer than (or equal to)
205
+// the given version.
206
+func CheckKernelVersion(k, major, minor int) bool {
207
+	v := GetKernelVersion()
208
+	if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: k, Major: major, Minor: minor}) < 0 {
209
+		return false
210
+	}
211
+	return true
212
+}