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