2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-12-21 18:42:04 -05:00
|
|
|
"fmt"
|
2015-09-02 20:56:01 -04:00
|
|
|
"regexp"
|
2014-10-06 21:54:52 -04:00
|
|
|
"strings"
|
2015-07-22 12:14:48 -04:00
|
|
|
"time"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
2015-09-02 20:56:01 -04:00
|
|
|
"github.com/docker/distribution/digest"
|
2015-09-09 09:36:44 -04:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-07-22 21:46:59 -04:00
|
|
|
"github.com/go-check/check"
|
2014-02-25 11:17:48 -05:00
|
|
|
)
|
|
|
|
|
2015-09-02 20:56:01 -04:00
|
|
|
// TestPullFromCentralRegistry pulls an image from the central registry and verifies that the client
|
|
|
|
// prints all expected output.
|
|
|
|
func (s *DockerHubPullSuite) TestPullFromCentralRegistry(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-09-02 20:56:01 -04:00
|
|
|
out := s.Cmd(c, "pull", "hello-world")
|
|
|
|
defer deleteImages("hello-world")
|
|
|
|
|
|
|
|
c.Assert(out, checker.Contains, "Using default tag: latest", check.Commentf("expected the 'latest' tag to be automatically assumed"))
|
|
|
|
c.Assert(out, checker.Contains, "Pulling from library/hello-world", check.Commentf("expected the 'library/' prefix to be automatically assumed"))
|
|
|
|
c.Assert(out, checker.Contains, "Downloaded newer image for hello-world:latest")
|
|
|
|
|
|
|
|
matches := regexp.MustCompile(`Digest: (.+)\n`).FindAllStringSubmatch(out, -1)
|
|
|
|
c.Assert(len(matches), checker.Equals, 1, check.Commentf("expected exactly one image digest in the output"))
|
|
|
|
c.Assert(len(matches[0]), checker.Equals, 2, check.Commentf("unexpected number of submatches for the digest"))
|
|
|
|
_, err := digest.ParseDigest(matches[0][1])
|
|
|
|
c.Check(err, checker.IsNil, check.Commentf("invalid digest %q in output", matches[0][1]))
|
|
|
|
|
|
|
|
// We should have a single entry in images.
|
|
|
|
img := strings.TrimSpace(s.Cmd(c, "images"))
|
2015-12-16 11:20:56 -05:00
|
|
|
splitImg := strings.Split(img, "\n")
|
|
|
|
c.Assert(splitImg, checker.HasLen, 2)
|
|
|
|
c.Assert(splitImg[1], checker.Matches, `hello-world\s+latest.*?`, check.Commentf("invalid output for `docker images` (expected image and tag name"))
|
2015-01-13 18:19:44 -05:00
|
|
|
}
|
2014-09-23 18:58:05 -04:00
|
|
|
|
2015-09-02 20:56:01 -04:00
|
|
|
// TestPullNonExistingImage pulls non-existing images from the central registry, with different
|
|
|
|
// combinations of implicit tag and library prefix.
|
|
|
|
func (s *DockerHubPullSuite) TestPullNonExistingImage(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-09-02 20:56:01 -04:00
|
|
|
for _, e := range []struct {
|
2015-11-18 17:20:54 -05:00
|
|
|
Repo string
|
2015-09-02 20:56:01 -04:00
|
|
|
Alias string
|
|
|
|
}{
|
2015-11-18 17:20:54 -05:00
|
|
|
{"library/asdfasdf", "asdfasdf:foobar"},
|
|
|
|
{"library/asdfasdf", "library/asdfasdf:foobar"},
|
|
|
|
{"library/asdfasdf", "asdfasdf"},
|
|
|
|
{"library/asdfasdf", "asdfasdf:latest"},
|
|
|
|
{"library/asdfasdf", "library/asdfasdf"},
|
|
|
|
{"library/asdfasdf", "library/asdfasdf:latest"},
|
2015-09-02 20:56:01 -04:00
|
|
|
} {
|
|
|
|
out, err := s.CmdWithError("pull", e.Alias)
|
|
|
|
c.Assert(err, checker.NotNil, check.Commentf("expected non-zero exit status when pulling non-existing image: %s", out))
|
2015-12-21 18:42:04 -05:00
|
|
|
// Hub returns 401 rather than 404 for nonexistent repos over
|
|
|
|
// the v2 protocol - but we should end up falling back to v1,
|
|
|
|
// which does return a 404.
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Error: image %s not found", e.Repo), check.Commentf("expected image not found error messages"))
|
2015-12-23 18:21:43 -05:00
|
|
|
|
|
|
|
// pull -a on a nonexistent registry should fall back as well
|
|
|
|
if !strings.ContainsRune(e.Alias, ':') {
|
|
|
|
out, err := s.CmdWithError("pull", "-a", e.Alias)
|
|
|
|
c.Assert(err, checker.NotNil, check.Commentf("expected non-zero exit status when pulling non-existing image: %s", out))
|
|
|
|
c.Assert(out, checker.Contains, fmt.Sprintf("Error: image %s not found", e.Repo), check.Commentf("expected image not found error messages"))
|
2016-01-18 17:17:39 -05:00
|
|
|
c.Assert(out, checker.Not(checker.Contains), "unauthorized", check.Commentf(`message should not contain "unauthorized"`))
|
2015-12-23 18:21:43 -05:00
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
2015-12-23 18:21:43 -05:00
|
|
|
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
2014-10-06 21:54:52 -04:00
|
|
|
|
2015-09-02 20:56:01 -04:00
|
|
|
// TestPullFromCentralRegistryImplicitRefParts pulls an image from the central registry and verifies
|
|
|
|
// that pulling the same image with different combinations of implicit elements of the the image
|
|
|
|
// reference (tag, repository, central registry url, ...) doesn't trigger a new pull nor leads to
|
|
|
|
// multiple images.
|
|
|
|
func (s *DockerHubPullSuite) TestPullFromCentralRegistryImplicitRefParts(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-09-02 20:56:01 -04:00
|
|
|
s.Cmd(c, "pull", "hello-world")
|
|
|
|
defer deleteImages("hello-world")
|
|
|
|
|
|
|
|
for _, i := range []string{
|
|
|
|
"hello-world",
|
|
|
|
"hello-world:latest",
|
2014-10-06 21:54:52 -04:00
|
|
|
"library/hello-world",
|
2015-09-02 20:56:01 -04:00
|
|
|
"library/hello-world:latest",
|
2014-10-06 21:54:52 -04:00
|
|
|
"docker.io/library/hello-world",
|
|
|
|
"index.docker.io/library/hello-world",
|
2015-09-02 20:56:01 -04:00
|
|
|
} {
|
|
|
|
out := s.Cmd(c, "pull", i)
|
|
|
|
c.Assert(out, checker.Contains, "Image is up to date for hello-world:latest")
|
2015-07-23 08:12:36 -04:00
|
|
|
}
|
|
|
|
|
2015-09-02 20:56:01 -04:00
|
|
|
// We should have a single entry in images.
|
|
|
|
img := strings.TrimSpace(s.Cmd(c, "images"))
|
2015-12-16 11:20:56 -05:00
|
|
|
splitImg := strings.Split(img, "\n")
|
|
|
|
c.Assert(splitImg, checker.HasLen, 2)
|
|
|
|
c.Assert(splitImg[1], checker.Matches, `hello-world\s+latest.*?`, check.Commentf("invalid output for `docker images` (expected image and tag name"))
|
2015-07-23 08:12:36 -04:00
|
|
|
}
|
|
|
|
|
2015-09-02 20:56:01 -04:00
|
|
|
// TestPullScratchNotAllowed verifies that pulling 'scratch' is rejected.
|
|
|
|
func (s *DockerHubPullSuite) TestPullScratchNotAllowed(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-09-02 20:56:01 -04:00
|
|
|
out, err := s.CmdWithError("pull", "scratch")
|
|
|
|
c.Assert(err, checker.NotNil, check.Commentf("expected pull of scratch to fail"))
|
|
|
|
c.Assert(out, checker.Contains, "'scratch' is a reserved name")
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), "Pulling repository scratch")
|
2015-07-20 01:56:10 -04:00
|
|
|
}
|
2015-07-22 12:14:48 -04:00
|
|
|
|
2015-09-02 20:56:01 -04:00
|
|
|
// TestPullAllTagsFromCentralRegistry pulls using `all-tags` for a given image and verifies that it
|
|
|
|
// results in more images than a naked pull.
|
|
|
|
func (s *DockerHubPullSuite) TestPullAllTagsFromCentralRegistry(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-09-02 20:56:01 -04:00
|
|
|
s.Cmd(c, "pull", "busybox")
|
|
|
|
outImageCmd := s.Cmd(c, "images", "busybox")
|
|
|
|
splitOutImageCmd := strings.Split(strings.TrimSpace(outImageCmd), "\n")
|
2015-12-16 11:20:56 -05:00
|
|
|
c.Assert(splitOutImageCmd, checker.HasLen, 2)
|
2015-09-02 20:56:01 -04:00
|
|
|
|
|
|
|
s.Cmd(c, "pull", "--all-tags=true", "busybox")
|
|
|
|
outImageAllTagCmd := s.Cmd(c, "images", "busybox")
|
2015-12-16 11:20:56 -05:00
|
|
|
linesCount := strings.Count(outImageAllTagCmd, "\n")
|
|
|
|
c.Assert(linesCount, checker.GreaterThan, 2, check.Commentf("pulling all tags should provide more than two images, got %s", outImageAllTagCmd))
|
2015-09-02 20:56:01 -04:00
|
|
|
|
|
|
|
// Verify that the line for 'busybox:latest' is left unchanged.
|
|
|
|
var latestLine string
|
|
|
|
for _, line := range strings.Split(outImageAllTagCmd, "\n") {
|
|
|
|
if strings.HasPrefix(line, "busybox") && strings.Contains(line, "latest") {
|
|
|
|
latestLine = line
|
|
|
|
break
|
2015-07-22 12:14:48 -04:00
|
|
|
}
|
2015-07-22 19:10:25 -04:00
|
|
|
}
|
2015-09-02 20:56:01 -04:00
|
|
|
c.Assert(latestLine, checker.Not(checker.Equals), "", check.Commentf("no entry for busybox:latest found after pulling all tags"))
|
|
|
|
splitLatest := strings.Fields(latestLine)
|
|
|
|
splitCurrent := strings.Fields(splitOutImageCmd[1])
|
Fix flaky test TestPullAllTagsFromCentralRegistry
This test was directly comparing lines of output from "docker images".
Sometimes, when busybox had been pushed to the hub recently, the
relative creation times would differ like this:
... obtained []string = []string{"busybox", "latest", "d9551b4026f0", "27", "minutes", "ago", "1.113", "MB"}
... expected []string = []string{"busybox", "latest", "d9551b4026f0", "26", "minutes", "ago", "1.113", "MB"}
Fixing by removing the time-since-creation fields from the comparison.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2015-12-08 14:23:04 -05:00
|
|
|
|
|
|
|
// Clear relative creation times, since these can easily change between
|
|
|
|
// two invocations of "docker images". Without this, the test can fail
|
|
|
|
// like this:
|
|
|
|
// ... obtained []string = []string{"busybox", "latest", "d9551b4026f0", "27", "minutes", "ago", "1.113", "MB"}
|
|
|
|
// ... expected []string = []string{"busybox", "latest", "d9551b4026f0", "26", "minutes", "ago", "1.113", "MB"}
|
|
|
|
splitLatest[3] = ""
|
|
|
|
splitLatest[4] = ""
|
|
|
|
splitLatest[5] = ""
|
|
|
|
splitCurrent[3] = ""
|
|
|
|
splitCurrent[4] = ""
|
|
|
|
splitCurrent[5] = ""
|
|
|
|
|
2015-09-02 20:56:01 -04:00
|
|
|
c.Assert(splitLatest, checker.DeepEquals, splitCurrent, check.Commentf("busybox:latest was changed after pulling all tags"))
|
2015-07-22 19:10:25 -04:00
|
|
|
}
|
2015-07-22 21:46:59 -04:00
|
|
|
|
2015-09-02 20:56:01 -04:00
|
|
|
// TestPullClientDisconnect kills the client during a pull operation and verifies that the operation
|
2015-11-13 19:59:01 -05:00
|
|
|
// gets cancelled.
|
2015-09-02 20:56:01 -04:00
|
|
|
//
|
|
|
|
// Ref: docker/docker#15589
|
|
|
|
func (s *DockerHubPullSuite) TestPullClientDisconnect(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-08-17 17:11:40 -04:00
|
|
|
repoName := "hello-world:latest"
|
|
|
|
|
2015-09-02 20:56:01 -04:00
|
|
|
pullCmd := s.MakeCmd("pull", repoName)
|
2015-08-17 17:11:40 -04:00
|
|
|
stdout, err := pullCmd.StdoutPipe()
|
2015-09-02 20:56:01 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-17 17:11:40 -04:00
|
|
|
err = pullCmd.Start()
|
2015-09-02 20:56:01 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-17 17:11:40 -04:00
|
|
|
|
2015-09-02 20:56:01 -04:00
|
|
|
// Cancel as soon as we get some output.
|
2015-08-17 17:11:40 -04:00
|
|
|
buf := make([]byte, 10)
|
|
|
|
_, err = stdout.Read(buf)
|
2015-09-02 20:56:01 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-17 17:11:40 -04:00
|
|
|
|
|
|
|
err = pullCmd.Process.Kill()
|
2015-09-02 20:56:01 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-17 17:11:40 -04:00
|
|
|
|
2015-11-13 19:59:01 -05:00
|
|
|
time.Sleep(2 * time.Second)
|
2015-12-16 11:20:56 -05:00
|
|
|
_, err = s.CmdWithError("inspect", repoName)
|
|
|
|
c.Assert(err, checker.NotNil, check.Commentf("image was pulled after client disconnected"))
|
2015-08-17 17:11:40 -04:00
|
|
|
}
|