Skip to content

Commit

Permalink
Merge pull request airbnb#194 from airbnb/sonic/put_backend_name_first
Browse files Browse the repository at this point in the history
[haproxy] Put backend['name'] first in constructing backend name
  • Loading branch information
SonicWang committed May 27, 2016
2 parents 250d4ee + dd5843c commit b904393
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/synapse/haproxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ def restart
def construct_name(backend)
name = "#{backend['host']}:#{backend['port']}"
if backend['name'] && !backend['name'].empty?
name = "#{name}_#{backend['name']}"
name = "#{backend['name']}_#{name}"
end

return name
Expand Down
31 changes: 27 additions & 4 deletions spec/lib/synapse/haproxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,39 @@ class MockWatcher; end;
describe 'generate backend stanza in correct order' do
let(:multiple_backends_stanza_map) do
{
'asc' => ["\nbackend example_service", [], ["\tserver somehost1:5555 somehost1:5555 cookie somehost1:5555 check inter 2000 rise 3 fall 2", "\tserver somehost2:5555 somehost2:5555 cookie somehost2:5555 check inter 2000 rise 3 fall 2", "\tserver somehost3:5555 somehost3:5555 cookie somehost3:5555 check inter 2000 rise 3 fall 2"]],
'desc' => ["\nbackend example_service", [], ["\tserver somehost3:5555 somehost3:5555 cookie somehost3:5555 check inter 2000 rise 3 fall 2", "\tserver somehost2:5555 somehost2:5555 cookie somehost2:5555 check inter 2000 rise 3 fall 2", "\tserver somehost1:5555 somehost1:5555 cookie somehost1:5555 check inter 2000 rise 3 fall 2"]],
'no_shuffle' => ["\nbackend example_service", [], ["\tserver somehost1:5555 somehost1:5555 cookie somehost1:5555 check inter 2000 rise 3 fall 2", "\tserver somehost3:5555 somehost3:5555 cookie somehost3:5555 check inter 2000 rise 3 fall 2", "\tserver somehost2:5555 somehost2:5555 cookie somehost2:5555 check inter 2000 rise 3 fall 2"]]
'asc' => [
"\nbackend example_service",
[],
["\tserver somehost1_10.11.11.11:5555 10.11.11.11:5555 cookie somehost1_10.11.11.11:5555 check inter 2000 rise 3 fall 2",
"\tserver somehost2_10.10.10.10:5555 10.10.10.10:5555 cookie somehost2_10.10.10.10:5555 check inter 2000 rise 3 fall 2",
"\tserver somehost3_10.22.22.22:5555 10.22.22.22:5555 cookie somehost3_10.22.22.22:5555 check inter 2000 rise 3 fall 2"
]
],
'desc' => [
"\nbackend example_service",
[],
["\tserver somehost3_10.22.22.22:5555 10.22.22.22:5555 cookie somehost3_10.22.22.22:5555 check inter 2000 rise 3 fall 2",
"\tserver somehost2_10.10.10.10:5555 10.10.10.10:5555 cookie somehost2_10.10.10.10:5555 check inter 2000 rise 3 fall 2",
"\tserver somehost1_10.11.11.11:5555 10.11.11.11:5555 cookie somehost1_10.11.11.11:5555 check inter 2000 rise 3 fall 2"
]
],
'no_shuffle' => [
"\nbackend example_service",
[],
["\tserver somehost1_10.11.11.11:5555 10.11.11.11:5555 cookie somehost1_10.11.11.11:5555 check inter 2000 rise 3 fall 2",
"\tserver somehost3_10.22.22.22:5555 10.22.22.22:5555 cookie somehost3_10.22.22.22:5555 check inter 2000 rise 3 fall 2",
"\tserver somehost2_10.10.10.10:5555 10.10.10.10:5555 cookie somehost2_10.10.10.10:5555 check inter 2000 rise 3 fall 2"
]
]
}
end

let(:mockwatcher_with_multiple_backends) do
mockWatcher = double(Synapse::ServiceWatcher)
allow(mockWatcher).to receive(:name).and_return('example_service')
backends = [{ 'host' => 'somehost1', 'port' => 5555}, {'host' => 'somehost3', 'port' => 5555}, { 'host' => 'somehost2', 'port' => 5555}]
backends = [{ 'host' => '10.11.11.11', 'port' => 5555, 'name' => 'somehost1'},
{ 'host' => '10.22.22.22', 'port' => 5555, 'name' => 'somehost3'},
{ 'host' => '10.10.10.10', 'port' => 5555, 'name' => 'somehost2'}]
allow(mockWatcher).to receive(:backends).and_return(backends)
mockWatcher
end
Expand Down

0 comments on commit b904393

Please sign in to comment.