Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing internal tests from hcsshim's cri-containerd tests #1998

Merged
merged 6 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ updates:
- go
- tests
ignore:
# updating CRI would break tests that rely on `v1alpha2` API
- dependency-name: "k8s.io/cri-api"
# keep containerd and related dependencies in sync with the shim/the root repo
- dependency-name: "github.com/containerd/*"
# ignore patch version increment updates in test; they shouldn't be critical
Expand Down
2 changes: 1 addition & 1 deletion test/cri-containerd/argsescaped_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
)

func Test_ArgsEscaped_Exec(t *testing.T) {
Expand Down
17 changes: 0 additions & 17 deletions test/cri-containerd/container_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ var _containerBenchmarkTests = []struct {
Image string
Command []string
}{
{
Name: "LCOW",
Feature: featureLCOW,
Runtime: lcowRuntimeHandler,
Image: imageLcowAlpine,
Command: []string{"ash", "-c", "tail -f /dev/null"},
},
{
Name: "WCOW_Hypervisor",
Feature: featureWCOWHypervisor,
Expand Down Expand Up @@ -55,8 +48,6 @@ func BenchmarkPodCreate(b *testing.B) {
requireFeatures(b, tt.Feature)

switch tt.Feature {
case featureLCOW:
pullRequiredLCOWImages(b, append([]string{imageLcowK8sPause}, tt.Image))
case featureWCOWHypervisor, featureWCOWProcess:
pullRequiredImages(b, []string{tt.Image})
}
Expand Down Expand Up @@ -92,8 +83,6 @@ func BenchmarkContainerCreate(b *testing.B) {
requireFeatures(b, tt.Feature)

switch tt.Feature {
case featureLCOW:
pullRequiredLCOWImages(b, append([]string{imageLcowK8sPause}, tt.Image))
case featureWCOWHypervisor, featureWCOWProcess:
pullRequiredImages(b, []string{tt.Image})
}
Expand Down Expand Up @@ -127,8 +116,6 @@ func BenchmarkContainerCreate(b *testing.B) {
requireFeatures(b, tt.Feature)

switch tt.Feature {
case featureLCOW:
pullRequiredLCOWImages(b, append([]string{imageLcowK8sPause}, tt.Image))
case featureWCOWHypervisor, featureWCOWProcess:
pullRequiredImages(b, []string{tt.Image})
}
Expand Down Expand Up @@ -169,8 +156,6 @@ func BenchmarkContainerStart(b *testing.B) {
requireFeatures(b, tt.Feature)

switch tt.Feature {
case featureLCOW:
pullRequiredLCOWImages(b, append([]string{imageLcowK8sPause}, tt.Image))
case featureWCOWHypervisor, featureWCOWProcess:
pullRequiredImages(b, []string{tt.Image})
}
Expand Down Expand Up @@ -206,8 +191,6 @@ func BenchmarkContainerStart(b *testing.B) {
requireFeatures(b, tt.Feature)

switch tt.Feature {
case featureLCOW:
pullRequiredLCOWImages(b, append([]string{imageLcowK8sPause}, tt.Image))
case featureWCOWHypervisor, featureWCOWProcess:
pullRequiredImages(b, []string{tt.Image})
}
Expand Down
2 changes: 1 addition & 1 deletion test/cri-containerd/container_downlevel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/Microsoft/hcsshim/osversion"
"github.com/Microsoft/hcsshim/test/pkg/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
)

func Test_CreateContainer_DownLevel_WCOW_Hypervisor(t *testing.T) {
Expand Down
96 changes: 1 addition & 95 deletions test/cri-containerd/container_fileshare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/Microsoft/hcsshim/pkg/annotations"
"github.com/Microsoft/hcsshim/test/pkg/definitions/hcs"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
)

func Test_Container_File_Share_Writable_WCOW(t *testing.T) {
Expand Down Expand Up @@ -108,97 +108,3 @@ func Test_Container_File_Share_Writable_WCOW(t *testing.T) {
t.Fatalf("did not correctly read file; got %q, expected %q", output, testContent)
}
}

func Test_Container_File_Share_Writable_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW)

pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})

client := newTestRuntimeClient(t)
ctx := context.Background()

sbRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler,
WithSandboxAnnotations(map[string]string{
annotations.DisableWritableFileShares: "true",
}),
)
podID := runPodSandbox(t, client, ctx, sbRequest)
defer removePodSandbox(t, client, ctx, podID)
defer stopPodSandbox(t, client, ctx, podID)

var (
tempDir = t.TempDir()
containerPath = "/mnt/test"
testFile = "t.txt"
testContent = "hello world"
)

if err := os.WriteFile(
filepath.Join(tempDir, testFile),
[]byte(testContent),
0644,
); err != nil {
t.Fatalf("could not create test file: %v", err)
}

cRequest := &runtime.CreateContainerRequest{
Config: &runtime.ContainerConfig{
Metadata: &runtime.ContainerMetadata{
Name: t.Name(),
},
Image: &runtime.ImageSpec{
Image: imageLcowAlpine,
},
Command: []string{
"ash",
"-c",
"tail -f /dev/null",
},
Mounts: []*runtime.Mount{
{
HostPath: tempDir,
ContainerPath: containerPath,
Readonly: false,
},
},
},
PodSandboxId: podID,
SandboxConfig: sbRequest.Config,
}
cID := createContainer(t, client, ctx, cRequest)
defer removeContainer(t, client, ctx, cID)

// container should fail because of writable mount
_, err := client.StartContainer(ctx, &runtime.StartContainerRequest{ContainerId: cID})
if err == nil {
stopContainer(t, client, ctx, cID)
}
// error is serialized over gRPC then embedded into "rpc error: code = %s desc = %s"
// so error.Is() wont work
if err == nil || !strings.Contains(err.Error(), fmt.Errorf("adding writable shares is denied: %w", hcs.ErrOperationDenied).Error()) {
t.Fatalf("StartContainer did not fail with writable fileshare: error is %v", err)
}

// set it to read only
cRequest.Config.Metadata.Name = t.Name() + "_2"
cRequest.Config.Mounts[0].Readonly = true

cID = createContainer(t, client, ctx, cRequest)
defer removeContainer(t, client, ctx, cID)
startContainer(t, client, ctx, cID)
defer stopContainer(t, client, ctx, cID)

testExec := []string{
"ash",
"-c",
// filepath.Join replaces `/` with `\`, so Join path manually
"cat " + containerPath + "/" + testFile,
}
output, errMsg, exitCode := execContainer(t, client, ctx, cID, testExec)
if exitCode != 0 {
t.Fatalf("could not find mounted file: %s %s", errMsg, output)
}
if output != testContent {
t.Fatalf("did not correctly read file; got %q, expected %q", output, testContent)
}
}
2 changes: 1 addition & 1 deletion test/cri-containerd/container_gmsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/Microsoft/hcsshim/pkg/annotations"
"github.com/Microsoft/hcsshim/test/pkg/definitions/hcs"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
)

func Test_RunContainer_GMSA_WCOW(t *testing.T) {
Expand Down
90 changes: 3 additions & 87 deletions test/cri-containerd/container_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,87 +4,15 @@
package cri_containerd

import (
"bufio"
"context"
"os"
"path/filepath"
"strings"
"testing"
"time"

runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
)

func Test_Container_Network_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW)

pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine})

