diff --git a/integration-cli/check_test.go b/integration-cli/check_test.go index 226445a28c..4dfc2f2722 100644 --- a/integration-cli/check_test.go +++ b/integration-cli/check_test.go @@ -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() { diff --git a/integration-cli/daemon.go b/integration-cli/daemon.go index ba0dce3054..69e5d8985f 100644 --- a/integration-cli/daemon.go +++ b/integration-cli/daemon.go @@ -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 {