requirements_unix.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // +build !windows
  2. package main
  3. import (
  4. "bytes"
  5. "io/ioutil"
  6. "os/exec"
  7. "strings"
  8. "github.com/docker/docker/pkg/sysinfo"
  9. )
  10. var (
  11. // SysInfo stores information about which features a kernel supports.
  12. SysInfo *sysinfo.SysInfo
  13. cpuCfsPeriod = testRequirement{
  14. func() bool {
  15. return SysInfo.CPUCfsPeriod
  16. },
  17. "Test requires an environment that supports cgroup cfs period.",
  18. }
  19. cpuCfsQuota = testRequirement{
  20. func() bool {
  21. return SysInfo.CPUCfsQuota
  22. },
  23. "Test requires an environment that supports cgroup cfs quota.",
  24. }
  25. cpuShare = testRequirement{
  26. func() bool {
  27. return SysInfo.CPUShares
  28. },
  29. "Test requires an environment that supports cgroup cpu shares.",
  30. }
  31. oomControl = testRequirement{
  32. func() bool {
  33. return SysInfo.OomKillDisable
  34. },
  35. "Test requires Oom control enabled.",
  36. }
  37. pidsLimit = testRequirement{
  38. func() bool {
  39. return SysInfo.PidsLimit
  40. },
  41. "Test requires pids limit enabled.",
  42. }
  43. kernelMemorySupport = testRequirement{
  44. func() bool {
  45. return SysInfo.KernelMemory
  46. },
  47. "Test requires an environment that supports cgroup kernel memory.",
  48. }
  49. memoryLimitSupport = testRequirement{
  50. func() bool {
  51. return SysInfo.MemoryLimit
  52. },
  53. "Test requires an environment that supports cgroup memory limit.",
  54. }
  55. memoryReservationSupport = testRequirement{
  56. func() bool {
  57. return SysInfo.MemoryReservation
  58. },
  59. "Test requires an environment that supports cgroup memory reservation.",
  60. }
  61. swapMemorySupport = testRequirement{
  62. func() bool {
  63. return SysInfo.SwapLimit
  64. },
  65. "Test requires an environment that supports cgroup swap memory limit.",
  66. }
  67. memorySwappinessSupport = testRequirement{
  68. func() bool {
  69. return SysInfo.MemorySwappiness
  70. },
  71. "Test requires an environment that supports cgroup memory swappiness.",
  72. }
  73. blkioWeight = testRequirement{
  74. func() bool {
  75. return SysInfo.BlkioWeight
  76. },
  77. "Test requires an environment that supports blkio weight.",
  78. }
  79. cgroupCpuset = testRequirement{
  80. func() bool {
  81. return SysInfo.Cpuset
  82. },
  83. "Test requires an environment that supports cgroup cpuset.",
  84. }
  85. seccompEnabled = testRequirement{
  86. func() bool {
  87. return supportsSeccomp && SysInfo.Seccomp
  88. },
  89. "Test requires that seccomp support be enabled in the daemon.",
  90. }
  91. bridgeNfIptables = testRequirement{
  92. func() bool {
  93. return !SysInfo.BridgeNFCallIPTablesDisabled
  94. },
  95. "Test requires that bridge-nf-call-iptables support be enabled in the daemon.",
  96. }
  97. bridgeNfIP6tables = testRequirement{
  98. func() bool {
  99. return !SysInfo.BridgeNFCallIP6TablesDisabled
  100. },
  101. "Test requires that bridge-nf-call-ip6tables support be enabled in the daemon.",
  102. }
  103. unprivilegedUsernsClone = testRequirement{
  104. func() bool {
  105. content, err := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone")
  106. if err == nil && strings.Contains(string(content), "0") {
  107. return false
  108. }
  109. return true
  110. },
  111. "Test cannot be run with 'sysctl kernel.unprivileged_userns_clone' = 0",
  112. }
  113. ambientCapabilities = testRequirement{
  114. func() bool {
  115. content, err := ioutil.ReadFile("/proc/self/status")
  116. if err == nil && strings.Contains(string(content), "CapAmb:") {
  117. return true
  118. }
  119. return false
  120. },
  121. "Test cannot be run without a kernel (4.3+) supporting ambient capabilities",
  122. }
  123. overlaySupported = testRequirement{
  124. func() bool {
  125. cmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "/bin/sh", "-c", "cat /proc/filesystems")
  126. out, err := cmd.CombinedOutput()
  127. if err != nil {
  128. return false
  129. }
  130. return bytes.Contains(out, []byte("overlay\n"))
  131. },
  132. "Test cannot be run wihtout suppport for ovelayfs",
  133. }
  134. )
  135. func init() {
  136. SysInfo = sysinfo.New(true)
  137. }