Merge pull request #7210 from mxpv/image-list

Use image lists form integration/client tests
This commit is contained in:
Phil Estes 2022-07-26 12:09:41 -04:00 committed by GitHub
commit 584110f0b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 100 additions and 58 deletions

View File

@ -25,6 +25,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -38,7 +40,7 @@ func TestAdditionalGids(t *testing.T) {
WithPodLogDirectory(testPodLogDir)) WithPodLogDirectory(testPodLogDir))
var ( var (
testImage = GetImage(BusyBox) testImage = images.Get(images.BusyBox)
containerName = "test-container" containerName = "test-container"
) )

View File

@ -30,6 +30,7 @@ import (
"github.com/containerd/containerd/defaults" "github.com/containerd/containerd/defaults"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images" "github.com/containerd/containerd/images"
imagelist "github.com/containerd/containerd/integration/images"
"github.com/containerd/containerd/leases" "github.com/containerd/containerd/leases"
"github.com/containerd/containerd/log" "github.com/containerd/containerd/log"
"github.com/containerd/containerd/log/logtest" "github.com/containerd/containerd/log/logtest"
@ -333,7 +334,7 @@ func TestImagePullAllPlatforms(t *testing.T) {
defer cancel() defer cancel()
cs := client.ContentStore() cs := client.ContentStore()
img, err := client.Fetch(ctx, "k8s.gcr.io/pause:3.7") img, err := client.Fetch(ctx, imagelist.Get(imagelist.Pause))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -23,6 +23,7 @@ import (
"testing" "testing"
. "github.com/containerd/containerd" . "github.com/containerd/containerd"
"github.com/containerd/containerd/integration/images"
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
) )
@ -33,8 +34,8 @@ const (
) )
var ( var (
testImage = "ghcr.io/containerd/busybox:1.32" testImage = images.Get(images.BusyBox)
testMultiLayeredImage = "ghcr.io/containerd/volume-copy-up:2.1" testMultiLayeredImage = images.Get(images.VolumeCopyUp)
shortCommand = withProcessArgs("true") shortCommand = withProcessArgs("true")
longCommand = withProcessArgs("/bin/sh", "-c", "while true; do sleep 1; done") longCommand = withProcessArgs("/bin/sh", "-c", "while true; do sleep 1; done")
) )

View File

