MCPcopy
hub / github.com/containerd/containerd / checkLoopbackResult

Function checkLoopbackResult

integration/issue10244_loopback_linux_test.go:50–102  ·  view source on GitHub ↗

checkLoopbackResult validates whether the loopback interface status within a container is UP

(t *testing.T, useInternalLoopback bool)

Source from the content-addressed store, hash-verified

48
49// checkLoopbackResult validates whether the loopback interface status within a container is UP
50func 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}

Callers 1

TestIssue10244LoopbackV2Function · 0.85

Calls 15

GetFunction · 0.92
newCtrdProcFunction · 0.85
cleanupPodsFunction · 0.85
pullImagesByCRIFunction · 0.85
newPodTCtxFunction · 0.85
WithCommandFunction · 0.85
WithVolumeMountFunction · 0.85
isReadyMethod · 0.80
LogMethod · 0.80
criRuntimeServiceMethod · 0.80
criImageServiceMethod · 0.80
WriteFileMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…