|
| 1 | +//go:build windows && functional |
| 2 | +// +build windows,functional |
| 3 | + |
| 4 | +// V2 LCOW-specific CRI tests. These mirror the Test_V2Sandbox_* pattern |
| 5 | +// established in the azcri test suite: each test gates on featureLCOWV2 and |
| 6 | +// targets lcowV2RuntimeHandler directly (no v1 fallback), because the |
| 7 | +// scenarios under test exercise the V2 runtime path. |
| 8 | +// |
| 9 | +// To run these tests: |
| 10 | +// 1. The CI containerd config must register `runhcs-lcow-v2` → |
| 11 | +// `containerd-shim-lcow-v2.exe` (runtime_type io.containerd.lcow.v2). |
| 12 | +// 2. The test binary must be invoked with -feature=LCOWV2. |
| 13 | + |
| 14 | +package cri_containerd |
| 15 | + |
| 16 | +import ( |
| 17 | + "context" |
| 18 | + "testing" |
| 19 | + |
| 20 | + runtime "k8s.io/cri-api/pkg/apis/runtime/v1" |
| 21 | +) |
| 22 | + |
| 23 | +// Test_V2_LCOW_PodLifecycle exercises the basic pod-sandbox lifecycle through |
| 24 | +// the V2 shim: RunPodSandbox → StopPodSandbox → RemovePodSandbox. This is the |
| 25 | +// minimum end-to-end smoke test that proves containerd → shim handshake works |
| 26 | +// on the V2 path. |
| 27 | +func Test_V2_LCOW_PodLifecycle(t *testing.T) { |
| 28 | + requireFeatures(t, featureLCOWV2) |
| 29 | + |
| 30 | + pullRequiredLCOWImages(t, []string{imageLcowK8sPause}) |
| 31 | + |
| 32 | + client := newTestRuntimeClient(t) |
| 33 | + ctx, cancel := context.WithCancel(context.Background()) |
| 34 | + defer cancel() |
| 35 | + |
| 36 | + podReq := getRunPodSandboxRequest(t, lcowV2RuntimeHandler) |
| 37 | + podID := runPodSandbox(t, client, ctx, podReq) |
| 38 | + defer removePodSandbox(t, client, ctx, podID) |
| 39 | + defer stopPodSandbox(t, client, ctx, podID) |
| 40 | +} |
| 41 | + |
| 42 | +// Test_V2_LCOW_ContainerLifecycle exercises a full container lifecycle inside |
| 43 | +// a V2 sandbox: RunPodSandbox → CreateContainer → StartContainer → |
| 44 | +// StopContainer → RemoveContainer → StopPodSandbox → RemovePodSandbox. |
| 45 | +func Test_V2_LCOW_ContainerLifecycle(t *testing.T) { |
| 46 | + requireFeatures(t, featureLCOWV2) |
| 47 | + |
| 48 | + pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine}) |
| 49 | + |
| 50 | + client := newTestRuntimeClient(t) |
| 51 | + ctx, cancel := context.WithCancel(context.Background()) |
| 52 | + defer cancel() |
| 53 | + |
| 54 | + podReq := getRunPodSandboxRequest(t, lcowV2RuntimeHandler) |
| 55 | + podID := runPodSandbox(t, client, ctx, podReq) |
| 56 | + defer removePodSandbox(t, client, ctx, podID) |
| 57 | + defer stopPodSandbox(t, client, ctx, podID) |
| 58 | + |
| 59 | + cReq := getCreateContainerRequest(podID, "alpine", imageLcowAlpine, |
| 60 | + []string{"echo", "hello"}, podReq.Config) |
| 61 | + containerID := createContainer(t, client, ctx, cReq) |
| 62 | + defer removeContainer(t, client, ctx, containerID) |
| 63 | + |
| 64 | + startContainer(t, client, ctx, containerID) |
| 65 | + stopContainer(t, client, ctx, containerID) |
| 66 | +} |
| 67 | + |
| 68 | +// Test_V2_LCOW_ContainerExec runs a workload container and verifies that |
| 69 | +// ExecSync into it succeeds with the expected exit code. Validates the GCS |
| 70 | +// exec path through the V2 controller. |
| 71 | +func Test_V2_LCOW_ContainerExec(t *testing.T) { |
| 72 | + requireFeatures(t, featureLCOWV2) |
| 73 | + |
| 74 | + pullRequiredLCOWImages(t, []string{imageLcowK8sPause, imageLcowAlpine}) |
| 75 | + |
| 76 | + client := newTestRuntimeClient(t) |
| 77 | + ctx, cancel := context.WithCancel(context.Background()) |
| 78 | + defer cancel() |
| 79 | + |
| 80 | + podReq := getRunPodSandboxRequest(t, lcowV2RuntimeHandler) |
| 81 | + podID := runPodSandbox(t, client, ctx, podReq) |
| 82 | + defer removePodSandbox(t, client, ctx, podID) |
| 83 | + defer stopPodSandbox(t, client, ctx, podID) |
| 84 | + |
| 85 | + cReq := getCreateContainerRequest(podID, "alpine", imageLcowAlpine, |
| 86 | + []string{"top"}, podReq.Config) |
| 87 | + containerID := createContainer(t, client, ctx, cReq) |
| 88 | + defer removeContainer(t, client, ctx, containerID) |
| 89 | + |
| 90 | + startContainer(t, client, ctx, containerID) |
| 91 | + defer stopContainer(t, client, ctx, containerID) |
| 92 | + |
| 93 | + execResp, err := client.ExecSync(ctx, &runtime.ExecSyncRequest{ |
| 94 | + ContainerId: containerID, |
| 95 | + Cmd: []string{"echo", "hello"}, |
| 96 | + Timeout: 20, |
| 97 | + }) |
| 98 | + if err != nil { |
| 99 | + t.Fatalf("ExecSync failed: %v", err) |
| 100 | + } |
| 101 | + if execResp.ExitCode != 0 { |
| 102 | + t.Fatalf("ExecSync returned exit code %d, stderr: %s", execResp.ExitCode, string(execResp.Stderr)) |
| 103 | + } |
| 104 | +} |
0 commit comments