Swarm integration tests

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Signed-off-by: Victor Vieux <vieux@docker.com>
Upstream-commit: 0d88d5b64b69a451d374e322b2abe64140a6cd1c
Component: engine
This commit is contained in:
Tonis Tiigi
2016-06-13 19:54:20 -07:00
parent be63983b3a
commit 7a33d63cb2
8 changed files with 913 additions and 13 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
@ -292,9 +293,9 @@ out1:
select {
case err := <-d.wait:
return err
case <-time.After(15 * time.Second):
case <-time.After(20 * time.Second):
// time for stopping jobs and run onShutdown hooks
d.c.Log("timeout")
d.c.Logf("timeout: %v", d.id)
break out1
}
}
@ -306,7 +307,7 @@ out2:
return err
case <-tick:
i++
if i > 4 {
if i > 5 {
d.c.Logf("tried to interrupt daemon for %d times, now try to kill it", i)
break out2
}
@ -452,6 +453,27 @@ func (d *Daemon) CmdWithArgs(daemonArgs []string, name string, arg ...string) (s
return string(b), err
}
// SockRequest executes a socket request on a daemon and returns statuscode and output.
func (d *Daemon) SockRequest(method, endpoint string, data interface{}) (int, []byte, error) {
jsonData := bytes.NewBuffer(nil)
if err := json.NewEncoder(jsonData).Encode(data); err != nil {
return -1, nil, err
}
res, body, err := d.SockRequestRaw(method, endpoint, jsonData, "application/json")
if err != nil {
return -1, nil, err
}
b, err := readBody(body)
return res.StatusCode, b, err
}
// SockRequestRaw executes a socket request on a daemon and returns a http
// response and a reader for the output data.
func (d *Daemon) SockRequestRaw(method, endpoint string, data io.Reader, ct string) (*http.Response, io.ReadCloser, error) {
return sockRequestRawToDaemon(method, endpoint, data, ct, d.sock())
}
// LogFileName returns the path the the daemon's log file
func (d *Daemon) LogFileName() string {
return d.logFile.Name()
@ -461,6 +483,16 @@ func (d *Daemon) getIDByName(name string) (string, error) {
return d.inspectFieldWithError(name, "Id")
}
func (d *Daemon) activeContainers() (ids []string) {
out, _ := d.Cmd("ps", "-q")
for _, id := range strings.Split(out, "\n") {
if id = strings.TrimSpace(id); id != "" {
ids = append(ids, id)
}
}
return
}
func (d *Daemon) inspectFilter(name, filter string) (string, error) {
format := fmt.Sprintf("{{%s}}", filter)
out, err := d.Cmd("inspect", "-f", format, name)
@ -486,3 +518,12 @@ func (d *Daemon) buildImageWithOut(name, dockerfile string, useCache bool, build
buildCmd := buildImageCmdWithHost(name, dockerfile, d.sock(), useCache, buildFlags...)
return runCommandWithOutput(buildCmd)
}
func (d *Daemon) checkActiveContainerCount(c *check.C) (interface{}, check.CommentInterface) {
out, err := d.Cmd("ps", "-q")
c.Assert(err, checker.IsNil)
if len(strings.TrimSpace(out)) == 0 {
return 0, nil
}
return len(strings.Split(strings.TrimSpace(out), "\n")), check.Commentf("output: %q", string(out))
}