Skip to content

Commit

Permalink
add test case for compatibility.go
Browse files Browse the repository at this point in the history
  • Loading branch information
carmark committed Dec 2, 2015
1 parent 7343ae4 commit 15b34b0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
56 changes: 56 additions & 0 deletions container/libcontainer/compatibility_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package libcontainer

import (
"path/filepath"
"testing"
)

func TestReadConfig(t *testing.T) {
var (
testdata string = "testdata"
containerID string = "1"
)
// Test with using the new config of docker v1.9.0
dockerRoot := filepath.Join(testdata, "docker-v1.9.1")
dockerRun := filepath.Join(testdata, "docker-v1.9.1")
config, err := ReadConfig(dockerRoot, dockerRun, containerID)
if err != nil {
t.Error(err)
}
if config.Hostname != containerID {
t.Errorf("Expected container hostname is %s, but got %s", containerID, config.Hostname)
}

// Test with using the pre config of docker v1.8.3
dockerRoot = filepath.Join(testdata, "docker-v1.8.3")
dockerRun = filepath.Join(testdata, "docker-v1.8.3")
config, err = ReadConfig(dockerRoot, dockerRun, containerID)
if err != nil {
t.Error(err)
}
if config.Hostname != containerID {
t.Errorf("Expected container hostname is %s, but got %s", containerID, config.Hostname)
}

// Test with using non-existed old config, return an error
dockerRoot = filepath.Join(testdata, "docker-v1.8.0")
dockerRun = filepath.Join(testdata, "docker-v1.8.0")
config, err = ReadConfig(dockerRoot, dockerRun, containerID)
if err == nil {
t.Error("Expected an error, but got nil")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":"1","init_process_pid":66241,"init_process_start":"4507843","cgroup_paths":{"blkio":"/sys/fs/cgroup/blkio/docker/1","cpu":"/sys/fs/cgroup/cpu/docker/1","cpuacct":"/sys/fs/cgroup/cpuacct/docker/1","cpuset":"/sys/fs/cgroup/cpuset/docker/1","devices":"/sys/fs/cgroup/devices/docker/1","freezer":"/sys/fs/cgroup/freezer/docker/1","hugetlb":"/sys/fs/cgroup/hugetlb/docker/1","memory":"/sys/fs/cgroup/memory/docker/1","net_cls":"/sys/fs/cgroup/net_cls/docker/1","net_prio":"/sys/fs/cgroup/net_prio/docker/1","perf_event":"/sys/fs/cgroup/perf_event/docker/1"},"namespace_paths":{"NEWIPC":"/proc/66241/ns/ipc","NEWNET":"/var/run/docker/netns/e05ddb1777f3","NEWNS":"/proc/66241/ns/mnt","NEWPID":"/proc/66241/ns/pid","NEWUSER":"/proc/66241/ns/user","NEWUTS":"/proc/66241/ns/uts"},"config":{"no_pivot_root":false,"parent_death_signal":0,"pivot_dir":"","rootfs":"/var/lib/docker/devicemapper/mnt/1/rootfs","readonlyfs":false,"privatefs":true,"mounts":[{"source":"proc","destination":"/proc","device":"proc","flags":14,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"tmpfs","destination":"/dev","device":"tmpfs","flags":16777218,"data":"mode=755","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"devpts","destination":"/dev/pts","device":"devpts","flags":10,"data":"newinstance,ptmxmode=0666,mode=0620,gid=5","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"shm","destination":"/dev/shm","device":"tmpfs","flags":14,"data":"mode=1777,size=65536k","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"mqueue","destination":"/dev/mqueue","device":"mqueue","flags":14,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"sysfs","destination":"/sys","device":"sysfs","flags":15,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"cgroup","destination":"/sys/fs/cgroup","device":"cgroup","flags":15,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"/var/lib/docker/containers/1/resolv.conf","destination":"/etc/resolv.conf","device":"bind","flags":20480,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"/var/lib/docker/containers/1/hostname","destination":"/etc/hostname","device":"bind","flags":20480,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"/var/lib/docker/containers/1/hosts","destination":"/etc/hosts","device":"bind","flags":20480,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null}],"devices":[{"type":99,"path":"/dev/fuse","major":10,"minor":229,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"/dev/null","major":1,"minor":3,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/zero","major":1,"minor":5,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/full","major":1,"minor":7,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/tty","major":5,"minor":0,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/urandom","major":1,"minor":9,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/random","major":1,"minor":8,"permissions":"rwm","file_mode":438,"uid":0,"gid":0}],"mount_label":"","hostname":"1","namespaces":[{"type":"NEWNS","path":""},{"type":"NEWUTS","path":""},{"type":"NEWIPC","path":""},{"type":"NEWPID","path":""},{"type":"NEWNET","path":"/var/run/docker/netns/e05ddb1777f3"}],"capabilities":["CHOWN","DAC_OVERRIDE","FSETID","FOWNER","MKNOD","NET_RAW","SETGID","SETUID","SETFCAP","SETPCAP","NET_BIND_SERVICE","SYS_CHROOT","KILL","AUDIT_WRITE"],"networks":null,"routes":null,"cgroups":{"name":"1","parent":"docker","allow_all_devices":false,"allowed_devices":[{"type":99,"path":"","major":-1,"minor":-1,"permissions":"m","file_mode":0,"uid":0,"gid":0},{"type":98,"path":"","major":-1,"minor":-1,"permissions":"m","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"/dev/console","major":5,"minor":1,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"/dev/tty0","major":4,"minor":0,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"/dev/tty1","major":4,"minor":1,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"","major":136,"minor":-1,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"","major":5,"minor":2,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"","major":10,"minor":200,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"/dev/null","major":1,"minor":3,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/zero","major":1,"minor":5,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/full","major":1,"minor":7,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/tty","major":5,"minor":0,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/urandom","major":1,"minor":9,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/random","major":1,"minor":8,"permissions":"rwm","file_mode":438,"uid":0,"gid":0}],"denied_devices":null,"memory":0,"memory_reservation":0,"memory_swap":0,"kernel_memory":0,"cpu_shares":0,"cpuset_cpus":"","cpuset_mems":"","blkio_throttle_read_bps_device":"","blkio_throttle_write_bps_device":"","blkio_throttle_read_iops_device":"","blkio_throttle_write_iops_device":"","blkio_weight":0,"blkio_weight_device":"","freezer":"","hugetlb_limit":null,"slice":"","oom_kill_disable":false,"memory_swappiness":-1,"net_prio_ifpriomap":null,"net_cls_classid":""},"apparmor_profile":"docker-default","process_label":"","rlimits":null,"additional_groups":null,"uid_mappings":null,"gid_mappings":null,"mask_paths":["/proc/kcore","/proc/latency_stats","/proc/timer_stats"],"readonly_paths":["/proc/asound","/proc/bus","/proc/fs","/proc/irq","/proc/sys","/proc/sysrq-trigger"],"sysctl":null,"seccomp":null},"external_descriptors":["/dev/null","/dev/null","/dev/null"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":"1","init_process_pid":64076,"init_process_start":"3211353","cgroup_paths":{"blkio":"/sys/fs/cgroup/blkio/docker/1","cpu":"/sys/fs/cgroup/cpu/docker/1","cpuacct":"/sys/fs/cgroup/cpuacct/docker/1","cpuset":"/sys/fs/cgroup/cpuset/docker/1","devices":"/sys/fs/cgroup/devices/docker/1","freezer":"/sys/fs/cgroup/freezer/docker/1","hugetlb":"/sys/fs/cgroup/hugetlb/docker/1","memory":"/sys/fs/cgroup/memory/docker/1","net_cls":"/sys/fs/cgroup/net_cls/docker/1","net_prio":"/sys/fs/cgroup/net_prio/docker/1","perf_event":"/sys/fs/cgroup/perf_event/docker/1"},"namespace_paths":{"NEWIPC":"/proc/64076/ns/ipc","NEWNET":"/proc/64076/ns/net","NEWNS":"/proc/64076/ns/mnt","NEWPID":"/proc/64076/ns/pid","NEWUSER":"/proc/64076/ns/user","NEWUTS":"/proc/64076/ns/uts"},"config":{"no_pivot_root":false,"parent_death_signal":0,"pivot_dir":"","rootfs":"/var/lib/docker/devicemapper/mnt/1/rootfs","readonlyfs":false,"rootPropagation":278528,"mounts":[{"source":"proc","destination":"/proc","device":"proc","flags":14,"propagation_flags":null,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"tmpfs","destination":"/dev","device":"tmpfs","flags":16777218,"propagation_flags":null,"data":"mode=755","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"devpts","destination":"/dev/pts","device":"devpts","flags":10,"propagation_flags":null,"data":"newinstance,ptmxmode=0666,mode=0620,gid=5","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"sysfs","destination":"/sys","device":"sysfs","flags":15,"propagation_flags":null,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"cgroup","destination":"/sys/fs/cgroup","device":"cgroup","flags":15,"propagation_flags":null,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"/var/lib/docker/containers/1/resolv.conf","destination":"/etc/resolv.conf","device":"bind","flags":20480,"propagation_flags":null,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"/var/lib/docker/containers/1/hostname","destination":"/etc/hostname","device":"bind","flags":20480,"propagation_flags":null,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"/var/lib/docker/containers/1/hosts","destination":"/etc/hosts","device":"bind","flags":20480,"propagation_flags":null,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"/var/lib/docker/containers/1/shm","destination":"/dev/shm","device":"bind","flags":20480,"propagation_flags":null,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null},{"source":"/var/lib/docker/containers/1/mqueue","destination":"/dev/mqueue","device":"bind","flags":20480,"propagation_flags":null,"data":"","relabel":"","premount_cmds":null,"postmount_cmds":null}],"devices":[{"type":99,"path":"/dev/fuse","major":10,"minor":229,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"/dev/null","major":1,"minor":3,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/zero","major":1,"minor":5,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/full","major":1,"minor":7,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/tty","major":5,"minor":0,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/urandom","major":1,"minor":9,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/random","major":1,"minor":8,"permissions":"rwm","file_mode":438,"uid":0,"gid":0}],"mount_label":"","hostname":"1","namespaces":[{"type":"NEWNS","path":""},{"type":"NEWUTS","path":""},{"type":"NEWIPC","path":""},{"type":"NEWPID","path":""},{"type":"NEWNET","path":""}],"capabilities":["CAP_CHOWN","CAP_DAC_OVERRIDE","CAP_FSETID","CAP_FOWNER","CAP_MKNOD","CAP_NET_RAW","CAP_SETGID","CAP_SETUID","CAP_SETFCAP","CAP_SETPCAP","CAP_NET_BIND_SERVICE","CAP_SYS_CHROOT","CAP_KILL","CAP_AUDIT_WRITE"],"networks":null,"routes":null,"cgroups":{"name":"1","parent":"docker","allow_all_devices":false,"allowed_devices":[{"type":99,"path":"","major":-1,"minor":-1,"permissions":"m","file_mode":0,"uid":0,"gid":0},{"type":98,"path":"","major":-1,"minor":-1,"permissions":"m","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"/dev/console","major":5,"minor":1,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"/dev/tty0","major":4,"minor":0,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"/dev/tty1","major":4,"minor":1,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"","major":136,"minor":-1,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"","major":5,"minor":2,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"","major":10,"minor":200,"permissions":"rwm","file_mode":0,"uid":0,"gid":0},{"type":99,"path":"/dev/null","major":1,"minor":3,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/zero","major":1,"minor":5,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/full","major":1,"minor":7,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/tty","major":5,"minor":0,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/urandom","major":1,"minor":9,"permissions":"rwm","file_mode":438,"uid":0,"gid":0},{"type":99,"path":"/dev/random","major":1,"minor":8,"permissions":"rwm","file_mode":438,"uid":0,"gid":0}],"denied_devices":null,"memory":0,"memory_reservation":0,"memory_swap":0,"kernel_memory":0,"cpu_shares":0,"cpuset_cpus":"","cpuset_mems":"","blkio_weight":0,"blkio_leaf_weight":0,"blkio_weight_device":null,"blkio_throttle_read_bps_device":null,"blkio_throttle_write_bps_device":null,"blkio_throttle_read_iops_device":null,"blkio_throttle_write_iops_device":null,"freezer":"","hugetlb_limit":null,"slice":"","oom_kill_disable":false,"memory_swappiness":-1,"net_prio_ifpriomap":null,"net_cls_classid":""},"apparmor_profile":"docker-default","process_label":"","rlimits":null,"oom_score_adj":0,"additional_groups":null,"uid_mappings":null,"gid_mappings":null,"mask_paths":["/proc/kcore","/proc/latency_stats","/proc/timer_stats"],"readonly_paths":["/proc/asound","/proc/bus","/proc/fs","/proc/irq","/proc/sys","/proc/sysrq-trigger"],"sysctl":null,"seccomp":null,"version":""},"external_descriptors":["/dev/null","/dev/null","/dev/null"]}

0 comments on commit 15b34b0

Please sign in to comment.