2015-04-18 12:46:47 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-06-05 16:09:53 -04:00
|
|
|
"fmt"
|
2016-03-09 03:18:30 -05:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-06-29 14:00:11 -04:00
|
|
|
"sync"
|
2016-07-28 10:19:09 -04:00
|
|
|
"syscall"
|
2015-04-18 12:46:47 -04:00
|
|
|
"testing"
|
|
|
|
|
2016-03-09 03:18:30 -05:00
|
|
|
"github.com/docker/docker/cliconfig"
|
2015-06-05 16:09:53 -04:00
|
|
|
"github.com/docker/docker/pkg/reexec"
|
2016-06-19 22:00:45 -04:00
|
|
|
"github.com/docker/engine-api/types/swarm"
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
2015-04-22 14:20:32 -04:00
|
|
|
func Test(t *testing.T) {
|
2015-06-05 16:09:53 -04:00
|
|
|
reexec.Init() // This is required for external graphdriver tests
|
|
|
|
|
|
|
|
if !isLocalDaemon {
|
|
|
|
fmt.Println("INFO: Testing against a remote daemon")
|
|
|
|
} else {
|
|
|
|
fmt.Println("INFO: Testing against a local daemon")
|
|
|
|
}
|
|
|
|
|
2015-04-22 14:20:32 -04:00
|
|
|
check.TestingT(t)
|
|
|
|
}
|
2015-04-18 12:46:47 -04:00
|
|
|
|
2015-04-24 17:16:56 -04:00
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerSuite{})
|
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
type DockerSuite struct {
|
|
|
|
}
|
|
|
|
|
2016-07-27 14:17:44 -04:00
|
|
|
func (s *DockerSuite) OnTimeout(c *check.C) {
|
|
|
|
if daemonPid > 0 && isLocalDaemon {
|
|
|
|
signalDaemonDump(daemonPid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TearDownTest(c *check.C) {
|
2015-10-27 16:12:33 -04:00
|
|
|
unpauseAllContainers()
|
2015-04-18 12:46:47 -04:00
|
|
|
deleteAllContainers()
|
2015-04-23 17:39:31 -04:00
|
|
|
deleteAllImages()
|
2015-06-12 09:25:32 -04:00
|
|
|
deleteAllVolumes()
|
2015-10-13 17:18:05 -04:00
|
|
|
deleteAllNetworks()
|
2015-04-18 12:46:47 -04:00
|
|
|
}
|
|
|
|
|
2015-04-24 17:16:56 -04:00
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerRegistrySuite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type DockerRegistrySuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
reg *testRegistryV2
|
2015-09-16 13:42:17 -04:00
|
|
|
d *Daemon
|
2015-04-24 17:16:56 -04:00
|
|
|
}
|
|
|
|
|
2016-07-27 14:17:44 -04:00
|
|
|
func (s *DockerRegistrySuite) OnTimeout(c *check.C) {
|
|
|
|
s.d.DumpStackAndQuit()
|
|
|
|
}
|
|
|
|
|
2015-04-24 17:16:56 -04:00
|
|
|
func (s *DockerRegistrySuite) SetUpTest(c *check.C) {
|
2016-01-29 16:35:20 -05:00
|
|
|
testRequires(c, DaemonIsLinux, RegistryHosting)
|
2016-03-14 16:11:35 -04:00
|
|
|
s.reg = setupRegistry(c, false, "", "")
|
2015-09-16 13:42:17 -04:00
|
|
|
s.d = NewDaemon(c)
|
2015-04-24 17:16:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerRegistrySuite) TearDownTest(c *check.C) {
|
2015-07-23 05:40:54 -04:00
|
|
|
if s.reg != nil {
|
|
|
|
s.reg.Close()
|
|
|
|
}
|
2016-01-13 04:51:01 -05:00
|
|
|
if s.d != nil {
|
|
|
|
s.d.Stop()
|
2015-07-23 05:40:54 -04:00
|
|
|
}
|
2016-01-13 04:51:01 -05:00
|
|
|
s.ds.TearDownTest(c)
|
2015-04-24 17:16:56 -04:00
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
|
2015-12-18 18:06:23 -05:00
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerSchema1RegistrySuite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type DockerSchema1RegistrySuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
reg *testRegistryV2
|
|
|
|
d *Daemon
|
|
|
|
}
|
|
|
|
|
2016-07-27 14:17:44 -04:00
|
|
|
func (s *DockerSchema1RegistrySuite) OnTimeout(c *check.C) {
|
|
|
|
s.d.DumpStackAndQuit()
|
|
|
|
}
|
|
|
|
|
2015-12-18 18:06:23 -05:00
|
|
|
func (s *DockerSchema1RegistrySuite) SetUpTest(c *check.C) {
|
2016-07-04 06:09:46 -04:00
|
|
|
testRequires(c, DaemonIsLinux, RegistryHosting, NotArm64)
|
2016-03-14 16:11:35 -04:00
|
|
|
s.reg = setupRegistry(c, true, "", "")
|
2015-12-18 18:06:23 -05:00
|
|
|
s.d = NewDaemon(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSchema1RegistrySuite) TearDownTest(c *check.C) {
|
|
|
|
if s.reg != nil {
|
|
|
|
s.reg.Close()
|
|
|
|
}
|
2016-01-13 04:51:01 -05:00
|
|
|
if s.d != nil {
|
|
|
|
s.d.Stop()
|
2015-12-18 18:06:23 -05:00
|
|
|
}
|
2016-01-13 04:51:01 -05:00
|
|
|
s.ds.TearDownTest(c)
|
2015-12-18 18:06:23 -05:00
|
|
|
}
|
|
|
|
|
2016-01-23 13:45:01 -05:00
|
|
|
func init() {
|
2016-03-14 16:11:35 -04:00
|
|
|
check.Suite(&DockerRegistryAuthHtpasswdSuite{
|
2016-01-23 13:45:01 -05:00
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-03-14 16:11:35 -04:00
|
|
|
type DockerRegistryAuthHtpasswdSuite struct {
|
2016-01-23 13:45:01 -05:00
|
|
|
ds *DockerSuite
|
|
|
|
reg *testRegistryV2
|
|
|
|
d *Daemon
|
|
|
|
}
|
|
|
|
|
2016-07-27 14:17:44 -04:00
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) OnTimeout(c *check.C) {
|
|
|
|
s.d.DumpStackAndQuit()
|
|
|
|
}
|
|
|
|
|
2016-03-14 16:11:35 -04:00
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) SetUpTest(c *check.C) {
|
2016-01-29 16:35:20 -05:00
|
|
|
testRequires(c, DaemonIsLinux, RegistryHosting)
|
2016-03-14 16:11:35 -04:00
|
|
|
s.reg = setupRegistry(c, false, "htpasswd", "")
|
2016-01-23 13:45:01 -05:00
|
|
|
s.d = NewDaemon(c)
|
|
|
|
}
|
|
|
|
|
2016-03-14 16:11:35 -04:00
|
|
|
func (s *DockerRegistryAuthHtpasswdSuite) TearDownTest(c *check.C) {
|
2016-01-23 13:45:01 -05:00
|
|
|
if s.reg != nil {
|
|
|
|
out, err := s.d.Cmd("logout", privateRegistryURL)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
|
|
|
s.reg.Close()
|
|
|
|
}
|
|
|
|
if s.d != nil {
|
|
|
|
s.d.Stop()
|
|
|
|
}
|
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
|
|
|
|
2016-03-14 16:11:35 -04:00
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerRegistryAuthTokenSuite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type DockerRegistryAuthTokenSuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
reg *testRegistryV2
|
|
|
|
d *Daemon
|
|
|
|
}
|
|
|
|
|
2016-07-27 14:17:44 -04:00
|
|
|
func (s *DockerRegistryAuthTokenSuite) OnTimeout(c *check.C) {
|
|
|
|
s.d.DumpStackAndQuit()
|
|
|
|
}
|
|
|
|
|
2016-03-14 16:11:35 -04:00
|
|
|
func (s *DockerRegistryAuthTokenSuite) SetUpTest(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux, RegistryHosting)
|
|
|
|
s.d = NewDaemon(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerRegistryAuthTokenSuite) TearDownTest(c *check.C) {
|
|
|
|
if s.reg != nil {
|
|
|
|
out, err := s.d.Cmd("logout", privateRegistryURL)
|
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
|
|
|
s.reg.Close()
|
|
|
|
}
|
|
|
|
if s.d != nil {
|
|
|
|
s.d.Stop()
|
|
|
|
}
|
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerRegistryAuthTokenSuite) setupRegistryWithTokenService(c *check.C, tokenURL string) {
|
|
|
|
if s == nil {
|
|
|
|
c.Fatal("registry suite isn't initialized")
|
|
|
|
}
|
|
|
|
s.reg = setupRegistry(c, false, "token", tokenURL)
|
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerDaemonSuite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type DockerDaemonSuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
d *Daemon
|
|
|
|
}
|
|
|
|
|
2016-07-27 14:17:44 -04:00
|
|
|
func (s *DockerDaemonSuite) OnTimeout(c *check.C) {
|
|
|
|
s.d.DumpStackAndQuit()
|
|
|
|
}
|
|
|
|
|
2015-04-25 22:47:42 -04:00
|
|
|
func (s *DockerDaemonSuite) SetUpTest(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-25 22:47:42 -04:00
|
|
|
s.d = NewDaemon(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerDaemonSuite) TearDownTest(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2016-01-13 04:51:01 -05:00
|
|
|
if s.d != nil {
|
|
|
|
s.d.Stop()
|
|
|
|
}
|
2015-04-25 22:47:42 -04:00
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
2015-07-20 01:56:10 -04:00
|
|
|
|
2016-07-28 10:19:09 -04:00
|
|
|
func (s *DockerDaemonSuite) TearDownSuite(c *check.C) {
|
2016-08-10 15:18:35 -04:00
|
|
|
filepath.Walk(daemonSockRoot, func(path string, fi os.FileInfo, err error) error {
|
2016-07-28 10:19:09 -04:00
|
|
|
if err != nil {
|
2016-08-10 15:18:35 -04:00
|
|
|
// ignore errors here
|
|
|
|
// not cleaning up sockets is not really an error
|
|
|
|
return nil
|
2016-07-28 10:19:09 -04:00
|
|
|
}
|
|
|
|
if fi.Mode() == os.ModeSocket {
|
|
|
|
syscall.Unlink(path)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
2016-08-10 15:18:35 -04:00
|
|
|
os.RemoveAll(daemonSockRoot)
|
2016-07-28 10:19:09 -04:00
|
|
|
}
|
|
|
|
|
2016-06-13 22:54:20 -04:00
|
|
|
const defaultSwarmPort = 2477
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerSwarmSuite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type DockerSwarmSuite struct {
|
2016-06-29 14:00:11 -04:00
|
|
|
ds *DockerSuite
|
|
|
|
daemons []*SwarmDaemon
|
|
|
|
daemonsLock sync.Mutex // protect access to daemons
|
|
|
|
portIndex int
|
2016-06-13 22:54:20 -04:00
|
|
|
}
|
|
|
|
|
2016-07-27 14:17:44 -04:00
|
|
|
func (s *DockerSwarmSuite) OnTimeout(c *check.C) {
|
|
|
|
s.daemonsLock.Lock()
|
|
|
|
defer s.daemonsLock.Unlock()
|
|
|
|
for _, d := range s.daemons {
|
|
|
|
d.DumpStackAndQuit()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-13 22:54:20 -04:00
|
|
|
func (s *DockerSwarmSuite) SetUpTest(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) AddDaemon(c *check.C, joinSwarm, manager bool) *SwarmDaemon {
|
|
|
|
d := &SwarmDaemon{
|
|
|
|
Daemon: NewDaemon(c),
|
|
|
|
port: defaultSwarmPort + s.portIndex,
|
|
|
|
}
|
|
|
|
d.listenAddr = fmt.Sprintf("0.0.0.0:%d", d.port)
|
2016-06-30 21:07:35 -04:00
|
|
|
err := d.StartWithBusybox("--iptables=false", "--swarm-default-advertise-addr=lo") // avoid networking conflicts
|
2016-06-13 22:54:20 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
if joinSwarm == true {
|
|
|
|
if len(s.daemons) > 0 {
|
2016-07-20 14:15:08 -04:00
|
|
|
tokens := s.daemons[0].joinTokens(c)
|
|
|
|
token := tokens.Worker
|
|
|
|
if manager {
|
|
|
|
token = tokens.Manager
|
|
|
|
}
|
2016-06-19 22:00:45 -04:00
|
|
|
c.Assert(d.Join(swarm.JoinRequest{
|
|
|
|
RemoteAddrs: []string{s.daemons[0].listenAddr},
|
2016-07-20 14:15:08 -04:00
|
|
|
JoinToken: token,
|
2016-06-19 22:00:45 -04:00
|
|
|
}), check.IsNil)
|
2016-07-20 14:15:08 -04:00
|
|
|
} else {
|
|
|
|
c.Assert(d.Init(swarm.InitRequest{}), check.IsNil)
|
2016-06-13 22:54:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s.portIndex++
|
2016-06-29 14:00:11 -04:00
|
|
|
s.daemonsLock.Lock()
|
2016-06-13 22:54:20 -04:00
|
|
|
s.daemons = append(s.daemons, d)
|
2016-06-29 14:00:11 -04:00
|
|
|
s.daemonsLock.Unlock()
|
2016-06-13 22:54:20 -04:00
|
|
|
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TearDownTest(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
2016-06-29 14:00:11 -04:00
|
|
|
s.daemonsLock.Lock()
|
2016-06-13 22:54:20 -04:00
|
|
|
for _, d := range s.daemons {
|
|
|
|
d.Stop()
|
2016-08-12 20:30:37 -04:00
|
|
|
// raft state file is quite big (64MB) so remove it after every test
|
|
|
|
walDir := filepath.Join(d.root, "swarm/raft/wal")
|
|
|
|
if err := os.RemoveAll(walDir); err != nil {
|
|
|
|
c.Logf("error removing %v: %v", walDir, err)
|
|
|
|
}
|
2016-06-13 22:54:20 -04:00
|
|
|
}
|
|
|
|
s.daemons = nil
|
2016-06-29 14:00:11 -04:00
|
|
|
s.daemonsLock.Unlock()
|
2016-06-13 22:54:20 -04:00
|
|
|
|
2016-06-29 14:00:11 -04:00
|
|
|
s.portIndex = 0
|
2016-06-13 22:54:20 -04:00
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
|
|
|
|
2015-07-20 01:56:10 -04:00
|
|
|
func init() {
|
|
|
|
check.Suite(&DockerTrustSuite{
|
|
|
|
ds: &DockerSuite{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type DockerTrustSuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
reg *testRegistryV2
|
|
|
|
not *testNotary
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerTrustSuite) SetUpTest(c *check.C) {
|
2016-03-11 17:11:35 -05:00
|
|
|
testRequires(c, RegistryHosting, NotaryServerHosting)
|
2016-03-14 16:11:35 -04:00
|
|
|
s.reg = setupRegistry(c, false, "", "")
|
2015-07-20 01:56:10 -04:00
|
|
|
s.not = setupNotary(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerTrustSuite) TearDownTest(c *check.C) {
|
2016-01-13 04:51:01 -05:00
|
|
|
if s.reg != nil {
|
|
|
|
s.reg.Close()
|
|
|
|
}
|
|
|
|
if s.not != nil {
|
|
|
|
s.not.Close()
|
|
|
|
}
|
2016-03-09 03:18:30 -05:00
|
|
|
|
|
|
|
// Remove trusted keys and metadata after test
|
|
|
|
os.RemoveAll(filepath.Join(cliconfig.ConfigDir(), "trust"))
|
2015-07-20 01:56:10 -04:00
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|