mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
fix up Image-name related issues in docker ps and CI
This patch include the following fixs: - fix image name error when docker ps - fix docker events test failure: use the exact image name for filter - fix docker build CI test failure due to "docker events" change Because of change of daemon log behavior. Now we record the exact Image name as you typed. So docker run -d busybux sh and docker run -d busybox:latest are not the same in the log. So it will affect the docker events. So change the related CI Signed-off-by: Liu Hua <sdu.liu@huawei.com>
This commit is contained in:
parent
663d913011
commit
645c020f5a
4 changed files with 59 additions and 40 deletions
|
@ -7,12 +7,9 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/graph"
|
||||
"github.com/docker/docker/nat"
|
||||
"github.com/docker/docker/pkg/graphdb"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
"github.com/docker/docker/pkg/parsers/filters"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// List returns an array of all containers registered in the daemon.
|
||||
|
@ -136,12 +133,7 @@ func (daemon *Daemon) Containers(config *ContainersConfig) ([]*types.Container,
|
|||
ID: container.ID,
|
||||
Names: names[container.ID],
|
||||
}
|
||||
img := container.Config.Image
|
||||
_, tag := parsers.ParseRepositoryTag(container.Config.Image)
|
||||
if tag == "" {
|
||||
img = utils.ImageReference(img, graph.DEFAULTTAG)
|
||||
}
|
||||
newC.Image = img
|
||||
newC.Image = container.Config.Image
|
||||
if len(container.Args) > 0 {
|
||||
args := []string{}
|
||||
for _, arg := range container.Args {
|
||||
|
|
|
@ -2009,8 +2009,16 @@ func TestBuildCancelationKillsSleep(t *testing.T) {
|
|||
}()
|
||||
|
||||
var started, died bool
|
||||
matchStart := regexp.MustCompile(" \\(from busybox\\:latest\\) start$")
|
||||
matchDie := regexp.MustCompile(" \\(from busybox\\:latest\\) die$")
|
||||
var imageID string
|
||||
|
||||
if out, err := exec.Command(dockerBinary, "inspect", "-f", "{{.Id}}", "busybox").CombinedOutput(); err != nil {
|
||||
t.Fatalf("failed to get the image ID of busybox: %s, %v", out, err)
|
||||
} else {
|
||||
imageID = strings.TrimSpace(string(out))
|
||||
}
|
||||
|
||||
matchStart := regexp.MustCompile(" \\(from " + imageID + "\\) start$")
|
||||
matchDie := regexp.MustCompile(" \\(from " + imageID + "\\) die$")
|
||||
|
||||
//
|
||||
// Read lines of `docker events` looking for container start and stop.
|
||||
|
|
|
@ -290,7 +290,7 @@ func TestEventsFilterImageName(t *testing.T) {
|
|||
since := daemonTime(t).Unix()
|
||||
defer deleteAllContainers()
|
||||
|
||||
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "container_1", "-d", "busybox", "true"))
|
||||
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "container_1", "-d", "busybox:latest", "true"))
|
||||
if err != nil {
|
||||
t.Fatal(out, err)
|
||||
}
|
||||
|
@ -302,9 +302,9 @@ func TestEventsFilterImageName(t *testing.T) {
|
|||
}
|
||||
container2 := strings.TrimSpace(out)
|
||||
|
||||
for _, s := range []string{"busybox", "busybox:latest"} {
|
||||
s := "busybox"
|
||||
eventsCmd := exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(t).Unix()), "--filter", fmt.Sprintf("image=%s", s))
|
||||
out, _, err := runCommandWithOutput(eventsCmd)
|
||||
out, _, err = runCommandWithOutput(eventsCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get events, error: %s(%s)", err, out)
|
||||
}
|
||||
|
@ -315,6 +315,7 @@ func TestEventsFilterImageName(t *testing.T) {
|
|||
}
|
||||
count1 := 0
|
||||
count2 := 0
|
||||
|
||||
for _, e := range events {
|
||||
if strings.Contains(e, container1) {
|
||||
count1++
|
||||
|
@ -325,7 +326,6 @@ func TestEventsFilterImageName(t *testing.T) {
|
|||
if count1 == 0 || count2 == 0 {
|
||||
t.Fatalf("Expected events from each container but got %d from %s and %d from %s", count1, container1, count2, container2)
|
||||
}
|
||||
}
|
||||
|
||||
logDone("events - filters using image")
|
||||
}
|
||||
|
@ -467,7 +467,7 @@ func TestEventsStreaming(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox:latest", "true")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
t.Fatal(out, err)
|
||||
|
|
|
@ -594,6 +594,21 @@ func TestPsRightTagName(t *testing.T) {
|
|||
} else {
|
||||
id2 = strings.TrimSpace(string(out))
|
||||
}
|
||||
|
||||
var imageID string
|
||||
if out, err := exec.Command(dockerBinary, "inspect", "-f", "{{.Id}}", "busybox").CombinedOutput(); err != nil {
|
||||
t.Fatalf("failed to get the image ID of busybox: %s, %v", out, err)
|
||||
} else {
|
||||
imageID = strings.TrimSpace(string(out))
|
||||
}
|
||||
|
||||
var id3 string
|
||||
if out, err := exec.Command(dockerBinary, "run", "-d", imageID, "top").CombinedOutput(); err != nil {
|
||||
t.Fatalf("Failed to run container: %s, out: %q", err, out)
|
||||
} else {
|
||||
id3 = strings.TrimSpace(string(out))
|
||||
}
|
||||
|
||||
out, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to run 'ps': %s, out: %q", err, out)
|
||||
|
@ -601,22 +616,26 @@ func TestPsRightTagName(t *testing.T) {
|
|||
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
// skip header
|
||||
lines = lines[1:]
|
||||
if len(lines) != 2 {
|
||||
t.Fatalf("There should be 2 running container, got %d", len(lines))
|
||||
if len(lines) != 3 {
|
||||
t.Fatalf("There should be 3 running container, got %d", len(lines))
|
||||
}
|
||||
for _, line := range lines {
|
||||
f := strings.Fields(line)
|
||||
switch f[0] {
|
||||
case id1:
|
||||
if f[1] != "busybox:latest" {
|
||||
if f[1] != "busybox" {
|
||||
t.Fatalf("Expected %s tag for id %s, got %s", "busybox", id1, f[1])
|
||||
}
|
||||
case id2:
|
||||
if f[1] != tag {
|
||||
t.Fatalf("Expected %s tag for id %s, got %s", tag, id1, f[1])
|
||||
t.Fatalf("Expected %s tag for id %s, got %s", tag, id2, f[1])
|
||||
}
|
||||
case id3:
|
||||
if f[1] != imageID {
|
||||
t.Fatalf("Expected %s imageID for id %s, got %s", tag, id3, f[1])
|
||||
}
|
||||
default:
|
||||
t.Fatalf("Unexpected id %s, expected %s and %s", f[0], id1, id2)
|
||||
t.Fatalf("Unexpected id %s, expected %s and %s and %s", f[0], id1, id2, id3)
|
||||
}
|
||||
}
|
||||
logDone("ps - right tags for containers")
|
||||
|
|
Loading…
Reference in a new issue