Merge branch 'master' of github.com:docker/docker into kill

Docker-DCO-1.1-Signed-off-by: Dan Walsh <dwalsh@redhat.com> (github: rhatdan)
Upstream-commit: 35a7f0c59ec4de748a8038a3ba45f8a17021e5ef
Component: engine
This commit is contained in:
Dan Walsh
2015-05-27 16:37:32 -04:00
10 changed files with 145 additions and 57 deletions
@@ -254,6 +254,42 @@ func (s *DockerSuite) TestGetContainerStats(c *check.C) {
}
}
func (s *DockerSuite) TestContainerStatsRmRunning(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
id := strings.TrimSpace(out)
buf := &channelBuffer{make(chan []byte, 1)}
defer buf.Close()
chErr := make(chan error)
go func() {
_, body, err := sockRequestRaw("GET", "/containers/"+id+"/stats?stream=1", nil, "application/json")
if err != nil {
chErr <- err
}
defer body.Close()
_, err = io.Copy(buf, body)
chErr <- err
}()
defer func() {
c.Assert(<-chErr, check.IsNil)
}()
b := make([]byte, 32)
// make sure we've got some stats
_, err := buf.ReadTimeout(b, 2*time.Second)
c.Assert(err, check.IsNil)
// Now remove without `-f` and make sure we are still pulling stats
_, err = runCommand(exec.Command(dockerBinary, "rm", id))
c.Assert(err, check.Not(check.IsNil), check.Commentf("rm should have failed but didn't"))
_, err = buf.ReadTimeout(b, 2*time.Second)
c.Assert(err, check.IsNil)
dockerCmd(c, "rm", "-f", id)
_, err = buf.ReadTimeout(b, 2*time.Second)
c.Assert(err, check.Not(check.IsNil))
}
func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
// TODO: this test does nothing because we are c.Assert'ing in goroutine
var (
@@ -595,3 +595,40 @@ func (s *DockerSuite) TestCpNameHasColon(c *check.C) {
c.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
}
}
func (s *DockerSuite) TestCopyAndRestart(c *check.C) {
expectedMsg := "hello"
out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", expectedMsg).CombinedOutput()
if err != nil {
c.Fatal(string(out), err)
}
id := strings.TrimSpace(string(out))
if out, err = exec.Command(dockerBinary, "wait", id).CombinedOutput(); err != nil {
c.Fatalf("unable to wait for container: %s", err)
}
status := strings.TrimSpace(string(out))
if status != "0" {
c.Fatalf("container exited with status %s", status)
}
tmpDir, err := ioutil.TempDir("", "test-docker-restart-after-copy-")
if err != nil {
c.Fatalf("unable to make temporary directory: %s", err)
}
defer os.RemoveAll(tmpDir)
if _, err = exec.Command(dockerBinary, "cp", fmt.Sprintf("%s:/etc/issue", id), tmpDir).CombinedOutput(); err != nil {
c.Fatalf("unable to copy from busybox container: %s", err)
}
if out, err = exec.Command(dockerBinary, "start", "-a", id).CombinedOutput(); err != nil {
c.Fatalf("unable to start busybox container after copy: %s - %s", err, out)
}
msg := strings.TrimSpace(string(out))
if msg != expectedMsg {
c.Fatalf("expected %q but got %q", expectedMsg, msg)
}
}
@@ -42,11 +42,11 @@ func (s *DockerSuite) TestKillofStoppedContainer(c *check.C) {
stopCmd := exec.Command(dockerBinary, "stop", cleanedContainerID)
out, _, err = runCommandWithOutput(stopCmd)
c.Assert(err, check.IsNil, check.Commentf("failed to stop container: %s, %v", out, err))
c.Assert(err, check.IsNil)
killCmd := exec.Command(dockerBinary, "kill", "-s", "30", cleanedContainerID)
_, _, err = runCommandWithOutput(killCmd)
c.Assert(err, check.Not(check.IsNil), check.Commentf("Kill succeeded on a stopped container"))
c.Assert(err, check.Not(check.IsNil), check.Commentf("Container %s is not running", cleanedContainerID))
}
func (s *DockerSuite) TestKillDifferentUserContainer(c *check.C) {
@@ -3172,7 +3172,7 @@ func (s *DockerSuite) TestTwoContainersInNetHost(c *check.C) {
}
func (s *DockerSuite) TestRunUnshareProc(c *check.C) {
testRequires(c, Apparmor)
testRequires(c, Apparmor, NativeExecDriver)
name := "acidburn"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "jess/unshare", "unshare", "-p", "-m", "-f", "-r", "--mount-proc=/proc", "mount")
+23 -21
View File
@@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"net/http"
"net/http/httptest"
"os"
"os/exec"
@@ -275,26 +274,6 @@ type FileServer struct {
*httptest.Server
}
func fileServer(files map[string]string) (*FileServer, error) {
var handler http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
if filePath, found := files[r.URL.Path]; found {
http.ServeFile(w, r, filePath)
} else {
http.Error(w, http.StatusText(404), 404)
}
}
for _, file := range files {
if _, err := os.Stat(file); err != nil {
return nil, err
}
}
server := httptest.NewServer(handler)
return &FileServer{
Server: server,
}, nil
}
// randomUnixTmpDirPath provides a temporary unix path with rand string appended.
// does not create or checks if it exists.
func randomUnixTmpDirPath(s string) string {
@@ -337,3 +316,26 @@ func parseCgroupPaths(procCgroupData string) map[string]string {
}
return cgroupPaths
}
type channelBuffer struct {
c chan []byte
}
func (c *channelBuffer) Write(b []byte) (int, error) {
c.c <- b
return len(b), nil
}
func (c *channelBuffer) Close() error {
close(c.c)
return nil
}
func (c *channelBuffer) ReadTimeout(p []byte, n time.Duration) (int, error) {
select {
case b := <-c.c:
return copy(p[0:], b), nil
case <-time.After(n):
return -1, fmt.Errorf("timeout reading from channel")
}
}