mcollective-client 2.2.4 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mcollective-client might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/lib/mcollective/application.rb +25 -34
- data/lib/mcollective/client.rb +91 -33
- data/lib/mcollective/config.rb +42 -43
- data/lib/mcollective/data/base.rb +1 -1
- data/lib/mcollective/data/result.rb +6 -2
- data/lib/mcollective/ddl/agentddl.rb +28 -1
- data/lib/mcollective/ddl/base.rb +8 -6
- data/lib/mcollective/log.rb +11 -3
- data/lib/mcollective/logger/file_logger.rb +4 -4
- data/lib/mcollective/matcher.rb +9 -1
- data/lib/mcollective/message.rb +14 -23
- data/lib/mcollective/optionparser.rb +9 -1
- data/lib/mcollective/pluginpackager.rb +24 -3
- data/lib/mcollective/pluginpackager/agent_definition.rb +12 -12
- data/lib/mcollective/pluginpackager/standard_definition.rb +12 -12
- data/lib/mcollective/rpc/agent.rb +15 -12
- data/lib/mcollective/rpc/client.rb +67 -31
- data/lib/mcollective/rpc/helpers.rb +7 -1
- data/lib/mcollective/rpc/reply.rb +3 -1
- data/lib/mcollective/shell.rb +45 -8
- data/lib/mcollective/util.rb +37 -1
- data/lib/mcollective/windows_daemon.rb +14 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/application_spec.rb +45 -26
- data/spec/unit/cache_spec.rb +3 -3
- data/spec/unit/client_spec.rb +269 -24
- data/spec/unit/config_spec.rb +89 -26
- data/spec/unit/data/base_spec.rb +1 -0
- data/spec/unit/data/result_spec.rb +19 -1
- data/spec/unit/data_spec.rb +3 -0
- data/spec/unit/ddl/agentddl_spec.rb +32 -0
- data/spec/unit/ddl/base_spec.rb +4 -0
- data/spec/unit/ddl/dataddl_spec.rb +1 -1
- data/spec/unit/log_spec.rb +44 -27
- data/spec/unit/logger/base_spec.rb +1 -1
- data/spec/unit/matcher_spec.rb +14 -0
- data/spec/unit/message_spec.rb +24 -0
- data/spec/unit/optionparser_spec.rb +99 -0
- data/spec/unit/pluginpackager/agent_definition_spec.rb +48 -17
- data/spec/unit/pluginpackager/standard_definition_spec.rb +44 -20
- data/spec/unit/pluginpackager_spec.rb +31 -7
- data/spec/unit/plugins/mcollective/agent/rpcutil_spec.rb +176 -0
- data/spec/unit/plugins/mcollective/application/plugin_spec.rb +81 -0
- data/spec/unit/plugins/mcollective/audit/logfile_spec.rb +44 -0
- data/spec/unit/plugins/mcollective/connector/activemq_spec.rb +118 -27
- data/spec/unit/plugins/mcollective/connector/rabbitmq_spec.rb +168 -34
- data/spec/unit/plugins/mcollective/data/agent_data_spec.rb +1 -0
- data/spec/unit/plugins/mcollective/data/fstat_data_spec.rb +1 -0
- data/spec/unit/plugins/mcollective/discovery/flatfile_spec.rb +10 -0
- data/spec/unit/plugins/mcollective/discovery/stdin_spec.rb +65 -0
- data/spec/unit/plugins/mcollective/facts/yaml_facts_spec.rb +65 -0
- data/spec/unit/plugins/mcollective/packagers/debpackage_packager_spec.rb +240 -219
- data/spec/unit/plugins/mcollective/packagers/modulepackage_packager_spec.rb +209 -0
- data/spec/unit/plugins/mcollective/packagers/rpmpackage_packager_spec.rb +223 -109
- data/spec/unit/rpc/actionrunner_spec.rb +2 -1
- data/spec/unit/rpc/agent_spec.rb +130 -1
- data/spec/unit/rpc/client_spec.rb +169 -3
- data/spec/unit/security/base_spec.rb +0 -1
- data/spec/unit/shell_spec.rb +76 -3
- data/spec/unit/util_spec.rb +69 -1
- data/spec/unit/windows_daemon_spec.rb +30 -9
- metadata +104 -90
- data/spec/unit/plugins/mcollective/connector/stomp/eventlogger_spec.rb +0 -34
- data/spec/unit/plugins/mcollective/connector/stomp_spec.rb +0 -424
- data/spec/unit/plugins/mcollective/validator/any_validator_spec.rb +0 -15
@@ -0,0 +1,176 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
@agent_file = File.join(File.dirname(__FILE__), '../../../../../', 'plugins', 'mcollective', 'agent', 'rpcutil.rb')
|
4
|
+
|
5
|
+
require 'spec_helper'
|
6
|
+
require @agent_file
|
7
|
+
|
8
|
+
module MCollective
|
9
|
+
module Agent
|
10
|
+
describe Rpcutil do
|
11
|
+
module Facts
|
12
|
+
def self.[](fact)
|
13
|
+
{'fact1' => 'value1', 'fact2' => 'value2', 'fact3' => 'value3'}[fact]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
before :each do
|
18
|
+
@agent = MCollective::Test::LocalAgentTest.new('rpcutil', :agent_file => @agent_file).plugin
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#inventory' do
|
22
|
+
it 'should return the node inventory' do
|
23
|
+
facts = mock
|
24
|
+
facts.stubs(:get_facts).returns({:key => 'value'})
|
25
|
+
Agents.stubs(:agentlist).returns(['test'])
|
26
|
+
PluginManager.stubs(:[]).with('facts_plugin').returns(facts)
|
27
|
+
MCollective.stubs(:version).returns('2.4.0')
|
28
|
+
PluginManager.stubs(:grep).with(/_data$/).returns(['test_data'])
|
29
|
+
Config.any_instance.stubs(:classesfile).returns('classes.txt')
|
30
|
+
File.stubs(:exist?).with('classes.txt').returns(true)
|
31
|
+
File.stubs(:readlines).with('classes.txt').returns(['class1', 'class2'])
|
32
|
+
result = @agent.call(:inventory)
|
33
|
+
result.should be_successful
|
34
|
+
result.should have_data_items({:agents=>["test"],
|
35
|
+
:facts=>{:key=>"value"},
|
36
|
+
:version=>"2.4.0",
|
37
|
+
:classes=>["class1", "class2"],
|
38
|
+
:main_collective=>"mcollective",
|
39
|
+
:collectives=>["production", "staging"],
|
40
|
+
:data_plugins=>["test_data"]})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#get_fact' do
|
45
|
+
it 'should return the value of the queried fact' do
|
46
|
+
result = @agent.call(:get_fact, :fact => 'fact1')
|
47
|
+
result.should be_successful
|
48
|
+
result.should have_data_items({:fact => 'fact1', :value => 'value1'})
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should not break if the fact is not present' do
|
52
|
+
result = @agent.call(:get_fact, :fact => 'fact4')
|
53
|
+
result.should be_successful
|
54
|
+
result.should have_data_items({:fact => 'fact4', :value => nil })
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#get_facts' do
|
59
|
+
it 'should return the value of the supplied facts' do
|
60
|
+
result = @agent.call(:get_facts, :facts => 'fact1, fact3')
|
61
|
+
result.should be_successful
|
62
|
+
result.should have_data_items(:values => {'fact1' => 'value1', 'fact3' => 'value3'})
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should not break if the facts are not present' do
|
66
|
+
result = @agent.call(:get_facts, :facts => 'fact4, fact5')
|
67
|
+
result.should be_successful
|
68
|
+
result.should have_data_items(:values => {'fact4' => nil, 'fact5' => nil})
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#daemon_stats' do
|
73
|
+
it "it should return the daemon's statistics" do
|
74
|
+
stats = {:threads => 2,
|
75
|
+
:agents => ['agent1', 'agent2'],
|
76
|
+
:pid => 42,
|
77
|
+
:times => 12345,
|
78
|
+
:configfile => '/etc/mcollective/server.cfg',
|
79
|
+
:version => '2.4.0',
|
80
|
+
:stats => {}}
|
81
|
+
config = mock
|
82
|
+
Config.stubs(:instance).returns(config)
|
83
|
+
MCollective.stubs(:version).returns('2.4.0')
|
84
|
+
config.stubs(:configfile).returns('/etc/mcollective/server.cfg')
|
85
|
+
PluginManager.stubs(:[]).returns(stats)
|
86
|
+
result = @agent.call(:daemon_stats)
|
87
|
+
result.should be_successful
|
88
|
+
stats.delete(:stats)
|
89
|
+
result.should have_data_items(stats)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#agent_inventory' do
|
94
|
+
it 'should return the agent inventory' do
|
95
|
+
meta = {:license => 'ASL 2',
|
96
|
+
:description => 'Agent for testing',
|
97
|
+
:url => 'http://www.theurl.net',
|
98
|
+
:version => '1',
|
99
|
+
:author => 'rspec'}
|
100
|
+
agent = mock
|
101
|
+
agent.stubs(:meta).returns(meta)
|
102
|
+
agent.stubs(:timeout).returns(2)
|
103
|
+
PluginManager.stubs(:[]).with('test_agent').returns(agent)
|
104
|
+
Agents.stubs(:agentlist).returns(['test'])
|
105
|
+
|
106
|
+
result = @agent.call(:agent_inventory)
|
107
|
+
result.should be_successful
|
108
|
+
result.should have_data_items(:agents => [meta.merge({:timeout => 2, :name => 'test', :agent => 'test'})])
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#get_config_item' do
|
113
|
+
it 'should return the value of the requested config item' do
|
114
|
+
Config.any_instance.stubs(:respond_to?).with(:main_collective).returns(true)
|
115
|
+
result = @agent.call(:get_config_item, :item => :main_collective)
|
116
|
+
result.should be_successful
|
117
|
+
result.should have_data_items(:item => :main_collective, :value => "mcollective")
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should fail if the config item has not been defined' do
|
121
|
+
result = @agent.call(:get_config_item, :item => :failure)
|
122
|
+
result.should be_aborted_error
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe '#ping' do
|
127
|
+
it 'should return the current time on the host' do
|
128
|
+
Time.expects(:now).returns("123456")
|
129
|
+
result = @agent.call(:ping)
|
130
|
+
result.should be_successful
|
131
|
+
result.should have_data_items(:pong => 123456)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '#collective_info' do
|
136
|
+
it 'should return the main collective and list of defined collectives' do
|
137
|
+
result = @agent.call(:collective_info)
|
138
|
+
result.should be_successful
|
139
|
+
result.should have_data_items({:main_collective => 'mcollective', :collectives => ['production', 'staging']})
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '#get_data' do
|
144
|
+
let(:query_data) do
|
145
|
+
{:key1 => 'value1', :key2 => 'value2'}
|
146
|
+
end
|
147
|
+
|
148
|
+
let(:data) do
|
149
|
+
mock
|
150
|
+
end
|
151
|
+
|
152
|
+
let(:ddl) do
|
153
|
+
mock
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'should return the data results if a query has been specified' do
|
157
|
+
data.stubs(:lookup).with('query').returns(query_data)
|
158
|
+
Data.stubs(:ddl).with('test_data').returns(ddl)
|
159
|
+
Data.stubs(:ddl_transform_input).with(ddl, 'query').returns('query')
|
160
|
+
Data.stubs(:[]).with('test_data').returns(data)
|
161
|
+
result = @agent.call(:get_data, :source => 'test_data', :query => 'query')
|
162
|
+
result.should be_successful
|
163
|
+
result.should have_data_items(:key1 => 'value1', :key2 => 'value2')
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should return the data results if no query has been specified' do
|
167
|
+
data.stubs(:lookup).with(nil).returns(query_data)
|
168
|
+
Data.stubs(:[]).with('test_data').returns(data)
|
169
|
+
result = @agent.call(:get_data, :source => 'test_data')
|
170
|
+
result.should be_successful
|
171
|
+
result.should have_data_items(:key1 => 'value1', :key2 => 'value2')
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require File.join(File.dirname(__FILE__), '../../../../../', 'plugins', 'mcollective', 'application', 'plugin.rb')
|
5
|
+
|
6
|
+
module MCollective
|
7
|
+
class Application
|
8
|
+
describe Plugin do
|
9
|
+
|
10
|
+
let(:ddl) { mock }
|
11
|
+
|
12
|
+
before do
|
13
|
+
@app = MCollective::Application::Plugin.new()
|
14
|
+
@app.configuration[:rpctemplate] = "rspec-helptemplate.erb"
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#doc_command" do
|
18
|
+
it "should display doc output for a plugin that exists when using 'plugin'" do
|
19
|
+
@app.configuration[:target] = "rspec"
|
20
|
+
PluginManager.stubs(:find).with(:agent, "ddl").returns(["rspec"])
|
21
|
+
PluginManager.stubs(:find).with(:aggregate, "ddl").returns([""])
|
22
|
+
PluginManager.stubs(:find).with(:data, "ddl").returns([""])
|
23
|
+
PluginManager.stubs(:find).with(:discovery, "ddl").returns([""])
|
24
|
+
PluginManager.stubs(:find).with(:validator, "ddl").returns([""])
|
25
|
+
@app.stubs(:load_plugin_ddl).with('rspec', :agent).returns(ddl)
|
26
|
+
ddl.expects(:help).with("rspec-helptemplate.erb").returns("agent_template")
|
27
|
+
@app.expects(:puts).with("agent_template")
|
28
|
+
@app.doc_command
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should display doc output for a plugin that exists when using 'plugintype/plugin'" do
|
32
|
+
@app.configuration[:target] = "agent/rspec"
|
33
|
+
@app.stubs(:load_plugin_ddl).with(:rspec, "agent").returns(ddl)
|
34
|
+
ddl.expects(:help).with("rspec-helptemplate.erb").returns("agent_template")
|
35
|
+
@app.expects(:puts).with("agent_template")
|
36
|
+
@app.doc_command
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should display a failure message for a plugin that doesn't exist when using 'plugin'" do
|
40
|
+
@app.configuration[:target] = "rspec"
|
41
|
+
PluginManager.stubs(:find).returns([""])
|
42
|
+
@app.expects(:abort).with("Could not find a plugin named 'rspec' in any supported plugin type").raises("test_error")
|
43
|
+
|
44
|
+
expect{
|
45
|
+
@app.doc_command
|
46
|
+
}.to raise_error "test_error"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should display a failure message for a plugin that doens't exist when using 'plugintype/plugin'" do
|
50
|
+
@app.configuration[:target] = "agent/rspec"
|
51
|
+
@app.expects(:load_plugin_ddl).with(:rspec, "agent").returns(nil)
|
52
|
+
@app.expects(:abort).with("Could not find a 'agent' plugin named 'rspec'").raises("test_error")
|
53
|
+
|
54
|
+
expect{
|
55
|
+
@app.doc_command
|
56
|
+
}.to raise_error "test_error"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should display a failure message if duplicate plugins are found" do
|
60
|
+
@app.configuration[:target] = "rspec"
|
61
|
+
PluginManager.stubs(:find).returns(["rspec"])
|
62
|
+
@app.stubs(:abort).with("Duplicate plugin name found, please specify a full path like agent/rpcutil").raises("test_error")
|
63
|
+
|
64
|
+
expect{
|
65
|
+
@app.doc_command
|
66
|
+
}.to raise_error "test_error"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should display a failure message for a plugintype that doens't exist" do
|
70
|
+
@app.configuration[:target] = "foo/rspec"
|
71
|
+
@app.stubs(:load_plugin_ddl).with(:rspec, "foo").returns(nil)
|
72
|
+
@app.stubs(:abort).with("Could not find a 'foo' plugin named 'rspec'").raises("test_error")
|
73
|
+
|
74
|
+
expect{
|
75
|
+
@app.doc_command
|
76
|
+
}.to raise_error "test_error"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require File.join(File.dirname(__FILE__), '../../../../../', 'plugins', 'mcollective', 'audit', 'logfile.rb')
|
5
|
+
|
6
|
+
module MCollective
|
7
|
+
module RPC
|
8
|
+
describe Logfile do
|
9
|
+
let(:file) do
|
10
|
+
mock
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:request) do
|
14
|
+
req = mock
|
15
|
+
req.stubs(:uniqid).returns("1234")
|
16
|
+
req.stubs(:time).returns(1389179593)
|
17
|
+
req.stubs(:caller).returns("test_user")
|
18
|
+
req.stubs(:sender).returns("test_host")
|
19
|
+
req.stubs(:agent).returns("rspec_agent")
|
20
|
+
req.stubs(:action).returns("testme")
|
21
|
+
req.stubs(:data).returns({})
|
22
|
+
req
|
23
|
+
end
|
24
|
+
|
25
|
+
before :each do
|
26
|
+
Time.stubs(:now).returns(Time.at(1389180255))
|
27
|
+
file.expects(:puts).with("[2014-01-08 11:24:15 UTC] reqid=1234: reqtime=1389179593 caller=test_user@test_host " +
|
28
|
+
"agent=rspec_agent action=testme data={}")
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should log to a user defined logfile' do
|
32
|
+
Config.any_instance.stubs(:pluginconf).returns("rpcaudit.logfile" => "/nonexisting")
|
33
|
+
File.expects(:open).with("/nonexisting", "a").yields(file)
|
34
|
+
Logfile.new.audit_request(request, nil)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should log to a default logfile' do
|
38
|
+
Config.any_instance.stubs(:pluginconf).returns({})
|
39
|
+
File.expects(:open).with("/var/log/mcollective-audit.log", "a").yields(file)
|
40
|
+
Logfile.new.audit_request(request, nil)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -95,6 +95,8 @@ module MCollective
|
|
95
95
|
"activemq.randomize" => "true",
|
96
96
|
"activemq.backup" => "true",
|
97
97
|
"activemq.timeout" => "1",
|
98
|
+
"activemq.max_hbrlck_fails" => 3,
|
99
|
+
"activemq.max_hbread_fails" => 3,
|
98
100
|
"activemq.connect_timeout" => "5"}
|
99
101
|
|
100
102
|
|
@@ -114,9 +116,12 @@ module MCollective
|
|
114
116
|
:use_exponential_back_off => false,
|
115
117
|
:max_reconnect_attempts => 5,
|
116
118
|
:initial_reconnect_delay => 0.02,
|
119
|
+
:max_hbread_fails => 3,
|
120
|
+
:max_hbrlck_fails => 3,
|
117
121
|
:randomize => true,
|
118
122
|
:reliable => true,
|
119
123
|
:logger => "logger",
|
124
|
+
:connect_headers => {},
|
120
125
|
:hosts => [{:passcode => 'password1',
|
121
126
|
:host => 'host1',
|
122
127
|
:port => 6163,
|
@@ -130,12 +135,56 @@ module MCollective
|
|
130
135
|
])
|
131
136
|
|
132
137
|
@c.expects(:ssl_parameters).with(2, true).returns(true)
|
138
|
+
@c.expects(:connection_headers).returns({})
|
133
139
|
|
134
140
|
@c.instance_variable_set("@connection", nil)
|
135
141
|
@c.connect(connector)
|
136
142
|
end
|
137
143
|
end
|
138
144
|
|
145
|
+
describe "#connection_headers" do
|
146
|
+
before do
|
147
|
+
@c.stubs(:stomp_version).returns("1.2.10")
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should default to stomp 1.0 only" do
|
151
|
+
@config.expects(:pluginconf).returns({}).at_least_once
|
152
|
+
@c.connection_headers[:"accept-version"] == "1.0"
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should support setting the vhost" do
|
156
|
+
@config.expects(:pluginconf).returns("activemq.vhost" => "rspec").at_least_once
|
157
|
+
@c.connection_headers.should == {:host => "rspec", :"accept-version" => "1.0"}
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should log a warning about not using Stomp 1.1" do
|
161
|
+
@config.expects(:pluginconf).returns("activemq.heartbeat_interval" => "0").at_least_once
|
162
|
+
Log.expects(:warn).with(regexp_matches(/without STOMP 1.1 heartbeats/))
|
163
|
+
@c.connection_headers
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should not support stomp 1.1 with older versions of the stomp gem" do
|
167
|
+
@config.expects(:pluginconf).returns("activemq.heartbeat_interval" => "30").at_least_once
|
168
|
+
@c.expects(:stomp_version).returns("1.0.0").once
|
169
|
+
expect { @c.connection_headers }.to raise_error("Setting STOMP 1.1 properties like heartbeat intervals require at least version 1.2.10 of the STOMP gem")
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should force the heartbeat to min 30 seconds" do
|
173
|
+
@config.expects(:pluginconf).returns("activemq.heartbeat_interval" => "10").at_least_once
|
174
|
+
@c.connection_headers[:"heart-beat"].should == "30500,29500"
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should default to 1.0 and 1.1 support" do
|
178
|
+
@config.expects(:pluginconf).returns("activemq.heartbeat_interval" => "30").at_least_once
|
179
|
+
@c.connection_headers[:"accept-version"].should == "1.1,1.0"
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should support stomp 1.1 only operation" do
|
183
|
+
@config.expects(:pluginconf).returns("activemq.heartbeat_interval" => "30", "activemq.stomp_1_0_fallback" => 0).at_least_once
|
184
|
+
@c.connection_headers[:"accept-version"].should == "1.1"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
139
188
|
describe "#ssl_paramaters" do
|
140
189
|
it "should ensure all settings are provided" do
|
141
190
|
pluginconf = {"activemq.pool.1.host" => "host1",
|
@@ -161,6 +210,8 @@ module MCollective
|
|
161
210
|
"activemq.pool.1.ssl.ca" => "rspec1.ca,rspec2.ca"}
|
162
211
|
|
163
212
|
@config.expects(:pluginconf).returns(pluginconf).at_least_once
|
213
|
+
@c.expects(:get_key_file).returns("rspec.key").at_least_once
|
214
|
+
@c.expects(:get_cert_file).returns("rspec.cert").at_least_once
|
164
215
|
|
165
216
|
File.expects(:exist?).with("rspec.cert").twice.returns(true)
|
166
217
|
File.expects(:exist?).with("rspec.key").twice.returns(true)
|
@@ -197,6 +248,33 @@ module MCollective
|
|
197
248
|
end
|
198
249
|
end
|
199
250
|
|
251
|
+
describe "#get_key_file" do
|
252
|
+
it "should return the filename from the environment variable" do
|
253
|
+
ENV["MCOLLECTIVE_ACTIVEMQ_POOL2_SSL_KEY"] = "/path/to/rspec/env"
|
254
|
+
@c.get_key_file(2).should == "/path/to/rspec/env"
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should return the filename defined in the config file if the environment varialbe doesn't exist" do
|
258
|
+
ENV.delete("MCOLLECTIVE_ACTIVEMQ_POOL2_SSL_KEY")
|
259
|
+
@c.expects(:get_option).with("activemq.pool.2.ssl.key", false).returns("/path/to/rspec/conf")
|
260
|
+
@c.get_key_file(2).should == "/path/to/rspec/conf"
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "#get_cert_file" do
|
266
|
+
it "should return the filename from the environment variable" do
|
267
|
+
ENV["MCOLLECTIVE_ACTIVEMQ_POOL2_SSL_CERT"] = "/path/to/rspec/env"
|
268
|
+
@c.get_cert_file(2).should == "/path/to/rspec/env"
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should return the filename defined in the config file if the environment varialbe doesn't exist" do
|
272
|
+
ENV.delete("MCOLLECTIVE_ACTIVEMQ_POOL2_SSL_CERT")
|
273
|
+
@c.expects(:get_option).with("activemq.pool.2.ssl.cert", false).returns("/path/to/rspec/conf")
|
274
|
+
@c.get_cert_file(2).should == "/path/to/rspec/conf"
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
200
278
|
describe "#receive" do
|
201
279
|
it "should receive from the middleware" do
|
202
280
|
payload = mock
|
@@ -376,24 +454,31 @@ module MCollective
|
|
376
454
|
it "should disconnect from the stomp connection" do
|
377
455
|
@connection.expects(:disconnect)
|
378
456
|
@c.disconnect
|
457
|
+
@c.connection.should == nil
|
379
458
|
end
|
380
459
|
end
|
381
460
|
|
382
461
|
describe "#headers_for" do
|
383
|
-
it "should
|
462
|
+
it "should not set priority header if priority is 0" do
|
384
463
|
message = mock
|
385
464
|
message.expects(:type).returns(:foo)
|
465
|
+
message.stubs(:ttl).returns(30)
|
466
|
+
|
467
|
+
Time.expects(:now).twice.returns(Time.at(1368557431))
|
386
468
|
|
387
469
|
@c.instance_variable_set("@msgpriority", 0)
|
388
|
-
@c.headers_for(message).
|
470
|
+
@c.headers_for(message).should_not includes("priority")
|
389
471
|
end
|
390
472
|
|
391
473
|
it "should return a priority if priority is non 0" do
|
392
474
|
message = mock
|
393
475
|
message.expects(:type).returns(:foo)
|
476
|
+
message.stubs(:ttl).returns(30)
|
477
|
+
|
478
|
+
Time.expects(:now).twice.returns(Time.at(1368557431))
|
394
479
|
|
395
480
|
@c.instance_variable_set("@msgpriority", 1)
|
396
|
-
@c.headers_for(message).should ==
|
481
|
+
@c.headers_for(message)["priority"].should == 1
|
397
482
|
end
|
398
483
|
|
399
484
|
it "should set mc_identity for direct requests" do
|
@@ -402,10 +487,16 @@ module MCollective
|
|
402
487
|
message.expects(:agent).returns("rspecagent")
|
403
488
|
message.expects(:collective).returns("mcollective")
|
404
489
|
message.expects(:reply_to).returns(nil)
|
490
|
+
message.stubs(:ttl).returns(30)
|
491
|
+
|
492
|
+
Time.expects(:now).twice.returns(Time.at(1368557431))
|
405
493
|
|
406
494
|
@c.instance_variable_set("@msgpriority", 0)
|
407
495
|
@c.expects(:make_target).with("rspecagent", :reply, "mcollective").returns({:name => "test"})
|
408
|
-
|
496
|
+
|
497
|
+
headers = @c.headers_for(message, "some.node")
|
498
|
+
headers["mc_identity"].should == "some.node"
|
499
|
+
headers["reply-to"].should == "test"
|
409
500
|
end
|
410
501
|
|
411
502
|
it "should set a reply-to header for :request type messages" do
|
@@ -414,10 +505,13 @@ module MCollective
|
|
414
505
|
message.expects(:agent).returns("rspecagent")
|
415
506
|
message.expects(:collective).returns("mcollective")
|
416
507
|
message.expects(:reply_to).returns(nil)
|
508
|
+
message.stubs(:ttl).returns(30)
|
509
|
+
|
510
|
+
Time.expects(:now).twice.returns(Time.at(1368557431))
|
417
511
|
|
418
512
|
@c.instance_variable_set("@msgpriority", 0)
|
419
513
|
@c.expects(:make_target).with("rspecagent", :reply, "mcollective").returns({:name => "test"})
|
420
|
-
@c.headers_for(message)
|
514
|
+
@c.headers_for(message)["reply-to"].should == "test"
|
421
515
|
end
|
422
516
|
|
423
517
|
it "should set reply-to correctly if the message defines it" do
|
@@ -426,9 +520,23 @@ module MCollective
|
|
426
520
|
message.expects(:agent).returns("rspecagent")
|
427
521
|
message.expects(:collective).returns("mcollective")
|
428
522
|
message.expects(:reply_to).returns("rspec").twice
|
523
|
+
message.stubs(:ttl).returns(30)
|
429
524
|
|
430
|
-
|
525
|
+
Time.expects(:now).twice.returns(Time.at(1368557431))
|
431
526
|
|
527
|
+
@c.headers_for(message)["reply-to"].should == "rspec"
|
528
|
+
end
|
529
|
+
|
530
|
+
it "should set the timestamp and ttl based on the message object" do
|
531
|
+
message = mock
|
532
|
+
message.expects(:type).returns(:foo)
|
533
|
+
message.stubs(:ttl).returns(100)
|
534
|
+
|
535
|
+
Time.expects(:now).twice.returns(Time.at(1368557431))
|
536
|
+
|
537
|
+
headers = @c.headers_for(message)
|
538
|
+
headers["timestamp"].should == "1368557431000"
|
539
|
+
headers["expires"].should == "1368557541000"
|
432
540
|
end
|
433
541
|
end
|
434
542
|
|
@@ -504,28 +612,11 @@ module MCollective
|
|
504
612
|
end
|
505
613
|
|
506
614
|
describe "#get_bool_option" do
|
507
|
-
it "should
|
508
|
-
@config.expects(:pluginconf).returns({})
|
509
|
-
|
510
|
-
end
|
511
|
-
|
512
|
-
["1", "yes", "true"].each do |boolean|
|
513
|
-
it "should map options to true correctly" do
|
514
|
-
@config.expects(:pluginconf).returns({"test" => boolean}).twice
|
515
|
-
@c.get_bool_option("test", "default").should == true
|
516
|
-
end
|
517
|
-
end
|
518
|
-
|
519
|
-
["0", "no", "false"].each do |boolean|
|
520
|
-
it "should map options to false correctly" do
|
521
|
-
@config.expects(:pluginconf).returns({"test" => boolean}).twice
|
522
|
-
@c.get_bool_option("test", "default").should == false
|
523
|
-
end
|
524
|
-
end
|
615
|
+
it "should use Util::str_to_bool to translate a boolean value found in the config" do
|
616
|
+
@config.expects(:pluginconf).returns({"rspec" => "true"})
|
617
|
+
Util.expects(:str_to_bool).with("true").returns(true)
|
525
618
|
|
526
|
-
|
527
|
-
@config.expects(:pluginconf).returns({"test" => "foo"}).twice
|
528
|
-
@c.get_bool_option("test", "default").should == "default"
|
619
|
+
@c.get_bool_option("rspec", "true").should be_true
|
529
620
|
end
|
530
621
|
end
|
531
622
|
end
|