diff --git a/integration-cli/docker_api_exec_test.go b/integration-cli/docker_api_exec_test.go index df7122dd75..1ed99a2561 100644 --- a/integration-cli/docker_api_exec_test.go +++ b/integration-cli/docker_api_exec_test.go @@ -1,3 +1,5 @@ +// +build !test_no_exec + package main import ( diff --git a/integration-cli/docker_cli_exec_test.go b/integration-cli/docker_cli_exec_test.go index 5dc0e8d71a..85906a8ae0 100644 --- a/integration-cli/docker_cli_exec_test.go +++ b/integration-cli/docker_cli_exec_test.go @@ -1,3 +1,5 @@ +// +build !test_no_exec + package main import ( @@ -5,6 +7,7 @@ import ( "fmt" "os" "os/exec" + "path/filepath" "reflect" "sort" "strings" @@ -453,3 +456,170 @@ func TestExecCgroup(t *testing.T) { logDone("exec - exec has the container cgroups") } + +func TestInspectExecID(t *testing.T) { + defer deleteAllContainers() + + out, exitCode, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "busybox", "top")) + if exitCode != 0 || err != nil { + t.Fatalf("failed to run container: %s, %v", out, err) + } + id := strings.TrimSuffix(out, "\n") + + out, err = inspectField(id, "ExecIDs") + if err != nil { + t.Fatalf("failed to inspect container: %s, %v", out, err) + } + if out != "" { + t.Fatalf("ExecIDs should be empty, got: %s", out) + } + + exitCode, err = runCommand(exec.Command(dockerBinary, "exec", "-d", id, "ls", "/")) + if exitCode != 0 || err != nil { + t.Fatalf("failed to exec in container: %s, %v", out, err) + } + + out, err = inspectField(id, "ExecIDs") + if err != nil { + t.Fatalf("failed to inspect container: %s, %v", out, err) + } + + out = strings.TrimSuffix(out, "\n") + if out == "[]" || out == "" { + t.Fatalf("ExecIDs should not be empty, got: %s", out) + } + + logDone("inspect - inspect a container with ExecIDs") +} + +func TestLinksPingLinkedContainersOnRename(t *testing.T) { + var out string + out, _, _ = dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10") + idA := stripTrailingCharacters(out) + if idA == "" { + t.Fatal(out, "id should not be nil") + } + out, _, _ = dockerCmd(t, "run", "-d", "--link", "container1:alias1", "--name", "container2", "busybox", "sleep", "10") + idB := stripTrailingCharacters(out) + if idB == "" { + t.Fatal(out, "id should not be nil") + } + + execCmd := exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1") + out, _, err := runCommandWithOutput(execCmd) + if err != nil { + t.Fatal(out, err) + } + + dockerCmd(t, "rename", "container1", "container_new") + + execCmd = exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1") + out, _, err = runCommandWithOutput(execCmd) + if err != nil { + t.Fatal(out, err) + } + + deleteAllContainers() + + logDone("links - ping linked container upon rename") +} + +func TestRunExecDir(t *testing.T) { + cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") + out, _, err := runCommandWithOutput(cmd) + if err != nil { + t.Fatal(err, out) + } + id := strings.TrimSpace(out) + execDir := filepath.Join(execDriverPath, id) + stateFile := filepath.Join(execDir, "state.json") + contFile := filepath.Join(execDir, "container.json") + + { + fi, err := os.Stat(execDir) + if err != nil { + t.Fatal(err) + } + if !fi.IsDir() { + t.Fatalf("%q must be a directory", execDir) + } + fi, err = os.Stat(stateFile) + if err != nil { + t.Fatal(err) + } + fi, err = os.Stat(contFile) + if err != nil { + t.Fatal(err) + } + } + + stopCmd := exec.Command(dockerBinary, "stop", id) + out, _, err = runCommandWithOutput(stopCmd) + if err != nil { + t.Fatal(err, out) + } + { + fi, err := os.Stat(execDir) + if err != nil { + t.Fatal(err) + } + if !fi.IsDir() { + t.Fatalf("%q must be a directory", execDir) + } + fi, err = os.Stat(stateFile) + if err == nil { + t.Fatalf("Statefile %q is exists for stopped container!", stateFile) + } + if !os.IsNotExist(err) { + t.Fatalf("Error should be about non-existing, got %s", err) + } + fi, err = os.Stat(contFile) + if err == nil { + t.Fatalf("Container file %q is exists for stopped container!", contFile) + } + if !os.IsNotExist(err) { + t.Fatalf("Error should be about non-existing, got %s", err) + } + } + startCmd := exec.Command(dockerBinary, "start", id) + out, _, err = runCommandWithOutput(startCmd) + if err != nil { + t.Fatal(err, out) + } + { + fi, err := os.Stat(execDir) + if err != nil { + t.Fatal(err) + } + if !fi.IsDir() { + t.Fatalf("%q must be a directory", execDir) + } + fi, err = os.Stat(stateFile) + if err != nil { + t.Fatal(err) + } + fi, err = os.Stat(contFile) + if err != nil { + t.Fatal(err) + } + } + rmCmd := exec.Command(dockerBinary, "rm", "-f", id) + out, _, err = runCommandWithOutput(rmCmd) + if err != nil { + t.Fatal(err, out) + } + { + _, err := os.Stat(execDir) + if err == nil { + t.Fatal(err) + } + if err == nil { + t.Fatalf("Exec directory %q is exists for removed container!", execDir) + } + if !os.IsNotExist(err) { + t.Fatalf("Error should be about non-existing, got %s", err) + } + } + + logDone("run - check execdriver dir behavior") +} diff --git a/integration-cli/docker_cli_inspect_test.go b/integration-cli/docker_cli_inspect_test.go index ee69a89a43..cf42217ac8 100644 --- a/integration-cli/docker_cli_inspect_test.go +++ b/integration-cli/docker_cli_inspect_test.go @@ -21,38 +21,3 @@ func TestInspectImage(t *testing.T) { logDone("inspect - inspect an image") } - -func TestInspectExecID(t *testing.T) { - defer deleteAllContainers() - - out, exitCode, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "busybox", "top")) - if exitCode != 0 || err != nil { - t.Fatalf("failed to run container: %s, %v", out, err) - } - id := strings.TrimSuffix(out, "\n") - - out, err = inspectField(id, "ExecIDs") - if err != nil { - t.Fatalf("failed to inspect container: %s, %v", out, err) - } - if out != "" { - t.Fatalf("ExecIDs should be empty, got: %s", out) - } - - exitCode, err = runCommand(exec.Command(dockerBinary, "exec", "-d", id, "ls", "/")) - if exitCode != 0 || err != nil { - t.Fatalf("failed to exec in container: %s, %v", out, err) - } - - out, err = inspectField(id, "ExecIDs") - if err != nil { - t.Fatalf("failed to inspect container: %s, %v", out, err) - } - - out = strings.TrimSuffix(out, "\n") - if out == "[]" || out == "" { - t.Fatalf("ExecIDs should not be empty, got: %s", out) - } - - logDone("inspect - inspect a container with ExecIDs") -} diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index fc99ec57fb..015db0f89f 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -92,38 +92,6 @@ func TestLinksPingLinkedContainersAfterRename(t *testing.T) { logDone("links - ping linked container after rename") } -func TestLinksPingLinkedContainersOnRename(t *testing.T) { - var out string - out, _, _ = dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10") - idA := stripTrailingCharacters(out) - if idA == "" { - t.Fatal(out, "id should not be nil") - } - out, _, _ = dockerCmd(t, "run", "-d", "--link", "container1:alias1", "--name", "container2", "busybox", "sleep", "10") - idB := stripTrailingCharacters(out) - if idB == "" { - t.Fatal(out, "id should not be nil") - } - - execCmd := exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1") - out, _, err := runCommandWithOutput(execCmd) - if err != nil { - t.Fatal(out, err) - } - - dockerCmd(t, "rename", "container1", "container_new") - - execCmd = exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1") - out, _, err = runCommandWithOutput(execCmd) - if err != nil { - t.Fatal(out, err) - } - - deleteAllContainers() - - logDone("links - ping linked container upon rename") -} - func TestLinksIpTablesRulesWhenLinkAndUnlink(t *testing.T) { dockerCmd(t, "run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "sleep", "10") dockerCmd(t, "run", "-d", "--name", "parent", "--link", "child:http", "busybox", "sleep", "10") diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 6da5b76565..a010c4e22a 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -2404,106 +2404,6 @@ func TestRunMountOrdering(t *testing.T) { logDone("run - volumes are mounted in the correct order") } -func TestRunExecDir(t *testing.T) { - cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") - out, _, err := runCommandWithOutput(cmd) - if err != nil { - t.Fatal(err, out) - } - id := strings.TrimSpace(out) - execDir := filepath.Join(execDriverPath, id) - stateFile := filepath.Join(execDir, "state.json") - contFile := filepath.Join(execDir, "container.json") - - { - fi, err := os.Stat(execDir) - if err != nil { - t.Fatal(err) - } - if !fi.IsDir() { - t.Fatalf("%q must be a directory", execDir) - } - fi, err = os.Stat(stateFile) - if err != nil { - t.Fatal(err) - } - fi, err = os.Stat(contFile) - if err != nil { - t.Fatal(err) - } - } - - stopCmd := exec.Command(dockerBinary, "stop", id) - out, _, err = runCommandWithOutput(stopCmd) - if err != nil { - t.Fatal(err, out) - } - { - fi, err := os.Stat(execDir) - if err != nil { - t.Fatal(err) - } - if !fi.IsDir() { - t.Fatalf("%q must be a directory", execDir) - } - fi, err = os.Stat(stateFile) - if err == nil { - t.Fatalf("Statefile %q is exists for stopped container!", stateFile) - } - if !os.IsNotExist(err) { - t.Fatalf("Error should be about non-existing, got %s", err) - } - fi, err = os.Stat(contFile) - if err == nil { - t.Fatalf("Container file %q is exists for stopped container!", contFile) - } - if !os.IsNotExist(err) { - t.Fatalf("Error should be about non-existing, got %s", err) - } - } - startCmd := exec.Command(dockerBinary, "start", id) - out, _, err = runCommandWithOutput(startCmd) - if err != nil { - t.Fatal(err, out) - } - { - fi, err := os.Stat(execDir) - if err != nil { - t.Fatal(err) - } - if !fi.IsDir() { - t.Fatalf("%q must be a directory", execDir) - } - fi, err = os.Stat(stateFile) - if err != nil { - t.Fatal(err) - } - fi, err = os.Stat(contFile) - if err != nil { - t.Fatal(err) - } - } - rmCmd := exec.Command(dockerBinary, "rm", "-f", id) - out, _, err = runCommandWithOutput(rmCmd) - if err != nil { - t.Fatal(err, out) - } - { - _, err := os.Stat(execDir) - if err == nil { - t.Fatal(err) - } - if err == nil { - t.Fatalf("Exec directory %q is exists for removed container!", execDir) - } - if !os.IsNotExist(err) { - t.Fatalf("Error should be about non-existing, got %s", err) - } - } - - logDone("run - check execdriver dir behavior") -} - // Regression test for https://github.com/docker/docker/issues/8259 func TestRunReuseBindVolumeThatIsSymlink(t *testing.T) { tmpDir, err := ioutil.TempDir(os.TempDir(), "testlink") diff --git a/project/make.sh b/project/make.sh index bb2a3419fa..97751cb67c 100755 --- a/project/make.sh +++ b/project/make.sh @@ -93,6 +93,10 @@ if [ -z "$DOCKER_CLIENTONLY" ]; then DOCKER_BUILDTAGS+=" daemon" fi +if [ "$DOCKER_EXECDRIVER" = 'lxc' ]; then + DOCKER_BUILDTAGS+=' test_no_exec' +fi + # Use these flags when compiling the tests and final binary LDFLAGS=' -X '$DOCKER_PKG'/dockerversion.GITCOMMIT "'$GITCOMMIT'"