checkLoopbackResult validates whether the loopback interface status within a container is UP
(t *testing.T, useInternalLoopback bool)
| 48 | |
| 49 | // checkLoopbackResult validates whether the loopback interface status within a container is UP |
| 50 | func checkLoopbackResult(t *testing.T, useInternalLoopback bool) bool { |
| 51 | t.Logf("Create containerd config with 'use_internal_loopback' set to '%t'", useInternalLoopback) |
| 52 | workDir := t.TempDir() |
| 53 | configPath := filepath.Join(workDir, "config.toml") |
| 54 | ctrdConfig := fmt.Sprintf(` |
| 55 | version = 3 |
| 56 | |
| 57 | [plugins] |
| 58 | [plugins.'io.containerd.cri.v1.runtime'] |
| 59 | [plugins.'io.containerd.cri.v1.runtime'.cni] |
| 60 | use_internal_loopback = %t`, |
| 61 | useInternalLoopback) |
| 62 | |
| 63 | err := os.WriteFile(configPath, []byte(ctrdConfig), 0600) |
| 64 | require.NoError(t, err) |
| 65 | |
| 66 | t.Logf("Start containerd") |
| 67 | currentProc := newCtrdProc(t, "containerd", workDir, nil) |
| 68 | require.NoError(t, currentProc.isReady()) |
| 69 | |
| 70 | t.Cleanup(func() { |
| 71 | t.Log("Cleanup all the pods") |
| 72 | cleanupPods(t, currentProc.criRuntimeService(t)) |
| 73 | |
| 74 | t.Log("Stop containerd process") |
| 75 | require.NoError(t, currentProc.kill(syscall.SIGTERM)) |
| 76 | require.NoError(t, currentProc.wait(5*time.Minute)) |
| 77 | }) |
| 78 | |
| 79 | var ( |
| 80 | testImage = images.Get(images.BusyBox) |
| 81 | containerName = "test-container-loopback-v2" |
| 82 | ) |
| 83 | |
| 84 | pullImagesByCRI(t, currentProc.criImageService(t), testImage) |
| 85 | |
| 86 | t.Log("Create a pod with a container that checks the loopback status") |
| 87 | podCtx := newPodTCtx(t, currentProc.criRuntimeService(t), "container-exec-lo-test", "sandbox") |
| 88 | cnID := podCtx.createContainer( |
| 89 | containerName, |
| 90 | testImage, |
| 91 | runtime.ContainerState_CONTAINER_RUNNING, |
| 92 | WithCommand("sleep", "1d"), |
| 93 | WithVolumeMount("/usr/local/bin/loopback-v2", "/loopback-v2"), |
| 94 | ) |
| 95 | |
| 96 | t.Logf("Check loopback status - should be UP (not DOWN) when 'use_internal_loopback' is '%t'", useInternalLoopback) |
| 97 | stdout, _, err := podCtx.rSvc.ExecSync(cnID, []string{"/loopback-v2"}, 5*time.Second) |
| 98 | require.NoError(t, err, "") |
| 99 | t.Logf("%s", stdout) |
| 100 | |
| 101 | return assert.Contains(t, string(stdout), "UP") |
| 102 | } |
no test coverage detected
searching dependent graphs…