@ -26,12 +26,13 @@ import (
. "github.com/containerd/containerd" . "github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images" "github.com/containerd/containerd/images"
imagelist "github.com/containerd/containerd/integration/images"
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
ocispec "github.com/opencontainers/image-spec/specs-go/v1" ocispec "github.com/opencontainers/image-spec/specs-go/v1"
) )
func TestImageIsUnpacked(t *testing.T) { func TestImageIsUnpacked(t *testing.T) {
const imageName = "k8s.gcr.io/pause:3.7" imageName := imagelist.Get(imagelist.Pause)
ctx, cancel := testContext(t) ctx, cancel := testContext(t)
defer cancel() defer cancel()
@ -137,7 +138,7 @@ func TestImageUsage(t *testing.T) {
t.Skip() t.Skip()
} }
imageName := "k8s.gcr.io/pause:3.7" imageName := imagelist.Get(imagelist.Pause)
ctx, cancel := testContext(t) ctx, cancel := testContext(t)
defer cancel() defer cancel()

View File

@ -23,6 +23,7 @@ import (
. "github.com/containerd/containerd" . "github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images" "github.com/containerd/containerd/images"
imagelist "github.com/containerd/containerd/integration/images"
"github.com/containerd/containerd/leases" "github.com/containerd/containerd/leases"
"github.com/opencontainers/image-spec/identity" "github.com/opencontainers/image-spec/identity"
) )
@ -55,7 +56,7 @@ func TestLeaseResources(t *testing.T) {
defer ls.Delete(ctx, l, leases.SynchronousDelete) defer ls.Delete(ctx, l, leases.SynchronousDelete)
// step 1: download image // step 1: download image
imageName := "k8s.gcr.io/pause:3.7" imageName := imagelist.Get(imagelist.Pause)
image, err := client.Pull(ctx, imageName, WithPullUnpack, WithPullSnapshotter(snapshotterName)) image, err := client.Pull(ctx, imageName, WithPullUnpack, WithPullSnapshotter(snapshotterName))
if err != nil { if err != nil {

View File

@ -24,6 +24,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -38,7 +40,7 @@ func TestContainerLogWithoutTailingNewLine(t *testing.T) {
) )
var ( var (
testImage = GetImage(BusyBox) testImage = images.Get(images.BusyBox)
containerName = "test-container" containerName = "test-container"
) )
@ -86,7 +88,7 @@ func TestLongContainerLog(t *testing.T) {
) )
var ( var (
testImage = GetImage(BusyBox) testImage = images.Get(images.BusyBox)
containerName = "test-container" containerName = "test-container"
) )

View File

@ -19,6 +19,7 @@ package integration
import ( import (
"testing" "testing"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -28,6 +29,7 @@ func TestContainerRestart(t *testing.T) {
t.Logf("Create a pod config and run sandbox container") t.Logf("Create a pod config and run sandbox container")
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "restart") sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "restart")
pauseImage := images.Get(images.Pause)
EnsureImageExists(t, pauseImage) EnsureImageExists(t, pauseImage)
t.Logf("Create a container config and run container in a pod") t.Logf("Create a container config and run container in a pod")
@ -62,6 +64,7 @@ func TestFailedContainerRestart(t *testing.T) {
t.Logf("Create a pod config and run sandbox container") t.Logf("Create a pod config and run sandbox container")
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "restart") sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "restart")
pauseImage := images.Get(images.Pause)
EnsureImageExists(t, pauseImage) EnsureImageExists(t, pauseImage)
t.Logf("Create a container config in a pod with a command that fails") t.Logf("Create a container config in a pod with a command that fails")

View File

@ -23,6 +23,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -33,6 +34,7 @@ func TestContainerStats(t *testing.T) {
t.Logf("Create a pod config and run sandbox container") t.Logf("Create a pod config and run sandbox container")
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "stats") sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "stats")
pauseImage := images.Get(images.Pause)
EnsureImageExists(t, pauseImage) EnsureImageExists(t, pauseImage)
t.Logf("Create a container config and run container in a pod") t.Logf("Create a container config and run container in a pod")
@ -74,7 +76,7 @@ func TestContainerConsumedStats(t *testing.T) {
t.Logf("Create a pod config and run sandbox container") t.Logf("Create a pod config and run sandbox container")
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "stats") sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "stats")
testImage := GetImage(ResourceConsumer) testImage := images.Get(images.ResourceConsumer)
EnsureImageExists(t, testImage) EnsureImageExists(t, testImage)
t.Logf("Create a container config and run container in a pod") t.Logf("Create a container config and run container in a pod")
@ -145,6 +147,7 @@ func TestContainerListStats(t *testing.T) {
t.Logf("Create a pod config and run sandbox container") t.Logf("Create a pod config and run sandbox container")
sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls") sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls")
pauseImage := images.Get(images.Pause)
EnsureImageExists(t, pauseImage) EnsureImageExists(t, pauseImage)
t.Logf("Create a container config and run containers in a pod") t.Logf("Create a container config and run containers in a pod")
@ -199,6 +202,7 @@ func TestContainerListStatsWithIdFilter(t *testing.T) {
t.Logf("Create a pod config and run sandbox container") t.Logf("Create a pod config and run sandbox container")
sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls") sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls")
pauseImage := images.Get(images.Pause)
EnsureImageExists(t, pauseImage) EnsureImageExists(t, pauseImage)
t.Logf("Create a container config and run containers in a pod") t.Logf("Create a container config and run containers in a pod")
@ -258,6 +262,7 @@ func TestContainerListStatsWithSandboxIdFilter(t *testing.T) {
t.Logf("Create a pod config and run sandbox container") t.Logf("Create a pod config and run sandbox container")
sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls") sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls")
pauseImage := images.Get(images.Pause)
EnsureImageExists(t, pauseImage) EnsureImageExists(t, pauseImage)
t.Logf("Create a container config and run containers in a pod") t.Logf("Create a container config and run containers in a pod")
@ -318,6 +323,7 @@ func TestContainerListStatsWithIdSandboxIdFilter(t *testing.T) {
t.Logf("Create a pod config and run sandbox container") t.Logf("Create a pod config and run sandbox container")
sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls") sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls")
pauseImage := images.Get(images.Pause)
EnsureImageExists(t, pauseImage) EnsureImageExists(t, pauseImage)
t.Logf("Create container config and run containers in a pod") t.Logf("Create container config and run containers in a pod")

