Small daemon refactoring and add swarm init/join helpers
Signed-off-by: Vincent Demeester <vincent@sbr.pm> Upstream-commit: 239a8a518904dfb51fe62087d8702519c20ce808 Component: engine
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package daemon
|
||||
|
||||
import "github.com/docker/docker/internal/test/environment"
|
||||
|
||||
// WithExperimental sets the daemon in experimental mode
|
||||
func WithExperimental(d *Daemon) {
|
||||
d.experimental = true
|
||||
@@ -25,3 +27,12 @@ func WithSwarmListenAddr(listenAddr string) func(*Daemon) {
|
||||
d.swarmListenAddr = listenAddr
|
||||
}
|
||||
}
|
||||
|
||||
// WithEnvironment sets options from internal/test/environment.Execution struct
|
||||
func WithEnvironment(e environment.Execution) func(*Daemon) {
|
||||
return func(d *Daemon) {
|
||||
if e.DaemonInfo.ExperimentalBuild {
|
||||
d.experimental = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,7 @@ import (
|
||||
// ServiceConstructor defines a swarm service constructor function
|
||||
type ServiceConstructor func(*swarm.Service)
|
||||
|
||||
// CreateServiceWithOptions creates a swarm service given the specified service constructors
|
||||
// and auth config
|
||||
func (d *Daemon) CreateServiceWithOptions(t assert.TestingT, opts types.ServiceCreateOptions, f ...ServiceConstructor) string {
|
||||
func (d *Daemon) createServiceWithOptions(t assert.TestingT, opts types.ServiceCreateOptions, f ...ServiceConstructor) string {
|
||||
var service swarm.Service
|
||||
for _, fn := range f {
|
||||
fn(&service)
|
||||
@@ -34,7 +32,7 @@ func (d *Daemon) CreateServiceWithOptions(t assert.TestingT, opts types.ServiceC
|
||||
|
||||
// CreateService creates a swarm service given the specified service constructor
|
||||
func (d *Daemon) CreateService(t assert.TestingT, f ...ServiceConstructor) string {
|
||||
return d.CreateServiceWithOptions(t, types.ServiceCreateOptions{}, f...)
|
||||
return d.createServiceWithOptions(t, types.ServiceCreateOptions{}, f...)
|
||||
}
|
||||
|
||||
// GetService returns the swarm service corresponding to the specified id
|
||||
|
||||
@@ -14,6 +14,32 @@ const (
|
||||
defaultSwarmListenAddr = "0.0.0.0"
|
||||
)
|
||||
|
||||
// StartAndSwarmInit starts the daemon (with busybox) and init the swarm
|
||||
func (d *Daemon) StartAndSwarmInit(t testingT) {
|
||||
// avoid networking conflicts
|
||||
args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"}
|
||||
d.StartWithBusybox(t, args...)
|
||||
|
||||
d.SwarmInit(t, swarm.InitRequest{})
|
||||
}
|
||||
|
||||
// StartAndSwarmJoin starts the daemon (with busybox) and join the specified swarm as worker or manager
|
||||
func (d *Daemon) StartAndSwarmJoin(t testingT, leader *Daemon, manager bool) {
|
||||
// avoid networking conflicts
|
||||
args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"}
|
||||
d.StartWithBusybox(t, args...)
|
||||
|
||||
tokens := leader.JoinTokens(t)
|
||||
token := tokens.Worker
|
||||
if manager {
|
||||
token = tokens.Manager
|
||||
}
|
||||
d.SwarmJoin(t, swarm.JoinRequest{
|
||||
RemoteAddrs: []string{leader.SwarmListenAddr()},
|
||||
JoinToken: token,
|
||||
})
|
||||
}
|
||||
|
||||
// SpecConstructor defines a swarm spec constructor
|
||||
type SpecConstructor func(*swarm.Spec)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user