-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
... and remove the one from tests/integration. The idea is similar to the one for the test case being removed -- try updating device rules many times to make sure we are not leaking eBPF programs after every update/Set(). This is better though as we can really change the device rules every time (which "runc update" can't) and check that the rule is applied. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
- Loading branch information
Showing
2 changed files
with
85 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package integration | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/opencontainers/runc/libcontainer" | ||
"github.com/opencontainers/runc/libcontainer/devices" | ||
) | ||
|
||
func TestUpdateDevices(t *testing.T) { | ||
if testing.Short() { | ||
return | ||
} | ||
rootfs, err := newRootfs() | ||
ok(t, err) | ||
defer remove(rootfs) | ||
config := newTemplateConfig(t, &tParam{rootfs: rootfs}) | ||
container, err := newContainer(t, config) | ||
ok(t, err) | ||
defer destroyContainer(container) | ||
|
||
// Execute a first process in the container | ||
stdinR, stdinW, err := os.Pipe() | ||
ok(t, err) | ||
process := &libcontainer.Process{ | ||
Cwd: "/", | ||
Args: []string{"cat"}, | ||
Env: standardEnvironment, | ||
Stdin: stdinR, | ||
Init: true, | ||
} | ||
err = container.Run(process) | ||
_ = stdinR.Close() | ||
defer func() { | ||
_ = stdinW.Close() | ||
if _, err := process.Wait(); err != nil { | ||
t.Log(err) | ||
} | ||
}() | ||
ok(t, err) | ||
|
||
var buf bytes.Buffer | ||
devCheck := &libcontainer.Process{ | ||
Cwd: "/", | ||
Args: []string{"/bin/sh", "-c", "echo > /dev/full; true"}, | ||
Env: standardEnvironment, | ||
Stderr: &buf, | ||
} | ||
isAllowed := true | ||
for i := 0; i < 300; i++ { | ||
// Check the access | ||
buf.Reset() | ||
err = container.Run(devCheck) | ||
ok(t, err) | ||
waitProcess(devCheck, t) | ||
|
||
var expected string | ||
if isAllowed { | ||
expected = "write error: No space left on device" | ||
} else { | ||
expected = "/dev/full: Operation not permitted" | ||
} | ||
if !strings.Contains(buf.String(), expected) { | ||
t.Fatalf("[%d] expected %q, got %q", i, expected, buf.String()) | ||
} | ||
|
||
// Now flip the access permission | ||
isAllowed = !isAllowed | ||
config.Cgroups.Resources.Devices = []*devices.Rule{ | ||
{ | ||
Type: devices.CharDevice, | ||
Major: 1, | ||
Minor: 7, | ||
Permissions: "rwm", | ||
Allow: isAllowed, | ||
}, | ||
} | ||
if err := container.Set(*config); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters