mcollective-client 1.3.3

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.

Files changed (103) hide show
  1. data/bin/mc-call-agent +54 -0
  2. data/bin/mco +27 -0
  3. data/lib/mcollective.rb +70 -0
  4. data/lib/mcollective/agents.rb +160 -0
  5. data/lib/mcollective/application.rb +354 -0
  6. data/lib/mcollective/applications.rb +145 -0
  7. data/lib/mcollective/client.rb +292 -0
  8. data/lib/mcollective/config.rb +202 -0
  9. data/lib/mcollective/connector.rb +18 -0
  10. data/lib/mcollective/connector/base.rb +24 -0
  11. data/lib/mcollective/facts.rb +39 -0
  12. data/lib/mcollective/facts/base.rb +86 -0
  13. data/lib/mcollective/log.rb +103 -0
  14. data/lib/mcollective/logger.rb +5 -0
  15. data/lib/mcollective/logger/base.rb +73 -0
  16. data/lib/mcollective/logger/console_logger.rb +61 -0
  17. data/lib/mcollective/logger/file_logger.rb +46 -0
  18. data/lib/mcollective/logger/syslog_logger.rb +53 -0
  19. data/lib/mcollective/matcher.rb +16 -0
  20. data/lib/mcollective/matcher/parser.rb +93 -0
  21. data/lib/mcollective/matcher/scanner.rb +123 -0
  22. data/lib/mcollective/message.rb +201 -0
  23. data/lib/mcollective/monkey_patches.rb +104 -0
  24. data/lib/mcollective/optionparser.rb +164 -0
  25. data/lib/mcollective/pluginmanager.rb +180 -0
  26. data/lib/mcollective/pluginpackager.rb +26 -0
  27. data/lib/mcollective/pluginpackager/agent_definition.rb +79 -0
  28. data/lib/mcollective/pluginpackager/standard_definition.rb +59 -0
  29. data/lib/mcollective/registration.rb +16 -0
  30. data/lib/mcollective/registration/base.rb +75 -0
  31. data/lib/mcollective/rpc.rb +188 -0
  32. data/lib/mcollective/rpc/actionrunner.rb +142 -0
  33. data/lib/mcollective/rpc/agent.rb +441 -0
  34. data/lib/mcollective/rpc/audit.rb +38 -0
  35. data/lib/mcollective/rpc/client.rb +793 -0
  36. data/lib/mcollective/rpc/ddl.rb +258 -0
  37. data/lib/mcollective/rpc/helpers.rb +339 -0
  38. data/lib/mcollective/rpc/progress.rb +63 -0
  39. data/lib/mcollective/rpc/reply.rb +61 -0
  40. data/lib/mcollective/rpc/request.rb +51 -0
  41. data/lib/mcollective/rpc/result.rb +41 -0
  42. data/lib/mcollective/rpc/stats.rb +185 -0
  43. data/lib/mcollective/runnerstats.rb +90 -0
  44. data/lib/mcollective/security.rb +26 -0
  45. data/lib/mcollective/security/base.rb +237 -0
  46. data/lib/mcollective/shell.rb +87 -0
  47. data/lib/mcollective/ssl.rb +246 -0
  48. data/lib/mcollective/unix_daemon.rb +37 -0
  49. data/lib/mcollective/util.rb +274 -0
  50. data/lib/mcollective/vendor.rb +41 -0
  51. data/lib/mcollective/vendor/require_vendored.rb +2 -0
  52. data/lib/mcollective/windows_daemon.rb +25 -0
  53. data/spec/Rakefile +16 -0
  54. data/spec/fixtures/application/test.rb +7 -0
  55. data/spec/fixtures/test-cert.pem +15 -0
  56. data/spec/fixtures/test-private.pem +15 -0
  57. data/spec/fixtures/test-public.pem +6 -0
  58. data/spec/monkey_patches/instance_variable_defined.rb +7 -0
  59. data/spec/spec.opts +1 -0
  60. data/spec/spec_helper.rb +25 -0
  61. data/spec/unit/agents_spec.rb +280 -0
  62. data/spec/unit/application_spec.rb +636 -0
  63. data/spec/unit/applications_spec.rb +155 -0
  64. data/spec/unit/array.rb +30 -0
  65. data/spec/unit/config_spec.rb +148 -0
  66. data/spec/unit/facts/base_spec.rb +118 -0
  67. data/spec/unit/facts_spec.rb +39 -0
  68. data/spec/unit/log_spec.rb +71 -0
  69. data/spec/unit/logger/base_spec.rb +110 -0
  70. data/spec/unit/logger/syslog_logger_spec.rb +86 -0
  71. data/spec/unit/matcher/parser_spec.rb +106 -0
  72. data/spec/unit/matcher/scanner_spec.rb +71 -0
  73. data/spec/unit/message_spec.rb +401 -0
  74. data/spec/unit/optionparser_spec.rb +113 -0
  75. data/spec/unit/pluginmanager_spec.rb +173 -0
  76. data/spec/unit/pluginpackager/agent_definition_spec.rb +130 -0
  77. data/spec/unit/pluginpackager/standard_definition_spec.rb +75 -0
  78. data/spec/unit/plugins/mcollective/connector/activemq_spec.rb +533 -0
  79. data/spec/unit/plugins/mcollective/connector/stomp/eventlogger_spec.rb +34 -0
  80. data/spec/unit/plugins/mcollective/connector/stomp_spec.rb +417 -0
  81. data/spec/unit/plugins/mcollective/packagers/ospackage_spec.rb +229 -0
  82. data/spec/unit/plugins/mcollective/security/psk_spec.rb +156 -0
  83. data/spec/unit/registration/base_spec.rb +77 -0
  84. data/spec/unit/rpc/actionrunner_spec.rb +213 -0
  85. data/spec/unit/rpc/agent_spec.rb +155 -0
  86. data/spec/unit/rpc/client_spec.rb +523 -0
  87. data/spec/unit/rpc/ddl_spec.rb +388 -0
  88. data/spec/unit/rpc/helpers_spec.rb +55 -0
  89. data/spec/unit/rpc/reply_spec.rb +143 -0
  90. data/spec/unit/rpc/request_spec.rb +115 -0
  91. data/spec/unit/rpc/result_spec.rb +66 -0
  92. data/spec/unit/rpc/stats_spec.rb +288 -0
  93. data/spec/unit/runnerstats_spec.rb +40 -0
  94. data/spec/unit/security/base_spec.rb +279 -0
  95. data/spec/unit/shell_spec.rb +144 -0
  96. data/spec/unit/ssl_spec.rb +244 -0
  97. data/spec/unit/symbol.rb +11 -0
  98. data/spec/unit/unix_daemon.rb +41 -0
  99. data/spec/unit/util_spec.rb +342 -0
  100. data/spec/unit/vendor_spec.rb +34 -0
  101. data/spec/unit/windows_daemon.rb +43 -0
  102. data/spec/windows_spec.opts +1 -0
  103. metadata +242 -0
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ describe Facts do
7
+ before do
8
+ class Facts::Testfacts<Facts::Base; end
9
+
10
+ PluginManager.delete("facts_plugin")
11
+ PluginManager << {:type => "facts_plugin", :class => "MCollective::Facts::Testfacts"}
12
+ end
13
+
14
+ describe "#has_fact?" do
15
+ it "should correctly report fact presense" do
16
+ Facts::Testfacts.any_instance.stubs("load_facts_from_source").returns({"foo" => "bar"})
17
+
18
+ Facts.has_fact?("foo", "foo").should == false
19
+ Facts.has_fact?("foo", "bar").should == true
20
+ end
21
+ end
22
+
23
+ describe "#get_fact" do
24
+ it "should return the correct fact" do
25
+ Facts::Testfacts.any_instance.stubs("load_facts_from_source").returns({"foo" => "bar"})
26
+
27
+ Facts.get_fact("foo").should == "bar"
28
+ end
29
+ end
30
+
31
+ describe "#[]" do
32
+ it "should return the correct fact" do
33
+ Facts::Testfacts.any_instance.stubs("load_facts_from_source").returns({"foo" => "bar"})
34
+
35
+ Facts["foo"].should == "bar"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ describe Log do
7
+ before do
8
+ @logger = mock("logger provider")
9
+ @logger.stubs(:log)
10
+ @logger.stubs(:start)
11
+ @logger.stubs(:set_logging_level)
12
+ @logger.stubs(:valid_levels)
13
+ end
14
+
15
+ describe "#cofigure" do
16
+ it "should default to console logging if called prior to configuration" do
17
+ Config.instance.instance_variable_set("@configured", false)
18
+ Log.configure
19
+ Log.logger.should == MCollective::Logger::Console_logger
20
+ end
21
+ end
22
+
23
+ describe "#instance" do
24
+ it "should return the correct reference" do
25
+ Log.configure(@logger)
26
+ Log.instance.should == MCollective::Log
27
+ end
28
+ end
29
+
30
+ describe "#log" do
31
+ it "should log at debug level" do
32
+ @logger.expects(:log).with(:debug, anything, regexp_matches(/debug test/))
33
+ Log.configure(@logger)
34
+ Log.debug("debug test")
35
+ end
36
+
37
+ it "should log at info level" do
38
+ @logger.expects(:log).with(:info, anything, regexp_matches(/info test/))
39
+ Log.configure(@logger)
40
+ Log.info("info test")
41
+ end
42
+
43
+ it "should log at fatal level" do
44
+ @logger.expects(:log).with(:fatal, anything, regexp_matches(/fatal test/))
45
+ Log.configure(@logger)
46
+ Log.fatal("fatal test")
47
+ end
48
+
49
+ it "should log at error level" do
50
+ @logger.expects(:log).with(:error, anything, regexp_matches(/error test/))
51
+ Log.configure(@logger)
52
+ Log.error("error test")
53
+ end
54
+
55
+ it "should log at warning level" do
56
+ @logger.expects(:log).with(:warn, anything, regexp_matches(/warn test/))
57
+ Log.configure(@logger)
58
+ Log.warn("warn test")
59
+ end
60
+ end
61
+
62
+ describe "#cycle_level" do
63
+ it "should cycle logger class levels" do
64
+ @logger.expects(:cycle_level)
65
+
66
+ Log.configure(@logger)
67
+ Log.cycle_level
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective::Logger
6
+ describe Base do
7
+ before do
8
+ Base.any_instance.stubs(:set_logging_level).returns(true)
9
+ Base.any_instance.stubs(:valid_levels).returns({:info => :info_test,
10
+ :warn => :warning_test,
11
+ :debug => :debug_test,
12
+ :fatal => :crit_test,
13
+ :error => :err_test})
14
+ end
15
+
16
+ describe "#initialize" do
17
+ it "should check for valid levels" do
18
+ Base.any_instance.stubs(:valid_levels).returns({})
19
+
20
+ expect {
21
+ Base.new
22
+ }.to raise_error(/Logger class did not specify a map for/)
23
+ end
24
+
25
+ it "should accept correct levels" do
26
+ Base.new
27
+ end
28
+ end
29
+
30
+ describe "#valid_levels" do
31
+ it "should report if valid_levels was not implimented" do
32
+ Base.any_instance.unstub(:valid_levels)
33
+
34
+ expect {
35
+ logger = Base.new
36
+ }.to raise_error("The logging class did not supply a valid_levels method")
37
+ end
38
+ end
39
+
40
+ describe "#log" do
41
+ it "should report if log was not implimented" do
42
+ logger = Base.new
43
+
44
+ expect {
45
+ logger.send(:log, nil, nil, nil)
46
+ }.to raise_error("The logging class did not supply a log method")
47
+ end
48
+ end
49
+
50
+ describe "#start" do
51
+ it "should report if log was not implimented" do
52
+ logger = Base.new
53
+
54
+ expect {
55
+ logger.send(:start)
56
+ }.to raise_error("The logging class did not supply a start method")
57
+ end
58
+ end
59
+
60
+ describe "#map_level" do
61
+ it "should map levels correctly" do
62
+ logger = Base.new
63
+
64
+ logger.send(:map_level, :info).should == :info_test
65
+ logger.send(:map_level, :warn).should == :warning_test
66
+ logger.send(:map_level, :debug).should == :debug_test
67
+ logger.send(:map_level, :fatal).should == :crit_test
68
+ logger.send(:map_level, :error).should == :err_test
69
+ end
70
+ end
71
+
72
+ describe "#get_next_level" do
73
+ it "should supply the correct next level" do
74
+ logger = Base.new
75
+ logger.set_level(:fatal)
76
+
77
+ logger.send(:get_next_level).should == :debug
78
+ end
79
+ end
80
+
81
+ describe "#cycle_level" do
82
+ it "should set the level to the next one and log the event" do
83
+ logger = Base.new
84
+
85
+ logger.stubs(:get_next_level).returns(:error)
86
+
87
+ logger.expects(:set_level).with(:error)
88
+ logger.expects(:log).with(:error, "", "Logging level is now ERROR")
89
+
90
+ logger.cycle_level
91
+ end
92
+ end
93
+
94
+ describe "#set_level" do
95
+ it "should set the active level" do
96
+ logger = Base.new
97
+
98
+ logger.set_level(:error)
99
+
100
+ logger.active_level.should == :error
101
+ end
102
+
103
+ it "should set the level on the logger" do
104
+ logger = Base.new
105
+
106
+ logger.set_level(:error)
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ unless Util.windows?
7
+ require 'mcollective/logger/syslog_logger'
8
+
9
+ module Logger
10
+ describe Syslog_logger do
11
+ describe "#start" do
12
+ before do
13
+ Config.any_instance.stubs(:logfacility).returns("user")
14
+ Config.any_instance.stubs(:loglevel).returns("error")
15
+ end
16
+
17
+ it "should close the syslog if already opened" do
18
+ Syslog.expects("opened?").returns(true)
19
+ Syslog.expects(:close).once
20
+ Syslog.expects(:open).once
21
+
22
+ logger = Syslog_logger.new
23
+ logger.start
24
+ end
25
+
26
+ it "should open syslog with the correct facility" do
27
+ logger = Syslog_logger.new
28
+ Syslog.expects(:open).with("rspec", 3, Syslog::LOG_USER).once
29
+ logger.start
30
+ end
31
+
32
+ it "should set the logger level correctly" do
33
+ logger = Syslog_logger.new
34
+ Syslog.expects(:open).with("rspec", 3, Syslog::LOG_USER).once
35
+ logger.expects(:set_level).with(:error).once
36
+ logger.start
37
+ end
38
+ end
39
+
40
+ describe "#syslog_facility" do
41
+ it "should support valid facilities" do
42
+ logger = Syslog_logger.new
43
+ logger.syslog_facility("LOCAL1").should == Syslog::LOG_LOCAL1
44
+ logger.syslog_facility("local1").should == Syslog::LOG_LOCAL1
45
+ end
46
+
47
+ it "should set LOG_USER for unknown facilities" do
48
+ logger = Syslog_logger.new
49
+ IO.any_instance.expects(:puts).with("Invalid syslog facility rspec supplied, reverting to USER")
50
+ logger.syslog_facility("rspec").should == Syslog::LOG_USER
51
+ end
52
+ end
53
+
54
+ describe "#log" do
55
+ it "should log higher than configured levels" do
56
+ logger = Syslog_logger.new
57
+ logger.set_level(:debug)
58
+ Syslog.expects(:err).once
59
+ logger.log(:error, "rspec", "rspec")
60
+ end
61
+
62
+ it "should not log lower than configured levels" do
63
+ logger = Syslog_logger.new
64
+ logger.set_level(:fatal)
65
+ Syslog.expects(:debug).never
66
+ logger.log(:debug, "rspec", "rspec")
67
+ end
68
+
69
+ it "should log using the correctly mapped level" do
70
+ logger = Syslog_logger.new
71
+ Syslog.expects(:err).with("rspec rspec").once
72
+ logger.set_level(:debug)
73
+ logger.log(:error, "rspec", "rspec")
74
+ end
75
+
76
+ it "should resort to STDERR output if all else fails" do
77
+ logger = Syslog_logger.new
78
+ IO.any_instance.expects(:puts).with("error: rspec").once
79
+
80
+ logger.log(:error, "rspec", "rspec")
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,106 @@
1
+ #! /usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ module Matcher
7
+ describe Parser do
8
+ describe '#parse' do
9
+ it "should parse statements seperated by '='" do
10
+ parser = Parser.new("foo=bar")
11
+ parser.execution_stack.should == [{"statement" => "foo=bar"}]
12
+ end
13
+
14
+ it "should parse statements seperated by '<'" do
15
+ parser = Parser.new("foo<bar")
16
+ parser.execution_stack.should == [{"statement" => "foo<bar"}]
17
+ end
18
+
19
+ it "should parse statements seperated by '>'" do
20
+ parser = Parser.new("foo>bar")
21
+ parser.execution_stack.should == [{"statement" => "foo>bar"}]
22
+ end
23
+
24
+ it "should parse statements seperated by '<='" do
25
+ parser = Parser.new("foo<=bar")
26
+ parser.execution_stack.should == [{"statement" => "foo<=bar"}]
27
+ end
28
+
29
+ it "should parse statements seperated by '>='" do
30
+ parser = Parser.new("foo>=bar")
31
+ parser.execution_stack.should == [{"statement" => "foo>=bar"}]
32
+ end
33
+
34
+ it "should parse class regex statements" do
35
+ parser = Parser.new("/foo/")
36
+ parser.execution_stack.should == [{"statement" => "/foo/"}]
37
+ end
38
+
39
+ it "should parse fact regex statements" do
40
+ parser = Parser.new("foo=/bar/")
41
+ parser.execution_stack.should == [{"statement" => "foo=/bar/"}]
42
+ end
43
+
44
+ it "should parse a correct 'and' token" do
45
+ parser = Parser.new("foo=bar and bar=foo")
46
+ parser.execution_stack.should == [{"statement" => "foo=bar"}, {"and" => "and"}, {"statement" => "bar=foo"}]
47
+ end
48
+
49
+ it "should not parse an incorrect and token" do
50
+ expect {
51
+ parser = Parser.new("and foo=bar")
52
+ }.to raise_error("Error at column 10. \n Expression cannot start with 'and'")
53
+ end
54
+
55
+ it "should parse a correct 'or' token" do
56
+ parser = Parser.new("foo=bar or bar=foo")
57
+ parser.execution_stack.should == [{"statement" => "foo=bar"}, {"or" => "or"}, {"statement" => "bar=foo"}]
58
+ end
59
+
60
+ it "should not parse an incorrect and token" do
61
+ expect {
62
+ parser = Parser.new("or foo=bar")
63
+ }.to raise_error("Error at column 9. \n Expression cannot start with 'or'")
64
+ end
65
+
66
+ it "should parse a correct 'not' token" do
67
+ parser = Parser.new("! bar=foo")
68
+ parser.execution_stack.should == [{"not" => "not"}, {"statement" => "bar=foo"}]
69
+ parser = Parser.new("not bar=foo")
70
+ parser.execution_stack.should == [{"not" => "not"}, {"statement" => "bar=foo"}]
71
+ end
72
+
73
+ it "should not parse an incorrect 'not' token" do
74
+ expect {
75
+ parser = Parser.new("foo=bar !")
76
+ }.to raise_error("Error at column 8. \nExpected 'and', 'or', ')'. Found 'not'")
77
+ end
78
+
79
+ it "should parse correct parentheses" do
80
+ parser = Parser.new("(foo=bar)")
81
+ parser.execution_stack.should == [{"(" => "("}, {"statement" => "foo=bar"}, {")" => ")"}]
82
+ end
83
+
84
+ it "should fail on incorrect parentheses" do
85
+ expect {
86
+ parser = Parser.new(")foo=bar(")
87
+ }.to raise_error("Error. Missing parentheses '('.")
88
+ end
89
+
90
+ it "should fail on missing parentheses" do
91
+ expect {
92
+ parser = Parser.new("(foo=bar")
93
+ }.to raise_error("Error. Missing parentheses ')'.")
94
+ end
95
+
96
+ it "should parse correctly formatted compound statements" do
97
+ parser = Parser.new("(foo=bar or foo=rab) and (bar=foo)")
98
+ parser.execution_stack.should == [{"(" => "("}, {"statement"=>"foo=bar"}, {"or"=>"or"}, {"statement"=>"foo=rab"},
99
+ {")"=>")"}, {"and"=>"and"}, {"("=>"("}, {"statement"=>"bar=foo"},
100
+ {")"=>")"}]
101
+ end
102
+
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,71 @@
1
+ #! /usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ module Matcher
7
+ describe 'scanner' do
8
+ it "should identify a '(' token" do
9
+ scanner = Scanner.new("(")
10
+ token = scanner.get_token
11
+ token.should == ["(", "("]
12
+ end
13
+
14
+ it "should identify a ')' token" do
15
+ scanner = Scanner.new(")")
16
+ token = scanner.get_token
17
+ token.should == [")", ")"]
18
+ end
19
+
20
+ it "should identify a 'and' token" do
21
+ scanner = Scanner.new("and ")
22
+ token = scanner.get_token
23
+ token.should == ["and", "and"]
24
+ end
25
+
26
+ it "should identify a 'or' token" do
27
+ scanner = Scanner.new("or ")
28
+ token = scanner.get_token
29
+ token.should == ["or", "or"]
30
+ end
31
+
32
+ it "should identify a 'not' token" do
33
+ scanner = Scanner.new("not ")
34
+ token = scanner.get_token
35
+ token.should == ["not", "not"]
36
+ end
37
+
38
+ it "should identify a '!' token" do
39
+ scanner = Scanner.new("!")
40
+ token = scanner.get_token
41
+ token.should == ["not", "not"]
42
+ end
43
+
44
+ it "should identify a fact statement token" do
45
+ scanner = Scanner.new("foo=bar")
46
+ token = scanner.get_token
47
+ token.should == ["statement", "foo=bar"]
48
+ end
49
+
50
+ it "should identify a fact statement token" do
51
+ scanner = Scanner.new("foo=bar")
52
+ token = scanner.get_token
53
+ token.should == ["statement", "foo=bar"]
54
+ end
55
+
56
+ it "should identify a class statement token" do
57
+ scanner = Scanner.new("/class/")
58
+ token = scanner.get_token
59
+ token.should == ["statement", "/class/"]
60
+ end
61
+
62
+ it "should fail if expression terminates with 'and'" do
63
+ scanner = Scanner.new("and")
64
+
65
+ expect {
66
+ token = scanner.get_token
67
+ }.to raise_error("Class name cannot be 'and', 'or', 'not'. Found 'and'")
68
+ end
69
+ end
70
+ end
71
+ end