Signed-off-by: Antonio Murdaca <me@runcom.ninja>
| ... | ... |
@@ -1005,20 +1005,18 @@ func postContainersWait(eng *engine.Engine, version version.Version, w http.Resp |
| 1005 | 1005 |
if vars == nil {
|
| 1006 | 1006 |
return fmt.Errorf("Missing parameter")
|
| 1007 | 1007 |
} |
| 1008 |
- var ( |
|
| 1009 |
- stdoutBuffer = bytes.NewBuffer(nil) |
|
| 1010 |
- job = eng.Job("wait", vars["name"])
|
|
| 1011 |
- ) |
|
| 1012 |
- job.Stdout.Add(stdoutBuffer) |
|
| 1013 |
- if err := job.Run(); err != nil {
|
|
| 1014 |
- return err |
|
| 1015 |
- } |
|
| 1016 |
- statusCode, err := strconv.Atoi(engine.Tail(stdoutBuffer, 1)) |
|
| 1008 |
+ |
|
| 1009 |
+ name := vars["name"] |
|
| 1010 |
+ d := getDaemon(eng) |
|
| 1011 |
+ cont, err := d.Get(name) |
|
| 1017 | 1012 |
if err != nil {
|
| 1018 | 1013 |
return err |
| 1019 | 1014 |
} |
| 1015 |
+ |
|
| 1016 |
+ status, _ := cont.WaitStop(-1 * time.Second) |
|
| 1017 |
+ |
|
| 1020 | 1018 |
return writeJSON(w, http.StatusOK, &types.ContainerWaitResponse{
|
| 1021 |
- StatusCode: statusCode, |
|
| 1019 |
+ StatusCode: status, |
|
| 1022 | 1020 |
}) |
| 1023 | 1021 |
} |
| 1024 | 1022 |
|
| ... | ... |
@@ -127,7 +127,6 @@ func (daemon *Daemon) Install(eng *engine.Engine) error {
|
| 127 | 127 |
"restart": daemon.ContainerRestart, |
| 128 | 128 |
"start": daemon.ContainerStart, |
| 129 | 129 |
"stop": daemon.ContainerStop, |
| 130 |
- "wait": daemon.ContainerWait, |
|
| 131 | 130 |
"execCreate": daemon.ContainerExecCreate, |
| 132 | 131 |
"execStart": daemon.ContainerExecStart, |
| 133 | 132 |
"execInspect": daemon.ContainerExecInspect, |
| 134 | 133 |
deleted file mode 100644 |
| ... | ... |
@@ -1,22 +0,0 @@ |
| 1 |
-package daemon |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "fmt" |
|
| 5 |
- "time" |
|
| 6 |
- |
|
| 7 |
- "github.com/docker/docker/engine" |
|
| 8 |
-) |
|
| 9 |
- |
|
| 10 |
-func (daemon *Daemon) ContainerWait(job *engine.Job) error {
|
|
| 11 |
- if len(job.Args) != 1 {
|
|
| 12 |
- return fmt.Errorf("Usage: %s", job.Name)
|
|
| 13 |
- } |
|
| 14 |
- name := job.Args[0] |
|
| 15 |
- container, err := daemon.Get(name) |
|
| 16 |
- if err != nil {
|
|
| 17 |
- return fmt.Errorf("%s: %v", job.Name, err)
|
|
| 18 |
- } |
|
| 19 |
- status, _ := container.WaitStop(-1 * time.Second) |
|
| 20 |
- job.Printf("%d\n", status)
|
|
| 21 |
- return nil |
|
| 22 |
-} |
| ... | ... |
@@ -896,3 +896,44 @@ func TestDaemonwithwrongkey(t *testing.T) {
|
| 896 | 896 |
os.Remove("/etc/docker/key.json")
|
| 897 | 897 |
logDone("daemon - it should be failed to start daemon with wrong key")
|
| 898 | 898 |
} |
| 899 |
+ |
|
| 900 |
+func TestDaemonRestartKillWait(t *testing.T) {
|
|
| 901 |
+ d := NewDaemon(t) |
|
| 902 |
+ if err := d.StartWithBusybox(); err != nil {
|
|
| 903 |
+ t.Fatalf("Could not start daemon with busybox: %v", err)
|
|
| 904 |
+ } |
|
| 905 |
+ defer d.Stop() |
|
| 906 |
+ |
|
| 907 |
+ out, err := d.Cmd("run", "-d", "busybox", "/bin/cat")
|
|
| 908 |
+ if err != nil {
|
|
| 909 |
+ t.Fatalf("Could not run /bin/cat: err=%v\n%s", err, out)
|
|
| 910 |
+ } |
|
| 911 |
+ containerID := strings.TrimSpace(out) |
|
| 912 |
+ |
|
| 913 |
+ if out, err := d.Cmd("kill", containerID); err != nil {
|
|
| 914 |
+ t.Fatalf("Could not kill %s: err=%v\n%s", containerID, err, out)
|
|
| 915 |
+ } |
|
| 916 |
+ |
|
| 917 |
+ if err := d.Restart(); err != nil {
|
|
| 918 |
+ t.Fatalf("Could not restart daemon: %v", err)
|
|
| 919 |
+ } |
|
| 920 |
+ |
|
| 921 |
+ errchan := make(chan error) |
|
| 922 |
+ go func() {
|
|
| 923 |
+ if out, err := d.Cmd("wait", containerID); err != nil {
|
|
| 924 |
+ errchan <- fmt.Errorf("%v:\n%s", err, out)
|
|
| 925 |
+ } |
|
| 926 |
+ close(errchan) |
|
| 927 |
+ }() |
|
| 928 |
+ |
|
| 929 |
+ select {
|
|
| 930 |
+ case <-time.After(5 * time.Second): |
|
| 931 |
+ t.Fatal("Waiting on a stopped (killed) container timed out")
|
|
| 932 |
+ case err := <-errchan: |
|
| 933 |
+ if err != nil {
|
|
| 934 |
+ t.Fatal(err) |
|
| 935 |
+ } |
|
| 936 |
+ } |
|
| 937 |
+ |
|
| 938 |
+ logDone("wait - wait on a stopped container doesn't timeout")
|
|
| 939 |
+} |
| ... | ... |
@@ -3,10 +3,8 @@ package docker |
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 | 5 |
"testing" |
| 6 |
- "time" |
|
| 7 | 6 |
|
| 8 | 7 |
"github.com/docker/docker/builder" |
| 9 |
- "github.com/docker/docker/daemon" |
|
| 10 | 8 |
"github.com/docker/docker/engine" |
| 11 | 9 |
) |
| 12 | 10 |
|
| ... | ... |
@@ -103,60 +101,6 @@ func TestMergeConfigOnCommit(t *testing.T) {
|
| 103 | 103 |
} |
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 |
-func TestRestartKillWait(t *testing.T) {
|
|
| 107 |
- eng := NewTestEngine(t) |
|
| 108 |
- runtime := mkDaemonFromEngine(eng, t) |
|
| 109 |
- defer runtime.Nuke() |
|
| 110 |
- |
|
| 111 |
- config, hostConfig, _, err := parseRun([]string{"-i", unitTestImageID, "/bin/cat"})
|
|
| 112 |
- if err != nil {
|
|
| 113 |
- t.Fatal(err) |
|
| 114 |
- } |
|
| 115 |
- |
|
| 116 |
- id := createTestContainer(eng, config, t) |
|
| 117 |
- |
|
| 118 |
- containers, err := runtime.Containers(&daemon.ContainersConfig{All: true})
|
|
| 119 |
- |
|
| 120 |
- if err != nil {
|
|
| 121 |
- t.Errorf("Error getting containers1: %q", err)
|
|
| 122 |
- } |
|
| 123 |
- |
|
| 124 |
- if len(containers) != 1 {
|
|
| 125 |
- t.Errorf("Expected 1 container, %v found", len(containers))
|
|
| 126 |
- } |
|
| 127 |
- |
|
| 128 |
- job := eng.Job("start", id)
|
|
| 129 |
- if err := job.ImportEnv(hostConfig); err != nil {
|
|
| 130 |
- t.Fatal(err) |
|
| 131 |
- } |
|
| 132 |
- if err := job.Run(); err != nil {
|
|
| 133 |
- t.Fatal(err) |
|
| 134 |
- } |
|
| 135 |
- |
|
| 136 |
- if err := runtime.ContainerKill(id, 0); err != nil {
|
|
| 137 |
- t.Fatal(err) |
|
| 138 |
- } |
|
| 139 |
- |
|
| 140 |
- eng = newTestEngine(t, false, runtime.Config().Root) |
|
| 141 |
- runtime = mkDaemonFromEngine(eng, t) |
|
| 142 |
- |
|
| 143 |
- containers, err = runtime.Containers(&daemon.ContainersConfig{All: true})
|
|
| 144 |
- |
|
| 145 |
- if err != nil {
|
|
| 146 |
- t.Errorf("Error getting containers1: %q", err)
|
|
| 147 |
- } |
|
| 148 |
- if len(containers) != 1 {
|
|
| 149 |
- t.Errorf("Expected 1 container, %v found", len(containers))
|
|
| 150 |
- } |
|
| 151 |
- |
|
| 152 |
- setTimeout(t, "Waiting on stopped container timedout", 5*time.Second, func() {
|
|
| 153 |
- job = eng.Job("wait", containers[0].ID)
|
|
| 154 |
- if err := job.Run(); err != nil {
|
|
| 155 |
- t.Fatal(err) |
|
| 156 |
- } |
|
| 157 |
- }) |
|
| 158 |
-} |
|
| 159 |
- |
|
| 160 | 106 |
func TestRunWithTooLowMemoryLimit(t *testing.T) {
|
| 161 | 107 |
eng := NewTestEngine(t) |
| 162 | 108 |
defer mkDaemonFromEngine(eng, t).Nuke() |