mcollective-client 2.0.0 → 2.2.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.
- data/lib/mcollective.rb +32 -23
- data/lib/mcollective/agent.rb +5 -0
- data/lib/mcollective/agents.rb +5 -16
- data/lib/mcollective/aggregate.rb +61 -0
- data/lib/mcollective/aggregate/base.rb +40 -0
- data/lib/mcollective/aggregate/result.rb +9 -0
- data/lib/mcollective/aggregate/result/base.rb +25 -0
- data/lib/mcollective/aggregate/result/collection_result.rb +19 -0
- data/lib/mcollective/aggregate/result/numeric_result.rb +13 -0
- data/lib/mcollective/application.rb +7 -4
- data/lib/mcollective/applications.rb +3 -14
- data/lib/mcollective/cache.rb +145 -0
- data/lib/mcollective/client.rb +10 -87
- data/lib/mcollective/config.rb +22 -8
- data/lib/mcollective/data.rb +87 -0
- data/lib/mcollective/data/base.rb +67 -0
- data/lib/mcollective/data/result.rb +40 -0
- data/lib/mcollective/ddl.rb +113 -0
- data/lib/mcollective/ddl/agentddl.rb +185 -0
- data/lib/mcollective/ddl/base.rb +220 -0
- data/lib/mcollective/ddl/dataddl.rb +56 -0
- data/lib/mcollective/ddl/discoveryddl.rb +52 -0
- data/lib/mcollective/ddl/validatorddl.rb +6 -0
- data/lib/mcollective/discovery.rb +143 -0
- data/lib/mcollective/generators.rb +7 -0
- data/lib/mcollective/generators/agent_generator.rb +51 -0
- data/lib/mcollective/generators/base.rb +46 -0
- data/lib/mcollective/generators/data_generator.rb +51 -0
- data/lib/mcollective/generators/templates/action_snippet.erb +13 -0
- data/lib/mcollective/generators/templates/data_input_snippet.erb +7 -0
- data/lib/mcollective/generators/templates/ddl.erb +8 -0
- data/lib/mcollective/generators/templates/plugin.erb +7 -0
- data/lib/mcollective/logger/console_logger.rb +15 -15
- data/lib/mcollective/matcher.rb +167 -0
- data/lib/mcollective/matcher/parser.rb +60 -25
- data/lib/mcollective/matcher/scanner.rb +156 -78
- data/lib/mcollective/message.rb +47 -6
- data/lib/mcollective/monkey_patches.rb +17 -0
- data/lib/mcollective/optionparser.rb +18 -1
- data/lib/mcollective/pluginmanager.rb +3 -3
- data/lib/mcollective/pluginpackager.rb +10 -3
- data/lib/mcollective/pluginpackager/agent_definition.rb +28 -20
- data/lib/mcollective/pluginpackager/standard_definition.rb +11 -9
- data/lib/mcollective/registration/base.rb +3 -1
- data/lib/mcollective/rpc.rb +18 -24
- data/lib/mcollective/rpc/agent.rb +37 -113
- data/lib/mcollective/rpc/client.rb +186 -64
- data/lib/mcollective/rpc/helpers.rb +42 -80
- data/lib/mcollective/rpc/progress.rb +3 -3
- data/lib/mcollective/rpc/reply.rb +37 -13
- data/lib/mcollective/rpc/request.rb +17 -6
- data/lib/mcollective/rpc/result.rb +9 -5
- data/lib/mcollective/rpc/stats.rb +71 -24
- data/lib/mcollective/security/base.rb +41 -34
- data/lib/mcollective/shell.rb +1 -1
- data/lib/mcollective/ssl.rb +34 -0
- data/lib/mcollective/util.rb +194 -23
- data/lib/mcollective/validator.rb +80 -0
- data/spec/fixtures/util/1.in +10 -0
- data/spec/fixtures/util/1.out +10 -0
- data/spec/fixtures/util/2.in +1 -0
- data/spec/fixtures/util/2.out +1 -0
- data/spec/fixtures/util/3.in +1 -0
- data/spec/fixtures/util/3.out +2 -0
- data/spec/fixtures/util/4.in +5 -0
- data/spec/fixtures/util/4.out +9 -0
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/agents_spec.rb +34 -19
- data/spec/unit/aggregate/base_spec.rb +57 -0
- data/spec/unit/aggregate/result/base_spec.rb +28 -0
- data/spec/unit/aggregate/result/collection_result_spec.rb +18 -0
- data/spec/unit/aggregate/result/numeric_result_spec.rb +22 -0
- data/spec/unit/aggregate_spec.rb +110 -0
- data/spec/unit/application_spec.rb +8 -3
- data/spec/unit/applications_spec.rb +2 -2
- data/spec/unit/cache_spec.rb +115 -0
- data/spec/unit/client_spec.rb +78 -0
- data/spec/unit/config_spec.rb +32 -34
- data/spec/unit/data/base_spec.rb +90 -0
- data/spec/unit/data/result_spec.rb +64 -0
- data/spec/unit/data_spec.rb +158 -0
- data/spec/unit/ddl/agentddl_spec.rb +217 -0
- data/spec/unit/{rpc/ddl_spec.rb → ddl/base_spec.rb} +238 -224
- data/spec/unit/ddl/dataddl_spec.rb +65 -0
- data/spec/unit/ddl/discoveryddl_spec.rb +58 -0
- data/spec/unit/ddl_spec.rb +84 -0
- data/spec/unit/discovery_spec.rb +196 -0
- data/spec/unit/facts/base_spec.rb +1 -1
- data/spec/unit/generators/agent_generator_spec.rb +72 -0
- data/spec/unit/generators/base_spec.rb +83 -0
- data/spec/unit/generators/data_generator_spec.rb +37 -0
- data/spec/unit/generators/snippets/agent_ddl +19 -0
- data/spec/unit/generators/snippets/data_ddl +20 -0
- data/spec/unit/logger/console_logger_spec.rb +76 -0
- data/spec/unit/logger/syslog_logger_spec.rb +2 -2
- data/spec/unit/matcher/parser_spec.rb +27 -10
- data/spec/unit/matcher/scanner_spec.rb +108 -5
- data/spec/unit/matcher_spec.rb +260 -0
- data/spec/unit/message_spec.rb +35 -13
- data/spec/unit/optionparser_spec.rb +2 -2
- data/spec/unit/pluginpackager/agent_definition_spec.rb +59 -42
- data/spec/unit/pluginpackager/standard_definition_spec.rb +10 -8
- data/spec/unit/pluginpackager_spec.rb +131 -0
- data/spec/unit/plugins/mcollective/aggregate/average_spec.rb +45 -0
- data/spec/unit/plugins/mcollective/aggregate/sum_spec.rb +31 -0
- data/spec/unit/plugins/mcollective/aggregate/summary_spec.rb +45 -0
- data/spec/unit/plugins/mcollective/connector/activemq_spec.rb +1 -1
- data/spec/unit/plugins/mcollective/connector/rabbitmq_spec.rb +478 -0
- data/spec/unit/plugins/mcollective/connector/stomp_spec.rb +2 -0
- data/spec/unit/plugins/mcollective/data/agent_data_spec.rb +43 -0
- data/spec/unit/plugins/mcollective/data/fstat_data_spec.rb +135 -0
- data/spec/unit/plugins/mcollective/discovery/flatfile_spec.rb +48 -0
- data/spec/unit/plugins/mcollective/discovery/mc_spec.rb +40 -0
- data/spec/unit/plugins/mcollective/packagers/debpackage_packager_spec.rb +41 -15
- data/spec/unit/plugins/mcollective/packagers/ospackage_spec.rb +1 -1
- data/spec/unit/plugins/mcollective/packagers/rpmpackage_packager_spec.rb +22 -38
- data/spec/unit/plugins/mcollective/validator/array_validator_spec.rb +19 -0
- data/spec/unit/plugins/mcollective/validator/ipv4address_validator_spec.rb +19 -0
- data/spec/unit/plugins/mcollective/validator/ipv6address_validator_spec.rb +19 -0
- data/spec/unit/plugins/mcollective/validator/length_validator_spec.rb +19 -0
- data/spec/unit/plugins/mcollective/validator/regex_validator_spec.rb +19 -0
- data/spec/unit/plugins/mcollective/validator/shellsafe_validator_spec.rb +21 -0
- data/spec/unit/plugins/mcollective/validator/typecheck_validator_spec.rb +23 -0
- data/spec/unit/registration/base_spec.rb +1 -1
- data/spec/unit/rpc/actionrunner_spec.rb +2 -2
- data/spec/unit/rpc/agent_spec.rb +41 -65
- data/spec/unit/rpc/client_spec.rb +430 -134
- data/spec/unit/rpc/reply_spec.rb +31 -1
- data/spec/unit/rpc/request_spec.rb +33 -12
- data/spec/unit/rpc/result_spec.rb +7 -0
- data/spec/unit/rpc/stats_spec.rb +14 -14
- data/spec/unit/rpc_spec.rb +16 -0
- data/spec/unit/security/base_spec.rb +8 -8
- data/spec/unit/ssl_spec.rb +20 -2
- data/spec/unit/string_spec.rb +15 -0
- data/spec/unit/util_spec.rb +141 -21
- data/spec/unit/validator_spec.rb +67 -0
- metadata +145 -7
- data/lib/mcollective/rpc/ddl.rb +0 -258
@@ -5,20 +5,261 @@ require 'spec_helper'
|
|
5
5
|
module MCollective
|
6
6
|
module RPC
|
7
7
|
describe Client do
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
before do
|
9
|
+
@coreclient = mock
|
10
|
+
@discoverer = mock
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
ddl = DDL.new("foo", "agent", false)
|
13
|
+
ddl.action("rspec", :description => "mock agent")
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
Config.any_instance.stubs(:direct_addressing).returns(true)
|
15
|
+
ddl.stubs(:meta).returns({:timeout => 2})
|
16
|
+
DDL.stubs(:new).returns(ddl)
|
18
17
|
|
19
|
-
|
18
|
+
@discoverer.stubs(:force_direct_mode?).returns(false)
|
19
|
+
@discoverer.stubs(:discovery_method).returns("mc")
|
20
|
+
@discoverer.stubs(:force_discovery_method_by_filter).returns(false)
|
21
|
+
@discoverer.stubs(:discovery_timeout).returns(2)
|
22
|
+
@discoverer.stubs(:ddl).returns(ddl)
|
23
|
+
|
24
|
+
@coreclient.stubs("options=")
|
25
|
+
@coreclient.stubs(:collective).returns("mcollective")
|
26
|
+
@coreclient.stubs(:timeout_for_compound_filter).returns(0)
|
27
|
+
@coreclient.stubs(:discoverer).returns(@discoverer)
|
28
|
+
|
29
|
+
Config.instance.stubs(:loadconfig).with("/nonexisting").returns(true)
|
30
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
31
|
+
Config.instance.stubs(:collectives).returns(["mcollective", "rspec"])
|
32
|
+
MCollective::Client.stubs(:new).returns(@coreclient)
|
33
|
+
|
34
|
+
@stderr = StringIO.new
|
35
|
+
@stdout = StringIO.new
|
36
|
+
|
37
|
+
@client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
38
|
+
@client.stubs(:ddl).returns(ddl)
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#initialize" do
|
42
|
+
it "should fail for missing DDLs" do
|
43
|
+
DDL.stubs(:new).raises("DDL failure")
|
44
|
+
expect { Client.new("foo", {:options => {:config => "/nonexisting"}}) }.to raise_error("DDL failure")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should set a empty filter when none is supplied" do
|
48
|
+
filter = Util.empty_filter
|
49
|
+
Util.expects(:empty_filter).once.returns(filter)
|
50
|
+
|
51
|
+
Client.new("foo", :options => {:config => "/nonexisting"})
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#process_results_with_block" do
|
56
|
+
it "should inform the stats object correctly for passed requests" do
|
57
|
+
response = {:senderid => "rspec", :body => {:statuscode => 0}}
|
58
|
+
|
59
|
+
@client.stubs(:rpc_result_from_reply).with("foo", "rspec", response)
|
60
|
+
@client.stats.expects(:ok)
|
61
|
+
@client.stats.expects(:node_responded).with("rspec")
|
62
|
+
@client.stats.expects(:time_block_execution).with(:start)
|
63
|
+
@client.stats.expects(:time_block_execution).with(:end)
|
64
|
+
@client.expects(:aggregate_reply).returns("aggregate stub")
|
65
|
+
|
66
|
+
blk = Proc.new {}
|
67
|
+
|
68
|
+
@client.process_results_with_block("rspec", response, blk, "").should == "aggregate stub"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should inform the stats object correctly for failed requests" do
|
72
|
+
@client.stats.expects(:fail)
|
73
|
+
@client.stats.expects(:node_responded).with("rspec")
|
74
|
+
|
75
|
+
response = {:senderid => "rspec", :body => {:statuscode => 1}}
|
76
|
+
blk = Proc.new {}
|
77
|
+
|
78
|
+
@client.stubs(:rpc_result_from_reply).with("foo", "rspec", response)
|
79
|
+
@client.process_results_with_block("rspec", response, blk, nil)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should raise correct exceptions on failure" do
|
83
|
+
blk = Proc.new {}
|
84
|
+
|
85
|
+
@client.stubs(:rpc_result_from_reply)
|
86
|
+
|
87
|
+
[[2, UnknownRPCAction], [3, MissingRPCData], [4, InvalidRPCData], [5, UnknownRPCError]].each do |err|
|
88
|
+
response = {:senderid => "rspec", :body => {:statuscode => err[0]}}
|
89
|
+
|
90
|
+
expect { @client.process_results_with_block("rspec", response, blk, nil) }.to raise_error(err[1])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should pass raw results for single arity blocks" do
|
95
|
+
response = {:senderid => "rspec", :body => {:statuscode => 1}}
|
96
|
+
blk = Proc.new {|r| r.should == response}
|
97
|
+
|
98
|
+
@client.stubs(:rpc_result_from_reply).with("foo", "rspec", response)
|
99
|
+
@client.process_results_with_block("rspec", response, blk, nil)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should pass raw and rpc style results for 2 arity blocks" do
|
103
|
+
response = {:senderid => "rspec", :body => {:statuscode => 1}}
|
104
|
+
blk = Proc.new do |r, s|
|
105
|
+
r.should == response
|
106
|
+
s.should.class == RPC::Result
|
107
|
+
end
|
108
|
+
|
109
|
+
@client.process_results_with_block("rspec", response, blk, nil)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "#process_results_without_block" do
|
114
|
+
it "should inform the stats object correctly for passed requests" do
|
115
|
+
response = {:senderid => "rspec", :body => {:statuscode => 0}}
|
116
|
+
@client.stubs(:rpc_result_from_reply).with("foo", "rspec", response)
|
117
|
+
@client.stats.expects(:ok)
|
118
|
+
@client.stats.expects(:node_responded).with("rspec")
|
119
|
+
@client.process_results_without_block(response, "rspec", nil)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should inform the stats object correctly for failed requests" do
|
123
|
+
@client.stats.expects(:fail).twice
|
124
|
+
@client.stats.expects(:node_responded).with("rspec").twice
|
125
|
+
|
126
|
+
response = {:senderid => "rspec", :body => {:statuscode => 1}}
|
127
|
+
@client.stubs(:rpc_result_from_reply).with("foo", "rspec", response)
|
128
|
+
@client.process_results_without_block(response, "rspec", nil)
|
129
|
+
|
130
|
+
response = {:senderid => "rspec", :body => {:statuscode => 3}}
|
131
|
+
@client.stubs(:rpc_result_from_reply).with("foo", "rspec", response)
|
132
|
+
@client.process_results_without_block(response, "rspec", nil)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should return the result and the aggregate" do
|
136
|
+
@client.expects(:aggregate_reply).returns("aggregate stub")
|
137
|
+
|
138
|
+
response = {:senderid => "rspec", :body => {:statuscode => 0}}
|
139
|
+
result = @client.rpc_result_from_reply("foo", "rspec", response)
|
140
|
+
|
141
|
+
@client.stubs(:rpc_result_from_reply).with("foo", "rspec", response).returns(result)
|
142
|
+
@client.process_results_without_block(response, "rspec", "").should == [result, "aggregate stub"]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "#load_aggregate_functions" do
|
147
|
+
it "should not load if the ddl is not set" do
|
148
|
+
@client.load_aggregate_functions("rspec", nil).should == nil
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should create the aggregate for the right action" do
|
152
|
+
@client.ddl.expects(:action_interface).with("rspec").returns({:aggregate => []}).twice
|
153
|
+
Aggregate.expects(:new).with(:aggregate => []).returns("rspec aggregate")
|
154
|
+
@client.load_aggregate_functions("rspec", @client.ddl).should == "rspec aggregate"
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should log and return nil on failure" do
|
158
|
+
@client.ddl.expects(:action_interface).raises("rspec")
|
159
|
+
Log.expects(:error).with(regexp_matches(/Failed to load aggregate/))
|
160
|
+
@client.load_aggregate_functions("rspec", @client.ddl)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "#aggregate_reply" do
|
165
|
+
it "should not call anything if the aggregate isnt set" do
|
166
|
+
@client.aggregate_reply(nil, nil).should == nil
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should call the aggregate functions with the right data" do
|
170
|
+
result = @client.rpc_result_from_reply("rspec", "rspec", {:body => {:data => "rspec"}})
|
171
|
+
|
172
|
+
aggregate = mock
|
173
|
+
aggregate.expects(:call_functions).with(result).returns(aggregate)
|
174
|
+
|
175
|
+
@client.aggregate_reply(result, aggregate).should == aggregate
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should log and return nil on failure" do
|
179
|
+
aggregate = mock
|
180
|
+
aggregate.expects(:call_functions).raises
|
181
|
+
|
182
|
+
Log.expects(:error).with(regexp_matches(/Failed to calculate aggregate summaries/))
|
183
|
+
|
184
|
+
@client.aggregate_reply({}, aggregate).should == nil
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "#collective=" do
|
189
|
+
it "should validate the collective" do
|
190
|
+
expect { @client.collective = "fail" }.to raise_error("Unknown collective fail")
|
191
|
+
@client.collective = "rspec"
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should set the collective" do
|
195
|
+
@client.options[:collective].should == "mcollective"
|
196
|
+
@client.collective = "rspec"
|
197
|
+
@client.options[:collective].should == "rspec"
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should reset the client" do
|
201
|
+
@client.expects(:reset)
|
202
|
+
@client.collective = "rspec"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "#discovery_method=" do
|
207
|
+
it "should set the method" do
|
208
|
+
@client.discovery_method = "rspec"
|
209
|
+
@client.discovery_method.should == "rspec"
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should set initial options if provided" do
|
213
|
+
client = Client.new("rspec", {:options => {:discovery_options => ["rspec"], :filter => Util.empty_filter, :config => "/nonexisting"}})
|
214
|
+
client.discovery_method = "rspec"
|
215
|
+
client.discovery_method.should == "rspec"
|
216
|
+
client.discovery_options.should == ["rspec"]
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should clear the options if none are given initially" do
|
220
|
+
@client.discovery_options = ["rspec"]
|
221
|
+
@client.discovery_method = "rspec"
|
222
|
+
@client.discovery_options.should == []
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should set the client options" do
|
226
|
+
@client.expects(:options).returns("rspec")
|
227
|
+
@client.client.expects(:options=).with("rspec")
|
228
|
+
@client.discovery_method = "rspec"
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should adjust discovery timeout for the new method" do
|
232
|
+
@client.expects(:discovery_timeout).once.returns(1)
|
233
|
+
@client.discovery_method = "rspec"
|
234
|
+
@client.instance_variable_get("@discovery_timeout").should == 1
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should reset the rpc client" do
|
238
|
+
@client.expects(:reset)
|
239
|
+
@client.discovery_method = "rspec"
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "#discovery_options=" do
|
244
|
+
it "should flatten the options array" do
|
245
|
+
@client.discovery_options = "foo"
|
246
|
+
@client.discovery_options.should == ["foo"]
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
describe "#discovery_timeout" do
|
251
|
+
it "should favour the initial options supplied timeout" do
|
252
|
+
client = Client.new("rspec", {:options => {:disctimeout => 3, :filter => Util.empty_filter, :config => "/nonexisting"}})
|
253
|
+
client.discovery_timeout.should == 3
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should return the DDL data if no specific options are supplied" do
|
257
|
+
client = Client.new("rspec", {:options => {:disctimeout => nil, :filter => Util.empty_filter, :config => "/nonexisting"}})
|
258
|
+
client.discovery_timeout.should == 2
|
20
259
|
end
|
260
|
+
end
|
21
261
|
|
262
|
+
describe "#limit_method" do
|
22
263
|
it "should force strings to symbols" do
|
23
264
|
@client.limit_method = "first"
|
24
265
|
@client.limit_method.should == :first
|
@@ -36,21 +277,12 @@ module MCollective
|
|
36
277
|
end
|
37
278
|
|
38
279
|
describe "#method_missing" do
|
39
|
-
before do
|
40
|
-
client = stub
|
41
|
-
client.stubs("options=")
|
42
|
-
client.stubs(:collective).returns("mcollective")
|
43
|
-
MCollective::Client.stubs(:new).returns(client)
|
44
|
-
|
45
|
-
Config.any_instance.stubs(:loadconfig).with("/nonexisting").returns(true)
|
46
|
-
end
|
47
|
-
|
48
280
|
it "should reset the stats" do
|
49
281
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
50
282
|
client.stubs(:call_agent)
|
51
283
|
|
52
284
|
Stats.any_instance.expects(:reset).once
|
53
|
-
client.
|
285
|
+
client.rspec
|
54
286
|
end
|
55
287
|
|
56
288
|
it "should validate the request against the ddl" do
|
@@ -59,7 +291,7 @@ module MCollective
|
|
59
291
|
client.stubs(:call_agent)
|
60
292
|
|
61
293
|
ddl = mock
|
62
|
-
ddl.expects(:
|
294
|
+
ddl.expects(:validate_rpc_request).with("rspec", {:arg => :val}).raises("validation failed")
|
63
295
|
client.instance_variable_set("@ddl", ddl)
|
64
296
|
|
65
297
|
expect { client.rspec(:arg => :val) }.to raise_error("validation failed")
|
@@ -70,14 +302,14 @@ module MCollective
|
|
70
302
|
client.limit_targets = 10
|
71
303
|
|
72
304
|
client.expects(:pick_nodes_from_discovered).with(10).returns(["one", "two"])
|
73
|
-
client.expects(:custom_request).with("
|
305
|
+
client.expects(:custom_request).with("rspec", {}, ["one", "two"], {"identity" => /^(one|two)$/}).once
|
74
306
|
|
75
|
-
client.
|
307
|
+
client.rspec
|
76
308
|
end
|
77
309
|
|
78
310
|
describe "batch mode" do
|
79
311
|
before do
|
80
|
-
Config.
|
312
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
81
313
|
@client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
82
314
|
end
|
83
315
|
|
@@ -122,22 +354,76 @@ module MCollective
|
|
122
354
|
it "should support normal calls" do
|
123
355
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
124
356
|
|
125
|
-
client.expects(:call_agent).with("
|
357
|
+
client.expects(:call_agent).with("rspec", {}, client.options, :auto).once
|
126
358
|
|
127
|
-
client.
|
359
|
+
client.rspec
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
describe "#pick_nodes_from_discovered" do
|
364
|
+
before do
|
365
|
+
client = stub
|
366
|
+
discoverer = stub
|
367
|
+
ddl = stub
|
368
|
+
|
369
|
+
ddl.stubs(:meta).returns({:timeout => 2})
|
370
|
+
|
371
|
+
discoverer.stubs(:ddl).returns(ddl)
|
372
|
+
|
373
|
+
client.stubs("options=")
|
374
|
+
client.stubs(:collective).returns("mcollective")
|
375
|
+
client.stubs(:discoverer).returns(discoverer)
|
376
|
+
|
377
|
+
Config.instance.stubs(:loadconfig).with("/nonexisting").returns(true)
|
378
|
+
MCollective::Client.stubs(:new).returns(client)
|
379
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
380
|
+
end
|
381
|
+
|
382
|
+
it "should return a percentage of discovered hosts" do
|
383
|
+
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
384
|
+
client.stubs(:discover).returns((1..10).map{|i| i.to_s})
|
385
|
+
client.limit_method = :first
|
386
|
+
client.pick_nodes_from_discovered("20%").should == ["1", "2"]
|
387
|
+
end
|
388
|
+
|
389
|
+
it "should return the same list when a random seed is supplied" do
|
390
|
+
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :limit_seed => 5}})
|
391
|
+
client.stubs(:discover).returns((1..10).map{|i| i.to_s})
|
392
|
+
client.limit_method = :random
|
393
|
+
client.pick_nodes_from_discovered("30%").should == ["3", "7", "8"]
|
394
|
+
client.pick_nodes_from_discovered("30%").should == ["3", "7", "8"]
|
395
|
+
client.pick_nodes_from_discovered("3").should == ["3", "7", "8"]
|
396
|
+
client.pick_nodes_from_discovered("3").should == ["3", "7", "8"]
|
397
|
+
end
|
398
|
+
|
399
|
+
it "should correctly pick a numeric amount of discovered nodes" do
|
400
|
+
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :limit_seed => 5}})
|
401
|
+
client.stubs(:discover).returns((1..10).map{|i| i.to_s})
|
402
|
+
client.limit_method = :first
|
403
|
+
client.pick_nodes_from_discovered(5).should == (1..5).map{|i| i.to_s}
|
404
|
+
client.pick_nodes_from_discovered(5).should == (1..5).map{|i| i.to_s}
|
128
405
|
end
|
129
406
|
end
|
130
407
|
|
131
408
|
describe "#limit_targets=" do
|
132
409
|
before do
|
133
410
|
client = stub
|
411
|
+
discoverer = stub
|
412
|
+
ddl = stub
|
413
|
+
|
414
|
+
ddl.stubs(:meta).returns({:timeout => 2})
|
415
|
+
|
416
|
+
discoverer.stubs(:force_direct_mode?).returns(false)
|
417
|
+
discoverer.stubs(:ddl).returns(ddl)
|
418
|
+
discoverer.stubs(:discovery_method).returns("mc")
|
134
419
|
|
135
420
|
client.stubs("options=")
|
136
421
|
client.stubs(:collective).returns("mcollective")
|
422
|
+
client.stubs(:discoverer).returns(discoverer)
|
137
423
|
|
138
|
-
Config.
|
424
|
+
Config.instance.stubs(:loadconfig).with("/nonexisting").returns(true)
|
139
425
|
MCollective::Client.expects(:new).returns(client)
|
140
|
-
Config.
|
426
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
141
427
|
|
142
428
|
@client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
143
429
|
end
|
@@ -168,17 +454,26 @@ module MCollective
|
|
168
454
|
describe "#call_agent_batched" do
|
169
455
|
before do
|
170
456
|
@client = stub
|
457
|
+
@discoverer = stub
|
458
|
+
@ddl = stub
|
459
|
+
|
460
|
+
@ddl.stubs(:meta).returns({:timeout => 2})
|
461
|
+
|
462
|
+
@discoverer.stubs(:force_direct_mode?).returns(false)
|
463
|
+
@discoverer.stubs(:ddl).returns(@ddl)
|
464
|
+
@discoverer.stubs(:discovery_method).returns("mc")
|
171
465
|
|
172
466
|
@client.stubs("options=")
|
173
467
|
@client.stubs(:collective).returns("mcollective")
|
468
|
+
@client.stubs(:discoverer).returns(@discoverer)
|
174
469
|
|
175
|
-
Config.
|
470
|
+
Config.instance.stubs(:loadconfig).with("/nonexisting").returns(true)
|
176
471
|
MCollective::Client.expects(:new).returns(@client)
|
177
|
-
Config.
|
472
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
178
473
|
end
|
179
474
|
|
180
475
|
it "should require direct addressing" do
|
181
|
-
Config.
|
476
|
+
Config.instance.stubs(:direct_addressing).returns(false)
|
182
477
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
183
478
|
|
184
479
|
expect {
|
@@ -218,7 +513,10 @@ module MCollective
|
|
218
513
|
discovered = mock
|
219
514
|
discovered.stubs(:size).returns(1)
|
220
515
|
discovered.expects(:in_groups_of).with(10).raises("spec pass")
|
221
|
-
|
516
|
+
|
517
|
+
client.instance_variable_set("@client", @coreclient)
|
518
|
+
@coreclient.stubs(:discover).returns(discovered)
|
519
|
+
@coreclient.stubs(:timeout_for_compound_filter).returns(0)
|
222
520
|
|
223
521
|
expect { client.send(:call_agent_batched, "foo", {}, {}, 10, 1) }.to raise_error("spec pass")
|
224
522
|
end
|
@@ -229,7 +527,9 @@ module MCollective
|
|
229
527
|
Message.expects(:new).with('req', nil, {:type => :direct_request, :agent => 'foo', :filter => nil, :options => {}, :collective => 'mcollective'}).raises("spec pass")
|
230
528
|
client.expects(:new_request).returns("req")
|
231
529
|
|
232
|
-
|
530
|
+
client.instance_variable_set("@client", @coreclient)
|
531
|
+
@coreclient.stubs(:discover).returns(["test"])
|
532
|
+
@coreclient.stubs(:timeout_for_compound_filter).returns(0)
|
233
533
|
|
234
534
|
expect { client.send(:call_agent_batched, "foo", {}, {}, 1, 1) }.to raise_error("spec pass")
|
235
535
|
end
|
@@ -239,30 +539,38 @@ module MCollective
|
|
239
539
|
|
240
540
|
msg = mock
|
241
541
|
msg.expects(:discovered_hosts=).times(10)
|
542
|
+
msg.expects(:create_reqid).returns("823a3419a0975c3facbde121f72ab61f")
|
543
|
+
msg.expects(:requestid=).with("823a3419a0975c3facbde121f72ab61f").times(10)
|
242
544
|
|
243
|
-
stats = {:noresponsefrom => [], :responses => 0, :blocktime => 0, :totaltime => 0, :discoverytime => 0}
|
545
|
+
stats = {:noresponsefrom => [], :responses => 0, :blocktime => 0, :totaltime => 0, :discoverytime => 0, :requestid => "823a3419a0975c3facbde121f72ab61f"}
|
244
546
|
|
245
547
|
Message.expects(:new).with('req', nil, {:type => :direct_request, :agent => 'foo', :filter => nil, :options => {}, :collective => 'mcollective'}).returns(msg).times(10)
|
246
548
|
client.expects(:new_request).returns("req")
|
247
549
|
client.expects(:sleep).with(1.0).times(9)
|
248
550
|
|
249
|
-
|
250
|
-
@
|
251
|
-
@
|
551
|
+
client.instance_variable_set("@client", @coreclient)
|
552
|
+
@coreclient.stubs(:discover).returns([1,2,3,4,5,6,7,8,9,0])
|
553
|
+
@coreclient.expects(:req).with(msg).yields("result").times(10)
|
554
|
+
@coreclient.stubs(:stats).returns stats
|
555
|
+
@coreclient.stubs(:timeout_for_compound_filter).returns(0)
|
252
556
|
|
253
|
-
client.expects(:process_results_with_block).with("foo", "result", instance_of(Proc)).times(10)
|
557
|
+
client.expects(:process_results_with_block).with("foo", "result", instance_of(Proc), nil).times(10)
|
254
558
|
|
255
559
|
result = client.send(:call_agent_batched, "foo", {}, {}, 1, 1) { }
|
560
|
+
result[:requestid].should == "823a3419a0975c3facbde121f72ab61f"
|
256
561
|
result.class.should == Stats
|
257
562
|
end
|
258
563
|
|
259
564
|
it "should return an array of results in array mode" do
|
260
565
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :stderr => StringIO.new}})
|
566
|
+
client.instance_variable_set("@client", @coreclient)
|
261
567
|
|
262
568
|
msg = mock
|
263
569
|
msg.expects(:discovered_hosts=).times(10)
|
570
|
+
msg.expects(:create_reqid).returns("823a3419a0975c3facbde121f72ab61f")
|
571
|
+
msg.expects(:requestid=).with("823a3419a0975c3facbde121f72ab61f").times(10)
|
264
572
|
|
265
|
-
stats = {:noresponsefrom => [], :responses => 0, :blocktime => 0, :totaltime => 0, :discoverytime => 0}
|
573
|
+
stats = {:noresponsefrom => [], :responses => 0, :blocktime => 0, :totaltime => 0, :discoverytime => 0, :requestid => "823a3419a0975c3facbde121f72ab61f"}
|
266
574
|
|
267
575
|
Progress.expects(:new).never
|
268
576
|
|
@@ -270,29 +578,22 @@ module MCollective
|
|
270
578
|
client.expects(:new_request).returns("req")
|
271
579
|
client.expects(:sleep).with(1.0).times(9)
|
272
580
|
|
273
|
-
@
|
274
|
-
@
|
275
|
-
@
|
581
|
+
@coreclient.stubs(:discover).returns([1,2,3,4,5,6,7,8,9,0])
|
582
|
+
@coreclient.expects(:req).with(msg).yields("result").times(10)
|
583
|
+
@coreclient.stubs(:stats).returns stats
|
584
|
+
@coreclient.stubs(:timeout_for_compound_filter).returns(0)
|
276
585
|
|
277
|
-
client.expects(:process_results_without_block).with("result", "foo").returns("rspec").times(10)
|
586
|
+
client.expects(:process_results_without_block).with("result", "foo", nil).returns("rspec").times(10)
|
278
587
|
|
279
588
|
client.send(:call_agent_batched, "foo", {}, {}, 1, 1).should == ["rspec", "rspec", "rspec", "rspec", "rspec", "rspec", "rspec", "rspec", "rspec", "rspec"]
|
589
|
+
|
590
|
+
client.stats[:requestid].should == "823a3419a0975c3facbde121f72ab61f"
|
280
591
|
end
|
281
592
|
end
|
282
593
|
|
283
594
|
describe "#batch_sleep_time=" do
|
284
|
-
before do
|
285
|
-
@client = stub
|
286
|
-
|
287
|
-
@client.stubs("options=")
|
288
|
-
@client.stubs(:collective).returns("mcollective")
|
289
|
-
|
290
|
-
Config.any_instance.stubs(:loadconfig).with("/nonexisting").returns(true)
|
291
|
-
MCollective::Client.expects(:new).returns(@client)
|
292
|
-
end
|
293
|
-
|
294
595
|
it "should correctly set the sleep" do
|
295
|
-
Config.
|
596
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
296
597
|
|
297
598
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
298
599
|
client.batch_sleep_time = 5
|
@@ -300,7 +601,8 @@ module MCollective
|
|
300
601
|
end
|
301
602
|
|
302
603
|
it "should only allow batch sleep to be set for direct addressing capable clients" do
|
303
|
-
Config.
|
604
|
+
Config.instance.stubs(:direct_addressing).returns(false)
|
605
|
+
Config.instance.stubs(:loadconfig).with("/nonexisting").returns(true)
|
304
606
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
305
607
|
|
306
608
|
expect { client.batch_sleep_time = 5 }.to raise_error("Can only set batch sleep time if direct addressing is supported")
|
@@ -308,18 +610,8 @@ module MCollective
|
|
308
610
|
end
|
309
611
|
|
310
612
|
describe "#batch_size=" do
|
311
|
-
before do
|
312
|
-
@client = stub
|
313
|
-
|
314
|
-
@client.stubs("options=")
|
315
|
-
@client.stubs(:collective).returns("mcollective")
|
316
|
-
|
317
|
-
Config.any_instance.stubs(:loadconfig).with("/nonexisting").returns(true)
|
318
|
-
MCollective::Client.expects(:new).returns(@client)
|
319
|
-
end
|
320
|
-
|
321
613
|
it "should correctly set the size" do
|
322
|
-
Config.
|
614
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
323
615
|
|
324
616
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
325
617
|
client.batch_mode.should == false
|
@@ -329,14 +621,15 @@ module MCollective
|
|
329
621
|
end
|
330
622
|
|
331
623
|
it "should only allow batch size to be set for direct addressing capable clients" do
|
332
|
-
Config.
|
624
|
+
Config.instance.stubs(:loadconfig).with("/nonexisting").returns(true)
|
625
|
+
Config.instance.stubs(:direct_addressing).returns(false)
|
333
626
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
334
627
|
|
335
628
|
expect { client.batch_size = 5 }.to raise_error("Can only set batch size if direct addressing is supported")
|
336
629
|
end
|
337
630
|
|
338
631
|
it "should support disabling batch mode when supplied a batch size of 0" do
|
339
|
-
Config.
|
632
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
340
633
|
|
341
634
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
342
635
|
client.batch_size = 5
|
@@ -347,28 +640,15 @@ module MCollective
|
|
347
640
|
end
|
348
641
|
|
349
642
|
describe "#discover" do
|
350
|
-
before do
|
351
|
-
@client = stub
|
352
|
-
|
353
|
-
@client.stubs("options=")
|
354
|
-
@client.stubs(:collective).returns("mcollective")
|
355
|
-
|
356
|
-
@stderr = stub
|
357
|
-
@stdout = stub
|
358
|
-
|
359
|
-
Config.any_instance.stubs(:loadconfig).with("/nonexisting").returns(true)
|
360
|
-
MCollective::Client.expects(:new).returns(@client)
|
361
|
-
end
|
362
|
-
|
363
643
|
it "should not accept invalid flags" do
|
364
|
-
Config.
|
644
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
365
645
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
366
646
|
|
367
647
|
expect { client.discover(:rspec => :rspec) }.to raise_error("Unknown option rspec passed to discover")
|
368
648
|
end
|
369
649
|
|
370
650
|
it "should reset when :json, :hosts or :nodes are provided" do
|
371
|
-
Config.
|
651
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
372
652
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
373
653
|
client.expects(:reset).times(3)
|
374
654
|
client.discover(:hosts => ["one"])
|
@@ -377,7 +657,7 @@ module MCollective
|
|
377
657
|
end
|
378
658
|
|
379
659
|
it "should only allow discovery data in direct addressing mode" do
|
380
|
-
Config.
|
660
|
+
Config.instance.stubs(:direct_addressing).returns(false)
|
381
661
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
382
662
|
client.expects(:reset).once
|
383
663
|
|
@@ -387,7 +667,7 @@ module MCollective
|
|
387
667
|
end
|
388
668
|
|
389
669
|
it "should parse :nodes and :hosts and force direct requests" do
|
390
|
-
Config.
|
670
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
391
671
|
Helpers.expects(:extract_hosts_from_array).with(["one"]).returns(["one"]).twice
|
392
672
|
|
393
673
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
@@ -398,7 +678,7 @@ module MCollective
|
|
398
678
|
end
|
399
679
|
|
400
680
|
it "should parse :json and force direct requests" do
|
401
|
-
Config.
|
681
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
402
682
|
Helpers.expects(:extract_hosts_from_json).with('["one"]').returns(["one"]).once
|
403
683
|
|
404
684
|
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting"}})
|
@@ -407,19 +687,30 @@ module MCollective
|
|
407
687
|
client.instance_variable_get("@discovered_agents").should == ["one"]
|
408
688
|
end
|
409
689
|
|
690
|
+
it "should not set direct mode for non 'mc' discovery methods" do
|
691
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
692
|
+
|
693
|
+
client = Client.new("foo", {:options => {:discovery_method => "rspec", :filter => {"identity" => ["foo"], "agent" => []}, :config => "/nonexisting"}})
|
694
|
+
@coreclient.expects(:discover).returns(["foo"])
|
695
|
+
|
696
|
+
client.discover
|
697
|
+
client.instance_variable_get("@discovered_agents").should == ["foo"]
|
698
|
+
client.instance_variable_get("@force_direct_request").should == false
|
699
|
+
end
|
700
|
+
|
410
701
|
it "should force direct mode for non regex identity filters" do
|
411
|
-
Config.
|
702
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
412
703
|
|
413
|
-
client = Client.new("foo", {:options => {:filter => {"identity" => ["foo"], "agent" => []}, :config => "/nonexisting"}})
|
704
|
+
client = Client.new("foo", {:options => {:discovery_method => "mc", :filter => {"identity" => ["foo"], "agent" => []}, :config => "/nonexisting"}})
|
414
705
|
client.discover
|
415
706
|
client.instance_variable_get("@discovered_agents").should == ["foo"]
|
416
707
|
client.instance_variable_get("@force_direct_request").should == true
|
417
708
|
end
|
418
709
|
|
419
710
|
it "should not set direct mode if its disabled" do
|
420
|
-
Config.
|
711
|
+
Config.instance.stubs(:direct_addressing).returns(false)
|
421
712
|
|
422
|
-
client = Client.new("foo", {:options => {:filter => {"identity" => ["foo"], "agent" => []}, :config => "/nonexisting"}})
|
713
|
+
client = Client.new("foo", {:options => {:discovery_method => "mc", :filter => {"identity" => ["foo"], "agent" => []}, :config => "/nonexisting"}})
|
423
714
|
|
424
715
|
client.discover
|
425
716
|
client.instance_variable_get("@force_direct_request").should == false
|
@@ -427,95 +718,100 @@ module MCollective
|
|
427
718
|
end
|
428
719
|
|
429
720
|
it "should not set direct mode for regex identities" do
|
430
|
-
Config.
|
721
|
+
Config.instance.stubs(:direct_addressing).returns(false)
|
431
722
|
|
432
|
-
|
433
|
-
client = Client.new("foo", {:options => {:filter => {"identity" => ["/foo/"], "agent" => []}, :config => "/nonexisting"}})
|
723
|
+
rpcclient = Client.new("foo", {:options => {:filter => {"identity" => ["/foo/"], "agent" => []}, :config => "/nonexisting"}})
|
434
724
|
|
435
|
-
client.discover
|
436
|
-
|
437
|
-
|
725
|
+
rpcclient.client.expects(:discover).with({'identity' => ['/foo/'], 'agent' => ['foo']}, 2).once.returns(["foo"])
|
726
|
+
|
727
|
+
rpcclient.discover
|
728
|
+
rpcclient.instance_variable_get("@force_direct_request").should == false
|
729
|
+
rpcclient.instance_variable_get("@discovered_agents").should == ["foo"]
|
438
730
|
end
|
439
731
|
|
440
732
|
it "should print status to stderr if in verbose mode" do
|
441
|
-
@
|
442
|
-
@stderr.expects(:print).with("Determining the amount of hosts matching filter for 2 seconds .... ")
|
733
|
+
@stderr.expects(:print).with("Discovering hosts using the mc method for 2 second(s) .... ")
|
443
734
|
@stderr.expects(:puts).with(1)
|
444
735
|
|
445
|
-
|
446
|
-
client.discover
|
447
|
-
end
|
736
|
+
rpcclient = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :verbose => true, :disctimeout => 2, :stderr => @stderr, :stdout => @stdout}})
|
448
737
|
|
449
|
-
|
450
|
-
@client.expects(:discover).with({'identity' => [], 'compound' => [], 'fact' => [], 'agent' => ['foo'], 'cf_class' => []}, 2).returns(["foo"])
|
451
|
-
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :verbose => false, :disctimeout => 2, :stderr => @stderr, :stdout => @stdout}})
|
738
|
+
rpcclient.client.expects(:discover).with({'identity' => [], 'compound' => [], 'fact' => [], 'agent' => ['foo'], 'cf_class' => []}, 2).returns(["foo"])
|
452
739
|
|
740
|
+
rpcclient.discover
|
741
|
+
end
|
742
|
+
|
743
|
+
it "should not print status to stderr if in nonverbose mode" do
|
453
744
|
@stderr.expects(:print).never
|
454
745
|
@stderr.expects(:puts).never
|
455
746
|
|
456
|
-
|
747
|
+
rpcclient = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :verbose => false, :disctimeout => 2, :stderr => @stderr, :stdout => @stdout}})
|
748
|
+
rpcclient.client.expects(:discover).with({'identity' => [], 'compound' => [], 'fact' => [], 'agent' => ['foo'], 'cf_class' => []}, 2).returns(["foo"])
|
749
|
+
|
750
|
+
rpcclient.discover
|
457
751
|
end
|
458
752
|
|
459
753
|
it "should record the start and end times" do
|
460
754
|
Stats.any_instance.expects(:time_discovery).with(:start)
|
461
755
|
Stats.any_instance.expects(:time_discovery).with(:end)
|
462
756
|
|
463
|
-
|
464
|
-
client
|
757
|
+
rpcclient = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :verbose => false, :disctimeout => 2}})
|
758
|
+
rpcclient.client.expects(:discover).with({'identity' => [], 'compound' => [], 'fact' => [], 'agent' => ['foo'], 'cf_class' => []}, 2).returns(["foo"])
|
465
759
|
|
466
|
-
|
760
|
+
rpcclient.discover
|
467
761
|
end
|
468
762
|
|
469
763
|
it "should discover using limits in :first rpclimit mode given a number" do
|
470
|
-
Config.
|
471
|
-
|
472
|
-
client
|
473
|
-
client.limit_targets = 1
|
764
|
+
Config.instance.stubs(:rpclimitmethod).returns(:first)
|
765
|
+
rpcclient = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :verbose => false, :disctimeout => 2}})
|
766
|
+
rpcclient.client.expects(:discover).with({'identity' => [], 'compound' => [], 'fact' => [], 'agent' => ['foo'], 'cf_class' => []}, 2, 1).returns(["foo"])
|
474
767
|
|
475
|
-
|
768
|
+
rpcclient.limit_targets = 1
|
769
|
+
|
770
|
+
rpcclient.discover
|
476
771
|
end
|
477
772
|
|
478
773
|
it "should not discover using limits in :first rpclimit mode given a string" do
|
479
|
-
Config.
|
480
|
-
|
481
|
-
client
|
482
|
-
|
774
|
+
Config.instance.stubs(:rpclimitmethod).returns(:first)
|
775
|
+
rpcclient = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :verbose => false, :disctimeout => 2}})
|
776
|
+
rpcclient.client.expects(:discover).with({'identity' => [], 'compound' => [], 'fact' => [], 'agent' => ['foo'], 'cf_class' => []}, 2).returns(["foo"])
|
777
|
+
rpcclient.limit_targets = "10%"
|
483
778
|
|
484
|
-
|
779
|
+
rpcclient.discover
|
485
780
|
end
|
486
781
|
|
487
782
|
it "should not discover using limits when not in :first mode" do
|
488
|
-
Config.
|
489
|
-
@client.expects(:discover).with({'identity' => [], 'compound' => [], 'fact' => [], 'agent' => ['foo'], 'cf_class' => []}, 2).returns(["foo"])
|
490
|
-
client = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :verbose => false, :disctimeout => 2}})
|
491
|
-
client.limit_targets = 1
|
783
|
+
Config.instance.stubs(:rpclimitmethod).returns(:random)
|
492
784
|
|
493
|
-
|
785
|
+
rpcclient = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :verbose => false, :disctimeout => 2}})
|
786
|
+
rpcclient.client.expects(:discover).with({'identity' => [], 'compound' => [], 'fact' => [], 'agent' => ['foo'], 'cf_class' => []}, 2).returns(["foo"])
|
787
|
+
|
788
|
+
rpcclient.limit_targets = 1
|
789
|
+
rpcclient.discover
|
494
790
|
end
|
495
791
|
|
496
792
|
it "should ensure force_direct mode is false when doing traditional discovery" do
|
497
|
-
|
498
|
-
client
|
793
|
+
rpcclient = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :verbose => false, :disctimeout => 2}})
|
794
|
+
rpcclient.client.expects(:discover).with({'identity' => [], 'compound' => [], 'fact' => [], 'agent' => ['foo'], 'cf_class' => []}, 2).returns(["foo"])
|
499
795
|
|
500
|
-
|
501
|
-
|
502
|
-
|
796
|
+
rpcclient.instance_variable_set("@force_direct_request", true)
|
797
|
+
rpcclient.discover
|
798
|
+
rpcclient.instance_variable_get("@force_direct_request").should == false
|
503
799
|
end
|
504
800
|
|
505
801
|
it "should store discovered nodes in stats" do
|
506
|
-
|
507
|
-
client
|
802
|
+
rpcclient = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :verbose => false, :disctimeout => 2}})
|
803
|
+
rpcclient.client.expects(:discover).with({'identity' => [], 'compound' => [], 'fact' => [], 'agent' => ['foo'], 'cf_class' => []}, 2).returns(["foo"])
|
508
804
|
|
509
|
-
|
510
|
-
|
805
|
+
rpcclient.discover
|
806
|
+
rpcclient.stats.discovered_nodes.should == ["foo"]
|
511
807
|
end
|
512
808
|
|
513
809
|
it "should save discovered nodes in RPC" do
|
514
|
-
|
515
|
-
client
|
810
|
+
rpcclient = Client.new("foo", {:options => {:filter => Util.empty_filter, :config => "/nonexisting", :verbose => false, :disctimeout => 2}})
|
811
|
+
rpcclient.client.expects(:discover).with({'identity' => [], 'compound' => [], 'fact' => [], 'agent' => ['foo'], 'cf_class' => []}, 2).returns(["foo"])
|
516
812
|
|
517
813
|
RPC.expects(:discovered).with(["foo"]).once
|
518
|
-
|
814
|
+
rpcclient.discover
|
519
815
|
end
|
520
816
|
end
|
521
817
|
end
|