MCPcopy
hub / github.com/containerd/containerd / TestImageLoad

Function TestImageLoad

integration/image_load_test.go:33–109  ·  view source on GitHub ↗

Test to load an image from tarball.

(t *testing.T)

Source from the content-addressed store, hash-verified

31
32// Test to load an image from tarball.
33func TestImageLoad(t *testing.T) {
34 // TODO(kiashok): Docker is not able to pull the right
35 // image manifest of `testImage` on WS2025 host. Temporarily
36 // skipping this test for WS2025 while its fixed on docker.
37 // This test is validated on WS2022 anyway.
38 if goruntime.GOOS == "windows" && client.SkipTestOnHost() {
39 t.Skip("Temporarily skip validating on WS2025")
40 }
41
42 testImage := images.Get(images.BusyBox)
43 loadedImage := testImage
44 _, err := exec.LookPath("docker")
45 if err != nil {
46 t.Skipf("Docker is not available: %v", err)
47 }
48 t.Logf("docker save image into tarball")
49 output, err := exec.Command("docker", "pull", testImage).CombinedOutput()
50 require.NoError(t, err, "output: %q", output)
51 // os.CreateTemp also opens a file, which might prevent us from overwriting that file with docker save.
52 tarDir := t.TempDir()
53 tar := filepath.Join(tarDir, "image.tar")
54 require.NoError(t, err)
55 output, err = exec.Command("docker", "save", testImage, "-o", tar).CombinedOutput()
56 require.NoError(t, err, "output: %q", output)
57
58 t.Logf("make sure no such image in cri")
59 img, err := imageService.ImageStatus(&runtime.ImageSpec{Image: testImage})
60 require.NoError(t, err)
61 if img != nil {
62 require.NoError(t, imageService.RemoveImage(&runtime.ImageSpec{Image: testImage}))
63 }
64
65 t.Logf("load image in cri")
66 ctr, err := exec.LookPath("ctr")
67 require.NoError(t, err, "ctr should be installed, make sure you've run `make install-deps`")
68 // Add --local=true option since currently the transfer service
69 // does not provide enough progress to avoid timeout
70 // and --platform to only check for manifests for this platform. The "ctr image import"
71 // command otherwise might fail, if the above docker commands use the containerd image
72 // store, as in that case `docker save` produces OCI artifacts referencing manifests for
73 // other platforms that are not included in what we downloaded. By specifying a platform, we
74 // just ignore the references to other platforms.
75 platform := "--platform=" + goruntime.GOOS + "/" + goruntime.GOARCH
76 output, err = exec.Command(ctr, "-address="+containerdEndpoint,
77 "-n=k8s.io", "images", "import", "--local=true",
78 platform, tar).CombinedOutput()
79 require.NoError(t, err, "output: %q", output)
80
81 t.Logf("make sure image is loaded")
82 // Use Eventually because the cri plugin needs a short period of time
83 // to pick up images imported into containerd directly.
84 require.NoError(t, Eventually(func() (bool, error) {
85 img, err = imageService.ImageStatus(&runtime.ImageSpec{Image: testImage})
86 if err != nil {
87 return false, err
88 }
89 return img != nil, nil
90 }, 100*time.Millisecond, 10*time.Second))

Callers

nothing calls this directly

Calls 12

SkipTestOnHostFunction · 0.92
GetFunction · 0.92
EventuallyFunction · 0.85
RandomizeFunction · 0.85
ContainerConfigFunction · 0.85
WithCommandFunction · 0.85
CreateContainerMethod · 0.65
StartContainerMethod · 0.65
ImageStatusMethod · 0.45
RemoveImageMethod · 0.45
ContainerStatusMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…