MCPcopy
hub / github.com/opencontainers/runc / TestInitJoinNetworkAndUser

Function TestInitJoinNetworkAndUser

libcontainer/integration/exec_test.go:1517–1602  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1515}
1516
1517func TestInitJoinNetworkAndUser(t *testing.T) {
1518 needUserNS(t)
1519 if testing.Short() {
1520 return
1521 }
1522
1523 // Execute a long-running container
1524 config1 := newTemplateConfig(t, &tParam{userns: true})
1525 container1, err := newContainer(t, config1)
1526 ok(t, err)
1527 defer destroyContainer(container1)
1528
1529 stdinR1, stdinW1, err := os.Pipe()
1530 ok(t, err)
1531 init1 := &libcontainer.Process{
1532 Cwd: "/",
1533 Args: []string{"cat"},
1534 Env: standardEnvironment,
1535 Stdin: stdinR1,
1536 Init: true,
1537 }
1538 err = container1.Run(init1)
1539 _ = stdinR1.Close()
1540 defer stdinW1.Close()
1541 ok(t, err)
1542
1543 // get the state of the first container
1544 state1, err := container1.State()
1545 ok(t, err)
1546 netns1 := state1.NamespacePaths[configs.NEWNET]
1547 userns1 := state1.NamespacePaths[configs.NEWUSER]
1548
1549 // Run a container inside the existing pidns but with different cgroups.
1550 config2 := newTemplateConfig(t, &tParam{userns: true})
1551 config2.Namespaces.Add(configs.NEWNET, netns1)
1552 config2.Namespaces.Add(configs.NEWUSER, userns1)
1553 // Emulate specconv.setupUserNamespace().
1554 uidMap, gidMap, err := userns.GetUserNamespaceMappings(userns1)
1555 ok(t, err)
1556 config2.UIDMappings = uidMap
1557 config2.GIDMappings = gidMap
1558 config2.Cgroups.Path = "integration/test2"
1559 container2, err := newContainer(t, config2)
1560 ok(t, err)
1561 defer destroyContainer(container2)
1562
1563 stdinR2, stdinW2, err := os.Pipe()
1564 ok(t, err)
1565 init2 := &libcontainer.Process{
1566 Cwd: "/",
1567 Args: []string{"cat"},
1568 Env: standardEnvironment,
1569 Stdin: stdinR2,
1570 Init: true,
1571 }
1572 err = container2.Run(init2)
1573 _ = stdinR2.Close()
1574 defer stdinW2.Close()

Callers

nothing calls this directly

Calls 11

GetUserNamespaceMappingsFunction · 0.92
needUserNSFunction · 0.85
newTemplateConfigFunction · 0.85
newContainerFunction · 0.85
okFunction · 0.85
destroyContainerFunction · 0.85
waitProcessFunction · 0.85
StateMethod · 0.80
AddMethod · 0.80
RunMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…