Merge pull request #10455 from ashahab-altiscale/9875-lxc-symlink

Fixes symlink, container size, and kmsg tests
This commit is contained in:
Michael Crosby 2015-02-02 13:13:27 -08:00
commit 382f187b1a
3 changed files with 34 additions and 8 deletions

View File

@ -89,10 +89,22 @@ func TestDiffEnsureOnlyKmsgAndPtmx(t *testing.T) {
deleteContainer(cleanCID) deleteContainer(cleanCID)
expected := map[string]bool{ expected := map[string]bool{
"C /dev": true, "C /dev": true,
"A /dev/full": true, // busybox "A /dev/full": true, // busybox
"C /dev/ptmx": true, // libcontainer "C /dev/ptmx": true, // libcontainer
"A /dev/kmsg": true, // lxc "A /dev/kmsg": true, // lxc
"A /dev/fd": true,
"A /dev/fuse": true,
"A /dev/ptmx": true,
"A /dev/null": true,
"A /dev/random": true,
"A /dev/stdout": true,
"A /dev/stderr": true,
"A /dev/tty1": true,
"A /dev/stdin": true,
"A /dev/tty": true,
"A /dev/urandom": true,
"A /dev/zero": true,
} }
for _, line := range strings.Split(out, "\n") { for _, line := range strings.Split(out, "\n") {

View File

@ -1,7 +1,9 @@
package main package main
import ( import (
"fmt"
"os/exec" "os/exec"
"strconv"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -243,6 +245,18 @@ func assertContainerList(out string, expected []string) bool {
} }
func TestPsListContainersSize(t *testing.T) { func TestPsListContainersSize(t *testing.T) {
cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "hello")
runCommandWithOutput(cmd)
cmd = exec.Command(dockerBinary, "ps", "-s", "-n=1")
base_out, _, err := runCommandWithOutput(cmd)
base_lines := strings.Split(strings.Trim(base_out, "\n "), "\n")
base_sizeIndex := strings.Index(base_lines[0], "SIZE")
base_foundSize := base_lines[1][base_sizeIndex:]
base_bytes, err := strconv.Atoi(strings.Split(base_foundSize, " ")[0])
if err != nil {
t.Fatal(err)
}
name := "test_size" name := "test_size"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test") runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test")
out, _, err := runCommandWithOutput(runCmd) out, _, err := runCommandWithOutput(runCmd)
@ -275,7 +289,7 @@ func TestPsListContainersSize(t *testing.T) {
if foundID != id[:12] { if foundID != id[:12] {
t.Fatalf("Expected id %s, got %s", id[:12], foundID) t.Fatalf("Expected id %s, got %s", id[:12], foundID)
} }
expectedSize := "2 B" expectedSize := fmt.Sprintf("%d B", (2 + base_bytes))
foundSize := lines[1][sizeIndex:] foundSize := lines[1][sizeIndex:]
if foundSize != expectedSize { if foundSize != expectedSize {
t.Fatalf("Expected size %q, got %q", expectedSize, foundSize) t.Fatalf("Expected size %q, got %q", expectedSize, foundSize)

View File

@ -572,14 +572,14 @@ func TestRunCreateVolume(t *testing.T) {
func TestRunCreateVolumeWithSymlink(t *testing.T) { func TestRunCreateVolumeWithSymlink(t *testing.T) {
buildCmd := exec.Command(dockerBinary, "build", "-t", "docker-test-createvolumewithsymlink", "-") buildCmd := exec.Command(dockerBinary, "build", "-t", "docker-test-createvolumewithsymlink", "-")
buildCmd.Stdin = strings.NewReader(`FROM busybox buildCmd.Stdin = strings.NewReader(`FROM busybox
RUN mkdir /foo && ln -s /foo /bar`) RUN ln -s home /bar`)
buildCmd.Dir = workingDirectory buildCmd.Dir = workingDirectory
err := buildCmd.Run() err := buildCmd.Run()
if err != nil { if err != nil {
t.Fatalf("could not build 'docker-test-createvolumewithsymlink': %v", err) t.Fatalf("could not build 'docker-test-createvolumewithsymlink': %v", err)
} }
cmd := exec.Command(dockerBinary, "run", "-v", "/bar/foo", "--name", "test-createvolumewithsymlink", "docker-test-createvolumewithsymlink", "sh", "-c", "mount | grep -q /foo/foo") cmd := exec.Command(dockerBinary, "run", "-v", "/bar/foo", "--name", "test-createvolumewithsymlink", "docker-test-createvolumewithsymlink", "sh", "-c", "mount | grep -q /home/foo")
exitCode, err := runCommand(cmd) exitCode, err := runCommand(cmd)
if err != nil || exitCode != 0 { if err != nil || exitCode != 0 {
t.Fatalf("[run] err: %v, exitcode: %d", err, exitCode) t.Fatalf("[run] err: %v, exitcode: %d", err, exitCode)
@ -615,7 +615,7 @@ func TestRunVolumesFromSymlinkPath(t *testing.T) {
name := "docker-test-volumesfromsymlinkpath" name := "docker-test-volumesfromsymlinkpath"
buildCmd := exec.Command(dockerBinary, "build", "-t", name, "-") buildCmd := exec.Command(dockerBinary, "build", "-t", name, "-")
buildCmd.Stdin = strings.NewReader(`FROM busybox buildCmd.Stdin = strings.NewReader(`FROM busybox
RUN mkdir /baz && ln -s /baz /foo RUN ln -s home /foo
VOLUME ["/foo/bar"]`) VOLUME ["/foo/bar"]`)
buildCmd.Dir = workingDirectory buildCmd.Dir = workingDirectory
err := buildCmd.Run() err := buildCmd.Run()