2015-04-08 01:57:54 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2015-04-20 21:03:56 +00:00
|
|
|
"net/http"
|
2017-04-14 23:01:56 +00:00
|
|
|
"net/http/httptest"
|
2018-05-09 21:03:48 +00:00
|
|
|
"runtime"
|
|
|
|
"strconv"
|
2015-04-14 03:02:29 +00:00
|
|
|
"strings"
|
2015-04-08 01:57:54 +00:00
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
2017-05-24 03:56:26 +00:00
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
|
|
"github.com/docker/docker/client"
|
2016-12-30 17:23:00 +00:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2017-03-23 17:35:22 +00:00
|
|
|
"github.com/docker/docker/integration-cli/cli"
|
|
|
|
"github.com/docker/docker/integration-cli/cli/build"
|
2018-04-17 08:22:04 +00:00
|
|
|
"github.com/docker/docker/internal/test/request"
|
2018-05-09 21:03:48 +00:00
|
|
|
"github.com/docker/docker/pkg/parsers/kernel"
|
2015-04-18 16:46:47 +00:00
|
|
|
"github.com/go-check/check"
|
2015-04-08 01:57:54 +00:00
|
|
|
)
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSuite) TestAPIImagesFilter(c *check.C) {
|
2019-01-03 21:49:00 +00:00
|
|
|
cli, err := client.NewClientWithOpts(client.FromEnv)
|
2017-05-24 03:56:26 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer cli.Close()
|
|
|
|
|
2015-04-10 21:51:40 +00:00
|
|
|
name := "utest:tag1"
|
|
|
|
name2 := "utest/docker:tag2"
|
|
|
|
name3 := "utest:5000/docker:tag3"
|
2015-04-18 16:46:47 +00:00
|
|
|
for _, n := range []string{name, name2, name3} {
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "tag", "busybox", n)
|
2015-04-18 16:46:47 +00:00
|
|
|
}
|
2017-05-24 03:56:26 +00:00
|
|
|
getImages := func(filter string) []types.ImageSummary {
|
|
|
|
filters := filters.NewArgs()
|
|
|
|
filters.Add("reference", filter)
|
|
|
|
options := types.ImageListOptions{
|
|
|
|
All: false,
|
|
|
|
Filters: filters,
|
|
|
|
}
|
|
|
|
images, err := cli.ImageList(context.Background(), options)
|
2015-11-18 13:06:29 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-04-10 21:51:40 +00:00
|
|
|
|
|
|
|
return images
|
|
|
|
}
|
|
|
|
|
2015-11-18 13:06:29 +00:00
|
|
|
//incorrect number of matches returned
|
|
|
|
images := getImages("utest*/*")
|
|
|
|
c.Assert(images[0].RepoTags, checker.HasLen, 2)
|
|
|
|
|
|
|
|
images = getImages("utest")
|
|
|
|
c.Assert(images[0].RepoTags, checker.HasLen, 1)
|
|
|
|
|
|
|
|
images = getImages("utest*")
|
|
|
|
c.Assert(images[0].RepoTags, checker.HasLen, 1)
|
|
|
|
|
|
|
|
images = getImages("*5000*/*")
|
|
|
|
c.Assert(images[0].RepoTags, checker.HasLen, 1)
|
2015-04-10 21:51:40 +00:00
|
|
|
}
|
2015-04-14 03:02:29 +00:00
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSuite) TestAPIImagesSaveAndLoad(c *check.C) {
|
2018-05-09 21:03:48 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
v, err := kernel.GetKernelVersion()
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
build, _ := strconv.Atoi(strings.Split(strings.SplitN(v.String(), " ", 3)[2][1:], ".")[0])
|
|
|
|
if build == 16299 {
|
|
|
|
c.Skip("Temporarily disabled on RS3 builds")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
testRequires(c, Network)
|
2017-03-23 17:35:22 +00:00
|
|
|
buildImageSuccessfully(c, "saveandload", build.WithDockerfile("FROM busybox\nENV FOO bar"))
|
2017-01-16 10:30:14 +00:00
|
|
|
id := getIDByName(c, "saveandload")
|
2015-04-14 03:02:29 +00:00
|
|
|
|
2017-03-06 15:35:27 +00:00
|
|
|
res, body, err := request.Get("/images/" + id + "/get")
|
2015-11-18 13:06:29 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-04-14 03:02:29 +00:00
|
|
|
defer body.Close()
|
2015-11-18 13:06:29 +00:00
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
2015-04-14 03:02:29 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "rmi", id)
|
2015-04-14 03:02:29 +00:00
|
|
|
|
2017-03-06 15:35:27 +00:00
|
|
|
res, loadBody, err := request.Post("/images/load", request.RawContent(body), request.ContentType("application/x-tar"))
|
2015-11-18 13:06:29 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-04-14 03:02:29 +00:00
|
|
|
defer loadBody.Close()
|
2015-11-18 13:06:29 +00:00
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
2015-04-14 03:02:29 +00:00
|
|
|
|
2017-03-23 17:35:22 +00:00
|
|
|
inspectOut := cli.InspectCmd(c, id, cli.Format(".Id")).Combined()
|
2015-11-18 13:06:29 +00:00
|
|
|
c.Assert(strings.TrimSpace(string(inspectOut)), checker.Equals, id, check.Commentf("load did not work properly"))
|
2015-04-14 03:02:29 +00:00
|
|
|
}
|
2015-04-29 11:56:45 +00:00
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSuite) TestAPIImagesDelete(c *check.C) {
|
2019-01-03 21:49:00 +00:00
|
|
|
cli, err := client.NewClientWithOpts(client.FromEnv)
|
2017-05-24 03:56:26 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer cli.Close()
|
|
|
|
|
2018-01-15 14:32:06 +00:00
|
|
|
if testEnv.OSType != "windows" {
|
2016-01-23 05:13:38 +00:00
|
|
|
testRequires(c, Network)
|
|
|
|
}
|
2015-04-29 11:56:45 +00:00
|
|
|
name := "test-api-images-delete"
|
2017-03-23 17:35:22 +00:00
|
|
|
buildImageSuccessfully(c, name, build.WithDockerfile("FROM busybox\nENV FOO bar"))
|
2017-01-16 10:30:14 +00:00
|
|
|
id := getIDByName(c, name)
|
2015-04-29 11:56:45 +00:00
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
dockerCmd(c, "tag", name, "test:tag1")
|
2015-04-29 11:56:45 +00:00
|
|
|
|
2017-05-24 03:56:26 +00:00
|
|
|
_, err = cli.ImageRemove(context.Background(), id, types.ImageRemoveOptions{})
|
|
|
|
c.Assert(err.Error(), checker.Contains, "unable to delete")
|
2015-04-29 11:56:45 +00:00
|
|
|
|
2017-05-24 03:56:26 +00:00
|
|
|
_, err = cli.ImageRemove(context.Background(), "test:noexist", types.ImageRemoveOptions{})
|
|
|
|
c.Assert(err.Error(), checker.Contains, "No such image")
|
2015-05-04 07:39:40 +00:00
|
|
|
|
2017-05-24 03:56:26 +00:00
|
|
|
_, err = cli.ImageRemove(context.Background(), "test:tag1", types.ImageRemoveOptions{})
|
2015-11-18 13:06:29 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-04-29 11:56:45 +00:00
|
|
|
}
|
2015-05-02 05:30:35 +00:00
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSuite) TestAPIImagesHistory(c *check.C) {
|
2019-01-03 21:49:00 +00:00
|
|
|
cli, err := client.NewClientWithOpts(client.FromEnv)
|
2017-05-24 03:56:26 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer cli.Close()
|
|
|
|
|
2018-01-15 14:32:06 +00:00
|
|
|
if testEnv.OSType != "windows" {
|
2016-01-23 05:13:38 +00:00
|
|
|
testRequires(c, Network)
|
|
|
|
}
|
2015-05-02 05:30:35 +00:00
|
|
|
name := "test-api-images-history"
|
2017-03-23 17:35:22 +00:00
|
|
|
buildImageSuccessfully(c, name, build.WithDockerfile("FROM busybox\nENV FOO bar"))
|
2017-01-16 10:30:14 +00:00
|
|
|
id := getIDByName(c, name)
|
2015-05-02 05:30:35 +00:00
|
|
|
|
2017-05-24 03:56:26 +00:00
|
|
|
historydata, err := cli.ImageHistory(context.Background(), id)
|
2015-11-18 13:06:29 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-02 05:30:35 +00:00
|
|
|
|
2015-11-18 13:06:29 +00:00
|
|
|
c.Assert(historydata, checker.Not(checker.HasLen), 0)
|
2018-03-27 16:13:47 +00:00
|
|
|
var found bool
|
|
|
|
for _, tag := range historydata[0].Tags {
|
|
|
|
if tag == "test-api-images-history:latest" {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.Assert(found, checker.True)
|
2015-05-02 05:30:35 +00:00
|
|
|
}
|
2015-07-22 09:07:41 +00:00
|
|
|
|
2017-02-05 11:39:37 +00:00
|
|
|
func (s *DockerSuite) TestAPIImagesImportBadSrc(c *check.C) {
|
2018-05-09 21:03:48 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
v, err := kernel.GetKernelVersion()
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
build, _ := strconv.Atoi(strings.Split(strings.SplitN(v.String(), " ", 3)[2][1:], ".")[0])
|
|
|
|
if build == 16299 {
|
|
|
|
c.Skip("Temporarily disabled on RS3 builds")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-24 12:25:53 +00:00
|
|
|
testRequires(c, Network, testEnv.IsLocalDaemon)
|
2017-02-05 11:39:37 +00:00
|
|
|
|
2017-04-14 23:01:56 +00:00
|
|
|
server := httptest.NewServer(http.NewServeMux())
|
|
|
|
defer server.Close()
|
|
|
|
|
2017-02-05 11:39:37 +00:00
|
|
|
tt := []struct {
|
|
|
|
statusExp int
|
|
|
|
fromSrc string
|
|
|
|
}{
|
2017-04-14 23:01:56 +00:00
|
|
|
{http.StatusNotFound, server.URL + "/nofile.tar"},
|
|
|
|
{http.StatusNotFound, strings.TrimPrefix(server.URL, "http://") + "/nofile.tar"},
|
|
|
|
{http.StatusNotFound, strings.TrimPrefix(server.URL, "http://") + "%2Fdata%2Ffile.tar"},
|
2017-02-05 11:39:37 +00:00
|
|
|
{http.StatusInternalServerError, "%2Fdata%2Ffile.tar"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, te := range tt {
|
2017-05-24 03:56:26 +00:00
|
|
|
res, _, err := request.Post(strings.Join([]string{"/images/create?fromSrc=", te.fromSrc}, ""), request.JSON)
|
2017-02-05 11:39:37 +00:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, te.statusExp)
|
|
|
|
c.Assert(res.Header.Get("Content-Type"), checker.Equals, "application/json")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-22 09:07:41 +00:00
|
|
|
// #14846
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-28 01:50:12 +00:00
|
|
|
func (s *DockerSuite) TestAPIImagesSearchJSONContentType(c *check.C) {
|
2015-07-22 09:07:41 +00:00
|
|
|
testRequires(c, Network)
|
|
|
|
|
2017-03-06 15:35:27 +00:00
|
|
|
res, b, err := request.Get("/images/search?term=test", request.JSON)
|
2015-07-22 09:07:41 +00:00
|
|
|
c.Assert(err, check.IsNil)
|
2015-07-23 11:24:14 +00:00
|
|
|
b.Close()
|
2015-11-18 13:06:29 +00:00
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
|
|
|
c.Assert(res.Header.Get("Content-Type"), checker.Equals, "application/json")
|
2015-07-22 09:07:41 +00:00
|
|
|
}
|
2017-01-12 16:12:39 +00:00
|
|
|
|
|
|
|
// Test case for 30027: image size reported as -1 in v1.12 client against v1.13 daemon.
|
|
|
|
// This test checks to make sure both v1.12 and v1.13 client against v1.13 daemon get correct `Size` after the fix.
|
|
|
|
func (s *DockerSuite) TestAPIImagesSizeCompatibility(c *check.C) {
|
2017-09-19 20:12:29 +00:00
|
|
|
apiclient := testEnv.APIClient()
|
|
|
|
defer apiclient.Close()
|
2017-05-24 03:56:26 +00:00
|
|
|
|
2017-09-19 20:12:29 +00:00
|
|
|
images, err := apiclient.ImageList(context.Background(), types.ImageListOptions{})
|
2017-01-12 16:12:39 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(len(images), checker.Not(checker.Equals), 0)
|
|
|
|
for _, image := range images {
|
|
|
|
c.Assert(image.Size, checker.Not(checker.Equals), int64(-1))
|
|
|
|
}
|
|
|
|
|
2017-09-19 20:12:29 +00:00
|
|
|
apiclient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("v1.24"))
|
2017-01-12 16:12:39 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2017-09-19 20:12:29 +00:00
|
|
|
defer apiclient.Close()
|
2017-05-24 03:56:26 +00:00
|
|
|
|
2017-09-19 20:12:29 +00:00
|
|
|
v124Images, err := apiclient.ImageList(context.Background(), types.ImageListOptions{})
|
2017-01-12 16:12:39 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(len(v124Images), checker.Not(checker.Equals), 0)
|
|
|
|
for _, image := range v124Images {
|
|
|
|
c.Assert(image.Size, checker.Not(checker.Equals), int64(-1))
|
|
|
|
}
|
|
|
|
}
|