2015-04-07 21:57:54 -04:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2015-04-20 17:03:56 -04:00
|
|
|
|
"net/http"
|
2017-04-14 19:01:56 -04:00
|
|
|
|
"net/http/httptest"
|
2015-04-10 17:51:40 -04:00
|
|
|
|
"net/url"
|
2015-04-13 23:02:29 -04:00
|
|
|
|
"strings"
|
2015-04-07 21:57:54 -04:00
|
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
|
"github.com/docker/docker/api/types"
|
2016-11-09 16:32:53 -05:00
|
|
|
|
"github.com/docker/docker/api/types/image"
|
2016-12-30 12:23:00 -05:00
|
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2017-03-23 13:35:22 -04:00
|
|
|
|
"github.com/docker/docker/integration-cli/cli"
|
|
|
|
|
"github.com/docker/docker/integration-cli/cli/build"
|
2016-12-30 04:49:36 -05:00
|
|
|
|
"github.com/docker/docker/integration-cli/request"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
"github.com/go-check/check"
|
2015-04-07 21:57:54 -04: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-27 21:50:12 -04:00
|
|
|
|
func (s *DockerSuite) TestAPIImagesFilter(c *check.C) {
|
2015-04-10 17:51:40 -04:00
|
|
|
|
name := "utest:tag1"
|
|
|
|
|
name2 := "utest/docker:tag2"
|
|
|
|
|
name3 := "utest:5000/docker:tag3"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
for _, n := range []string{name, name2, name3} {
|
2015-07-14 02:35:36 -04:00
|
|
|
|
dockerCmd(c, "tag", "busybox", n)
|
2015-04-18 12:46:47 -04:00
|
|
|
|
}
|
2016-10-03 15:17:39 -04:00
|
|
|
|
type image types.ImageSummary
|
2015-04-10 17:51:40 -04:00
|
|
|
|
getImages := func(filter string) []image {
|
|
|
|
|
v := url.Values{}
|
|
|
|
|
v.Set("filter", filter)
|
2016-12-30 04:49:36 -05:00
|
|
|
|
status, b, err := request.SockRequest("GET", "/images/json?"+v.Encode(), nil, daemonHost())
|
2015-11-18 08:06:29 -05:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
c.Assert(status, checker.Equals, http.StatusOK)
|
2015-04-20 17:03:56 -04:00
|
|
|
|
|
2015-04-10 17:51:40 -04:00
|
|
|
|
var images []image
|
2015-11-18 08:06:29 -05:00
|
|
|
|
err = json.Unmarshal(b, &images)
|
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-04-10 17:51:40 -04:00
|
|
|
|
|
|
|
|
|
return images
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-18 08:06:29 -05: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 17:51:40 -04:00
|
|
|
|
}
|
2015-04-13 23:02:29 -04: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-27 21:50:12 -04:00
|
|
|
|
func (s *DockerSuite) TestAPIImagesSaveAndLoad(c *check.C) {
|
2016-01-23 00:13:38 -05:00
|
|
|
|
// TODO Windows to Windows CI: Investigate further why this test fails.
|
2015-04-18 12:46:47 -04:00
|
|
|
|
testRequires(c, Network)
|
2015-08-28 13:36:42 -04:00
|
|
|
|
testRequires(c, DaemonIsLinux)
|
2017-03-23 13:35:22 -04:00
|
|
|
|
buildImageSuccessfully(c, "saveandload", build.WithDockerfile("FROM busybox\nENV FOO bar"))
|
2017-01-16 05:30:14 -05:00
|
|
|
|
id := getIDByName(c, "saveandload")
|
2015-04-13 23:02:29 -04:00
|
|
|
|
|
2017-03-06 10:35:27 -05:00
|
|
|
|
res, body, err := request.Get("/images/" + id + "/get")
|
2015-11-18 08:06:29 -05:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-04-13 23:02:29 -04:00
|
|
|
|
defer body.Close()
|
2015-11-18 08:06:29 -05:00
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
2015-04-13 23:02:29 -04:00
|
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
|
dockerCmd(c, "rmi", id)
|
2015-04-13 23:02:29 -04:00
|
|
|
|
|
2017-03-06 10:35:27 -05:00
|
|
|
|
res, loadBody, err := request.Post("/images/load", request.RawContent(body), request.ContentType("application/x-tar"))
|
2015-11-18 08:06:29 -05:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-04-13 23:02:29 -04:00
|
|
|
|
defer loadBody.Close()
|
2015-11-18 08:06:29 -05:00
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
2015-04-13 23:02:29 -04:00
|
|
|
|
|
2017-03-23 13:35:22 -04:00
|
|
|
|
inspectOut := cli.InspectCmd(c, id, cli.Format(".Id")).Combined()
|
2015-11-18 08:06:29 -05:00
|
|
|
|
c.Assert(strings.TrimSpace(string(inspectOut)), checker.Equals, id, check.Commentf("load did not work properly"))
|
2015-04-13 23:02:29 -04:00
|
|
|
|
}
|
2015-04-29 07:56:45 -04: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-27 21:50:12 -04:00
|
|
|
|
func (s *DockerSuite) TestAPIImagesDelete(c *check.C) {
|
2017-01-13 11:23:28 -05:00
|
|
|
|
if testEnv.DaemonPlatform() != "windows" {
|
2016-01-23 00:13:38 -05:00
|
|
|
|
testRequires(c, Network)
|
|
|
|
|
}
|
2015-04-29 07:56:45 -04:00
|
|
|
|
name := "test-api-images-delete"
|
2017-03-23 13:35:22 -04:00
|
|
|
|
buildImageSuccessfully(c, name, build.WithDockerfile("FROM busybox\nENV FOO bar"))
|
2017-01-16 05:30:14 -05:00
|
|
|
|
id := getIDByName(c, name)
|
2015-04-29 07:56:45 -04:00
|
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
|
dockerCmd(c, "tag", name, "test:tag1")
|
2015-04-29 07:56:45 -04:00
|
|
|
|
|
2016-12-30 04:49:36 -05:00
|
|
|
|
status, _, err := request.SockRequest("DELETE", "/images/"+id, nil, daemonHost())
|
2015-11-18 08:06:29 -05:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
c.Assert(status, checker.Equals, http.StatusConflict)
|
2015-04-29 07:56:45 -04:00
|
|
|
|
|
2016-12-30 04:49:36 -05:00
|
|
|
|
status, _, err = request.SockRequest("DELETE", "/images/test:noexist", nil, daemonHost())
|
2015-11-18 08:06:29 -05:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
c.Assert(status, checker.Equals, http.StatusNotFound) //Status Codes:404 – no such image
|
2015-05-04 03:39:40 -04:00
|
|
|
|
|
2016-12-30 04:49:36 -05:00
|
|
|
|
status, _, err = request.SockRequest("DELETE", "/images/test:tag1", nil, daemonHost())
|
2015-11-18 08:06:29 -05:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
c.Assert(status, checker.Equals, http.StatusOK)
|
2015-04-29 07:56:45 -04:00
|
|
|
|
}
|
2015-05-02 01:30:35 -04: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-27 21:50:12 -04:00
|
|
|
|
func (s *DockerSuite) TestAPIImagesHistory(c *check.C) {
|
2017-01-13 11:23:28 -05:00
|
|
|
|
if testEnv.DaemonPlatform() != "windows" {
|
2016-01-23 00:13:38 -05:00
|
|
|
|
testRequires(c, Network)
|
|
|
|
|
}
|
2015-05-02 01:30:35 -04:00
|
|
|
|
name := "test-api-images-history"
|
2017-03-23 13:35:22 -04:00
|
|
|
|
buildImageSuccessfully(c, name, build.WithDockerfile("FROM busybox\nENV FOO bar"))
|
2017-01-16 05:30:14 -05:00
|
|
|
|
id := getIDByName(c, name)
|
2015-05-02 01:30:35 -04:00
|
|
|
|
|
2016-12-30 04:49:36 -05:00
|
|
|
|
status, body, err := request.SockRequest("GET", "/images/"+id+"/history", nil, daemonHost())
|
2015-11-18 08:06:29 -05:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
c.Assert(status, checker.Equals, http.StatusOK)
|
2015-05-02 01:30:35 -04:00
|
|
|
|
|
2016-11-09 16:32:53 -05:00
|
|
|
|
var historydata []image.HistoryResponseItem
|
2015-11-18 08:06:29 -05:00
|
|
|
|
err = json.Unmarshal(body, &historydata)
|
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("Error on unmarshal"))
|
2015-05-02 01:30:35 -04:00
|
|
|
|
|
2015-11-18 08:06:29 -05:00
|
|
|
|
c.Assert(historydata, checker.Not(checker.HasLen), 0)
|
|
|
|
|
c.Assert(historydata[0].Tags[0], checker.Equals, "test-api-images-history:latest")
|
2015-05-02 01:30:35 -04:00
|
|
|
|
}
|
2015-07-22 05:07:41 -04:00
|
|
|
|
|
2017-02-05 06:39:37 -05:00
|
|
|
|
func (s *DockerSuite) TestAPIImagesImportBadSrc(c *check.C) {
|
|
|
|
|
testRequires(c, Network)
|
|
|
|
|
|
2017-04-14 19:01:56 -04:00
|
|
|
|
server := httptest.NewServer(http.NewServeMux())
|
|
|
|
|
defer server.Close()
|
|
|
|
|
|
2017-02-05 06:39:37 -05:00
|
|
|
|
tt := []struct {
|
|
|
|
|
statusExp int
|
|
|
|
|
fromSrc string
|
|
|
|
|
}{
|
2017-04-14 19:01:56 -04: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 06:39:37 -05:00
|
|
|
|
{http.StatusInternalServerError, "%2Fdata%2Ffile.tar"},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, te := range tt {
|
|
|
|
|
res, b, err := request.SockRequestRaw("POST", strings.Join([]string{"/images/create?fromSrc=", te.fromSrc}, ""), nil, "application/json", daemonHost())
|
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
b.Close()
|
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, te.statusExp)
|
|
|
|
|
c.Assert(res.Header.Get("Content-Type"), checker.Equals, "application/json")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 05:07:41 -04: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-27 21:50:12 -04:00
|
|
|
|
func (s *DockerSuite) TestAPIImagesSearchJSONContentType(c *check.C) {
|
2015-07-22 05:07:41 -04:00
|
|
|
|
testRequires(c, Network)
|
|
|
|
|
|
2017-03-06 10:35:27 -05:00
|
|
|
|
res, b, err := request.Get("/images/search?term=test", request.JSON)
|
2015-07-22 05:07:41 -04:00
|
|
|
|
c.Assert(err, check.IsNil)
|
2015-07-23 07:24:14 -04:00
|
|
|
|
b.Close()
|
2015-11-18 08:06:29 -05:00
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
|
|
|
|
c.Assert(res.Header.Get("Content-Type"), checker.Equals, "application/json")
|
2015-07-22 05:07:41 -04:00
|
|
|
|
}
|
2017-01-12 11:12:39 -05: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) {
|
|
|
|
|
status, b, err := request.SockRequest("GET", "/images/json", nil, daemonHost())
|
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
c.Assert(status, checker.Equals, http.StatusOK)
|
|
|
|
|
var images []types.ImageSummary
|
|
|
|
|
err = json.Unmarshal(b, &images)
|
|
|
|
|
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))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type v124Image struct {
|
|
|
|
|
ID string `json:"Id"`
|
|
|
|
|
ParentID string `json:"ParentId"`
|
|
|
|
|
RepoTags []string
|
|
|
|
|
RepoDigests []string
|
|
|
|
|
Created int64
|
|
|
|
|
Size int64
|
|
|
|
|
VirtualSize int64
|
|
|
|
|
Labels map[string]string
|
|
|
|
|
}
|
|
|
|
|
status, b, err = request.SockRequest("GET", "/v1.24/images/json", nil, daemonHost())
|
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
c.Assert(status, checker.Equals, http.StatusOK)
|
|
|
|
|
var v124Images []v124Image
|
|
|
|
|
err = json.Unmarshal(b, &v124Images)
|
|
|
|
|
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))
|
|
|
|
|
}
|
|
|
|
|
}
|