View File

@ -22,6 +22,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -42,7 +43,7 @@ func TestSharedPidMultiProcessContainerStop(t *testing.T) {
}() }()
var ( var (
testImage = GetImage(BusyBox) testImage = images.Get(images.BusyBox)
containerName = "test-container" containerName = "test-container"
) )
@ -79,7 +80,7 @@ func TestContainerStopCancellation(t *testing.T) {
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "cancel-container-stop") sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "cancel-container-stop")
var ( var (
testImage = GetImage(BusyBox) testImage = images.Get(images.BusyBox)
containerName = "test-container" containerName = "test-container"
) )

View File

@ -29,6 +29,7 @@ import (
"github.com/containerd/cgroups" "github.com/containerd/cgroups"
cgroupsv2 "github.com/containerd/cgroups/v2" cgroupsv2 "github.com/containerd/cgroups/v2"
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/containerd/containerd/integration/images"
runtimespec "github.com/opencontainers/runtime-spec/specs-go" runtimespec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -151,6 +152,7 @@ func TestUpdateContainerResources_MemorySwap(t *testing.T) {
t.Log("Create a sandbox") t.Log("Create a sandbox")
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "update-container-swap-resources") sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "update-container-swap-resources")
pauseImage := images.Get(images.Pause)
EnsureImageExists(t, pauseImage) EnsureImageExists(t, pauseImage)
memoryLimit := int64(128 * 1024 * 1024) memoryLimit := int64(128 * 1024 * 1024)
@ -223,6 +225,7 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
t.Log("Create a sandbox") t.Log("Create a sandbox")
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "update-container-resources") sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "update-container-resources")
pauseImage := images.Get(images.Pause)
EnsureImageExists(t, pauseImage) EnsureImageExists(t, pauseImage)
t.Log("Create a container with memory limit") t.Log("Create a container with memory limit")

View File

@ -23,6 +23,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -99,7 +100,7 @@ func TestContainerSymlinkVolumes(t *testing.T) {
) )
var ( var (
testImage = GetImage(BusyBox) testImage = images.Get(images.BusyBox)
containerName = "test-container" containerName = "test-container"
containerMountPath = "/mounted_file" containerMountPath = "/mounted_file"
) )

View File

