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
@@ -16,10 +16,12 @@ module MCollective
|
|
16
16
|
end
|
17
17
|
|
18
18
|
before :each do
|
19
|
+
PluginPackager.stubs(:build_tool?).with("rpmbuild-md5").returns(true)
|
19
20
|
PluginPackager.stubs(:build_tool?).with("rpmbuild").returns(true)
|
20
21
|
@plugin = mock()
|
21
22
|
@plugin.stubs(:iteration).returns("1")
|
22
23
|
@plugin.stubs(:metadata).returns({:name => "test", :version => "1"})
|
24
|
+
@plugin.stubs(:mcname).returns("mcollective")
|
23
25
|
end
|
24
26
|
|
25
27
|
after :all do
|
@@ -28,11 +30,12 @@ module MCollective
|
|
28
30
|
|
29
31
|
describe "#initialize" do
|
30
32
|
|
31
|
-
it "should raise and exception if
|
33
|
+
it "should raise and exception if neither rpmbuild or rpmbuild-md5 is installed is not present" do
|
34
|
+
PluginPackager.expects(:build_tool?).with("rpmbuild-md5").returns(false)
|
32
35
|
PluginPackager.expects(:build_tool?).with("rpmbuild").returns(false)
|
33
36
|
expect{
|
34
37
|
RpmpackagePackager.new("plugin")
|
35
|
-
}.to raise_exception
|
38
|
+
}.to raise_exception(RuntimeError, "creating rpms require 'rpmbuild' or 'rpmbuild-md5' to be installed")
|
36
39
|
end
|
37
40
|
|
38
41
|
it "should set the correct libdir" do
|
@@ -81,57 +84,62 @@ module MCollective
|
|
81
84
|
end
|
82
85
|
|
83
86
|
it "should create the package" do
|
84
|
-
|
85
|
-
|
87
|
+
Dir.expects(:chdir)
|
88
|
+
PluginPackager.expects(:safe_system).with("rpmbuild -ta /tmp/mcollective-testplugin-test-1.tgz")
|
89
|
+
FileUtils.expects(:cp).times(2)
|
86
90
|
@packager.tmpdir = "/tmp"
|
87
91
|
@packager.verbose = "true"
|
88
92
|
@packager.expects(:make_spec_file)
|
89
93
|
@packager.current_package_name = "mcollective-testplugin-test"
|
90
|
-
@packager.expects(:puts).with(
|
94
|
+
@packager.expects(:puts).with('Created RPM and SRPM packages for mcollective-testplugin-test')
|
91
95
|
@packager.create_package(:test, {:files => ["foo.rb"]})
|
92
96
|
end
|
93
97
|
|
94
98
|
it "should sign the package if a signature is given" do
|
95
|
-
|
96
|
-
|
99
|
+
Dir.expects(:chdir)
|
100
|
+
PluginPackager.expects(:safe_system).with("rpmbuild -ta --sign /tmp/mcollective-testplugin-test-1.tgz")
|
101
|
+
FileUtils.expects(:cp).times(2)
|
97
102
|
@packager.signature = true
|
98
103
|
@packager.tmpdir = "/tmp"
|
99
104
|
@packager.verbose = "true"
|
100
105
|
@packager.expects(:make_spec_file)
|
101
106
|
@packager.current_package_name = "mcollective-testplugin-test"
|
102
|
-
@packager.expects(:puts).with(
|
107
|
+
@packager.expects(:puts).with('Created RPM and SRPM packages for mcollective-testplugin-test')
|
103
108
|
@packager.create_package(:test, {:files => ["foo.rb"]})
|
104
109
|
end
|
105
110
|
|
106
111
|
it "should raise an error if the package can't be built" do
|
107
112
|
@packager = RpmpackagePackager.new(@plugin)
|
113
|
+
@packager.tmpdir = "/tmp"
|
108
114
|
@packager.expects(:make_spec_file)
|
109
115
|
PluginPackager.stubs(:do_quietly?).raises("foo")
|
110
116
|
expect{
|
111
117
|
@packager.create_package("", "")
|
112
|
-
}.to raise_error
|
118
|
+
}.to raise_error(RuntimeError, "Could not build package. Reason - foo")
|
113
119
|
end
|
114
120
|
end
|
115
121
|
|
116
122
|
describe "#make_spec_file" do
|
117
123
|
before :each do
|
118
|
-
@
|
124
|
+
@plugin = mock
|
125
|
+
@packager = RpmpackagePackager.new(@plugin)
|
119
126
|
end
|
120
127
|
|
121
128
|
it "should raise an exception if specfile cannot be built" do
|
122
129
|
File.expects(:dirname).raises("test error")
|
123
130
|
expect{
|
124
131
|
@packager.make_spec_file
|
125
|
-
}.to raise_error
|
132
|
+
}.to raise_error(RuntimeError, "Could not create specfile - test error")
|
126
133
|
end
|
127
134
|
|
128
135
|
it "should create the specfile from the erb" do
|
129
136
|
File.stubs(:read).returns("specfile")
|
130
|
-
@
|
137
|
+
@plugin.stubs(:metadata).returns({:version => 2})
|
138
|
+
@packager.current_package_name = "test"
|
131
139
|
@packager.tmpdir = maketmpdir
|
132
|
-
Dir.mkdir(File.join(@packager.tmpdir, "
|
140
|
+
Dir.mkdir(File.join(@packager.tmpdir, "test-2"))
|
133
141
|
@packager.make_spec_file
|
134
|
-
File.read(File.join(@packager.tmpdir, "
|
142
|
+
File.read(File.join(@packager.tmpdir, "test-2", "test-2.spec")).should == "specfile"
|
135
143
|
end
|
136
144
|
end
|
137
145
|
|
@@ -139,7 +147,6 @@ module MCollective
|
|
139
147
|
it "should create the tmp dirs and cp the package files" do
|
140
148
|
@plugin.stubs(:target_path).returns("")
|
141
149
|
packager = RpmpackagePackager.new(@plugin)
|
142
|
-
packager.expects(:make_rpm_dirs)
|
143
150
|
FileUtils.expects(:mkdir_p)
|
144
151
|
File.stubs(:join).returns("/target")
|
145
152
|
FileUtils.expects(:cp_r).with("test.rb", "/target")
|
@@ -147,29 +154,6 @@ module MCollective
|
|
147
154
|
end
|
148
155
|
end
|
149
156
|
|
150
|
-
describe "#make_rpm_dirs" do
|
151
|
-
before :each do
|
152
|
-
@packager = RpmpackagePackager.new("package")
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should raise an exception if a directory can't be created" do
|
156
|
-
File.expects(:join).raises("test error")
|
157
|
-
expect{
|
158
|
-
@packager.make_rpm_dirs
|
159
|
-
}.to raise_error RuntimeError, "Could not create BUILD directory - test error"
|
160
|
-
end
|
161
|
-
|
162
|
-
it "should create the correct RPM build directories" do
|
163
|
-
@packager.tmpdir = maketmpdir
|
164
|
-
@packager.make_rpm_dirs
|
165
|
-
File.directory?(File.join(@packager.tmpdir, "SPECS")).should == true
|
166
|
-
File.directory?(File.join(@packager.tmpdir, "SOURCES")).should == true
|
167
|
-
File.directory?(File.join(@packager.tmpdir, "SRPMS")).should == true
|
168
|
-
File.directory?(File.join(@packager.tmpdir, "BUILD")).should == true
|
169
|
-
File.directory?(File.join(@packager.tmpdir, "RPMS")).should == true
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
157
|
describe "#cleanup_tmpdirs" do
|
174
158
|
it "should remove the temp directories" do
|
175
159
|
packager = RpmpackagePackager.new("package")
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/validator/array_validator.rb'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
module Validator
|
7
|
+
describe "#validate" do
|
8
|
+
it "should raise an exception if a given element is not defined in a given array" do
|
9
|
+
expect{
|
10
|
+
Validator::ArrayValidator.validate("element1",["element0", "element2"])
|
11
|
+
}.to raise_error(ValidatorError, "value should be one of element0, element2")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not raise an exception if a given element is defined in a given array" do
|
15
|
+
Validator::ArrayValidator.validate("element1", ["element1", "element2"])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/validator/ipv4address_validator.rb'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
module Validator
|
7
|
+
describe "#validate" do
|
8
|
+
it "should raise an exception if the supplied value is not an ipv4 address" do
|
9
|
+
expect{
|
10
|
+
Ipv4addressValidator.validate("foobar")
|
11
|
+
}.to raise_error(ValidatorError, "value should be an ipv4 address")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not raise an exception if the supplied value is an ipv4 address" do
|
15
|
+
Ipv4addressValidator.validate("1.2.3.4")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/validator/ipv6address_validator.rb'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
module Validator
|
7
|
+
describe "#validate" do
|
8
|
+
it "should raise an exception if the supplied value is not an ipv6 address" do
|
9
|
+
expect{
|
10
|
+
Ipv6addressValidator.validate("foobar")
|
11
|
+
}.to raise_error(ValidatorError, "value should be an ipv6 address")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not raise an exception if the supplied value is an ipv6 address" do
|
15
|
+
Ipv6addressValidator.validate("2001:db8:85a3:8d3:1319:8a2e:370:7348")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/validator/length_validator.rb'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
module Validator
|
7
|
+
describe "#validate" do
|
8
|
+
it "should raise an exception if the given string's length is greater than the given value" do
|
9
|
+
expect{
|
10
|
+
LengthValidator.validate("test", 3)
|
11
|
+
}.to raise_error(ValidatorError, "Input string is longer than 3 character(s)")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not raise an exception if the given string's length is less than the given value" do
|
15
|
+
LengthValidator.validate("test", 4)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/validator/regex_validator.rb'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
module Validator
|
7
|
+
describe "#validate" do
|
8
|
+
it "should raise an exception if the given string does not matches the given regular expression" do
|
9
|
+
expect{
|
10
|
+
RegexValidator.validate("test", "nottest")
|
11
|
+
}.to raise_error(ValidatorError, "value should match nottest")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not raise an exception if the given string's length is less than the given value" do
|
15
|
+
RegexValidator.validate("test", "test")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/validator/shellsafe_validator.rb'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
module Validator
|
7
|
+
describe "#validate" do
|
8
|
+
it "should raise an exception if the given string is not shellsafe" do
|
9
|
+
['`', '$', ';', '|', '&&', '>', '<'].each do |chr|
|
10
|
+
expect{
|
11
|
+
ShellsafeValidator.validate("#{chr}test")
|
12
|
+
}.to raise_error(ValidatorError, "value should not have #{chr} in it")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not raise an exception if the given string is shellsafe" do
|
17
|
+
ShellsafeValidator.validate("test")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/validator/typecheck_validator.rb'
|
4
|
+
|
5
|
+
module MCollective
|
6
|
+
module Validator
|
7
|
+
describe "#validate" do
|
8
|
+
it "should raise an exception if the given value is not of the supplied type" do
|
9
|
+
[[1, String], ['test', :integer], ['test', :float], ['test', :number], [1, :string], ['test', :boolean]].each do |val|
|
10
|
+
expect{
|
11
|
+
TypecheckValidator.validate(*val)
|
12
|
+
}.to raise_error(ValidatorError, "value should be a #{val[1].to_s}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not raise an exception if the given value is of the supplied type" do
|
17
|
+
[["test", String], [1, :integer], [1.2, :float], [1, :number], ["test", :string], [true, :boolean]].each do |val|
|
18
|
+
TypecheckValidator.validate(*val)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -185,7 +185,7 @@ module MCollective
|
|
185
185
|
end
|
186
186
|
|
187
187
|
it "should find the first match in the libdir" do
|
188
|
-
Config.
|
188
|
+
Config.instance.expects(:libdir).returns(["#{File::SEPARATOR}libdir1", "#{File::SEPARATOR}libdir2"])
|
189
189
|
|
190
190
|
action_in_first_dir = File.join(File::SEPARATOR, "libdir1", "agent", "spectester", "action.sh")
|
191
191
|
action_in_last_dir = File.join(File::SEPARATOR, "libdir2", "agent", "spectester", "action.sh")
|
@@ -197,7 +197,7 @@ module MCollective
|
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should find the match even in the last libdir" do
|
200
|
-
Config.
|
200
|
+
Config.instance.expects(:libdir).returns(["#{File::SEPARATOR}libdir1", "#{File::SEPARATOR}libdir2"])
|
201
201
|
|
202
202
|
action_in_first_dir = File.join(File::SEPARATOR, "libdir1", "agent", "spectester", "action.sh")
|
203
203
|
action_in_last_dir = File.join(File::SEPARATOR, "libdir2", "agent", "spectester", "action.sh")
|
data/spec/unit/rpc/agent_spec.rb
CHANGED
@@ -6,11 +6,48 @@ module MCollective
|
|
6
6
|
module RPC
|
7
7
|
describe Agent do
|
8
8
|
before do
|
9
|
+
ddl = stub
|
10
|
+
ddl.stubs(:meta).returns({})
|
11
|
+
DDL.stubs(:new).returns(ddl)
|
12
|
+
|
9
13
|
@agent = Agent.new
|
10
14
|
@agent.reply = {}
|
11
15
|
@agent.request = {}
|
12
16
|
end
|
13
17
|
|
18
|
+
describe "#meta" do
|
19
|
+
it "should be deprecated" do
|
20
|
+
Log.expects(:warn).with(regexp_matches(/setting meta data in agents have been deprecated/))
|
21
|
+
Agent.metadata("foo")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#load_ddl" do
|
26
|
+
it "should load the correct DDL" do
|
27
|
+
ddl = stub
|
28
|
+
ddl.stubs(:meta).returns({:timeout => 5})
|
29
|
+
|
30
|
+
DDL.expects(:new).with("agent", :agent).returns(ddl)
|
31
|
+
|
32
|
+
Agent.new.timeout.should == 5
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should fail if the DDL isn't loaded" do
|
36
|
+
DDL.expects(:new).raises("failed to load")
|
37
|
+
Log.expects(:error).once
|
38
|
+
expect { Agent.new }.to raise_error(DDLValidationError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should default to 10 second timeout" do
|
42
|
+
ddl = stub
|
43
|
+
ddl.stubs(:meta).returns({})
|
44
|
+
|
45
|
+
DDL.expects(:new).with("agent", :agent).returns(ddl)
|
46
|
+
|
47
|
+
Agent.new.timeout.should == 10
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
14
51
|
describe "#run" do
|
15
52
|
before do
|
16
53
|
@status = mock
|
@@ -83,71 +120,10 @@ module MCollective
|
|
83
120
|
expect { @agent.send(:validate, :foo, String) }.to raise_error(MissingRPCData, "please supply a foo argument")
|
84
121
|
end
|
85
122
|
|
86
|
-
it "should
|
87
|
-
@agent.request = {:
|
88
|
-
|
89
|
-
expect { @agent.send(:validate, :
|
90
|
-
@agent.send(:validate, :foo, /is a test, \d\d\d$/)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should support type checking" do
|
94
|
-
@agent.request = {:str => "foo"}
|
95
|
-
|
96
|
-
expect { @agent.send(:validate, :str, Numeric) }.to raise_error(InvalidRPCData, /str should be a Numeric/)
|
97
|
-
@agent.send(:validate, :str, String)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should correctly validate ipv4 addresses" do
|
101
|
-
@agent.request = {:goodip4 => "1.1.1.1",
|
102
|
-
:badip4 => "300.300.300.300"}
|
103
|
-
|
104
|
-
expect { @agent.send(:validate, :badip4, :ipv4address) }.to raise_error(InvalidRPCData, /badip4 should be an ipv4 address/)
|
105
|
-
@agent.send(:validate, :goodip4, :ipv4address)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should correctly validate ipv6 addresses" do
|
109
|
-
@agent.request = {:goodip6 => "2a00:1450:8006::93",
|
110
|
-
:badip6 => "300.300.300.300"}
|
111
|
-
|
112
|
-
expect { @agent.send(:validate, :badip6, :ipv6address) }.to raise_error(InvalidRPCData, /badip6 should be an ipv6 address/)
|
113
|
-
@agent.send(:validate, :goodip6, :ipv6address)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should correctly validate boolean data" do
|
117
|
-
@agent.request = {:true => true, :false => false, :string => "foo", :number => 1}
|
118
|
-
|
119
|
-
@agent.send(:validate, :true, :boolean)
|
120
|
-
@agent.send(:validate, :false, :boolean)
|
121
|
-
expect { @agent.send(:validate, :string, :boolean) }.to raise_error(InvalidRPCData)
|
122
|
-
expect { @agent.send(:validate, :number, :boolean) }.to raise_error(InvalidRPCData)
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should correctly validate list data" do
|
126
|
-
@agent.request = {:str => "foo"}
|
127
|
-
expect { @agent.send(:validate, :str, ["bar", "baz"]) }.to raise_error(InvalidRPCData, /str should be one of bar, baz/)
|
128
|
-
|
129
|
-
@agent.request = {:str => "foo"}
|
130
|
-
expect { @agent.send(:validate, :str, ["bar", "baz", "foo"]) }
|
131
|
-
@agent.send(:validate, :str, ["bar", "baz", "foo"])
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should correctly identify characters that are not shell safe" do
|
135
|
-
@agent.request = {:backtick => 'foo`bar',
|
136
|
-
:semicolon => 'foo;bar',
|
137
|
-
:dollar => 'foo$(bar)',
|
138
|
-
:pipe => 'foo|bar',
|
139
|
-
:redirto => 'foo>bar',
|
140
|
-
:inputfrom => 'foo<bar',
|
141
|
-
:good => 'foo bar baz'}
|
142
|
-
|
143
|
-
expect { @agent.send(:validate, :backtick, :shellsafe) }.to raise_error(InvalidRPCData, /backtick should not have ` in it/)
|
144
|
-
expect { @agent.send(:validate, :semicolon, :shellsafe) }.to raise_error(InvalidRPCData, /semicolon should not have ; in it/)
|
145
|
-
expect { @agent.send(:validate, :dollar, :shellsafe) }.to raise_error(InvalidRPCData, /dollar should not have \$ in it/)
|
146
|
-
expect { @agent.send(:validate, :pipe, :shellsafe) }.to raise_error(InvalidRPCData, /pipe should not have \| in it/)
|
147
|
-
expect { @agent.send(:validate, :redirto, :shellsafe) }.to raise_error(InvalidRPCData, /redirto should not have > in it/)
|
148
|
-
expect { @agent.send(:validate, :inputfrom, :shellsafe) }.to raise_error(InvalidRPCData, /inputfrom should not have \< in it/)
|
149
|
-
|
150
|
-
@agent.send(:validate, :good, :shellsafe)
|
123
|
+
it "should catch validation errors and turn them into use case specific ones" do
|
124
|
+
@agent.request = {:input_key => "should be a number"}
|
125
|
+
Validator.expects(:validate).raises(ValidatorError, "input_key should be a number")
|
126
|
+
expect { @agent.send(:validate, :input_key, :number) }.to raise_error("Input input_key did not pass validation: input_key should be a number")
|
151
127
|
end
|
152
128
|
end
|
153
129
|
end
|