Ver Fonte

Merge pull request #25171 from cpuguy83/23545_test_sockets_in_separate_dir

Use temp dir for integration daemon sockets
Sebastiaan van Stijn há 9 anos atrás
pai
commit
f23c3a1263
2 ficheiros alterados com 28 adições e 2 exclusões
  1. 17 0
      integration-cli/check_test.go
  2. 11 2
      integration-cli/daemon.go

+ 17 - 0
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() {

+ 11 - 2
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 {