mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #10194 from jfrazelle/lxc-test-fixes
ignore exec tests when passing DOCKER_EXECDRIVER lxc
This commit is contained in:
commit
a3c5223b2a
6 changed files with 176 additions and 167 deletions
|
@ -1,3 +1,5 @@
|
|||
// +build !test_no_exec
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
|
|
@ -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 != "<no value>" {
|
||||
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 == "<no value>" {
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -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 != "<no value>" {
|
||||
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 == "<no value>" {
|
||||
t.Fatalf("ExecIDs should not be empty, got: %s", out)
|
||||
}
|
||||
|
||||
logDone("inspect - inspect a container with ExecIDs")
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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'"
|
||||
|
|
Loading…
Add table
Reference in a new issue