2015-02-27 11:00:17 +08:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/libcontainer/configs"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
allowedDevices = []*configs.Device{
|
|
|
|
{
|
|
|
|
Path: "/dev/zero",
|
|
|
|
Type: 'c',
|
|
|
|
Major: 1,
|
|
|
|
Minor: 5,
|
|
|
|
Permissions: "rwm",
|
|
|
|
FileMode: 0666,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
allowedList = "c 1:5 rwm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDevicesSetAllow(t *testing.T) {
|
|
|
|
helper := NewCgroupTestUtil("devices", t)
|
|
|
|
defer helper.cleanup()
|
|
|
|
|
|
|
|
helper.writeFileContents(map[string]string{
|
2015-03-09 09:32:02 +08:00
|
|
|
"devices.deny": "a",
|
2015-02-27 11:00:17 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
helper.CgroupData.c.AllowAllDevices = false
|
|
|
|
helper.CgroupData.c.AllowedDevices = allowedDevices
|
|
|
|
devices := &DevicesGroup{}
|
|
|
|
if err := devices.Set(helper.CgroupPath, helper.CgroupData.c); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
value, err := getCgroupParamString(helper.CgroupPath, "devices.allow")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to parse devices.allow - %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if value != allowedList {
|
|
|
|
t.Fatal("Got the wrong value, set devices.allow failed.")
|
|
|
|
}
|
|
|
|
}
|