Преглед на файлове

Fix the TestPullImageFromCentralRegistry to skip and add local v1 registry test when net=none

Closes #10966
Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
Srini Brahmaroutu преди 10 години
родител
ревизия
5d70a97b1f

+ 3 - 0
Dockerfile

@@ -164,6 +164,9 @@ RUN set -x \
 	&& (cd /go/src/github.com/BurntSushi/toml && git checkout -q $TOMLV_COMMIT) \
 	&& go install -v github.com/BurntSushi/toml/cmd/tomlv
 
+COPY contrib/download-frozen-image.sh /go/src/github.com/docker/docker/contrib/
+RUN ./contrib/download-frozen-image.sh ./integration-cli/registry registry
+
 # Wrap all commands in the "docker-in-docker" script to allow nested containers
 ENTRYPOINT ["hack/dind"]
 

+ 10 - 0
hack/make/.ensure-registry

@@ -0,0 +1,10 @@
+#!/bin/bash
+set -e
+
+if ! docker inspect registry > /dev/null; then
+	if [ -d /docker-registry ]; then
+		( set -x; docker build -t registry /docker-registry )
+	else
+		( set -x; tar -cC integration-cli/registry . | docker load & )
+	fi
+fi

+ 1 - 0
hack/make/.integration-daemon-start

@@ -19,6 +19,7 @@ if [ -z "$DOCKER_TEST_HOST" ]; then
 	export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock" # "pwd" tricks to make sure $DEST is an absolute path, not a relative one
 	( set -x; exec \
 		docker --daemon --debug \
+		--insecure-registry 0.0.0.0:5000 \
 		--host "$DOCKER_HOST" \
 		--storage-driver "$DOCKER_GRAPHDRIVER" \
 		--exec-driver "$DOCKER_EXECDRIVER" \

+ 1 - 0
hack/make/test-integration-cli

@@ -18,6 +18,7 @@ bundle_test_integration_cli() {
 	if ! {
 		source "$(dirname "$BASH_SOURCE")/.ensure-frozen-images"
 		source "$(dirname "$BASH_SOURCE")/.ensure-httpserver"
+		source "$(dirname "$BASH_SOURCE")/.ensure-registry"
 		source "$(dirname "$BASH_SOURCE")/.ensure-emptyfs"
 
 		bundle_test_integration_cli

+ 29 - 0
integration-cli/docker_cli_pull_test.go

@@ -85,6 +85,8 @@ func TestPullVerified(t *testing.T) {
 
 // pulling an image from the central registry should work
 func TestPullImageFromCentralRegistry(t *testing.T) {
+	testRequires(t, Network)
+
 	defer deleteImages("hello-world")
 
 	pullCmd := exec.Command(dockerBinary, "pull", "hello-world")
@@ -94,6 +96,33 @@ func TestPullImageFromCentralRegistry(t *testing.T) {
 	logDone("pull - pull hello-world")
 }
 
+// pulling an image from the local registry should work
+func TestPullImageFromlocalRegistry(t *testing.T) {
+	defer deleteAllContainers()
+
+	if err := startRegistryV1(); err != nil {
+		t.Fatal(err)
+	}
+	repoName := privateV1RegistryURL
+	defer deleteImages(repoName)
+
+	repo := fmt.Sprintf("%v/%v:%v", repoName, "busybox", "latest")
+	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repo)); err != nil {
+		t.Fatalf("Failed to tag image %v: error %v, output %q", repo, err, out)
+	}
+	defer deleteImages(repo)
+
+	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "push", repo)); err != nil {
+		t.Fatalf("Failed to push image %v: error %v, output %q", repo, err, string(out))
+	}
+
+	pullCmd := exec.Command(dockerBinary, "pull", repo)
+	if out, _, err := runCommandWithOutput(pullCmd); err != nil {
+		t.Fatalf("pulling the hello-world image from the registry has failed: %s, %v", out, err)
+	}
+	logDone("pull - pull local hello-world")
+}
+
 // pulling a non-existing image from the central registry should return a non-zero exit code
 func TestPullNonExistingImage(t *testing.T) {
 	pullCmd := exec.Command(dockerBinary, "pull", "fooblahblah1234")

+ 2 - 1
integration-cli/docker_test_vars.go

@@ -14,7 +14,8 @@ var (
 	registryImageName = "registry"
 
 	// the private registry to use for tests
-	privateRegistryURL = "127.0.0.1:5000"
+	privateRegistryURL   = "127.0.0.1:5000"
+	privateV1RegistryURL = "0.0.0.0:5000"
 
 	dockerBasePath       = "/var/lib/docker"
 	execDriverPath       = dockerBasePath + "/execdriver/native"

+ 47 - 0
integration-cli/registry.go

@@ -7,7 +7,9 @@ import (
 	"os"
 	"os/exec"
 	"path/filepath"
+	"strings"
 	"testing"
+	"time"
 )
 
 const v2binary = "registry-v2"
@@ -69,3 +71,48 @@ func (r *testRegistryV2) Close() {
 	r.cmd.Process.Kill()
 	os.RemoveAll(r.dir)
 }
+
+func pingV1(ip string) error {
+	// We always ping through HTTP for our test registry.
+	resp, err := http.Get(fmt.Sprintf("http://%s/v1/search", ip))
+	if err != nil {
+		return err
+	}
+	if resp.StatusCode != 200 {
+		return fmt.Errorf("registry ping replied with an unexpected status code %d", resp.StatusCode)
+	}
+	return nil
+}
+
+func startRegistryV1() error {
+	//wait for registry image to be available
+	for i := 0; i < 10; i++ {
+		imagesCmd := exec.Command(dockerBinary, "images")
+		out, _, err := runCommandWithOutput(imagesCmd)
+		if err != nil {
+			return err
+		}
+		if strings.Contains(out, "registry") {
+			break
+		}
+		time.Sleep(60000 * time.Millisecond)
+		if i == 10 {
+			fmt.Errorf("No registry image is found to start the regictry V1 services")
+		}
+	}
+
+	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "regserver", "-d", "-p", "5000:5000", "registry", "docker-registry")); err != nil {
+		fmt.Errorf("Failed to start registry: error %v, output %q", err, out)
+	}
+	ip := privateV1RegistryURL
+	//wait until registry server is available
+	for i := 0; i < 10; i++ {
+		if err := pingV1(ip); err == nil {
+			return nil
+		} else if i == 10 && err != nil {
+			return err
+		}
+		time.Sleep(2000 * time.Millisecond)
+	}
+	return nil
+}