Adds ipc namespace capability to lxc, and fixes tests.

This fixes various tests by checking for non zero exit code, accounting for lxc-specific base-diffs, and by removing lxc specific environment vars.
It also adds the --share-ipc option to lxc-start for shared ipc namespaces.
Signed-off-by: Abin Shahab <ashahab@altiscale.com> (github: ashahab-altiscale)
Docker-DCO-1.1-Signed-off-by: Abin Shahab <ashahab@altiscale.com> (github: ashahab-altiscale)
Upstream-commit: 3ca5af6b1ab6d1b75e014265e1ad4f5e45960826
Component: engine
This commit is contained in:
Abin Shahab
2015-01-20 00:32:29 +00:00
parent 566a151923
commit 3d77110890
4 changed files with 76 additions and 16 deletions

View File

@ -792,7 +792,13 @@ func TestRunEnvironment(t *testing.T) {
t.Fatal(err, out)
}
actualEnv := strings.Split(strings.TrimSpace(out), "\n")
actualEnvLxc := strings.Split(strings.TrimSpace(out), "\n")
actualEnv := []string{}
for i := range actualEnvLxc {
if actualEnvLxc[i] != "container=lxc" {
actualEnv = append(actualEnv, actualEnvLxc[i])
}
}
sort.Strings(actualEnv)
goodEnv := []string{
@ -831,7 +837,13 @@ func TestRunEnvironmentErase(t *testing.T) {
t.Fatal(err, out)
}
actualEnv := strings.Split(strings.TrimSpace(out), "\n")
actualEnvLxc := strings.Split(strings.TrimSpace(out), "\n")
actualEnv := []string{}
for i := range actualEnvLxc {
if actualEnvLxc[i] != "container=lxc" {
actualEnv = append(actualEnv, actualEnvLxc[i])
}
}
sort.Strings(actualEnv)
goodEnv := []string{
@ -863,7 +875,13 @@ func TestRunEnvironmentOverride(t *testing.T) {
t.Fatal(err, out)
}
actualEnv := strings.Split(strings.TrimSpace(out), "\n")
actualEnvLxc := strings.Split(strings.TrimSpace(out), "\n")
actualEnv := []string{}
for i := range actualEnvLxc {
if actualEnvLxc[i] != "container=lxc" {
actualEnv = append(actualEnv, actualEnvLxc[i])
}
}
sort.Strings(actualEnv)
goodEnv := []string{
@ -1969,13 +1987,44 @@ func TestRunWriteHostsFileAndNotCommit(t *testing.T) {
if err != nil {
t.Fatal(err, out)
}
if len(strings.Trim(out, "\r\n")) != 0 {
if len(strings.Trim(out, "\r\n")) != 0 && !eqToBaseDiff(out, t) {
t.Fatal("diff should be empty")
}
logDone("run - write to /etc/hosts and not commited")
}
func eqToBaseDiff(out string, t *testing.T) bool {
cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "hello")
out1, _, err := runCommandWithOutput(cmd)
cID := stripTrailingCharacters(out1)
cmd = exec.Command(dockerBinary, "diff", cID)
base_diff, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err, base_diff)
}
base_arr := strings.Split(base_diff, "\n")
sort.Strings(base_arr)
out_arr := strings.Split(out, "\n")
sort.Strings(out_arr)
return sliceEq(base_arr, out_arr)
}
func sliceEq(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
// Test for #2267
func TestRunWriteHostnameFileAndNotCommit(t *testing.T) {
defer deleteAllContainers()
@ -1998,7 +2047,7 @@ func TestRunWriteHostnameFileAndNotCommit(t *testing.T) {
if err != nil {
t.Fatal(err, out)
}
if len(strings.Trim(out, "\r\n")) != 0 {
if len(strings.Trim(out, "\r\n")) != 0 && !eqToBaseDiff(out, t) {
t.Fatal("diff should be empty")
}
@ -2027,7 +2076,7 @@ func TestRunWriteResolvFileAndNotCommit(t *testing.T) {
if err != nil {
t.Fatal(err, out)
}
if len(strings.Trim(out, "\r\n")) != 0 {
if len(strings.Trim(out, "\r\n")) != 0 && !eqToBaseDiff(out, t) {
t.Fatal("diff should be empty")
}
@ -2737,10 +2786,7 @@ func TestRunUnknownCommand(t *testing.T) {
cID = strings.TrimSpace(cID)
runCmd = exec.Command(dockerBinary, "start", cID)
_, _, _, err = runCommandWithStdoutStderr(runCmd)
if err == nil {
t.Fatalf("Container should not have been able to start!")
}
_, _, _, _ = runCommandWithStdoutStderr(runCmd)
runCmd = exec.Command(dockerBinary, "inspect", "--format={{.State.ExitCode}}", cID)
rc, _, _, err2 := runCommandWithStdoutStderr(runCmd)
@ -2750,8 +2796,8 @@ func TestRunUnknownCommand(t *testing.T) {
t.Fatalf("Error getting status of container: %v", err2)
}
if rc != "-1" {
t.Fatalf("ExitCode(%v) was supposed to be -1", rc)
if rc == "0" {
t.Fatalf("ExitCode(%v) cannot be 0", rc)
}
logDone("run - Unknown Command")