
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>
75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
// +build linux
|
|
|
|
/*
|
|
Copyright The containerd Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package integration
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
|
)
|
|
|
|
func TestImageFSInfo(t *testing.T) {
|
|
config := PodSandboxConfig("running-pod", "imagefs")
|
|
|
|
t.Logf("Pull an image to make sure image fs is not empty")
|
|
EnsureImageExists(t, GetImage(BusyBox))
|
|
|
|
t.Logf("Create a sandbox to make sure there is an active snapshot")
|
|
sb, err := runtimeService.RunPodSandbox(config, *runtimeHandler)
|
|
require.NoError(t, err)
|
|
defer func() {
|
|
assert.NoError(t, runtimeService.StopPodSandbox(sb))
|
|
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
|
|
}()
|
|
|
|
// It takes time to populate imagefs stats. Use eventually
|
|
// to check for a period of time.
|
|
t.Logf("Check imagefs info")
|
|
var info *runtime.FilesystemUsage
|
|
require.NoError(t, Eventually(func() (bool, error) {
|
|
stats, err := imageService.ImageFsInfo()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if len(stats) == 0 {
|
|
return false, nil
|
|
}
|
|
if len(stats) >= 2 {
|
|
return false, errors.Errorf("unexpected stats length: %d", len(stats))
|
|
}
|
|
info = stats[0]
|
|
if info.GetTimestamp() != 0 &&
|
|
info.GetUsedBytes().GetValue() != 0 &&
|
|
info.GetInodesUsed().GetValue() != 0 &&
|
|
info.GetFsId().GetMountpoint() != "" {
|
|
return true, nil
|
|
}
|
|
return false, nil
|
|
}, time.Second, 30*time.Second))
|
|
|
|
t.Logf("Image filesystem mountpath should exist")
|
|
_, err = os.Stat(info.GetFsId().GetMountpoint())
|
|
assert.NoError(t, err)
|
|
}
|