agent: resolve some conflicts and fix tests

pull/4275/head
Mitchell Hashimoto 2018-05-03 08:52:36 -07:00
parent d9bd4ffebd
commit 3d3eee2f6e
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 18 additions and 17 deletions

View File

@ -1021,7 +1021,7 @@ func (s *HTTPServer) AgentConnectProxyConfig(resp http.ResponseWriter, req *http
// done deeper though as it will be needed for actually managing proxy // done deeper though as it will be needed for actually managing proxy
// lifecycle. // lifecycle.
command := proxy.Proxy.Command command := proxy.Proxy.Command
if command == "" { if len(command) == 0 {
if execMode == "daemon" { if execMode == "daemon" {
command = s.agent.config.ConnectProxyDefaultDaemonCommand command = s.agent.config.ConnectProxyDefaultDaemonCommand
} }
@ -1030,8 +1030,8 @@ func (s *HTTPServer) AgentConnectProxyConfig(resp http.ResponseWriter, req *http
} }
} }
// No global defaults set either... // No global defaults set either...
if command == "" { if len(command) == 0 {
command = "consul connect proxy" command = []string{"consul", "connect", "proxy"}
} }
// Set defaults for anything that is still not specified but required. // Set defaults for anything that is still not specified but required.

View File

@ -2354,7 +2354,7 @@ func TestAgentConnectProxyConfig_Blocking(t *testing.T) {
TargetServiceName: "test", TargetServiceName: "test",
ContentHash: "365a50cbb9a748b6", ContentHash: "365a50cbb9a748b6",
ExecMode: "daemon", ExecMode: "daemon",
Command: nil, Command: []string{"consul", "connect", "proxy"},
Config: map[string]interface{}{ Config: map[string]interface{}{
"upstreams": []interface{}{ "upstreams": []interface{}{
map[string]interface{}{ map[string]interface{}{
@ -2372,7 +2372,7 @@ func TestAgentConnectProxyConfig_Blocking(t *testing.T) {
ur, err := copystructure.Copy(expectedResponse) ur, err := copystructure.Copy(expectedResponse)
require.NoError(t, err) require.NoError(t, err)
updatedResponse := ur.(*api.ConnectProxyConfig) updatedResponse := ur.(*api.ConnectProxyConfig)
updatedResponse.ContentHash = "b5bb0e4a0a58ca25" updatedResponse.ContentHash = "538d0366b7b1dc3e"
upstreams := updatedResponse.Config["upstreams"].([]interface{}) upstreams := updatedResponse.Config["upstreams"].([]interface{})
upstreams = append(upstreams, upstreams = append(upstreams,
map[string]interface{}{ map[string]interface{}{
@ -2538,7 +2538,7 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
globalConfig string globalConfig string
proxy structs.ServiceDefinitionConnectProxy proxy structs.ServiceDefinitionConnectProxy
wantMode api.ProxyExecMode wantMode api.ProxyExecMode
wantCommand string wantCommand []string
wantConfig map[string]interface{} wantConfig map[string]interface{}
}{ }{
{ {
@ -2555,7 +2555,7 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
`, `,
proxy: structs.ServiceDefinitionConnectProxy{}, proxy: structs.ServiceDefinitionConnectProxy{},
wantMode: api.ProxyExecModeDaemon, wantMode: api.ProxyExecModeDaemon,
wantCommand: "consul connect proxy", wantCommand: []string{"consul", "connect", "proxy"},
wantConfig: map[string]interface{}{ wantConfig: map[string]interface{}{
"bind_address": "0.0.0.0", "bind_address": "0.0.0.0",
"bind_port": 10000, // "randomly" chosen from our range of 1 "bind_port": 10000, // "randomly" chosen from our range of 1
@ -2572,13 +2572,13 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
bind_min_port = 10000 bind_min_port = 10000
bind_max_port = 10000 bind_max_port = 10000
exec_mode = "script" exec_mode = "script"
script_command = "script.sh" script_command = ["script.sh"]
} }
} }
`, `,
proxy: structs.ServiceDefinitionConnectProxy{}, proxy: structs.ServiceDefinitionConnectProxy{},
wantMode: api.ProxyExecModeScript, wantMode: api.ProxyExecModeScript,
wantCommand: "script.sh", wantCommand: []string{"script.sh"},
wantConfig: map[string]interface{}{ wantConfig: map[string]interface{}{
"bind_address": "0.0.0.0", "bind_address": "0.0.0.0",
"bind_port": 10000, // "randomly" chosen from our range of 1 "bind_port": 10000, // "randomly" chosen from our range of 1
@ -2595,13 +2595,13 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
bind_min_port = 10000 bind_min_port = 10000
bind_max_port = 10000 bind_max_port = 10000
exec_mode = "daemon" exec_mode = "daemon"
daemon_command = "daemon.sh" daemon_command = ["daemon.sh"]
} }
} }
`, `,
proxy: structs.ServiceDefinitionConnectProxy{}, proxy: structs.ServiceDefinitionConnectProxy{},
wantMode: api.ProxyExecModeDaemon, wantMode: api.ProxyExecModeDaemon,
wantCommand: "daemon.sh", wantCommand: []string{"daemon.sh"},
wantConfig: map[string]interface{}{ wantConfig: map[string]interface{}{
"bind_address": "0.0.0.0", "bind_address": "0.0.0.0",
"bind_port": 10000, // "randomly" chosen from our range of 1 "bind_port": 10000, // "randomly" chosen from our range of 1
@ -2629,7 +2629,7 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
}, },
}, },
wantMode: api.ProxyExecModeDaemon, wantMode: api.ProxyExecModeDaemon,
wantCommand: "consul connect proxy", wantCommand: []string{"consul", "connect", "proxy"},
wantConfig: map[string]interface{}{ wantConfig: map[string]interface{}{
"bind_address": "0.0.0.0", "bind_address": "0.0.0.0",
"bind_port": 10000, // "randomly" chosen from our range of 1 "bind_port": 10000, // "randomly" chosen from our range of 1
@ -2648,8 +2648,8 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
bind_min_port = 10000 bind_min_port = 10000
bind_max_port = 10000 bind_max_port = 10000
exec_mode = "daemon" exec_mode = "daemon"
daemon_command = "daemon.sh" daemon_command = ["daemon.sh"]
script_command = "script.sh" script_command = ["script.sh"]
config = { config = {
connect_timeout_ms = 1000 connect_timeout_ms = 1000
} }
@ -2658,7 +2658,7 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
`, `,
proxy: structs.ServiceDefinitionConnectProxy{ proxy: structs.ServiceDefinitionConnectProxy{
ExecMode: "script", ExecMode: "script",
Command: "foo.sh", Command: []string{"foo.sh"},
Config: map[string]interface{}{ Config: map[string]interface{}{
"connect_timeout_ms": 2000, "connect_timeout_ms": 2000,
"bind_address": "127.0.0.1", "bind_address": "127.0.0.1",
@ -2667,7 +2667,7 @@ func TestAgentConnectProxyConfig_ConfigHandling(t *testing.T) {
}, },
}, },
wantMode: api.ProxyExecModeScript, wantMode: api.ProxyExecModeScript,
wantCommand: "foo.sh", wantCommand: []string{"foo.sh"},
wantConfig: map[string]interface{}{ wantConfig: map[string]interface{}{
"bind_address": "127.0.0.1", "bind_address": "127.0.0.1",
"bind_port": float64(1024), "bind_port": float64(1024),

View File

@ -1725,8 +1725,9 @@ func TestStateProxyManagement(t *testing.T) {
{ {
// Re-registering same proxy again should not pick a random port but re-use // Re-registering same proxy again should not pick a random port but re-use
// the assigned one. // the assigned one.
svcDup, err := state.AddProxy(&p1, "fake-token") pstateDup, err := state.AddProxy(&p1, "fake-token")
require.NoError(err) require.NoError(err)
svcDup := pstateDup.Proxy.ProxyService
assert.Equal("web-proxy", svcDup.ID) assert.Equal("web-proxy", svcDup.ID)
assert.Equal("web-proxy", svcDup.Service) assert.Equal("web-proxy", svcDup.Service)