mirror of https://github.com/hashicorp/consul
agent: Simplifying configs
parent
922014530f
commit
8dd1e51bae
|
@ -67,16 +67,13 @@ func Create(config *Config, logOutput io.Writer) (*Agent, error) {
|
||||||
return nil, fmt.Errorf("Must configure a DataDir")
|
return nil, fmt.Errorf("Must configure a DataDir")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the Bind Addr is sane
|
|
||||||
if _, err := net.ResolveTCPAddr("tcp", config.BindAddr); err != nil {
|
|
||||||
return nil, fmt.Errorf("Bad server address: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to get an advertise address
|
// Try to get an advertise address
|
||||||
if config.AdvertiseAddr != "" {
|
if config.AdvertiseAddr != "" {
|
||||||
if ip := net.ParseIP(config.AdvertiseAddr); ip == nil {
|
if ip := net.ParseIP(config.AdvertiseAddr); ip == nil {
|
||||||
return nil, fmt.Errorf("Failed to parse advertise address: %v", config.AdvertiseAddr)
|
return nil, fmt.Errorf("Failed to parse advertise address: %v", config.AdvertiseAddr)
|
||||||
}
|
}
|
||||||
|
} else if config.BindAddr != "0.0.0.0" && config.BindAddr != "" {
|
||||||
|
config.AdvertiseAddr = config.BindAddr
|
||||||
} else {
|
} else {
|
||||||
ip, err := consul.GetPrivateIP()
|
ip, err := consul.GetPrivateIP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -159,7 +156,7 @@ func (a *Agent) consulConfig() *consul.Config {
|
||||||
base.SerfWANConfig.MemberlistConfig.AdvertiseAddr = a.config.AdvertiseAddr
|
base.SerfWANConfig.MemberlistConfig.AdvertiseAddr = a.config.AdvertiseAddr
|
||||||
base.RPCAdvertise = &net.TCPAddr{
|
base.RPCAdvertise = &net.TCPAddr{
|
||||||
IP: net.ParseIP(a.config.AdvertiseAddr),
|
IP: net.ParseIP(a.config.AdvertiseAddr),
|
||||||
Port: base.RPCAddr.Port,
|
Port: a.config.Ports.RPC,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if a.config.Bootstrap {
|
if a.config.Bootstrap {
|
||||||
|
|
|
@ -84,7 +84,7 @@ func TestHTTPAgentMembers(t *testing.T) {
|
||||||
t.Fatalf("bad members: %v", obj)
|
t.Fatalf("bad members: %v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
if int(val[0].Port) != srv.agent.config.SerfLanPort {
|
if int(val[0].Port) != srv.agent.config.Ports.SerfLan {
|
||||||
t.Fatalf("not lan: %v", obj)
|
t.Fatalf("not lan: %v", obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ func TestHTTPAgentMembers_WAN(t *testing.T) {
|
||||||
t.Fatalf("bad members: %v", obj)
|
t.Fatalf("bad members: %v", obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
if int(val[0].Port) != srv.agent.config.SerfWanPort {
|
if int(val[0].Port) != srv.agent.config.Ports.SerfWan {
|
||||||
t.Fatalf("not wan: %v", obj)
|
t.Fatalf("not wan: %v", obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ func TestHTTPAgentJoin(t *testing.T) {
|
||||||
defer os.RemoveAll(dir2)
|
defer os.RemoveAll(dir2)
|
||||||
defer a2.Shutdown()
|
defer a2.Shutdown()
|
||||||
|
|
||||||
addr := fmt.Sprintf("127.0.0.1:%d", a2.config.SerfLanPort)
|
addr := fmt.Sprintf("127.0.0.1:%d", a2.config.Ports.SerfLan)
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s", addr), nil)
|
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s", addr), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
|
@ -153,7 +153,7 @@ func TestHTTPAgentJoin_WAN(t *testing.T) {
|
||||||
defer os.RemoveAll(dir2)
|
defer os.RemoveAll(dir2)
|
||||||
defer a2.Shutdown()
|
defer a2.Shutdown()
|
||||||
|
|
||||||
addr := fmt.Sprintf("127.0.0.1:%d", a2.config.SerfWanPort)
|
addr := fmt.Sprintf("127.0.0.1:%d", a2.config.Ports.SerfWan)
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s?wan=true", addr), nil)
|
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/join/%s?wan=true", addr), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
|
@ -183,7 +183,7 @@ func TestHTTPAgentForceLeave(t *testing.T) {
|
||||||
defer a2.Shutdown()
|
defer a2.Shutdown()
|
||||||
|
|
||||||
// Join first
|
// Join first
|
||||||
addr := fmt.Sprintf("127.0.0.1:%d", a2.config.SerfLanPort)
|
addr := fmt.Sprintf("127.0.0.1:%d", a2.config.Ports.SerfLan)
|
||||||
_, err := srv.agent.JoinLAN([]string{addr})
|
_, err := srv.agent.JoinLAN([]string{addr})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
|
|
|
@ -15,21 +15,21 @@ import (
|
||||||
var offset uint64
|
var offset uint64
|
||||||
|
|
||||||
func nextConfig() *Config {
|
func nextConfig() *Config {
|
||||||
idx := atomic.AddUint64(&offset, 1)
|
idx := int(atomic.AddUint64(&offset, 1))
|
||||||
conf := DefaultConfig()
|
conf := DefaultConfig()
|
||||||
|
|
||||||
conf.AdvertiseAddr = "127.0.0.1"
|
conf.AdvertiseAddr = "127.0.0.1"
|
||||||
conf.Bootstrap = true
|
conf.Bootstrap = true
|
||||||
conf.Datacenter = "dc1"
|
conf.Datacenter = "dc1"
|
||||||
conf.NodeName = fmt.Sprintf("Node %d", idx)
|
conf.NodeName = fmt.Sprintf("Node %d", idx)
|
||||||
conf.DNSAddr = fmt.Sprintf("127.0.0.1:%d", 18600+idx)
|
conf.BindAddr = "127.0.0.1"
|
||||||
conf.HTTPAddr = fmt.Sprintf("127.0.0.1:%d", 18500+idx)
|
conf.Ports.DNS = 18600 + idx
|
||||||
conf.RPCAddr = fmt.Sprintf("127.0.0.1:%d", 18400+idx)
|
conf.Ports.HTTP = 18500 + idx
|
||||||
conf.SerfBindAddr = "127.0.0.1"
|
conf.Ports.RPC = 18400 + idx
|
||||||
conf.SerfLanPort = int(18200 + idx)
|
conf.Ports.SerfLan = 18200 + idx
|
||||||
conf.SerfWanPort = int(18300 + idx)
|
conf.Ports.SerfWan = 18300 + idx
|
||||||
|
conf.Ports.Server = 18100 + idx
|
||||||
conf.Server = true
|
conf.Server = true
|
||||||
conf.ServerAddr = fmt.Sprintf("127.0.0.1:%d", 18100+idx)
|
|
||||||
|
|
||||||
cons := consul.DefaultConfig()
|
cons := consul.DefaultConfig()
|
||||||
conf.ConsulConfig = cons
|
conf.ConsulConfig = cons
|
||||||
|
|
|
@ -23,7 +23,7 @@ type PortConfig struct {
|
||||||
HTTP int // HTTP API
|
HTTP int // HTTP API
|
||||||
RPC int // CLI RPC
|
RPC int // CLI RPC
|
||||||
SerfLan int `mapstructure:"serf_lan"` // LAN gossip (Client + Server)
|
SerfLan int `mapstructure:"serf_lan"` // LAN gossip (Client + Server)
|
||||||
SerfWan int `mapstructure:"serv_wan"` // WAN gossip (Server onlyg)
|
SerfWan int `mapstructure:"serf_wan"` // WAN gossip (Server onlyg)
|
||||||
Server int // Server internal RPC
|
Server int // Server internal RPC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,6 +145,7 @@ func DefaultConfig() *Config {
|
||||||
Domain: "consul.",
|
Domain: "consul.",
|
||||||
LogLevel: "INFO",
|
LogLevel: "INFO",
|
||||||
ClientAddr: "127.0.0.1",
|
ClientAddr: "127.0.0.1",
|
||||||
|
BindAddr: "0.0.0.0",
|
||||||
Ports: PortConfig{
|
Ports: PortConfig{
|
||||||
DNS: 8600,
|
DNS: 8600,
|
||||||
HTTP: 8500,
|
HTTP: 8500,
|
||||||
|
|
|
@ -94,13 +94,13 @@ func TestDecodeConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DNS setup
|
// DNS setup
|
||||||
input = `{"dns_addr": "127.0.0.1:8500", "recursor": "8.8.8.8", "domain": "foobar"}`
|
input = `{"ports": {"dns": 8500}, "recursor": "8.8.8.8", "domain": "foobar"}`
|
||||||
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
|
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.DNSAddr != "127.0.0.1:8500" {
|
if config.Ports.DNS != 8500 {
|
||||||
t.Fatalf("bad: %#v", config)
|
t.Fatalf("bad: %#v", config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,51 +113,55 @@ func TestDecodeConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPC configs
|
// RPC configs
|
||||||
input = `{"http_addr": "127.0.0.1:1234", "rpc_addr": "127.0.0.1:8100"}`
|
input = `{"ports": {"http": 1234, "rpc": 8100}, "client_addr": "0.0.0.0"}`
|
||||||
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
|
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.HTTPAddr != "127.0.0.1:1234" {
|
if config.ClientAddr != "0.0.0.0" {
|
||||||
t.Fatalf("bad: %#v", config)
|
t.Fatalf("bad: %#v", config)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.RPCAddr != "127.0.0.1:8100" {
|
if config.Ports.HTTP != 1234 {
|
||||||
|
t.Fatalf("bad: %#v", config)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Ports.RPC != 8100 {
|
||||||
t.Fatalf("bad: %#v", config)
|
t.Fatalf("bad: %#v", config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serf configs
|
// Serf configs
|
||||||
input = `{"serf_bind_addr": "127.0.0.2", "serf_lan_port": 1000, "serf_wan_port": 2000}`
|
input = `{"ports": {"serf_lan": 1000, "serf_wan": 2000}}`
|
||||||
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
|
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.SerfBindAddr != "127.0.0.2" {
|
if config.Ports.SerfLan != 1000 {
|
||||||
t.Fatalf("bad: %#v", config)
|
t.Fatalf("bad: %#v", config)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.SerfLanPort != 1000 {
|
if config.Ports.SerfWan != 2000 {
|
||||||
t.Fatalf("bad: %#v", config)
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.SerfWanPort != 2000 {
|
|
||||||
t.Fatalf("bad: %#v", config)
|
t.Fatalf("bad: %#v", config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server addrs
|
// Server addrs
|
||||||
input = `{"server_addr": "127.0.0.1:8000", "advertise_addr": "127.0.0.1:8000"}`
|
input = `{"ports": {"server": 8000}, "bind_addr": "127.0.0.2", "advertise_addr": "127.0.0.3"}`
|
||||||
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
|
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.ServerAddr != "127.0.0.1:8000" {
|
if config.BindAddr != "127.0.0.2" {
|
||||||
t.Fatalf("bad: %#v", config)
|
t.Fatalf("bad: %#v", config)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.AdvertiseAddr != "127.0.0.1:8000" {
|
if config.AdvertiseAddr != "127.0.0.3" {
|
||||||
|
t.Fatalf("bad: %#v", config)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Ports.Server != 8000 {
|
||||||
t.Fatalf("bad: %#v", config)
|
t.Fatalf("bad: %#v", config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,18 +316,13 @@ func TestMergeConfig(t *testing.T) {
|
||||||
Bootstrap: false,
|
Bootstrap: false,
|
||||||
Datacenter: "dc1",
|
Datacenter: "dc1",
|
||||||
DataDir: "/tmp/foo",
|
DataDir: "/tmp/foo",
|
||||||
DNSAddr: "127.0.0.1:1000",
|
|
||||||
DNSRecursor: "127.0.0.1:1001",
|
DNSRecursor: "127.0.0.1:1001",
|
||||||
Domain: "basic",
|
Domain: "basic",
|
||||||
HTTPAddr: "",
|
|
||||||
LogLevel: "debug",
|
LogLevel: "debug",
|
||||||
NodeName: "foo",
|
NodeName: "foo",
|
||||||
RPCAddr: "",
|
ClientAddr: "127.0.0.1",
|
||||||
SerfBindAddr: "127.0.0.1",
|
BindAddr: "127.0.0.1",
|
||||||
SerfLanPort: 1000,
|
AdvertiseAddr: "127.0.0.1",
|
||||||
SerfWanPort: 2000,
|
|
||||||
ServerAddr: "127.0.0.1:8000",
|
|
||||||
AdvertiseAddr: "127.0.0.1:8000",
|
|
||||||
Server: false,
|
Server: false,
|
||||||
LeaveOnTerm: false,
|
LeaveOnTerm: false,
|
||||||
SkipLeaveOnInt: false,
|
SkipLeaveOnInt: false,
|
||||||
|
@ -334,18 +333,21 @@ func TestMergeConfig(t *testing.T) {
|
||||||
Bootstrap: true,
|
Bootstrap: true,
|
||||||
Datacenter: "dc2",
|
Datacenter: "dc2",
|
||||||
DataDir: "/tmp/bar",
|
DataDir: "/tmp/bar",
|
||||||
DNSAddr: "127.0.0.2:1000",
|
|
||||||
DNSRecursor: "127.0.0.2:1001",
|
DNSRecursor: "127.0.0.2:1001",
|
||||||
Domain: "other",
|
Domain: "other",
|
||||||
HTTPAddr: "127.0.0.1:12345",
|
|
||||||
LogLevel: "info",
|
LogLevel: "info",
|
||||||
NodeName: "baz",
|
NodeName: "baz",
|
||||||
RPCAddr: "127.0.0.1:9999",
|
ClientAddr: "127.0.0.1",
|
||||||
SerfBindAddr: "127.0.0.2",
|
BindAddr: "127.0.0.1",
|
||||||
SerfLanPort: 3000,
|
AdvertiseAddr: "127.0.0.1",
|
||||||
SerfWanPort: 4000,
|
Ports: PortConfig{
|
||||||
ServerAddr: "127.0.0.2:8000",
|
DNS: 1,
|
||||||
AdvertiseAddr: "127.0.0.2:8000",
|
HTTP: 2,
|
||||||
|
RPC: 3,
|
||||||
|
SerfLan: 4,
|
||||||
|
SerfWan: 5,
|
||||||
|
Server: 6,
|
||||||
|
},
|
||||||
Server: true,
|
Server: true,
|
||||||
LeaveOnTerm: true,
|
LeaveOnTerm: true,
|
||||||
SkipLeaveOnInt: true,
|
SkipLeaveOnInt: true,
|
||||||
|
|
|
@ -12,9 +12,10 @@ import (
|
||||||
|
|
||||||
func makeDNSServer(t *testing.T) (string, *DNSServer) {
|
func makeDNSServer(t *testing.T) (string, *DNSServer) {
|
||||||
conf := nextConfig()
|
conf := nextConfig()
|
||||||
|
addr, _ := conf.ClientListener(conf.Ports.DNS)
|
||||||
dir, agent := makeAgent(t, conf)
|
dir, agent := makeAgent(t, conf)
|
||||||
server, err := NewDNSServer(agent, agent.logOutput, conf.Domain,
|
server, err := NewDNSServer(agent, agent.logOutput, conf.Domain,
|
||||||
conf.DNSAddr, "8.8.8.8:53")
|
addr.String(), "8.8.8.8:53")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -40,7 +41,8 @@ func TestDNS_IsAlive(t *testing.T) {
|
||||||
m.SetQuestion("_test.consul.", dns.TypeANY)
|
m.SetQuestion("_test.consul.", dns.TypeANY)
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
in, _, err := c.Exchange(m, srv.agent.config.DNSAddr)
|
addr, _ := srv.agent.config.ClientListener(srv.agent.config.Ports.DNS)
|
||||||
|
in, _, err := c.Exchange(m, addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -81,7 +83,8 @@ func TestDNS_NodeLookup(t *testing.T) {
|
||||||
m.SetQuestion("foo.node.consul.", dns.TypeANY)
|
m.SetQuestion("foo.node.consul.", dns.TypeANY)
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
in, _, err := c.Exchange(m, srv.agent.config.DNSAddr)
|
addr, _ := srv.agent.config.ClientListener(srv.agent.config.Ports.DNS)
|
||||||
|
in, _, err := c.Exchange(m, addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -103,7 +106,7 @@ func TestDNS_NodeLookup(t *testing.T) {
|
||||||
m.SetQuestion("foo.node.dc1.consul.", dns.TypeANY)
|
m.SetQuestion("foo.node.dc1.consul.", dns.TypeANY)
|
||||||
|
|
||||||
c = new(dns.Client)
|
c = new(dns.Client)
|
||||||
in, _, err = c.Exchange(m, srv.agent.config.DNSAddr)
|
in, _, err = c.Exchange(m, addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -144,7 +147,8 @@ func TestDNS_NodeLookup_AAAA(t *testing.T) {
|
||||||
m.SetQuestion("bar.node.consul.", dns.TypeANY)
|
m.SetQuestion("bar.node.consul.", dns.TypeANY)
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
in, _, err := c.Exchange(m, srv.agent.config.DNSAddr)
|
addr, _ := srv.agent.config.ClientListener(srv.agent.config.Ports.DNS)
|
||||||
|
in, _, err := c.Exchange(m, addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -185,7 +189,8 @@ func TestDNS_NodeLookup_CNAME(t *testing.T) {
|
||||||
m.SetQuestion("google.node.consul.", dns.TypeANY)
|
m.SetQuestion("google.node.consul.", dns.TypeANY)
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
in, _, err := c.Exchange(m, srv.agent.config.DNSAddr)
|
addr, _ := srv.agent.config.ClientListener(srv.agent.config.Ports.DNS)
|
||||||
|
in, _, err := c.Exchange(m, addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -232,7 +237,8 @@ func TestDNS_ServiceLookup(t *testing.T) {
|
||||||
m.SetQuestion("db.service.consul.", dns.TypeSRV)
|
m.SetQuestion("db.service.consul.", dns.TypeSRV)
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
in, _, err := c.Exchange(m, srv.agent.config.DNSAddr)
|
addr, _ := srv.agent.config.ClientListener(srv.agent.config.Ports.DNS)
|
||||||
|
in, _, err := c.Exchange(m, addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -322,7 +328,8 @@ func TestDNS_ServiceLookup_Dedup(t *testing.T) {
|
||||||
m.SetQuestion("db.service.consul.", dns.TypeANY)
|
m.SetQuestion("db.service.consul.", dns.TypeANY)
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
in, _, err := c.Exchange(m, srv.agent.config.DNSAddr)
|
addr, _ := srv.agent.config.ClientListener(srv.agent.config.Ports.DNS)
|
||||||
|
in, _, err := c.Exchange(m, addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -398,7 +405,8 @@ func TestDNS_ServiceLookup_Dedup_SRV(t *testing.T) {
|
||||||
m.SetQuestion("db.service.consul.", dns.TypeSRV)
|
m.SetQuestion("db.service.consul.", dns.TypeSRV)
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
in, _, err := c.Exchange(m, srv.agent.config.DNSAddr)
|
addr, _ := srv.agent.config.ClientListener(srv.agent.config.Ports.DNS)
|
||||||
|
in, _, err := c.Exchange(m, addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -454,7 +462,8 @@ func TestDNS_Recurse(t *testing.T) {
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
c.Net = "tcp"
|
c.Net = "tcp"
|
||||||
in, _, err := c.Exchange(m, srv.agent.config.DNSAddr)
|
addr, _ := srv.agent.config.ClientListener(srv.agent.config.Ports.DNS)
|
||||||
|
in, _, err := c.Exchange(m, addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -519,7 +528,8 @@ func TestDNS_ServiceLookup_FilterCritical(t *testing.T) {
|
||||||
m.SetQuestion("db.service.consul.", dns.TypeANY)
|
m.SetQuestion("db.service.consul.", dns.TypeANY)
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
in, _, err := c.Exchange(m, srv.agent.config.DNSAddr)
|
addr, _ := srv.agent.config.ClientListener(srv.agent.config.Ports.DNS)
|
||||||
|
in, _, err := c.Exchange(m, addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -557,12 +567,13 @@ func TestDNS_ServiceLookup_Randomize(t *testing.T) {
|
||||||
|
|
||||||
// Ensure the response is randomized each time
|
// Ensure the response is randomized each time
|
||||||
uniques := map[string]struct{}{}
|
uniques := map[string]struct{}{}
|
||||||
|
addr, _ := srv.agent.config.ClientListener(srv.agent.config.Ports.DNS)
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetQuestion("web.service.consul.", dns.TypeANY)
|
m.SetQuestion("web.service.consul.", dns.TypeANY)
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
in, _, err := c.Exchange(m, srv.agent.config.DNSAddr)
|
in, _, err := c.Exchange(m, addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -620,7 +631,8 @@ func TestDNS_ServiceLookup_CNAME(t *testing.T) {
|
||||||
m.SetQuestion("search.service.consul.", dns.TypeANY)
|
m.SetQuestion("search.service.consul.", dns.TypeANY)
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
in, _, err := c.Exchange(m, srv.agent.config.DNSAddr)
|
addr, _ := srv.agent.config.ClientListener(srv.agent.config.Ports.DNS)
|
||||||
|
in, _, err := c.Exchange(m, addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@ import (
|
||||||
func makeHTTPServer(t *testing.T) (string, *HTTPServer) {
|
func makeHTTPServer(t *testing.T) (string, *HTTPServer) {
|
||||||
conf := nextConfig()
|
conf := nextConfig()
|
||||||
dir, agent := makeAgent(t, conf)
|
dir, agent := makeAgent(t, conf)
|
||||||
server, err := NewHTTPServer(agent, true, agent.logOutput, conf.HTTPAddr)
|
addr, _ := agent.config.ClientListener(agent.config.Ports.HTTP)
|
||||||
|
server, err := NewHTTPServer(agent, true, agent.logOutput, addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ func TestRPCClientForceLeave(t *testing.T) {
|
||||||
defer p2.Close()
|
defer p2.Close()
|
||||||
testutil.Yield()
|
testutil.Yield()
|
||||||
|
|
||||||
s2Addr := fmt.Sprintf("127.0.0.1:%d", p2.agent.config.SerfLanPort)
|
s2Addr := fmt.Sprintf("127.0.0.1:%d", p2.agent.config.Ports.SerfLan)
|
||||||
if _, err := p1.agent.JoinLAN([]string{s2Addr}); err != nil {
|
if _, err := p1.agent.JoinLAN([]string{s2Addr}); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ func TestRPCClientJoinLAN(t *testing.T) {
|
||||||
defer p2.Close()
|
defer p2.Close()
|
||||||
testutil.Yield()
|
testutil.Yield()
|
||||||
|
|
||||||
s2Addr := fmt.Sprintf("127.0.0.1:%d", p2.agent.config.SerfLanPort)
|
s2Addr := fmt.Sprintf("127.0.0.1:%d", p2.agent.config.Ports.SerfLan)
|
||||||
n, err := p1.client.Join([]string{s2Addr}, false)
|
n, err := p1.client.Join([]string{s2Addr}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
|
@ -115,7 +115,7 @@ func TestRPCClientJoinWAN(t *testing.T) {
|
||||||
defer p2.Close()
|
defer p2.Close()
|
||||||
testutil.Yield()
|
testutil.Yield()
|
||||||
|
|
||||||
s2Addr := fmt.Sprintf("127.0.0.1:%d", p2.agent.config.SerfWanPort)
|
s2Addr := fmt.Sprintf("127.0.0.1:%d", p2.agent.config.Ports.SerfWan)
|
||||||
n, err := p1.client.Join([]string{s2Addr}, true)
|
n, err := p1.client.Join([]string{s2Addr}, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
|
@ -142,7 +142,7 @@ func TestRPCClientLANMembers(t *testing.T) {
|
||||||
t.Fatalf("bad: %#v", mem)
|
t.Fatalf("bad: %#v", mem)
|
||||||
}
|
}
|
||||||
|
|
||||||
s2Addr := fmt.Sprintf("127.0.0.1:%d", p2.agent.config.SerfLanPort)
|
s2Addr := fmt.Sprintf("127.0.0.1:%d", p2.agent.config.Ports.SerfLan)
|
||||||
_, err = p1.client.Join([]string{s2Addr}, false)
|
_, err = p1.client.Join([]string{s2Addr}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
|
@ -176,7 +176,7 @@ func TestRPCClientWANMembers(t *testing.T) {
|
||||||
t.Fatalf("bad: %#v", mem)
|
t.Fatalf("bad: %#v", mem)
|
||||||
}
|
}
|
||||||
|
|
||||||
s2Addr := fmt.Sprintf("127.0.0.1:%d", p2.agent.config.SerfWanPort)
|
s2Addr := fmt.Sprintf("127.0.0.1:%d", p2.agent.config.Ports.SerfWan)
|
||||||
_, err = p1.client.Join([]string{s2Addr}, true)
|
_, err = p1.client.Join([]string{s2Addr}, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
|
|
Loading…
Reference in New Issue