Added a test for testing that http addr is set properly
This commit is contained in:
parent
0e7a2d68c1
commit
f33a010f8d
|
@ -150,34 +150,9 @@ func (a *Agent) serverConfig() (*nomad.Config, error) {
|
||||||
return conf, nil
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// setupServer is used to setup the server if enabled
|
// clientConfig is used to generate a new client configuration struct
|
||||||
func (a *Agent) setupServer() error {
|
// for initializing a nomad client.
|
||||||
if !a.config.Server.Enabled {
|
func (a *Agent) clientConfig() (*clientconfig.Config, error) {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup the configuration
|
|
||||||
conf, err := a.serverConfig()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("server config setup failed: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the server
|
|
||||||
server, err := nomad.NewServer(conf)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("server setup failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
a.server = server
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// setupClient is used to setup the client if enabled
|
|
||||||
func (a *Agent) setupClient() error {
|
|
||||||
if !a.config.Client.Enabled {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup the configuration
|
// Setup the configuration
|
||||||
conf := a.config.ClientConfig
|
conf := a.config.ClientConfig
|
||||||
if conf == nil {
|
if conf == nil {
|
||||||
|
@ -212,7 +187,7 @@ func (a *Agent) setupClient() error {
|
||||||
if a.config.Client.MaxKillTimeout != "" {
|
if a.config.Client.MaxKillTimeout != "" {
|
||||||
dur, err := time.ParseDuration(a.config.Client.MaxKillTimeout)
|
dur, err := time.ParseDuration(a.config.Client.MaxKillTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error parsing retry interval: %s", err)
|
return nil, fmt.Errorf("Error parsing retry interval: %s", err)
|
||||||
}
|
}
|
||||||
conf.MaxKillTimeout = dur
|
conf.MaxKillTimeout = dur
|
||||||
}
|
}
|
||||||
|
@ -229,16 +204,52 @@ func (a *Agent) setupClient() error {
|
||||||
if a.config.Addresses.HTTP != "" && a.config.AdvertiseAddrs.HTTP == "" {
|
if a.config.Addresses.HTTP != "" && a.config.AdvertiseAddrs.HTTP == "" {
|
||||||
httpAddr = fmt.Sprintf("%s:%d", a.config.Addresses.HTTP, a.config.Ports.HTTP)
|
httpAddr = fmt.Sprintf("%s:%d", a.config.Addresses.HTTP, a.config.Ports.HTTP)
|
||||||
if _, err := net.ResolveTCPAddr("tcp", httpAddr); err != nil {
|
if _, err := net.ResolveTCPAddr("tcp", httpAddr); err != nil {
|
||||||
return fmt.Errorf("error resolving http addr: %v:", err)
|
return nil, fmt.Errorf("error resolving http addr: %v:", err)
|
||||||
}
|
}
|
||||||
} else if a.config.AdvertiseAddrs.HTTP != "" {
|
} else if a.config.AdvertiseAddrs.HTTP != "" {
|
||||||
addr, err := net.ResolveTCPAddr("tcp", a.config.AdvertiseAddrs.HTTP)
|
addr, err := net.ResolveTCPAddr("tcp", a.config.AdvertiseAddrs.HTTP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error resolving advertise http addr: %v", err)
|
return nil, fmt.Errorf("error resolving advertise http addr: %v", err)
|
||||||
}
|
}
|
||||||
httpAddr = fmt.Sprintf("%s:%d", addr.IP.String(), addr.Port)
|
httpAddr = fmt.Sprintf("%s:%d", addr.IP.String(), addr.Port)
|
||||||
}
|
}
|
||||||
conf.Node.HTTPAddr = httpAddr
|
conf.Node.HTTPAddr = httpAddr
|
||||||
|
return conf, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// setupServer is used to setup the server if enabled
|
||||||
|
func (a *Agent) setupServer() error {
|
||||||
|
if !a.config.Server.Enabled {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup the configuration
|
||||||
|
conf, err := a.serverConfig()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("server config setup failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the server
|
||||||
|
server, err := nomad.NewServer(conf)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("server setup failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
a.server = server
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// setupClient is used to setup the client if enabled
|
||||||
|
func (a *Agent) setupClient() error {
|
||||||
|
if !a.config.Client.Enabled {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup the configuration
|
||||||
|
conf, err := a.clientConfig()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("client setup failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Reserve some ports for the plugins
|
// Reserve some ports for the plugins
|
||||||
if err := a.reservePortsForClient(conf); err != nil {
|
if err := a.reservePortsForClient(conf); err != nil {
|
||||||
|
|
|
@ -198,3 +198,21 @@ func TestAgent_ServerConfig(t *testing.T) {
|
||||||
t.Fatalf("should have bootstrap-expect = 3")
|
t.Fatalf("should have bootstrap-expect = 3")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAgent_ClientConfig(t *testing.T) {
|
||||||
|
conf := DefaultConfig()
|
||||||
|
a := &Agent{config: conf}
|
||||||
|
conf.Client.Enabled = true
|
||||||
|
conf.Addresses.HTTP = "127.0.0.1"
|
||||||
|
conf.Ports.HTTP = 5678
|
||||||
|
|
||||||
|
c, err := a.clientConfig()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("got err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedHttpAddr := "127.0.0.1:5678"
|
||||||
|
if c.Node.HTTPAddr != expectedHttpAddr {
|
||||||
|
t.Fatalf("Expected http addr: %v, got: %v", expectedHttpAddr, c.Node.HTTPAddr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue