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
@@ -0,0 +1,260 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
describe Matcher do
|
7
|
+
describe "#create_function_hash" do
|
8
|
+
it "should create a correct hash for a 'normal' function call using single quotes" do
|
9
|
+
result = Matcher.create_function_hash("foo('bar').res=1")
|
10
|
+
result["value"].should == "res"
|
11
|
+
result["params"].should == "bar"
|
12
|
+
result["r_compare"].should == "1"
|
13
|
+
result["operator"].should == "=="
|
14
|
+
result["name"].should == "foo"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create a correct hash for a 'normal' function call using double quotes" do
|
18
|
+
result = Matcher.create_function_hash('foo("bar").res=1')
|
19
|
+
result["value"].should == "res"
|
20
|
+
result["params"].should == "bar"
|
21
|
+
result["r_compare"].should == "1"
|
22
|
+
result["operator"].should == "=="
|
23
|
+
result["name"].should == "foo"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should create a correct hash when a paramater contains a dot value" do
|
27
|
+
result = Matcher.create_function_hash("foo('bar.1').res=1")
|
28
|
+
result["value"].should == "res"
|
29
|
+
result["params"].should == "bar.1"
|
30
|
+
result["r_compare"].should == "1"
|
31
|
+
result["operator"].should == "=="
|
32
|
+
result["name"].should == "foo"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should create a correct hash when right compare value is a regex" do
|
36
|
+
result = Matcher.create_function_hash("foo('bar').res=/reg/")
|
37
|
+
result["value"].should == "res"
|
38
|
+
result["params"].should == "bar"
|
39
|
+
result["r_compare"].should == /reg/
|
40
|
+
result["operator"].should == "=~"
|
41
|
+
result["name"].should == "foo"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should create a correct hash when the operator is >= or <=" do
|
45
|
+
result = Matcher.create_function_hash("foo('bar').res<=1")
|
46
|
+
result["value"].should == "res"
|
47
|
+
result["params"].should == "bar"
|
48
|
+
result["r_compare"].should == "1"
|
49
|
+
result["operator"].should == "<="
|
50
|
+
result["name"].should == "foo"
|
51
|
+
|
52
|
+
result = Matcher.create_function_hash("foo('bar').res>=1")
|
53
|
+
result["value"].should == "res"
|
54
|
+
result["params"].should == "bar"
|
55
|
+
result["r_compare"].should == "1"
|
56
|
+
result["operator"].should == ">="
|
57
|
+
result["name"].should == "foo"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should create a correct hash when no dot value is present" do
|
61
|
+
result = Matcher.create_function_hash("foo('bar')<=1")
|
62
|
+
result["value"].should == nil
|
63
|
+
result["params"].should == "bar"
|
64
|
+
result["r_compare"].should == "1"
|
65
|
+
result["operator"].should == "<="
|
66
|
+
result["name"].should == "foo"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should create a correct hash when a dot is present in a parameter but no dot value is present" do
|
70
|
+
result = Matcher.create_function_hash("foo('bar.one')<=1")
|
71
|
+
result["value"].should == nil
|
72
|
+
result["params"].should == "bar.one"
|
73
|
+
result["r_compare"].should == "1"
|
74
|
+
result["operator"].should == "<="
|
75
|
+
result["name"].should == "foo"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should create a correct hash when multiple dots are present in parameters but no dot value is present" do
|
79
|
+
result = Matcher.create_function_hash("foo('bar.one.two, bar.three.four')<=1")
|
80
|
+
result["value"].should == nil
|
81
|
+
result["params"].should == "bar.one.two, bar.three.four"
|
82
|
+
result["r_compare"].should == "1"
|
83
|
+
result["operator"].should == "<="
|
84
|
+
result["name"].should == "foo"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should create a correct hash when no parameters are given" do
|
88
|
+
result = Matcher.create_function_hash("foo()<=1")
|
89
|
+
result["value"].should == nil
|
90
|
+
result["params"].should == nil
|
91
|
+
result["r_compare"].should == "1"
|
92
|
+
result["operator"].should == "<="
|
93
|
+
result["name"].should == "foo"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should create a correct hash parameters are empty strings" do
|
97
|
+
result = Matcher.create_function_hash("foo('')=1")
|
98
|
+
result["value"].should == nil
|
99
|
+
result["params"].should == ""
|
100
|
+
result["r_compare"].should == "1"
|
101
|
+
result["operator"].should == "=="
|
102
|
+
result["name"].should == "foo"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#execute_function" do
|
107
|
+
it "should return the result of an evaluated function with a dot value" do
|
108
|
+
data = mock
|
109
|
+
data.expects(:send).with("value").returns("success")
|
110
|
+
MCollective::Data.expects(:send).with("foo", "bar").returns(data)
|
111
|
+
result = Matcher.execute_function({"name" => "foo", "params" => "bar", "value" => "value"})
|
112
|
+
result.should == "success"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should return the result of an evaluated function without a dot value" do
|
116
|
+
MCollective::Data.expects(:send).with("foo", "bar").returns("success")
|
117
|
+
result = Matcher.execute_function({"name" => "foo", "params" => "bar"})
|
118
|
+
result.should == "success"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "#eval_compound_statement" do
|
123
|
+
it "should return correctly on a regex class statement" do
|
124
|
+
Util.expects(:has_cf_class?).with("/foo/").returns(true)
|
125
|
+
Matcher.eval_compound_statement({"statement" => "/foo/"}).should == true
|
126
|
+
Util.expects(:has_cf_class?).with("/foo/").returns(false)
|
127
|
+
Matcher.eval_compound_statement({"statement" => "/foo/"}).should == false
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should return correcly for string and regex facts" do
|
131
|
+
Util.expects(:has_fact?).with("foo", "bar", "==").returns(true)
|
132
|
+
Matcher.eval_compound_statement({"statement" => "foo=bar"}).should == "true"
|
133
|
+
Util.expects(:has_fact?).with("foo", "/bar/", "=~").returns(false)
|
134
|
+
Matcher.eval_compound_statement({"statement" => "foo=/bar/"}).should == "false"
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should return correctly on a string class statement" do
|
138
|
+
Util.expects(:has_cf_class?).with("foo").returns(true)
|
139
|
+
Matcher.eval_compound_statement({"statement" => "foo"}).should == true
|
140
|
+
Util.expects(:has_cf_class?).with("foo").returns(false)
|
141
|
+
Matcher.eval_compound_statement({"statement" => "foo"}).should == false
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "#eval_compound_fstatement" do
|
146
|
+
describe "it should return false if a string, true or false are compared with > or <" do
|
147
|
+
let(:function_hash) do
|
148
|
+
{"name" => "foo",
|
149
|
+
"params" => "bar",
|
150
|
+
"value" => "value",
|
151
|
+
"operator" => "<",
|
152
|
+
"r_compare" => "teststring"}
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
it "should return false if a string is compare with a < or >" do
|
157
|
+
Matcher.expects(:execute_function).returns("teststring")
|
158
|
+
result = Matcher.eval_compound_fstatement(function_hash)
|
159
|
+
result.should == false
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should return false if a TrueClass is compared with a < or > " do
|
163
|
+
Matcher.expects(:execute_function).returns(true)
|
164
|
+
result = Matcher.eval_compound_fstatement(function_hash)
|
165
|
+
result.should == false
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should return false if a FalseClass is compared with a < or >" do
|
169
|
+
Matcher.expects(:execute_function).returns(false)
|
170
|
+
result = Matcher.eval_compound_fstatement(function_hash)
|
171
|
+
result.should == false
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "it should return false if backticks are present in parameters and if non strings are compared with regex's" do
|
176
|
+
before :each do
|
177
|
+
@function_hash = {"name" => "foo",
|
178
|
+
"params" => "bar",
|
179
|
+
"value" => "value",
|
180
|
+
"operator" => "=",
|
181
|
+
"r_compare" => "1"}
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should return false if a backtick is present in a parameter" do
|
185
|
+
@function_hash["params"] = "`bar`"
|
186
|
+
Matcher.expects(:execute_function).returns("teststring")
|
187
|
+
MCollective::Log.expects(:debug).with("Cannot use backticks in function parameters")
|
188
|
+
result = Matcher.eval_compound_fstatement(@function_hash)
|
189
|
+
result.should == false
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should return false if left compare object isn't a string and right compare is a regex" do
|
193
|
+
Matcher.expects(:execute_function).returns(1)
|
194
|
+
@function_hash["r_compare"] = "/foo/"
|
195
|
+
@function_hash["operator"] = "=~"
|
196
|
+
MCollective::Log.expects(:debug).with("Cannot do a regex check on a non string value.")
|
197
|
+
result = Matcher.eval_compound_fstatement(@function_hash)
|
198
|
+
result.should == false
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "it should return the expected result for valid function hashes" do
|
203
|
+
before :each do
|
204
|
+
@function_hash = {"name" => "foo",
|
205
|
+
"params" => "bar",
|
206
|
+
"value" => "value",
|
207
|
+
"operator" => "=",
|
208
|
+
"r_compare" => ""}
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should return true if right value is a regex and matches the left value" do
|
212
|
+
Matcher.expects(:execute_function).returns("teststring")
|
213
|
+
@function_hash["r_compare"] = /teststring/
|
214
|
+
@function_hash["operator"] = "=~"
|
215
|
+
result = Matcher.eval_compound_fstatement(@function_hash)
|
216
|
+
result.should == true
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should return false if right value is a regex, operator is != and regex equals left value" do
|
220
|
+
Matcher.expects(:execute_function).returns("teststring")
|
221
|
+
@function_hash["r_compare"] = /teststring/
|
222
|
+
@function_hash["operator"] = "!=~"
|
223
|
+
result = Matcher.eval_compound_fstatement(@function_hash)
|
224
|
+
result.should == false
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should return false if right value is a regex and does not match left value" do
|
228
|
+
Matcher.expects(:execute_function).returns("testsnotstring")
|
229
|
+
@function_hash["r_compare"] = /teststring/
|
230
|
+
@function_hash["operator"] = "=~"
|
231
|
+
result = Matcher.eval_compound_fstatement(@function_hash)
|
232
|
+
result.should == false
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should return true if left value logically compares to the right value" do
|
236
|
+
Matcher.expects(:execute_function).returns(1)
|
237
|
+
@function_hash["r_compare"] = 1
|
238
|
+
@function_hash["operator"] = ">="
|
239
|
+
result = Matcher.eval_compound_fstatement(@function_hash)
|
240
|
+
result.should == true
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should return false if left value does not logically compare to right value" do
|
244
|
+
Matcher.expects(:execute_function).returns("1")
|
245
|
+
@function_hash["r_compare"] = "1"
|
246
|
+
@function_hash["operator"] = ">"
|
247
|
+
result = Matcher.eval_compound_fstatement(@function_hash)
|
248
|
+
result.should == false
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
describe "#create_compound_callstack" do
|
254
|
+
it "should create a callstack from a valid call_string" do
|
255
|
+
result = Matcher.create_compound_callstack("foo('bar')=1 and bar=/bar/")
|
256
|
+
result.should == [{"fstatement" => {"params"=>"bar", "name"=>"foo", "operator"=>"==", "r_compare"=>"1"}}, {"and" => "and"}, {"statement" => "bar=/bar/"}]
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
data/spec/unit/message_spec.rb
CHANGED
@@ -67,7 +67,7 @@ module MCollective
|
|
67
67
|
|
68
68
|
describe "#reply_to=" do
|
69
69
|
it "should only set the reply-to header for requests" do
|
70
|
-
Config.instance.
|
70
|
+
Config.instance.expects(:direct_addressing).returns(true)
|
71
71
|
m = Message.new("payload", "message", :type => :reply)
|
72
72
|
m.discovered_hosts = ["foo"]
|
73
73
|
expect { m.reply_to = "foo" }.to raise_error(/reply targets/)
|
@@ -146,7 +146,7 @@ module MCollective
|
|
146
146
|
describe "#type=" do
|
147
147
|
it "should only allow types to be set when discovered hosts were given" do
|
148
148
|
m = Message.new("payload", "message")
|
149
|
-
Config.instance.
|
149
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
150
150
|
|
151
151
|
expect {
|
152
152
|
m.type = :direct_request
|
@@ -155,7 +155,7 @@ module MCollective
|
|
155
155
|
|
156
156
|
it "should not allow direct_request to be set if direct addressing isnt enabled" do
|
157
157
|
m = Message.new("payload", "message")
|
158
|
-
Config.instance.
|
158
|
+
Config.instance.stubs(:direct_addressing).returns(false)
|
159
159
|
|
160
160
|
expect {
|
161
161
|
m.type = :direct_request
|
@@ -164,13 +164,24 @@ module MCollective
|
|
164
164
|
|
165
165
|
it "should only accept valid types" do
|
166
166
|
m = Message.new("payload", "message")
|
167
|
-
Config.instance.
|
167
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
168
168
|
|
169
169
|
expect {
|
170
170
|
m.type = :foo
|
171
171
|
}.to raise_error("Unknown message type foo")
|
172
172
|
end
|
173
173
|
|
174
|
+
it "should clear the filter in direct_request mode and add just an agent filter" do
|
175
|
+
m = Message.new("payload", "message")
|
176
|
+
m.discovered_hosts = ["rspec"]
|
177
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
178
|
+
|
179
|
+
m.filter = Util.empty_filter.merge({"cf_class" => ["test"]})
|
180
|
+
m.agent = "rspec"
|
181
|
+
m.type = :direct_request
|
182
|
+
m.filter.should == Util.empty_filter.merge({"agent" => ["rspec"]})
|
183
|
+
end
|
184
|
+
|
174
185
|
it "should set the type" do
|
175
186
|
m = Message.new("payload", "message")
|
176
187
|
m.type = :request
|
@@ -201,7 +212,7 @@ module MCollective
|
|
201
212
|
security.expects(:encoderequest).with("identity", 'payload', '123', Util.empty_filter, 'rspec_agent', 'mcollective', 60).twice
|
202
213
|
PluginManager.expects("[]").with("security_plugin").returns(security).twice
|
203
214
|
|
204
|
-
Config.
|
215
|
+
Config.instance.expects(:identity).returns("identity").twice
|
205
216
|
|
206
217
|
Message.any_instance.expects(:requestid).returns("123").twice
|
207
218
|
|
@@ -212,6 +223,20 @@ module MCollective
|
|
212
223
|
m.encode!
|
213
224
|
end
|
214
225
|
|
226
|
+
it "should retain the requestid if it was specifically set" do
|
227
|
+
security = mock
|
228
|
+
security.expects(:encoderequest).with("identity", 'payload', '123', Util.empty_filter, 'rspec_agent', 'mcollective', 60)
|
229
|
+
PluginManager.expects("[]").with("security_plugin").returns(security)
|
230
|
+
|
231
|
+
Config.instance.expects(:identity).returns("identity")
|
232
|
+
|
233
|
+
m = Message.new("payload", "message", :type => :request, :agent => "rspec_agent", :collective => "mcollective")
|
234
|
+
m.expects(:create_reqid).never
|
235
|
+
m.requestid = "123"
|
236
|
+
m.encode!
|
237
|
+
m.requestid.should == "123"
|
238
|
+
end
|
239
|
+
|
215
240
|
it "should not allow bad callerids when replying" do
|
216
241
|
request = mock
|
217
242
|
request.stubs(:agent).returns("rspec_agent")
|
@@ -358,8 +383,8 @@ module MCollective
|
|
358
383
|
m = Message.new("msg", "message", :type => :request)
|
359
384
|
m.discovered_hosts = ["one", "two", "three"]
|
360
385
|
|
361
|
-
Config.
|
362
|
-
Config.
|
386
|
+
Config.instance.stubs(:direct_addressing).returns(true)
|
387
|
+
Config.instance.stubs(:direct_addressing_threshold).returns(10)
|
363
388
|
|
364
389
|
connector = mock
|
365
390
|
connector.expects(:publish).with(m)
|
@@ -373,8 +398,8 @@ module MCollective
|
|
373
398
|
m = Message.new("msg", "message", :type => :request)
|
374
399
|
m.discovered_hosts = ["one", "two", "three"]
|
375
400
|
|
376
|
-
Config.
|
377
|
-
Config.
|
401
|
+
Config.instance.expects(:direct_addressing).returns(true)
|
402
|
+
Config.instance.expects(:direct_addressing_threshold).returns(1)
|
378
403
|
|
379
404
|
connector = mock
|
380
405
|
connector.expects(:publish).with(m)
|
@@ -389,10 +414,7 @@ module MCollective
|
|
389
414
|
it "should create a valid request id" do
|
390
415
|
m = Message.new("msg", "message", :agent => "rspec", :collective => "mc")
|
391
416
|
|
392
|
-
|
393
|
-
Time.expects(:now).returns(1.1)
|
394
|
-
|
395
|
-
Digest::MD5.expects(:hexdigest).with("rspec-1.1-rspec-mc").returns("reqid")
|
417
|
+
SSL.expects(:uuid).returns("reqid")
|
396
418
|
|
397
419
|
m.create_reqid.should == "reqid"
|
398
420
|
end
|
@@ -97,7 +97,7 @@ module MCollective
|
|
97
97
|
parser = Optionparser.new(defaults={:collective => "rspec"})
|
98
98
|
parser.stubs(:add_required_options)
|
99
99
|
parser.stubs(:add_common_options)
|
100
|
-
Config.
|
100
|
+
Config.instance.expects(:main_collective).never
|
101
101
|
parser.parse
|
102
102
|
end
|
103
103
|
|
@@ -105,7 +105,7 @@ module MCollective
|
|
105
105
|
parser = Optionparser.new(defaults={})
|
106
106
|
parser.stubs(:add_required_options)
|
107
107
|
parser.stubs(:add_common_options)
|
108
|
-
Config.
|
108
|
+
Config.instance.expects(:main_collective).returns(:rspec).once
|
109
109
|
parser.parse[:collective].should == :rspec
|
110
110
|
end
|
111
111
|
end
|
@@ -6,25 +6,27 @@ module MCollective
|
|
6
6
|
module PluginPackager
|
7
7
|
describe AgentDefinition do
|
8
8
|
before :each do
|
9
|
-
PluginPackager.expects(:get_metadata).once.returns({:name => "foo"})
|
9
|
+
PluginPackager.expects(:get_metadata).once.returns({:name => "foo", :version => 1})
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "#initialize" do
|
13
13
|
it "should replace spaces in the package name with dashes" do
|
14
|
+
AgentDefinition.any_instance.expects(:common)
|
14
15
|
agent = AgentDefinition.new(".", "test package", nil, nil, nil, nil, [], {}, "agent")
|
15
16
|
agent.metadata[:name].should == "test-package"
|
16
17
|
end
|
17
18
|
|
18
19
|
it "should set dependencies if present" do
|
19
|
-
|
20
|
-
agent.
|
20
|
+
AgentDefinition.any_instance.expects(:common)
|
21
|
+
agent = AgentDefinition.new(".", "test-package", nil, nil, nil, nil, [:name => "foo", :version => nil], {}, "agent")
|
22
|
+
agent.dependencies.should == [{:name => "foo", :version => nil}, {:name => "mcollective-common", :version => nil}]
|
21
23
|
end
|
22
24
|
|
23
|
-
it "should set mc
|
24
|
-
|
25
|
-
agent.
|
26
|
-
agent.
|
27
|
-
agent.
|
25
|
+
it "should set mc name and version" do
|
26
|
+
AgentDefinition.any_instance.expects(:common)
|
27
|
+
agent = AgentDefinition.new(".", "test-package", nil, nil, nil, nil, [], {:mcname =>"pe-mcollective-common", :mcversion =>"1.2"}, "agent")
|
28
|
+
agent.mcname.should == "pe-mcollective-common"
|
29
|
+
agent.mcversion.should == "1.2"
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
@@ -53,45 +55,64 @@ module MCollective
|
|
53
55
|
agent.packagedata[:agent].should == nil
|
54
56
|
end
|
55
57
|
|
56
|
-
it "should
|
58
|
+
it "should add the agent file if the agent directory and implementation file is present" do
|
57
59
|
AgentDefinition.any_instance.expects(:common).returns(nil)
|
58
|
-
PluginPackager.
|
59
|
-
File.stubs(:join).returns("tmpdir")
|
60
|
-
|
60
|
+
PluginPackager.stubs(:check_dir_present).returns(true)
|
61
|
+
File.stubs(:join).with(".", "agent").returns("tmpdir/agent")
|
62
|
+
File.stubs(:join).with("tmpdir/agent", "*.ddl").returns("tmpdir/agent/*.ddl")
|
63
|
+
File.stubs(:join).with("tmpdir/agent", "*").returns("tmpdir/agent/*")
|
64
|
+
Dir.stubs(:glob).with("tmpdir/agent/*.ddl").returns([])
|
65
|
+
Dir.stubs(:glob).with("tmpdir/agent/*").returns(["implementation.rb"])
|
61
66
|
|
62
67
|
agent = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
|
63
|
-
agent.packagedata[:agent][:files].should == ["
|
68
|
+
agent.packagedata[:agent][:files].should == ["implementation.rb"]
|
64
69
|
end
|
65
70
|
|
66
71
|
it "should add common package as dependency if present" do
|
67
72
|
AgentDefinition.any_instance.expects(:common).returns({:files=> ["test.rb"]})
|
68
|
-
PluginPackager.expects(:check_dir_present).returns(true)
|
69
|
-
File.stubs(:join).returns("
|
73
|
+
PluginPackager.expects(:check_dir_present).with("tmpdir/agent").returns(true)
|
74
|
+
File.stubs(:join).returns("/tmp")
|
75
|
+
File.stubs(:join).with(".", "agent").returns("tmpdir/agent")
|
76
|
+
File.stubs(:join).with(".", "aggregate").returns("tmpdir/aggregate")
|
70
77
|
Dir.stubs(:glob).returns([])
|
71
78
|
|
72
79
|
agent = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
|
73
|
-
agent.packagedata[:agent][:dependencies].should == [
|
80
|
+
agent.packagedata[:agent][:dependencies].should == [{:name => "mcollective-common", :version => nil},
|
81
|
+
{:name => "mcollective-foo-common", :version =>1}]
|
74
82
|
end
|
75
83
|
end
|
76
84
|
|
77
85
|
describe "#common" do
|
78
|
-
|
86
|
+
it "should populate the common files if there are any" do
|
79
87
|
AgentDefinition.any_instance.expects(:agent)
|
80
88
|
AgentDefinition.any_instance.expects(:client)
|
81
|
-
|
89
|
+
File.expects(:join).with(".", "data", "**").returns("datadir")
|
90
|
+
File.expects(:join).with(".", "util", "**", "**").returns("utildir")
|
91
|
+
File.expects(:join).with(".", "agent", "*.ddl").returns("ddldir")
|
92
|
+
File.expects(:join).with(".", "validator", "**").returns("validatordir")
|
93
|
+
Dir.expects(:glob).with("datadir").returns(["data.rb"])
|
94
|
+
Dir.expects(:glob).with("utildir").returns(["util.rb"])
|
95
|
+
Dir.expects(:glob).with("validatordir").returns(["validator.rb"])
|
96
|
+
Dir.expects(:glob).with("ddldir").returns(["agent.ddl"])
|
82
97
|
|
83
|
-
it "should not populate the commong files if the util directory is empty" do
|
84
|
-
PluginPackager.expects(:check_dir_present).returns(false)
|
85
98
|
common = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
|
86
|
-
common.packagedata[:common].should ==
|
99
|
+
common.packagedata[:common][:files].should == ["data.rb", "util.rb", "validator.rb", "agent.ddl"]
|
87
100
|
end
|
88
101
|
|
89
|
-
it "should
|
90
|
-
|
91
|
-
File.
|
92
|
-
|
93
|
-
|
94
|
-
|
102
|
+
it "should raise an exception if the ddl file isn't present" do
|
103
|
+
File.expects(:join).with(".", "data", "**").returns("datadir")
|
104
|
+
File.expects(:join).with(".", "util", "**", "**").returns("utildir")
|
105
|
+
File.expects(:join).with(".", "agent", "*.ddl").returns("ddldir")
|
106
|
+
File.expects(:join).with(".", "agent").returns("ddldir")
|
107
|
+
File.expects(:join).with(".", "validator", "**").returns("validatordir")
|
108
|
+
Dir.expects(:glob).with("datadir").returns(["data.rb"])
|
109
|
+
Dir.expects(:glob).with("utildir").returns(["util.rb"])
|
110
|
+
Dir.expects(:glob).with("validatordir").returns(["validator.rb"])
|
111
|
+
Dir.expects(:glob).with("ddldir").returns([])
|
112
|
+
|
113
|
+
expect{
|
114
|
+
common = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
|
115
|
+
}.to raise_error(RuntimeError, "cannot create package - No ddl file found in ddldir")
|
95
116
|
end
|
96
117
|
end
|
97
118
|
|
@@ -99,27 +120,24 @@ module MCollective
|
|
99
120
|
before do
|
100
121
|
AgentDefinition.any_instance.expects(:agent).returns(nil)
|
101
122
|
File.expects(:join).with(".", "application").returns("clientdir")
|
102
|
-
File.expects(:join).with(".", "
|
103
|
-
File.expects(:join).with(".", "agent").returns("agentdir")
|
123
|
+
File.expects(:join).with(".", "aggregate").returns("aggregatedir")
|
104
124
|
end
|
105
125
|
|
106
126
|
it "should populate client files if all directories are present" do
|
107
127
|
AgentDefinition.any_instance.expects(:common).returns(nil)
|
108
|
-
PluginPackager.expects(:check_dir_present).times(
|
128
|
+
PluginPackager.expects(:check_dir_present).times(2).returns(true)
|
109
129
|
File.expects(:join).with("clientdir", "*").returns("clientdir/*")
|
110
|
-
File.expects(:join).with("
|
111
|
-
File.expects(:join).with("agentdir", "*.ddl").returns("agentdir/*.ddl")
|
130
|
+
File.expects(:join).with("aggregatedir", "*").returns("aggregatedir/*")
|
112
131
|
Dir.expects(:glob).with("clientdir/*").returns(["client.rb"])
|
113
|
-
Dir.expects(:glob).with("
|
114
|
-
Dir.expects(:glob).with("agentdir/*.ddl").returns(["agent.ddl"])
|
132
|
+
Dir.expects(:glob).with("aggregatedir/*").returns(["aggregate.rb"])
|
115
133
|
|
116
134
|
client = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
|
117
|
-
client.packagedata[:client][:files].should == ["client.rb",
|
135
|
+
client.packagedata[:client][:files].should == ["client.rb", "aggregate.rb"]
|
118
136
|
end
|
119
137
|
|
120
138
|
it "should not populate client files if directories are not present" do
|
121
139
|
AgentDefinition.any_instance.expects(:common).returns(nil)
|
122
|
-
PluginPackager.expects(:check_dir_present).times(
|
140
|
+
PluginPackager.expects(:check_dir_present).times(2).returns(false)
|
123
141
|
|
124
142
|
client = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
|
125
143
|
client.packagedata[:client].should == nil
|
@@ -127,16 +145,15 @@ module MCollective
|
|
127
145
|
|
128
146
|
it "should add common package as dependency if present" do
|
129
147
|
AgentDefinition.any_instance.expects(:common).returns("common")
|
130
|
-
PluginPackager.expects(:check_dir_present).times(
|
148
|
+
PluginPackager.expects(:check_dir_present).times(2).returns(true)
|
131
149
|
File.expects(:join).with("clientdir", "*").returns("clientdir/*")
|
132
|
-
File.expects(:join).with("
|
133
|
-
File.expects(:join).with("agentdir", "*.ddl").returns("agentdir/*.ddl")
|
150
|
+
File.expects(:join).with("aggregatedir", "*").returns("aggregatedir/*")
|
134
151
|
Dir.expects(:glob).with("clientdir/*").returns(["client.rb"])
|
135
|
-
Dir.expects(:glob).with("
|
136
|
-
Dir.expects(:glob).with("agentdir/*.ddl").returns(["agent.ddl"])
|
152
|
+
Dir.expects(:glob).with("aggregatedir/*").returns(["aggregate.rb"])
|
137
153
|
|
138
154
|
client = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
|
139
|
-
client.packagedata[:client][:dependencies].should == ["mcollective-
|
155
|
+
client.packagedata[:client][:dependencies].should == [{:name => "mcollective-common", :version => nil},
|
156
|
+
{:name => "mcollective-foo-common", :version => 1}]
|
140
157
|
end
|
141
158
|
end
|
142
159
|
end
|