Use canonical names for the functional test images

And add some cleanup and improved logging as well
pull/11164/head
Anders F Björklund 2021-04-23 22:00:17 +02:00
parent c9a0a7a8aa
commit 5d8d3d3e55
1 changed files with 28 additions and 16 deletions

View File

@ -157,12 +157,19 @@ func cleanupUnwantedImages(ctx context.Context, t *testing.T, profile string) {
t.Skipf("docker is not installed, cannot delete docker images")
} else {
t.Run("delete busybox image", func(t *testing.T) {
newImage := fmt.Sprintf("busybox:%s", profile)
newImage := fmt.Sprintf("docker.io/library/busybox:%s", profile)
rr, err := Run(t, exec.CommandContext(ctx, "docker", "rmi", "-f", newImage))
if err != nil {
t.Logf("failed to remove image busybox from docker images. args %q: %v", rr.Command(), err)
}
})
t.Run("delete my-image image", func(t *testing.T) {
newImage := fmt.Sprintf("localhost/my-image:%s", profile)
rr, err := Run(t, exec.CommandContext(ctx, "docker", "rmi", "-f", newImage))
if err != nil {
t.Logf("failed to remove image my-image from docker images. args %q: %v", rr.Command(), err)
}
})
t.Run("delete minikube cached images", func(t *testing.T) {
img := "minikube-local-cache-test:" + profile
@ -208,7 +215,7 @@ func validateLoadImage(ctx context.Context, t *testing.T, profile string) {
}
// tag busybox
newImage := fmt.Sprintf("busybox:%s", profile)
newImage := fmt.Sprintf("docker.io/library/busybox:%s", profile)
rr, err = Run(t, exec.CommandContext(ctx, "docker", "tag", busybox, newImage))
if err != nil {
t.Fatalf("failed to setup test (tag image) : %v\n%s", err, rr.Output())
@ -260,13 +267,7 @@ func validateRemoveImage(ctx context.Context, t *testing.T, profile string) {
t.Fatalf("removing image from minikube: %v\n%s", err, rr.Output())
}
// make sure the image was removed
var cmd *exec.Cmd
if ContainerRuntime() == "docker" {
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "docker", "images")
} else {
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "sudo", "crictl", "images")
}
rr, err = Run(t, cmd)
rr, err = listImages(ctx, t, profile)
if err != nil {
t.Fatalf("listing images: %v\n%s", err, rr.Output())
}
@ -280,13 +281,22 @@ func inspectImage(ctx context.Context, t *testing.T, profile string, image strin
var cmd *exec.Cmd
if ContainerRuntime() == "docker" {
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "docker", "image", "inspect", image)
} else if ContainerRuntime() == "containerd" {
// crictl inspecti busybox:test-example
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "sudo", "crictl", "inspecti", image)
} else {
// crio adds localhost prefix
// crictl inspecti localhost/busybox:test-example
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "sudo", "crictl", "inspecti", "localhost/"+image)
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "sudo", "crictl", "inspecti", image)
}
rr, err := Run(t, cmd)
if err != nil {
return rr, err
}
return rr, nil
}
func listImages(ctx context.Context, t *testing.T, profile string) (*RunResult, error) {
var cmd *exec.Cmd
if ContainerRuntime() == "docker" {
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "docker", "images")
} else {
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "sudo", "crictl", "images")
}
rr, err := Run(t, cmd)
if err != nil {
@ -305,7 +315,7 @@ func validateBuildImage(ctx context.Context, t *testing.T, profile string) {
}
defer PostMortemLogs(t, profile)
newImage := "my-image"
newImage := fmt.Sprintf("localhost/my-image:%s", profile)
if ContainerRuntime() == "containerd" {
startBuildkit(ctx, t, profile)
// unix:///run/buildkit/buildkitd.sock
@ -326,6 +336,8 @@ func validateBuildImage(ctx context.Context, t *testing.T, profile string) {
// make sure the image was correctly built
rr, err = inspectImage(ctx, t, profile, newImage)
if err != nil {
ll, _ := listImages(ctx, t, profile)
t.Logf("(dbg) images: %s", ll.Output())
t.Fatalf("listing images: %v\n%s", err, rr.Output())
}
if !strings.Contains(rr.Output(), newImage) {