1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Use temp dir for integration daemon sockets

Instead of using the bundles dir, which may be mounted in and ultimately
break if using b2d/d4mac/d4win. This makes it much easier to collect
test daemon logs and more natural for use d4mac/d4win users to run tests.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2016-07-28 10:19:09 -04:00
parent b09f280161
commit 4804eb700c
2 changed files with 28 additions and 2 deletions

View file

@ -5,9 +5,11 @@ import (
"os"
"path/filepath"
"sync"
"syscall"
"testing"
"github.com/docker/docker/cliconfig"
"github.com/docker/docker/pkg/integration/checker"
"github.com/docker/docker/pkg/reexec"
"github.com/docker/engine-api/types/swarm"
"github.com/go-check/check"
@ -186,6 +188,21 @@ func (s *DockerDaemonSuite) TearDownTest(c *check.C) {
s.ds.TearDownTest(c)
}
func (s *DockerDaemonSuite) TearDownSuite(c *check.C) {
err := filepath.Walk(daemonSockRoot, func(path string, fi os.FileInfo, err error) error {
if err != nil {
return err
}
if fi.Mode() == os.ModeSocket {
syscall.Unlink(path)
}
return nil
})
c.Assert(err, checker.IsNil, check.Commentf("error while cleaning up daemon sockets"))
err = os.RemoveAll(daemonSockRoot)
c.Assert(err, checker.IsNil, check.Commentf("could not cleanup daemon socket root"))
}
const defaultSwarmPort = 2477
func init() {

View file

@ -22,6 +22,8 @@ import (
"github.com/go-check/check"
)
var daemonSockRoot = filepath.Join(os.TempDir(), "docker-integration")
// Daemon represents a Docker daemon for the testing framework.
type Daemon struct {
GlobalFlags []string
@ -54,6 +56,9 @@ func NewDaemon(c *check.C) *Daemon {
dest := os.Getenv("DEST")
c.Assert(dest, check.Not(check.Equals), "", check.Commentf("Please set the DEST environment variable"))
err := os.MkdirAll(daemonSockRoot, 0700)
c.Assert(err, checker.IsNil, check.Commentf("could not create daemon socket root"))
id := fmt.Sprintf("d%d", time.Now().UnixNano()%100000000)
dir := filepath.Join(dest, id)
daemonFolder, err := filepath.Abs(dir)
@ -108,7 +113,7 @@ func (d *Daemon) getClientConfig() (*clientConfig, error) {
scheme = "http"
transport = &http.Transport{}
} else {
addr = filepath.Join(d.folder, "docker.sock")
addr = d.sockPath()
proto = "unix"
scheme = "http"
transport = &http.Transport{}
@ -410,7 +415,11 @@ func (d *Daemon) queryRootDir() (string, error) {
}
func (d *Daemon) sock() string {
return fmt.Sprintf("unix://%s/docker.sock", d.folder)
return fmt.Sprintf("unix://" + d.sockPath())
}
func (d *Daemon) sockPath() string {
return filepath.Join(daemonSockRoot, d.id+".sock")
}
func (d *Daemon) waitRun(contID string) error {