diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index df0b042c41..188c821f32 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -32,6 +32,62 @@ import ( "github.com/go-check/check" ) +func init() { + out, err := exec.Command(dockerBinary, "images").CombinedOutput() + if err != nil { + panic(err) + } + lines := strings.Split(string(out), "\n")[1:] + for _, l := range lines { + if l == "" { + continue + } + fields := strings.Fields(l) + imgTag := fields[0] + ":" + fields[1] + // just for case if we have dangling images in tested daemon + if imgTag != ":" { + protectedImages[imgTag] = struct{}{} + } + } + + // Obtain the daemon platform so that it can be used by tests to make + // intelligent decisions about how to configure themselves, and validate + // that the target platform is valid. + res, _, err := sockRequestRaw("GET", "/version", nil, "application/json") + if err != nil || res == nil || (res != nil && res.StatusCode != http.StatusOK) { + panic(fmt.Errorf("Init failed to get version: %v. Res=%v", err.Error(), res)) + } + svrHeader, _ := httputils.ParseServerHeader(res.Header.Get("Server")) + daemonPlatform = svrHeader.OS + if daemonPlatform != "linux" && daemonPlatform != "windows" { + panic("Cannot run tests against platform: " + daemonPlatform) + } + + // On Windows, extract out the version as we need to make selective + // decisions during integration testing as and when features are implemented. + if daemonPlatform == "windows" { + if body, err := ioutil.ReadAll(res.Body); err == nil { + var server types.Version + if err := json.Unmarshal(body, &server); err == nil { + // eg in "10.0 10550 (10550.1000.amd64fre.branch.date-time)" we want 10550 + windowsDaemonKV, _ = strconv.Atoi(strings.Split(server.KernelVersion, " ")[1]) + } + } + } + + // Now we know the daemon platform, can set paths used by tests. + _, body, err := sockRequest("GET", "/info", nil) + if err != nil { + panic(err) + } + + var info types.Info + err = json.Unmarshal(body, &info) + dockerBasePath = info.DockerRootDir + volumesConfigPath = filepath.Join(dockerBasePath, "volumes") + containerStoragePath = filepath.Join(dockerBasePath, "containers") +} + // Daemon represents a Docker daemon for the testing framework. type Daemon struct { // Defaults to "daemon" @@ -607,61 +663,6 @@ func getAllVolumes() ([]*types.Volume, error) { var protectedImages = map[string]struct{}{} -func init() { - out, err := exec.Command(dockerBinary, "images").CombinedOutput() - if err != nil { - panic(err) - } - lines := strings.Split(string(out), "\n")[1:] - for _, l := range lines { - if l == "" { - continue - } - fields := strings.Fields(l) - imgTag := fields[0] + ":" + fields[1] - // just for case if we have dangling images in tested daemon - if imgTag != ":" { - protectedImages[imgTag] = struct{}{} - } - } - - // Obtain the daemon platform so that it can be used by tests to make - // intelligent decisions about how to configure themselves, and validate - // that the target platform is valid. - res, _, err := sockRequestRaw("GET", "/version", nil, "application/json") - if err != nil || res == nil || (res != nil && res.StatusCode != http.StatusOK) { - panic(fmt.Errorf("Init failed to get version: %v. Res=%v", err.Error(), res)) - } - svrHeader, _ := httputils.ParseServerHeader(res.Header.Get("Server")) - daemonPlatform = svrHeader.OS - if daemonPlatform != "linux" && daemonPlatform != "windows" { - panic("Cannot run tests against platform: " + daemonPlatform) - } - - // On Windows, extract out the version as we need to make selective - // decisions during integration testing as and when features are implemented. - if daemonPlatform == "windows" { - if body, err := ioutil.ReadAll(res.Body); err == nil { - var server types.Version - if err := json.Unmarshal(body, &server); err == nil { - // eg in "10.0 10550 (10550.1000.amd64fre.branch.date-time)" we want 10550 - windowsDaemonKV, _ = strconv.Atoi(strings.Split(server.KernelVersion, " ")[1]) - } - } - } - - // Now we know the daemon platform, can set paths used by tests. - if daemonPlatform == "windows" { - dockerBasePath = `c:\programdata\docker` - volumesConfigPath = dockerBasePath + `\volumes` - containerStoragePath = dockerBasePath + `\containers` - } else { - dockerBasePath = "/var/lib/docker" - volumesConfigPath = dockerBasePath + "/volumes" - containerStoragePath = dockerBasePath + "/containers" - } -} - func deleteAllImages() error { out, err := exec.Command(dockerBinary, "images").CombinedOutput() if err != nil {