MCPcopy
hub / github.com/containerd/containerd / TestNriLinuxDeviceInjection

Function TestNriLinuxDeviceInjection

integration/nri_test.go:259–302  ·  view source on GitHub ↗

Test linux device injection by NRI plugins.

(t *testing.T)

Source from the content-addressed store, hash-verified

257
258// Test linux device injection by NRI plugins.
259func TestNriLinuxDeviceInjection(t *testing.T) {
260 skipNriTestIfNecessary(t)
261
262 t.Log("Test that NRI plugins can inject linux devices into containers.")
263
264 var (
265 out = t.TempDir()
266 tc = &nriTest{
267 t: t,
268 plugins: []*mockPlugin{{}},
269 }
270 injectDev = func(p *mockPlugin, pod *api.PodSandbox, ctr *api.Container) (*api.ContainerAdjustment, []*api.ContainerUpdate, error) {
271 adjust := &api.ContainerAdjustment{}
272 adjust.AddMount(&api.Mount{
273 Destination: "/out",
274 Source: out,
275 Type: "bind",
276 Options: []string{"bind"},
277 })
278 adjust.AddDevice(&api.LinuxDevice{
279 Path: "/dev/pie",
280 Type: "c",
281 Major: 31,
282 Minor: 41,
283 Uid: api.UInt32(uint32(11)),
284 Gid: api.UInt32(uint32(22)),
285 FileMode: api.FileMode(uint32(0664)),
286 })
287 return adjust, nil, nil
288 }
289 )
290
291 tc.plugins[0].createContainer = injectDev
292 tc.setup()
293
294 podID := tc.runPod("pod0")
295 tc.startContainer(podID, "ctr0",
296 WithCommand("/bin/sh", "-c", "stat -c %F-%a-%u:%g-%t:%T /dev/pie > /out/result; sleep 3600"),
297 )
298
299 chk, err := waitForFileAndRead(filepath.Join(out, "result"), time.Second)
300 require.NoError(t, err, "read result")
301 require.Equal(t, "character special file-664-11:22-1f:29\n", string(chk), "check result")
302}
303
304// Test linux cpuset adjustment by NRI plugins.
305func TestNriLinuxCpusetAdjustment(t *testing.T) {

Callers

nothing calls this directly

Calls 8

skipNriTestIfNecessaryFunction · 0.85
WithCommandFunction · 0.85
waitForFileAndReadFunction · 0.85
LogMethod · 0.80
AddDeviceMethod · 0.80
setupMethod · 0.80
runPodMethod · 0.80
startContainerMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…