Fix container.json sample to be loadable by nsinit.

Docker-DCO-1.1-Signed-off-by: Rohit Jnagal <jnagal@google.com> (github: rjnagal)
This commit is contained in:
Rohit Jnagal 2014-04-25 00:17:45 +00:00
parent bcfc527abb
commit 60159f9737
3 changed files with 102 additions and 41 deletions

View file

@ -41,21 +41,21 @@ Sample `container.json` file:
"TERM=xterm" "TERM=xterm"
], ],
"capabilities_mask" : [ "capabilities_mask" : [
"SETPCAP", { "key": "SETPCAP" },
"SYS_MODULE", { "key": "SYS_MODULE" },
"SYS_RAWIO", { "key": "SYS_RAWIO" },
"SYS_PACCT", { "key": "SYS_PACCT" },
"SYS_ADMIN", { "key": "SYS_ADMIN" },
"SYS_NICE", { "key": "SYS_NICE" },
"SYS_RESOURCE", { "key": "SYS_RESOURCE" },
"SYS_TIME", { "key": "SYS_TIME" },
"SYS_TTY_CONFIG", { "key": "SYS_TTY_CONFIG" },
"MKNOD", { "key": "MKNOD" },
"AUDIT_WRITE", { "key": "AUDIT_WRITE" },
"AUDIT_CONTROL", { "key": "AUDIT_CONTROL" },
"MAC_OVERRIDE", { "key": "MAC_OVERRIDE" },
"MAC_ADMIN", { "key": "MAC_ADMIN" },
"NET_ADMIN" { "key": "NET_ADMIN" }
], ],
"context" : { "context" : {
"apparmor_profile" : "docker-default" "apparmor_profile" : "docker-default"
@ -81,11 +81,11 @@ Sample `container.json` file:
} }
], ],
"namespaces" : [ "namespaces" : [
"NEWNS", { "key": "NEWNS" },
"NEWUTS", { "key": "NEWUTS" },
"NEWIPC", { "key": "NEWIPC" },
"NEWPID", { "key": "NEWPID" },
"NEWNET" { "key": "NEWNET" }
] ]
} }
``` ```

View file

@ -8,28 +8,28 @@
"TERM=xterm-256color" "TERM=xterm-256color"
], ],
"namespaces": [ "namespaces": [
"NEWIPC", { "key": "NEWIPC" },
"NEWNS", { "key": "NEWNS" },
"NEWPID", { "key": "NEWPID" },
"NEWUTS", { "key": "NEWUTS" },
"NEWNET" { "key": "NEWNET" }
], ],
"capabilities_mask": [ "capabilities_mask": [
"SETPCAP", { "key": "SETPCAP" },
"SYS_MODULE", { "key": "SYS_MODULE" },
"SYS_RAWIO", { "key": "SYS_RAWIO" },
"SYS_PACCT", { "key": "SYS_PACCT" },
"SYS_ADMIN", { "key": "SYS_ADMIN" },
"SYS_NICE", { "key": "SYS_NICE" },
"SYS_RESOURCE", { "key": "SYS_RESOURCE" },
"SYS_TIME", { "key": "SYS_TIME" },
"SYS_TTY_CONFIG", { "key": "SYS_TTY_CONFIG" },
"MKNOD", { "key": "MKNOD" },
"AUDIT_WRITE", { "key": "AUDIT_WRITE" },
"AUDIT_CONTROL", { "key": "AUDIT_CONTROL" },
"MAC_OVERRIDE", { "key": "MAC_OVERRIDE" },
"MAC_ADMIN", { "key": "MAC_ADMIN" },
"NET_ADMIN" { "key": "NET_ADMIN" }
], ],
"networks": [{ "networks": [{
"type": "veth", "type": "veth",
@ -45,6 +45,7 @@
"cgroups": { "cgroups": {
"name": "docker-koye", "name": "docker-koye",
"parent": "docker", "parent": "docker",
"memory": 5248000 "memory": 5248000,
"cpu_shares": 1024
} }
} }

View file

@ -0,0 +1,60 @@
package libcontainer
import (
"encoding/json"
"os"
"testing"
)
func TestContainerJsonFormat(t *testing.T) {
f, err := os.Open("container.json")
if err != nil {
t.Fatal("Unable to open container.json")
}
defer f.Close()
var container *Container
if err := json.NewDecoder(f).Decode(&container); err != nil {
t.Log("failed to decode container config")
t.FailNow()
}
if container.Hostname != "koye" {
t.Log("hostname is not set")
t.Fail()
}
if !container.Tty {
t.Log("tty should be set to true")
t.Fail()
}
if !container.Namespaces.Contains("NEWNET") {
t.Log("namespaces should contain NEWNET")
t.Fail()
}
if container.Namespaces.Contains("NEWUSER") {
t.Log("namespaces should not contain NEWUSER")
t.Fail()
}
if !container.CapabilitiesMask.Contains("SYS_ADMIN") {
t.Log("capabilities should contain SYS_ADMIN")
t.Fail()
}
if container.CapabilitiesMask.Contains("SYS_CHROOT") {
t.Log("capabitlies should not contain SYS_CHROOT")
t.Fail()
}
if container.Cgroups.CpuShares != 1024 {
t.Log("cpu shares not set correctly")
t.Fail()
}
if container.Cgroups.Memory != 5248000 {
t.Log("memory limit not set correctly")
t.Fail()
}
}