// create a directory and log file
dir := t.TempDir()
log := filepath.Join(dir, "ping.txt")

sandboxRequest := getRunPodSandboxRequest(t, lcowRuntimeHandler)

client := newTestRuntimeClient(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

podID := runPodSandbox(t, client, ctx, sandboxRequest)
defer removePodSandbox(t, client, ctx, podID)
defer stopPodSandbox(t, client, ctx, podID)

request := &runtime.CreateContainerRequest{
PodSandboxId: podID,
Config: &runtime.ContainerConfig{
Metadata: &runtime.ContainerMetadata{
Name: t.Name() + "-Container",
},
Image: &runtime.ImageSpec{
Image: imageLcowAlpine,
},
Command: []string{
"ping",
"-q", // -q outputs ping stats only.
"-c",
"10",
"google.com",
},
LogPath: log,
Linux: &runtime.LinuxContainerConfig{},
},
SandboxConfig: sandboxRequest.Config,
}

containerID := createContainer(t, client, ctx, request)
defer removeContainer(t, client, ctx, containerID)

startContainer(t, client, ctx, containerID)
defer stopContainer(t, client, ctx, containerID)

// wait a while for container to write to stdout
time.Sleep(3 * time.Second)

// open the log and test for any packet loss
logFile, err := os.Open(log)
if err != nil {
t.Fatal(err)
}
defer logFile.Close()

s := bufio.NewScanner(logFile)
for s.Scan() {
v := strings.Fields(s.Text())
t.Logf("ping output: %v", v)

if v != nil && v[len(v)-1] == "loss" && v[len(v)-3] != "0%" {
t.Fatalf("expected 0%% packet loss, got %v packet loss", v[len(v)-3])
}
}
}

func Test_Container_Network_Hostname(t *testing.T) {
requireAnyFeature(t, featureWCOWProcess, featureWCOWHypervisor, featureLCOW)
requireAnyFeature(t, featureWCOWProcess, featureWCOWHypervisor)

type config struct {
name string
Expand All @@ -111,25 +39,13 @@ func Test_Container_Network_Hostname(t *testing.T) {
containerImage: imageWindowsNanoserver,
cmd: []string{"cmd", "/c", "ping", "-t", "127.0.0.1"},
},
{
name: "LCOW",
requiredFeatures: []string{featureLCOW},
runtimeHandler: lcowRuntimeHandler,
sandboxImage: imageLcowK8sPause,
containerImage: imageLcowAlpine,
cmd: []string{"top"},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
requireFeatures(t, test.requiredFeatures...)

if test.runtimeHandler == lcowRuntimeHandler {
pullRequiredLCOWImages(t, []string{test.sandboxImage, test.containerImage})
} else {
pullRequiredImages(t, []string{test.sandboxImage, test.containerImage})
}
pullRequiredImages(t, []string{test.sandboxImage, test.containerImage})

sandboxRequest := getRunPodSandboxRequest(t, test.runtimeHandler)
sandboxRequest.Config.Hostname = "TestHost"
Expand Down
Loading
Loading