mcollective-client 2.4.1 → 2.5.0.rc1
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.
- data/lib/mcollective.rb +1 -14
- data/lib/mcollective/config.rb +4 -1
- data/lib/mcollective/exceptions.rb +27 -0
- data/lib/mcollective/unix_daemon.rb +4 -1
- data/lib/mcollective/windows_daemon.rb +18 -9
- data/spec/unit/plugins/mcollective/connector/activemq_spec.rb +331 -228
- data/spec/unit/plugins/mcollective/connector/rabbitmq_spec.rb +332 -239
- data/spec/unit/runner_spec.rb +253 -0
- data/spec/unit/unix_daemon_spec.rb +2 -2
- data/spec/unit/windows_daemon_spec.rb +1 -7
- metadata +8 -23
- data/spec/unit/security/runner_spec.rb +0 -67
@@ -0,0 +1,253 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
describe Runner do
|
7
|
+
let(:config) do
|
8
|
+
c = mock
|
9
|
+
c.stubs(:loadconfig)
|
10
|
+
c.stubs(:configured).returns(true)
|
11
|
+
c.stubs(:mode=)
|
12
|
+
c.stubs(:direct_addressing).returns(true)
|
13
|
+
c.stubs(:registerinterval).returns(1)
|
14
|
+
c.stubs(:soft_shutdown).returns(false)
|
15
|
+
c
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:stats) { mock }
|
19
|
+
|
20
|
+
let(:security) do
|
21
|
+
s = mock
|
22
|
+
s.stubs(:initiated_by=)
|
23
|
+
s
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:connector) do
|
27
|
+
c = mock
|
28
|
+
c.stubs(:connect)
|
29
|
+
c.stubs(:disconnect)
|
30
|
+
c
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:agents) { mock }
|
34
|
+
|
35
|
+
let(:receiver_thread) do
|
36
|
+
rt = mock
|
37
|
+
rt
|
38
|
+
end
|
39
|
+
|
40
|
+
before :each do
|
41
|
+
Config.stubs(:instance).returns(config)
|
42
|
+
PluginManager.stubs(:[]).with('global_stats').returns(stats)
|
43
|
+
PluginManager.stubs(:[]).with('security_plugin').returns(security)
|
44
|
+
PluginManager.stubs(:[]).with('connector_plugin').returns(connector)
|
45
|
+
Agents.stubs(:new).returns(agents)
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'initialize' do
|
49
|
+
it 'should set up the signal handlers when not on windows' do
|
50
|
+
Util.stubs(:windows).returns(false)
|
51
|
+
Signal.expects(:trap).with('USR1')
|
52
|
+
Signal.expects(:trap).with('USR2')
|
53
|
+
Runner.new(nil)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should not set up the signal handlers when on windows' do
|
57
|
+
Util.stubs(:windows?).returns(true)
|
58
|
+
Signal.expects(:trap).with('USR1').never
|
59
|
+
Signal.expects(:trap).with('USR2').never
|
60
|
+
|
61
|
+
Util.expects(:setup_windows_sleeper)
|
62
|
+
Runner.new(nil)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should log a message when it cannot initialize the runner' do
|
66
|
+
Config.stubs(:instance).raises('failure')
|
67
|
+
Log.expects(:error).times(3)
|
68
|
+
expect {
|
69
|
+
Runner.new(nil)
|
70
|
+
}.to raise_error 'failure'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#main_loop' do
|
75
|
+
let(:runner) do
|
76
|
+
Runner.new(nil)
|
77
|
+
end
|
78
|
+
|
79
|
+
let(:receiver_thread) do
|
80
|
+
rt = mock
|
81
|
+
rt.stubs(:alive?).returns(false)
|
82
|
+
rt
|
83
|
+
end
|
84
|
+
|
85
|
+
let(:agent_thread) do
|
86
|
+
at = mock
|
87
|
+
at.stubs(:alive?).returns(true)
|
88
|
+
at.expects(:join)
|
89
|
+
at
|
90
|
+
end
|
91
|
+
|
92
|
+
before :each do
|
93
|
+
Log.stubs(:debug)
|
94
|
+
Log.stubs(:info)
|
95
|
+
Log.stubs(:warn)
|
96
|
+
Log.stubs(:error)
|
97
|
+
runner.stubs(:start_receiver_thread).returns(receiver_thread)
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'stopping' do
|
101
|
+
it 'should stop normally' do
|
102
|
+
receiver_thread.stubs(:alive?).returns(true)
|
103
|
+
runner.instance_variable_set(:@state, :stopping)
|
104
|
+
runner.expects(:stop_threads)
|
105
|
+
runner.main_loop
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should not do a soft_shutdown on windows' do
|
109
|
+
config.stubs(:soft_shutdown).returns(true)
|
110
|
+
Util.stubs(:windows?).returns(true)
|
111
|
+
Log.expects(:warn).with("soft_shutdown specified. This feature is not available on Windows. Shutting down normally.")
|
112
|
+
runner.instance_variable_set(:@state, :stopping)
|
113
|
+
runner.main_loop
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should do a soft_shutdown' do
|
117
|
+
config.stubs(:soft_shutdown).returns(true)
|
118
|
+
Util.stubs(:windows?).returns(false)
|
119
|
+
runner.instance_variable_set(:@state, :stopping)
|
120
|
+
runner.instance_variable_set(:@agent_threads, [agent_thread])
|
121
|
+
runner.main_loop
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Because paused is not a terminal state, we raise after testing pause
|
126
|
+
# which forces a run. This means checks like #stop_threads will happen twice
|
127
|
+
context 'pausing' do
|
128
|
+
before :each do
|
129
|
+
receiver_thread.stubs(:alive?).returns(false)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should pause' do
|
133
|
+
runner.instance_variable_set(:@state, :pausing)
|
134
|
+
runner.expects(:stop_threads).twice
|
135
|
+
runner.expects(:sleep).with(0.1).raises("error")
|
136
|
+
runner.main_loop
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should resume' do
|
140
|
+
runner.instance_variable_set(:@state, :unpausing)
|
141
|
+
runner.expects(:stop_threads)
|
142
|
+
runner.expects(:start_receiver_thread).returns(receiver_thread)
|
143
|
+
runner.expects(:sleep).with(0.1).raises("error")
|
144
|
+
runner.main_loop
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'action methods' do
|
150
|
+
let(:runner) do
|
151
|
+
Runner.new(nil)
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '#stop' do
|
155
|
+
it 'should change the state to stopping' do
|
156
|
+
runner.instance_variable_set(:@state, :running)
|
157
|
+
runner.stop
|
158
|
+
runner.state.should == :stopping
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '#pause' do
|
163
|
+
it 'should change the state to pausing' do
|
164
|
+
runner.instance_variable_set(:@state, :running)
|
165
|
+
runner.pause
|
166
|
+
runner.state.should == :pausing
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should fail if state is not running' do
|
170
|
+
Log.expects(:error).with('Cannot pause MCollective while not in a running state')
|
171
|
+
runner.pause
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe '#resume' do
|
176
|
+
it 'should change the state to unpausing' do
|
177
|
+
runner.instance_variable_set(:@state, :paused)
|
178
|
+
runner.resume
|
179
|
+
runner.state.should == :unpausing
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should fail if state is not paused' do
|
183
|
+
runner.instance_variable_set(:@state, :running)
|
184
|
+
Log.expects(:error).with('Cannot unpause MCollective when it is not paused')
|
185
|
+
runner.resume
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe '#receiver_thread' do
|
190
|
+
let(:runner) do
|
191
|
+
Runner.new(nil)
|
192
|
+
end
|
193
|
+
|
194
|
+
let(:registration_agent) do
|
195
|
+
ra = mock
|
196
|
+
ra.stubs(:run)
|
197
|
+
ra
|
198
|
+
end
|
199
|
+
|
200
|
+
let(:request) do
|
201
|
+
r = mock
|
202
|
+
r.stubs(:agent).returns("rspec")
|
203
|
+
r
|
204
|
+
end
|
205
|
+
|
206
|
+
before :each do
|
207
|
+
PluginManager.stubs(:[]).with("registration_plugin").returns(registration_agent)
|
208
|
+
Data.expects(:load_data_sources)
|
209
|
+
Util.expects(:subscribe).twice
|
210
|
+
Util.expects(:make_subscriptions).twice
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should receive a message and spawn an agent thread' do
|
214
|
+
runner.expects(:receive).returns(request)
|
215
|
+
runner.expects(:agentmsg).with(request)
|
216
|
+
runner.instance_variable_set(:@exit_receiver_thread, true)
|
217
|
+
runner.send(:receiver_thread)
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should discard controller messages with an error message' do
|
221
|
+
runner.expects(:receive).returns(request)
|
222
|
+
request.stubs(:agent).returns("mcollective")
|
223
|
+
Log.expects(:error).with("Received a control message, possibly via 'mco controller' but this has been deprecated and removed")
|
224
|
+
runner.instance_variable_set(:@exit_receiver_thread, true)
|
225
|
+
runner.send(:receiver_thread)
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'should warn when a received message has expired' do
|
229
|
+
runner.expects(:receive).raises(MsgTTLExpired)
|
230
|
+
runner.instance_variable_set(:@exit_receiver_thread, true)
|
231
|
+
Log.expects(:warn)
|
232
|
+
runner.send(:receiver_thread)
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'should log if a message was received by not directed at the server' do
|
236
|
+
runner.expects(:receive).raises(NotTargettedAtUs)
|
237
|
+
runner.instance_variable_set(:@exit_receiver_thread, true)
|
238
|
+
Log.expects(:debug).with("Message does not pass filters, ignoring")
|
239
|
+
runner.send(:receiver_thread)
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should back off on MessageNotReceived and UnexpectedMessageType' do
|
243
|
+
runner.expects(:receive).raises(MessageNotReceived.new(1))
|
244
|
+
runner.instance_variable_set(:@exit_receiver_thread, true)
|
245
|
+
Log.expects(:warn)
|
246
|
+
Log.expects(:info).with("sleeping for suggested 1 seconds")
|
247
|
+
runner.expects(:sleep).with(1)
|
248
|
+
runner.send(:receiver_thread)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
@@ -18,7 +18,7 @@ module MCollective
|
|
18
18
|
File.expects(:open).with("/nonexisting", "w").yields(f)
|
19
19
|
|
20
20
|
r = mock
|
21
|
-
r.expects(:
|
21
|
+
r.expects(:main_loop)
|
22
22
|
|
23
23
|
Runner.expects(:new).returns(r)
|
24
24
|
UnixDaemon.expects(:daemonize).yields
|
@@ -28,7 +28,7 @@ module MCollective
|
|
28
28
|
|
29
29
|
it "should not write a pid file unless requested", :unless => MCollective::Util.windows? do
|
30
30
|
r = mock
|
31
|
-
r.expects(:
|
31
|
+
r.expects(:main_loop)
|
32
32
|
|
33
33
|
UnixDaemon.expects(:daemonize).yields
|
34
34
|
Runner.expects(:new).returns(r)
|
@@ -29,9 +29,7 @@ module MCollective
|
|
29
29
|
runner = mock
|
30
30
|
Runner.stubs(:new).returns(runner)
|
31
31
|
d = WindowsDaemon.new
|
32
|
-
|
33
|
-
d.stubs(:state).returns(WindowsDaemon::RUNNING)
|
34
|
-
runner.expects(:run)
|
32
|
+
runner.expects(:main_loop)
|
35
33
|
d.service_main
|
36
34
|
end
|
37
35
|
|
@@ -49,12 +47,8 @@ module MCollective
|
|
49
47
|
describe "#service_stop" do
|
50
48
|
it "should log, disconnect, stop the runner and exit" do
|
51
49
|
runner = mock
|
52
|
-
connector = mock
|
53
|
-
connector.expects(:disconnect)
|
54
50
|
Log.expects(:info)
|
55
|
-
PluginManager.stubs(:[]).with("connector_plugin").returns(connector)
|
56
51
|
d = WindowsDaemon.new
|
57
|
-
d.instance_variable_set(:@runner, runner)
|
58
52
|
runner.expects(:stop)
|
59
53
|
d.service_stop
|
60
54
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mcollective-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.5.0.rc1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Puppet Labs
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: systemu
|
@@ -59,22 +59,6 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: i18n
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :runtime
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
78
62
|
description: Client libraries for the Mcollective Application Server
|
79
63
|
email: info@puppetlabs.com
|
80
64
|
executables:
|
@@ -102,6 +86,7 @@ files:
|
|
102
86
|
- lib/mcollective/rpc/progress.rb
|
103
87
|
- lib/mcollective/rpc/agent.rb
|
104
88
|
- lib/mcollective/rpc/actionrunner.rb
|
89
|
+
- lib/mcollective/exceptions.rb
|
105
90
|
- lib/mcollective/log.rb
|
106
91
|
- lib/mcollective/data.rb
|
107
92
|
- lib/mcollective/logger.rb
|
@@ -180,6 +165,7 @@ files:
|
|
180
165
|
- spec/unit/shell_spec.rb
|
181
166
|
- spec/unit/matcher_spec.rb
|
182
167
|
- spec/unit/windows_daemon_spec.rb
|
168
|
+
- spec/unit/runner_spec.rb
|
183
169
|
- spec/unit/ssl_spec.rb
|
184
170
|
- spec/unit/registration/base_spec.rb
|
185
171
|
- spec/unit/client_spec.rb
|
@@ -250,7 +236,6 @@ files:
|
|
250
236
|
- spec/unit/pluginpackager_spec.rb
|
251
237
|
- spec/unit/util_spec.rb
|
252
238
|
- spec/unit/message_spec.rb
|
253
|
-
- spec/unit/security/runner_spec.rb
|
254
239
|
- spec/unit/security/base_spec.rb
|
255
240
|
- spec/unit/symbol_spec.rb
|
256
241
|
- spec/unit/logger/syslog_logger_spec.rb
|
@@ -294,9 +279,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
294
279
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
295
280
|
none: false
|
296
281
|
requirements:
|
297
|
-
- - ! '
|
282
|
+
- - ! '>'
|
298
283
|
- !ruby/object:Gem::Version
|
299
|
-
version:
|
284
|
+
version: 1.3.1
|
300
285
|
requirements: []
|
301
286
|
rubyforge_project:
|
302
287
|
rubygems_version: 1.8.23
|
@@ -324,6 +309,7 @@ test_files:
|
|
324
309
|
- spec/unit/shell_spec.rb
|
325
310
|
- spec/unit/matcher_spec.rb
|
326
311
|
- spec/unit/windows_daemon_spec.rb
|
312
|
+
- spec/unit/runner_spec.rb
|
327
313
|
- spec/unit/ssl_spec.rb
|
328
314
|
- spec/unit/registration/base_spec.rb
|
329
315
|
- spec/unit/client_spec.rb
|
@@ -394,7 +380,6 @@ test_files:
|
|
394
380
|
- spec/unit/pluginpackager_spec.rb
|
395
381
|
- spec/unit/util_spec.rb
|
396
382
|
- spec/unit/message_spec.rb
|
397
|
-
- spec/unit/security/runner_spec.rb
|
398
383
|
- spec/unit/security/base_spec.rb
|
399
384
|
- spec/unit/symbol_spec.rb
|
400
385
|
- spec/unit/logger/syslog_logger_spec.rb
|
@@ -1,67 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rspec
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module MCollective
|
6
|
-
describe Runner do
|
7
|
-
let(:config) do
|
8
|
-
c = mock
|
9
|
-
c.stubs(:loadconfig)
|
10
|
-
c.stubs(:configured).returns(true)
|
11
|
-
c.stubs(:mode=)
|
12
|
-
c
|
13
|
-
end
|
14
|
-
|
15
|
-
let(:stats) { mock }
|
16
|
-
|
17
|
-
let(:security) do
|
18
|
-
s = mock
|
19
|
-
s.stubs(:initiated_by=)
|
20
|
-
s
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:connector) do
|
24
|
-
c = mock
|
25
|
-
c.stubs(:connect)
|
26
|
-
c
|
27
|
-
end
|
28
|
-
|
29
|
-
let(:agents) { mock }
|
30
|
-
|
31
|
-
before :each do
|
32
|
-
Config.stubs(:instance).returns(config)
|
33
|
-
PluginManager.stubs(:[]).with('global_stats').returns(stats)
|
34
|
-
PluginManager.stubs(:[]).with('security_plugin').returns(security)
|
35
|
-
PluginManager.stubs(:[]).with('connector_plugin').returns(connector)
|
36
|
-
Agents.stubs(:new).returns(agents)
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'initialize' do
|
40
|
-
it 'should set up the signal handlers when not on windows' do
|
41
|
-
Util.stubs(:windows).returns(false)
|
42
|
-
Signal.expects(:trap).with('USR1').yields
|
43
|
-
Signal.expects(:trap).with('USR2').yields
|
44
|
-
agents.expects(:loadagents)
|
45
|
-
Log.expects(:info).twice
|
46
|
-
Log.expects(:cycle_level)
|
47
|
-
Runner.new(nil)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should not set up the signal handlers when on windows' do
|
51
|
-
Util.stubs(:windows?).returns(true)
|
52
|
-
Signal.expects(:trap).with('USR1').never
|
53
|
-
Signal.expects(:trap).with('USR2').never
|
54
|
-
Util.expects(:setup_windows_sleeper)
|
55
|
-
Runner.new(nil)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should log a message when it cannot initialize the runner' do
|
59
|
-
Config.stubs(:instance).raises('failure')
|
60
|
-
Log.expects(:error).times(3)
|
61
|
-
expect {
|
62
|
-
Runner.new(nil)
|
63
|
-
}.to raise_error 'failure'
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|