tests: Prepull images used in tests

Most of the tests are pulling and deleting the same test images, which
can be quite inefficient, especially on Windows nodes, where the images
are larger than the Linux ones (a nanoserver Container image is ~250MB
in size). We can instead pull them only once, and reuse them. This will
reduce the test run time on Windows considerably.

Additionally, some of the test images are currently hosted on dockerhub
(busybox image), which has introduced image ratelimiting in November 2020,
which means that test runners could potentially hit that limit faster with
the current implementation. This will reduce that risk.

Some tests are specifically deleting images, so we always have to ensure
that they are pulled.

Signed-off-by: Claudiu Belu <cbelu@cloudbasesolutions.com>
This commit is contained in:
Claudiu Belu
2021-04-19 20:51:42 +00:00
parent feee16e0e3
commit 273c2bb168
12 changed files with 45 additions and 78 deletions

View File

@@ -21,10 +21,13 @@ package integration
import (
"fmt"
"io/ioutil"
"testing"
"github.com/pelletier/go-toml"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
cri "k8s.io/cri-api/pkg/apis"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
)
// ImageList holds public image references
@@ -99,3 +102,20 @@ func initImageMap(imageList ImageList) map[int]string {
func GetImage(image int) string {
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
}