@ -19,6 +19,7 @@ package integration
import ( import (
"testing" "testing"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -30,7 +31,7 @@ func TestContainerLifecycleWithoutImageRef(t *testing.T) {
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "container-lifecycle-without-image-ref") sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "container-lifecycle-without-image-ref")
var ( var (
testImage = GetImage(BusyBox) testImage = images.Get(images.BusyBox)
containerName = "test-container" containerName = "test-container"
) )

View File

@ -25,6 +25,7 @@ import (
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/integration/images"
"github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/namespaces"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -33,7 +34,7 @@ import (
// Test to test the CRI plugin should see image pulled into containerd directly. // Test to test the CRI plugin should see image pulled into containerd directly.
func TestContainerdImage(t *testing.T) { func TestContainerdImage(t *testing.T) {
var testImage = GetImage(BusyBox) var testImage = images.Get(images.BusyBox)
ctx := context.Background() ctx := context.Background()
t.Logf("make sure the test image doesn't exist in the cri plugin") t.Logf("make sure the test image doesn't exist in the cri plugin")
@ -150,7 +151,7 @@ func TestContainerdImage(t *testing.T) {
// Test image managed by CRI plugin shouldn't be affected by images in other namespaces. // Test image managed by CRI plugin shouldn't be affected by images in other namespaces.
func TestContainerdImageInOtherNamespaces(t *testing.T) { func TestContainerdImageInOtherNamespaces(t *testing.T) {
var testImage = GetImage(BusyBox) var testImage = images.Get(images.BusyBox)
ctx := context.Background() ctx := context.Background()
t.Logf("make sure the test image doesn't exist in the cri plugin") t.Logf("make sure the test image doesn't exist in the cri plugin")

View File

@ -19,6 +19,7 @@ package integration
import ( import (
"testing" "testing"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -30,6 +31,7 @@ func TestDuplicateName(t *testing.T) {
_, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler) _, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
require.Error(t, err) require.Error(t, err)
pauseImage := images.Get(images.Pause)
EnsureImageExists(t, pauseImage) EnsureImageExists(t, pauseImage)
t.Logf("Create a container") t.Logf("Create a container")

View File

@ -21,6 +21,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
exec "golang.org/x/sys/execabs" exec "golang.org/x/sys/execabs"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -28,7 +29,7 @@ import (
// Test to load an image from tarball. // Test to load an image from tarball.
func TestImageLoad(t *testing.T) { func TestImageLoad(t *testing.T) {
testImage := GetImage(BusyBox) testImage := images.Get(images.BusyBox)
loadedImage := testImage loadedImage := testImage
_, err := exec.LookPath("docker") _, err := exec.LookPath("docker")
if err != nil { if err != nil {

View File

@ -22,6 +22,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -32,7 +33,7 @@ func TestImageFSInfo(t *testing.T) {
PodSandboxConfigWithCleanup(t, "running-pod", "imagefs") PodSandboxConfigWithCleanup(t, "running-pod", "imagefs")
t.Logf("Pull an image to make sure image fs is not empty") t.Logf("Pull an image to make sure image fs is not empty")
EnsureImageExists(t, GetImage(BusyBox)) EnsureImageExists(t, images.Get(images.BusyBox))
// It takes time to populate imagefs stats. Use eventually // It takes time to populate imagefs stats. Use eventually
// to check for a period of time. // to check for a period of time.

View File

@ -14,20 +14,20 @@
limitations under the License. limitations under the License.
*/ */
package integration package images
import ( import (
"flag"
"fmt" "fmt"
"os" "os"
"testing" "sync"
cri "github.com/containerd/containerd/integration/cri-api/pkg/apis"
"github.com/pelletier/go-toml" "github.com/pelletier/go-toml"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
) )
var imageListFile = flag.String("image-list", "", "The TOML file containing the non-default images to be used in tests.")
// ImageList holds public image references // ImageList holds public image references
type ImageList struct { type ImageList struct {
Alpine string Alpine string
@ -39,12 +39,12 @@ type ImageList struct {
} }
var ( var (
imageService cri.ImageManagerService
imageMap map[int]string imageMap map[int]string
imageList ImageList imageList ImageList
pauseImage string // This is the same with default sandbox image
) )
var initOnce sync.Once
func initImages(imageListFile string) { func initImages(imageListFile string) {
imageList = ImageList{ imageList = ImageList{
Alpine: "docker.io/library/alpine:latest", Alpine: "docker.io/library/alpine:latest",
@ -56,6 +56,8 @@ func initImages(imageListFile string) {
} }
if imageListFile != "" { if imageListFile != "" {
logrus.Infof("loading image list from file: %s", imageListFile)
fileContent, err := os.ReadFile(imageListFile) fileContent, err := os.ReadFile(imageListFile)
if err != nil { if err != nil {
panic(fmt.Errorf("error reading '%v' file contents: %v", imageList, err)) panic(fmt.Errorf("error reading '%v' file contents: %v", imageList, err))
@ -68,9 +70,7 @@ func initImages(imageListFile string) {
} }
logrus.Infof("Using the following image list: %+v", imageList) logrus.Infof("Using the following image list: %+v", imageList)
imageMap = initImageMap(imageList) imageMap = initImageMap(imageList)
pauseImage = GetImage(Pause)
} }
const ( const (
@ -101,24 +101,11 @@ func initImageMap(imageList ImageList) map[int]string {
return images return images
} }
// GetImage returns the fully qualified URI to an image (including version) // Get returns the fully qualified URI to an image (including version)
func GetImage(image int) string { func Get(image int) string {
initOnce.Do(func() {
initImages(*imageListFile)
})
return imageMap[image] return imageMap[image]
} }
// EnsureImageExists pulls the given image, ensures that no error was encountered
// while pulling it.
func EnsureImageExists(t *testing.T, imageName string) string {
img, err := imageService.ImageStatus(&runtime.ImageSpec{Image: imageName})
require.NoError(t, err)
if img != nil {
t.Logf("Image %q already exists, not pulling.", imageName)
return img.Id
}
t.Logf("Pull test image %q", imageName)
imgID, err := imageService.PullImage(&runtime.ImageSpec{Image: imageName}, nil, nil)
require.NoError(t, err)
return imgID
}

View File

@ -32,6 +32,7 @@ import (
"github.com/containerd/containerd" "github.com/containerd/containerd"
cri "github.com/containerd/containerd/integration/cri-api/pkg/apis" cri "github.com/containerd/containerd/integration/cri-api/pkg/apis"
_ "github.com/containerd/containerd/integration/images" // Keep this around to parse `imageListFile` command line var
"github.com/containerd/containerd/integration/remote" "github.com/containerd/containerd/integration/remote"
dialer "github.com/containerd/containerd/integration/remote/util" dialer "github.com/containerd/containerd/integration/remote/util"
criconfig "github.com/containerd/containerd/pkg/cri/config" criconfig "github.com/containerd/containerd/pkg/cri/config"
@ -54,6 +55,7 @@ const (
var ( var (
runtimeService cri.RuntimeService runtimeService cri.RuntimeService
imageService cri.ImageManagerService
containerdClient *containerd.Client containerdClient *containerd.Client
containerdEndpoint string containerdEndpoint string
) )
@ -62,11 +64,9 @@ var criEndpoint = flag.String("cri-endpoint", "unix:///run/containerd/containerd
var criRoot = flag.String("cri-root", "/var/lib/containerd/io.containerd.grpc.v1.cri", "The root directory of cri plugin.") var criRoot = flag.String("cri-root", "/var/lib/containerd/io.containerd.grpc.v1.cri", "The root directory of cri plugin.")
var runtimeHandler = flag.String("runtime-handler", "", "The runtime handler to use in the test.") var runtimeHandler = flag.String("runtime-handler", "", "The runtime handler to use in the test.")
var containerdBin = flag.String("containerd-bin", "containerd", "The containerd binary name. The name is used to restart containerd during test.") var containerdBin = flag.String("containerd-bin", "containerd", "The containerd binary name. The name is used to restart containerd during test.")
var imageListFile = flag.String("image-list", "", "The TOML file containing the non-default images to be used in tests.")
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
flag.Parse() flag.Parse()
initImages(*imageListFile)
if err := ConnectDaemons(); err != nil { if err := ConnectDaemons(); err != nil {
logrus.WithError(err).Fatalf("Failed to connect daemons") logrus.WithError(err).Fatalf("Failed to connect daemons")
} }
@ -506,3 +506,20 @@ func RestartContainerd(t *testing.T) {
return ConnectDaemons() == nil, nil return ConnectDaemons() == nil, nil
}, time.Second, 30*time.Second), "wait for containerd to be restarted") }, time.Second, 30*time.Second), "wait for containerd to be restarted")
} }
// EnsureImageExists pulls the given image, ensures that no error was encountered
// while pulling it.
func EnsureImageExists(t *testing.T, imageName string) string {
img, err := imageService.ImageStatus(&runtime.ImageSpec{Image: imageName})
require.NoError(t, err)
if img != nil {
t.Logf("Image %q already exists, not pulling.", imageName)
return img.Id
}
t.Logf("Pull test image %q", imageName)
imgID, err := imageService.PullImage(&runtime.ImageSpec{Image: imageName}, nil, nil)
require.NoError(t, err)
return imgID
}

View File

@ -25,6 +25,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -37,7 +38,7 @@ func TestPodDualStack(t *testing.T) {
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "dualstack", WithPodLogDirectory(testPodLogDir)) sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "dualstack", WithPodLogDirectory(testPodLogDir))
var ( var (
testImage = GetImage(BusyBox) testImage = images.Get(images.BusyBox)
containerName = "test-container" containerName = "test-container"
) )

View File

@ -24,6 +24,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -86,7 +87,7 @@ func TestPodHostname(t *testing.T) {
} }
var ( var (
testImage = GetImage(BusyBox) testImage = images.Get(images.BusyBox)
containerName = "test-container" containerName = "test-container"
) )

View File

@ -26,6 +26,7 @@ import (
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -108,6 +109,7 @@ func TestContainerdRestart(t *testing.T) {
runtimeService.RemovePodSandbox(sid) runtimeService.RemovePodSandbox(sid)
}() }()
pauseImage := images.Get(images.Pause)
EnsureImageExists(t, pauseImage) EnsureImageExists(t, pauseImage)
s.id = sid s.id = sid
@ -170,7 +172,7 @@ func TestContainerdRestart(t *testing.T) {
} }
t.Logf("Pull test images") t.Logf("Pull test images")
for _, image := range []string{GetImage(BusyBox), GetImage(Pause)} { for _, image := range []string{images.Get(images.BusyBox), images.Get(images.Pause)} {
EnsureImageExists(t, image) EnsureImageExists(t, image)
} }
imagesBeforeRestart, err := imageService.ListImages(nil) imagesBeforeRestart, err := imageService.ListImages(nil)

View File

@ -20,6 +20,7 @@ import (
goruntime "runtime" goruntime "runtime"
"testing" "testing"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -33,7 +34,7 @@ func TestTruncIndex(t *testing.T) {
sbConfig := PodSandboxConfig("sandbox", "truncindex") sbConfig := PodSandboxConfig("sandbox", "truncindex")
t.Logf("Pull an image") t.Logf("Pull an image")
var appImage = GetImage(BusyBox) var appImage = images.Get(images.BusyBox)
imgID := EnsureImageExists(t, appImage) imgID := EnsureImageExists(t, appImage)
imgTruncID := genTruncIndex(imgID) imgTruncID := genTruncIndex(imgID)

View File

@ -24,6 +24,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -37,7 +38,7 @@ const (
func TestVolumeCopyUp(t *testing.T) { func TestVolumeCopyUp(t *testing.T) {
var ( var (
testImage = GetImage(VolumeCopyUp) testImage = images.Get(images.VolumeCopyUp)
execTimeout = time.Minute execTimeout = time.Minute
) )
@ -95,7 +96,7 @@ func TestVolumeCopyUp(t *testing.T) {
func TestVolumeOwnership(t *testing.T) { func TestVolumeOwnership(t *testing.T) {
var ( var (
testImage = GetImage(VolumeOwnership) testImage = images.Get(images.VolumeOwnership)
execTimeout = time.Minute execTimeout = time.Minute
) )

View File

@ -26,6 +26,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -41,7 +42,7 @@ func TestWindowsDevice(t *testing.T) {
var ( var (
// TODO: An image with the device-dumper // TODO: An image with the device-dumper
testImage = GetImage(BusyBox) testImage = images.Get(images.BusyBox)
containerName = "test-container" containerName = "test-container"
) )

View File

@ -24,6 +24,7 @@ import (
"os" "os"
"testing" "testing"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -37,6 +38,7 @@ var (
// Tests to verify the Windows HostProcess // Tests to verify the Windows HostProcess
func TestWindowsHostProcess(t *testing.T) { func TestWindowsHostProcess(t *testing.T) {
pauseImage := images.Get(images.Pause)
EnsureImageExists(t, pauseImage) EnsureImageExists(t, pauseImage)
t.Run("run as Local Service", func(t *testing.T) { t.Run("run as Local Service", func(t *testing.T) {

View File

@ -28,6 +28,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/containerd/containerd/integration/images"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1" runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@ -42,7 +43,7 @@ func TestWindowsRootfsSize(t *testing.T) {
) )
var ( var (
testImage = GetImage(Pause) testImage = images.Get(images.Pause)
containerName = "test-container" containerName = "test-container"
) )