github.com/fabiokung/docker@v0.11.2-0.20170222101415-4534dcd49497/integration-cli/requirements_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "net/http" 7 "os" 8 "os/exec" 9 "strings" 10 "time" 11 12 "github.com/docker/docker/integration-cli/requirement" 13 "github.com/go-check/check" 14 ) 15 16 func PlatformIs(platform string) bool { 17 return testEnv.DaemonPlatform() == platform 18 } 19 20 func ArchitectureIs(arch string) bool { 21 return os.Getenv("DOCKER_ENGINE_GOARCH") == arch 22 } 23 24 func ArchitectureIsNot(arch string) bool { 25 return os.Getenv("DOCKER_ENGINE_GOARCH") != arch 26 } 27 28 func StorageDriverIs(storageDriver string) bool { 29 return strings.HasPrefix(testEnv.DaemonStorageDriver(), storageDriver) 30 } 31 32 func StorageDriverIsNot(storageDriver string) bool { 33 return !strings.HasPrefix(testEnv.DaemonStorageDriver(), storageDriver) 34 } 35 36 func DaemonIsWindows() bool { 37 return PlatformIs("windows") 38 } 39 40 func DaemonIsLinux() bool { 41 return PlatformIs("linux") 42 } 43 44 func ExperimentalDaemon() bool { 45 return testEnv.ExperimentalDaemon() 46 } 47 48 func NotExperimentalDaemon() bool { 49 return !testEnv.ExperimentalDaemon() 50 } 51 52 func IsAmd64() bool { 53 return ArchitectureIs("amd64") 54 } 55 56 func NotArm() bool { 57 return ArchitectureIsNot("arm") 58 } 59 60 func NotArm64() bool { 61 return ArchitectureIsNot("arm64") 62 } 63 64 func NotPpc64le() bool { 65 return ArchitectureIsNot("ppc64le") 66 } 67 68 func NotS390X() bool { 69 return ArchitectureIsNot("s390x") 70 } 71 72 func SameHostDaemon() bool { 73 return testEnv.LocalDaemon() 74 } 75 76 func UnixCli() bool { 77 return isUnixCli 78 } 79 80 func ExecSupport() bool { 81 return supportsExec 82 } 83 84 func Network() bool { 85 // Set a timeout on the GET at 15s 86 var timeout = time.Duration(15 * time.Second) 87 var url = "https://hub.docker.com" 88 89 client := http.Client{ 90 Timeout: timeout, 91 } 92 93 resp, err := client.Get(url) 94 if err != nil && strings.Contains(err.Error(), "use of closed network connection") { 95 panic(fmt.Sprintf("Timeout for GET request on %s", url)) 96 } 97 if resp != nil { 98 resp.Body.Close() 99 } 100 return err == nil 101 } 102 103 func Apparmor() bool { 104 buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled") 105 return err == nil && len(buf) > 1 && buf[0] == 'Y' 106 } 107 108 func NotaryHosting() bool { 109 // for now notary binary is built only if we're running inside 110 // container through `make test`. Figure that out by testing if 111 // notary-server binary is in PATH. 112 _, err := exec.LookPath(notaryServerBinary) 113 return err == nil 114 } 115 116 func NotaryServerHosting() bool { 117 // for now notary-server binary is built only if we're running inside 118 // container through `make test`. Figure that out by testing if 119 // notary-server binary is in PATH. 120 _, err := exec.LookPath(notaryServerBinary) 121 return err == nil 122 } 123 124 func NotOverlay() bool { 125 return StorageDriverIsNot("overlay") 126 } 127 128 func Devicemapper() bool { 129 return StorageDriverIs("devicemapper") 130 } 131 132 func IPv6() bool { 133 cmd := exec.Command("test", "-f", "/proc/net/if_inet6") 134 return cmd.Run() != nil 135 } 136 137 func UserNamespaceROMount() bool { 138 // quick case--userns not enabled in this test run 139 if os.Getenv("DOCKER_REMAP_ROOT") == "" { 140 return true 141 } 142 if _, _, err := dockerCmdWithError("run", "--rm", "--read-only", "busybox", "date"); err != nil { 143 return false 144 } 145 return true 146 } 147 148 func NotUserNamespace() bool { 149 root := os.Getenv("DOCKER_REMAP_ROOT") 150 return root == "" 151 } 152 153 func UserNamespaceInKernel() bool { 154 if _, err := os.Stat("/proc/self/uid_map"); os.IsNotExist(err) { 155 /* 156 * This kernel-provided file only exists if user namespaces are 157 * supported 158 */ 159 return false 160 } 161 162 // We need extra check on redhat based distributions 163 if f, err := os.Open("/sys/module/user_namespace/parameters/enable"); err == nil { 164 defer f.Close() 165 b := make([]byte, 1) 166 _, _ = f.Read(b) 167 return string(b) != "N" 168 } 169 170 return true 171 } 172 173 func IsPausable() bool { 174 if testEnv.DaemonPlatform() == "windows" { 175 return testEnv.Isolation() == "hyperv" 176 } 177 return true 178 } 179 180 func NotPausable() bool { 181 if testEnv.DaemonPlatform() == "windows" { 182 return testEnv.Isolation() == "process" 183 } 184 return false 185 } 186 187 func IsolationIs(expectedIsolation string) bool { 188 return testEnv.DaemonPlatform() == "windows" && string(testEnv.Isolation()) == expectedIsolation 189 } 190 191 func IsolationIsHyperv() bool { 192 return IsolationIs("hyperv") 193 } 194 195 func IsolationIsProcess() bool { 196 return IsolationIs("process") 197 } 198 199 // testRequires checks if the environment satisfies the requirements 200 // for the test to run or skips the tests. 201 func testRequires(c *check.C, requirements ...requirement.Test) { 202 requirement.Is(c, requirements...) 203 }