Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #202 from ripienaar/201
Browse files Browse the repository at this point in the history
(#201) Allow middleware servers to be randomized
  • Loading branch information
ripienaar committed Mar 6, 2017
2 parents 02807a1 + ce6c9be commit 812725e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
|Date |Issue |Description |
|----------|------|---------------------------------------------------------------------------------------------------------|
|2017/03/06|201 |Allow server randomization to be configured |
|2017/02/16|199 |Use the configured *ssl_dir* for storing the public cert cache |
|2017/02/19|186 |Add a Graphite event task |
|2017/02/17| |Release 0.0.23 |
Expand Down
6 changes: 3 additions & 3 deletions lib/mcollective/connector/nats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def connect
parameters = {
:max_reconnect_attempts => -1,
:reconnect_time_wait => 1,
:dont_randomize_servers => true,
:dont_randomize_servers => !choria.randomize_middleware_servers?,
:name => @config.identity,
:tls => {
:context => ssl_context
},
:name => @config.identity
}
}

servers = server_list
Expand Down
7 changes: 7 additions & 0 deletions lib/mcollective/util/choria.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ def middleware_servers(default_host, default_port)
[[default_host, default_port]]
end

# Determines if servers should be randomized
#
# @return [Boolean]
def randomize_middleware_servers?
Util.str_to_bool(get_option("choria.randomize_middleware_hosts", "false"))
end

# Attempts to look up some SRV records falling back to defaults
#
# When given a array of multiple names it will try each name individually
Expand Down
3 changes: 2 additions & 1 deletion spec/unit/mcollective/connector/nats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ module MCollective
it "should connect" do
mock_context = OpenSSL::SSL::SSLContext.new
connector.stubs(:ssl_context).returns(mock_context)
choria.expects(:randomize_middleware_servers?).returns(true)

connector.connection.expects(:start).with(
:max_reconnect_attempts => -1,
:reconnect_time_wait => 1,
:dont_randomize_servers => true,
:dont_randomize_servers => false,
:name => "rspec_identity",
:tls => {
:context => mock_context
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/mcollective/util/choria_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ module Util
let(:choria) { Choria.new("production", nil, false) }
let(:parsed_app) { JSON.parse(File.read("spec/fixtures/sample_app.json")) }

describe "#randomize_middleware_servers?" do
it "should default to false" do
Config.instance.stubs(:pluginconf).returns({})
expect(choria.randomize_middleware_servers?).to be(false)
end

it "should be configurable" do
Config.instance.stubs(:pluginconf).returns("choria.randomize_middleware_hosts" => "true")
expect(choria.randomize_middleware_servers?).to be(true)
end
end

describe "#should_use_srv?" do
it "should default to on" do
Config.instance.stubs(:pluginconf).returns({})
Expand Down

0 comments on commit 812725e

Please sign in to comment.