Use image lists in client tests

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko 2022-07-25 10:47:00 -07:00
parent db3ecb286b
commit 552d763447
21 changed files with 95 additions and 74 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

@ -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

@ -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,12 +29,12 @@ 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")
EnsureImageExists(t, pauseImage) EnsureImageExists(t, images.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")
containerConfig := ContainerConfig( containerConfig := ContainerConfig(
"container1", "container1",
pauseImage, images.PauseImage,
WithTestLabels(), WithTestLabels(),
WithTestAnnotations(), WithTestAnnotations(),
) )
@ -62,12 +63,12 @@ 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")
EnsureImageExists(t, pauseImage) EnsureImageExists(t, images.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")
containerConfig := ContainerConfig( containerConfig := ContainerConfig(
"container1", "container1",
pauseImage, images.PauseImage,
WithCommand("something-that-doesnt-exist"), WithCommand("something-that-doesnt-exist"),
WithTestLabels(), WithTestLabels(),
WithTestAnnotations(), WithTestAnnotations(),
@ -88,7 +89,7 @@ func TestFailedContainerRestart(t *testing.T) {
containerConfig = ContainerConfig( containerConfig = ContainerConfig(
"container1", "container1",
pauseImage, images.PauseImage,
WithTestLabels(), WithTestLabels(),
WithTestAnnotations(), WithTestAnnotations(),
) )

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,12 +34,12 @@ 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")
EnsureImageExists(t, pauseImage) EnsureImageExists(t, images.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")
containerConfig := ContainerConfig( containerConfig := ContainerConfig(
"container1", "container1",
pauseImage, images.PauseImage,
WithTestLabels(), WithTestLabels(),
WithTestAnnotations(), WithTestAnnotations(),
) )
@ -74,7 +75,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,7 +146,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")
EnsureImageExists(t, pauseImage) EnsureImageExists(t, images.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")
containerConfigMap := make(map[string]*runtime.ContainerConfig) containerConfigMap := make(map[string]*runtime.ContainerConfig)
@ -153,7 +154,7 @@ func TestContainerListStats(t *testing.T) {
cName := fmt.Sprintf("container%d", i) cName := fmt.Sprintf("container%d", i)
containerConfig := ContainerConfig( containerConfig := ContainerConfig(
cName, cName,
pauseImage, images.PauseImage,
WithTestLabels(), WithTestLabels(),
WithTestAnnotations(), WithTestAnnotations(),
) )
@ -199,7 +200,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")
EnsureImageExists(t, pauseImage) EnsureImageExists(t, images.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")
containerConfigMap := make(map[string]*runtime.ContainerConfig) containerConfigMap := make(map[string]*runtime.ContainerConfig)
@ -207,7 +208,7 @@ func TestContainerListStatsWithIdFilter(t *testing.T) {
cName := fmt.Sprintf("container%d", i) cName := fmt.Sprintf("container%d", i)
containerConfig := ContainerConfig( containerConfig := ContainerConfig(
cName, cName,
pauseImage, images.PauseImage,
WithTestLabels(), WithTestLabels(),
WithTestAnnotations(), WithTestAnnotations(),
) )
@ -258,7 +259,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")
EnsureImageExists(t, pauseImage) EnsureImageExists(t, images.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")
containerConfigMap := make(map[string]*runtime.ContainerConfig) containerConfigMap := make(map[string]*runtime.ContainerConfig)
@ -266,7 +267,7 @@ func TestContainerListStatsWithSandboxIdFilter(t *testing.T) {
cName := fmt.Sprintf("container%d", i) cName := fmt.Sprintf("container%d", i)
containerConfig := ContainerConfig( containerConfig := ContainerConfig(
cName, cName,
pauseImage, images.PauseImage,
WithTestLabels(), WithTestLabels(),
WithTestAnnotations(), WithTestAnnotations(),
) )
@ -318,7 +319,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")
EnsureImageExists(t, pauseImage) EnsureImageExists(t, images.PauseImage)
t.Logf("Create container config and run containers in a pod") t.Logf("Create container config and run containers in a pod")
containerConfigMap := make(map[string]*runtime.ContainerConfig) containerConfigMap := make(map[string]*runtime.ContainerConfig)
@ -326,7 +327,7 @@ func TestContainerListStatsWithIdSandboxIdFilter(t *testing.T) {
cName := fmt.Sprintf("container%d", i) cName := fmt.Sprintf("container%d", i)
containerConfig := ContainerConfig( containerConfig := ContainerConfig(
cName, cName,
pauseImage, images.PauseImage,
WithTestLabels(), WithTestLabels(),
WithTestAnnotations(), WithTestAnnotations(),
) )

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,7 +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")
EnsureImageExists(t, pauseImage) EnsureImageExists(t, images.PauseImage)
memoryLimit := int64(128 * 1024 * 1024) memoryLimit := int64(128 * 1024 * 1024)
baseSwapLimit := int64(200 * 1024 * 1024) baseSwapLimit := int64(200 * 1024 * 1024)
@ -168,7 +169,7 @@ func TestUpdateContainerResources_MemorySwap(t *testing.T) {
t.Log("Create a container with memory limit but no swap") t.Log("Create a container with memory limit but no swap")
cnConfig := ContainerConfig( cnConfig := ContainerConfig(
"container", "container",
pauseImage, images.PauseImage,
WithResources(&runtime.LinuxContainerResources{ WithResources(&runtime.LinuxContainerResources{
MemoryLimitInBytes: memoryLimit, MemoryLimitInBytes: memoryLimit,
MemorySwapLimitInBytes: baseSwapLimit, MemorySwapLimitInBytes: baseSwapLimit,
@ -223,12 +224,12 @@ 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")
EnsureImageExists(t, pauseImage) EnsureImageExists(t, images.PauseImage)
t.Log("Create a container with memory limit") t.Log("Create a container with memory limit")
cnConfig := ContainerConfig( cnConfig := ContainerConfig(
"container", "container",
pauseImage, images.PauseImage,
WithResources(&runtime.LinuxContainerResources{ WithResources(&runtime.LinuxContainerResources{
MemoryLimitInBytes: 200 * 1024 * 1024, MemoryLimitInBytes: 200 * 1024 * 1024,
}), }),

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,12 +31,12 @@ func TestDuplicateName(t *testing.T) {
_, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler) _, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
require.Error(t, err) require.Error(t, err)
EnsureImageExists(t, pauseImage) EnsureImageExists(t, images.PauseImage)
t.Logf("Create a container") t.Logf("Create a container")
cnConfig := ContainerConfig( cnConfig := ContainerConfig(
"container", "container",
pauseImage, images.PauseImage,
) )
_, err = runtimeService.CreateContainer(sb, cnConfig, sbConfig) _, err = runtimeService.CreateContainer(sb, cnConfig, sbConfig)
require.NoError(t, err) require.NoError(t, err)

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,19 @@
limitations under the License. limitations under the License.
*/ */
package integration package images
import ( import (
"flag"
"fmt" "fmt"
"os" "os"
"testing"
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 +38,15 @@ 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 PauseImage string // This is the same with default sandbox image
) )
func init() {
initImages(*imageListFile)
}
func initImages(imageListFile string) { func initImages(imageListFile string) {
imageList = ImageList{ imageList = ImageList{
Alpine: "docker.io/library/alpine:latest", Alpine: "docker.io/library/alpine:latest",
@ -70,7 +72,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) PauseImage = Get(Pause)
} }
const ( const (
@ -101,24 +103,7 @@ 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 {
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

@ -54,6 +54,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 +63,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 +505,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,12 +109,12 @@ func TestContainerdRestart(t *testing.T) {
runtimeService.RemovePodSandbox(sid) runtimeService.RemovePodSandbox(sid)
}() }()
EnsureImageExists(t, pauseImage) EnsureImageExists(t, images.PauseImage)
s.id = sid s.id = sid
for j := range s.containers { for j := range s.containers {
c := &s.containers[j] c := &s.containers[j]
cfg := ContainerConfig(c.name, pauseImage, cfg := ContainerConfig(c.name, images.PauseImage,
// Set pid namespace as per container, so that container won't die // Set pid namespace as per container, so that container won't die
// when sandbox container is killed. // when sandbox container is killed.
WithPidNamespace(runtime.NamespaceMode_CONTAINER), WithPidNamespace(runtime.NamespaceMode_CONTAINER),
@ -170,7 +171,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
) )