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.

Files changed (140) hide show
  1. data/lib/mcollective.rb +32 -23
  2. data/lib/mcollective/agent.rb +5 -0
  3. data/lib/mcollective/agents.rb +5 -16
  4. data/lib/mcollective/aggregate.rb +61 -0
  5. data/lib/mcollective/aggregate/base.rb +40 -0
  6. data/lib/mcollective/aggregate/result.rb +9 -0
  7. data/lib/mcollective/aggregate/result/base.rb +25 -0
  8. data/lib/mcollective/aggregate/result/collection_result.rb +19 -0
  9. data/lib/mcollective/aggregate/result/numeric_result.rb +13 -0
  10. data/lib/mcollective/application.rb +7 -4
  11. data/lib/mcollective/applications.rb +3 -14
  12. data/lib/mcollective/cache.rb +145 -0
  13. data/lib/mcollective/client.rb +10 -87
  14. data/lib/mcollective/config.rb +22 -8
  15. data/lib/mcollective/data.rb +87 -0
  16. data/lib/mcollective/data/base.rb +67 -0
  17. data/lib/mcollective/data/result.rb +40 -0
  18. data/lib/mcollective/ddl.rb +113 -0
  19. data/lib/mcollective/ddl/agentddl.rb +185 -0
  20. data/lib/mcollective/ddl/base.rb +220 -0
  21. data/lib/mcollective/ddl/dataddl.rb +56 -0
  22. data/lib/mcollective/ddl/discoveryddl.rb +52 -0
  23. data/lib/mcollective/ddl/validatorddl.rb +6 -0
  24. data/lib/mcollective/discovery.rb +143 -0
  25. data/lib/mcollective/generators.rb +7 -0
  26. data/lib/mcollective/generators/agent_generator.rb +51 -0
  27. data/lib/mcollective/generators/base.rb +46 -0
  28. data/lib/mcollective/generators/data_generator.rb +51 -0
  29. data/lib/mcollective/generators/templates/action_snippet.erb +13 -0
  30. data/lib/mcollective/generators/templates/data_input_snippet.erb +7 -0
  31. data/lib/mcollective/generators/templates/ddl.erb +8 -0
  32. data/lib/mcollective/generators/templates/plugin.erb +7 -0
  33. data/lib/mcollective/logger/console_logger.rb +15 -15
  34. data/lib/mcollective/matcher.rb +167 -0
  35. data/lib/mcollective/matcher/parser.rb +60 -25
  36. data/lib/mcollective/matcher/scanner.rb +156 -78
  37. data/lib/mcollective/message.rb +47 -6
  38. data/lib/mcollective/monkey_patches.rb +17 -0
  39. data/lib/mcollective/optionparser.rb +18 -1
  40. data/lib/mcollective/pluginmanager.rb +3 -3
  41. data/lib/mcollective/pluginpackager.rb +10 -3
  42. data/lib/mcollective/pluginpackager/agent_definition.rb +28 -20
  43. data/lib/mcollective/pluginpackager/standard_definition.rb +11 -9
  44. data/lib/mcollective/registration/base.rb +3 -1
  45. data/lib/mcollective/rpc.rb +18 -24
  46. data/lib/mcollective/rpc/agent.rb +37 -113
  47. data/lib/mcollective/rpc/client.rb +186 -64
  48. data/lib/mcollective/rpc/helpers.rb +42 -80
  49. data/lib/mcollective/rpc/progress.rb +3 -3
  50. data/lib/mcollective/rpc/reply.rb +37 -13
  51. data/lib/mcollective/rpc/request.rb +17 -6
  52. data/lib/mcollective/rpc/result.rb +9 -5
  53. data/lib/mcollective/rpc/stats.rb +71 -24
  54. data/lib/mcollective/security/base.rb +41 -34
  55. data/lib/mcollective/shell.rb +1 -1
  56. data/lib/mcollective/ssl.rb +34 -0
  57. data/lib/mcollective/util.rb +194 -23
  58. data/lib/mcollective/validator.rb +80 -0
  59. data/spec/fixtures/util/1.in +10 -0
  60. data/spec/fixtures/util/1.out +10 -0
  61. data/spec/fixtures/util/2.in +1 -0
  62. data/spec/fixtures/util/2.out +1 -0
  63. data/spec/fixtures/util/3.in +1 -0
  64. data/spec/fixtures/util/3.out +2 -0
  65. data/spec/fixtures/util/4.in +5 -0
  66. data/spec/fixtures/util/4.out +9 -0
  67. data/spec/spec.opts +1 -1
  68. data/spec/spec_helper.rb +2 -0
  69. data/spec/unit/agents_spec.rb +34 -19
  70. data/spec/unit/aggregate/base_spec.rb +57 -0
  71. data/spec/unit/aggregate/result/base_spec.rb +28 -0
  72. data/spec/unit/aggregate/result/collection_result_spec.rb +18 -0
  73. data/spec/unit/aggregate/result/numeric_result_spec.rb +22 -0
  74. data/spec/unit/aggregate_spec.rb +110 -0
  75. data/spec/unit/application_spec.rb +8 -3
  76. data/spec/unit/applications_spec.rb +2 -2
  77. data/spec/unit/cache_spec.rb +115 -0
  78. data/spec/unit/client_spec.rb +78 -0
  79. data/spec/unit/config_spec.rb +32 -34
  80. data/spec/unit/data/base_spec.rb +90 -0
  81. data/spec/unit/data/result_spec.rb +64 -0
  82. data/spec/unit/data_spec.rb +158 -0
  83. data/spec/unit/ddl/agentddl_spec.rb +217 -0
  84. data/spec/unit/{rpc/ddl_spec.rb → ddl/base_spec.rb} +238 -224
  85. data/spec/unit/ddl/dataddl_spec.rb +65 -0
  86. data/spec/unit/ddl/discoveryddl_spec.rb +58 -0
  87. data/spec/unit/ddl_spec.rb +84 -0
  88. data/spec/unit/discovery_spec.rb +196 -0
  89. data/spec/unit/facts/base_spec.rb +1 -1
  90. data/spec/unit/generators/agent_generator_spec.rb +72 -0
  91. data/spec/unit/generators/base_spec.rb +83 -0
  92. data/spec/unit/generators/data_generator_spec.rb +37 -0
  93. data/spec/unit/generators/snippets/agent_ddl +19 -0
  94. data/spec/unit/generators/snippets/data_ddl +20 -0
  95. data/spec/unit/logger/console_logger_spec.rb +76 -0
  96. data/spec/unit/logger/syslog_logger_spec.rb +2 -2
  97. data/spec/unit/matcher/parser_spec.rb +27 -10
  98. data/spec/unit/matcher/scanner_spec.rb +108 -5
  99. data/spec/unit/matcher_spec.rb +260 -0
  100. data/spec/unit/message_spec.rb +35 -13
  101. data/spec/unit/optionparser_spec.rb +2 -2
  102. data/spec/unit/pluginpackager/agent_definition_spec.rb +59 -42
  103. data/spec/unit/pluginpackager/standard_definition_spec.rb +10 -8
  104. data/spec/unit/pluginpackager_spec.rb +131 -0
  105. data/spec/unit/plugins/mcollective/aggregate/average_spec.rb +45 -0
  106. data/spec/unit/plugins/mcollective/aggregate/sum_spec.rb +31 -0
  107. data/spec/unit/plugins/mcollective/aggregate/summary_spec.rb +45 -0
  108. data/spec/unit/plugins/mcollective/connector/activemq_spec.rb +1 -1
  109. data/spec/unit/plugins/mcollective/connector/rabbitmq_spec.rb +478 -0
  110. data/spec/unit/plugins/mcollective/connector/stomp_spec.rb +2 -0
  111. data/spec/unit/plugins/mcollective/data/agent_data_spec.rb +43 -0
  112. data/spec/unit/plugins/mcollective/data/fstat_data_spec.rb +135 -0
  113. data/spec/unit/plugins/mcollective/discovery/flatfile_spec.rb +48 -0
  114. data/spec/unit/plugins/mcollective/discovery/mc_spec.rb +40 -0
  115. data/spec/unit/plugins/mcollective/packagers/debpackage_packager_spec.rb +41 -15
  116. data/spec/unit/plugins/mcollective/packagers/ospackage_spec.rb +1 -1
  117. data/spec/unit/plugins/mcollective/packagers/rpmpackage_packager_spec.rb +22 -38
  118. data/spec/unit/plugins/mcollective/validator/array_validator_spec.rb +19 -0
  119. data/spec/unit/plugins/mcollective/validator/ipv4address_validator_spec.rb +19 -0
  120. data/spec/unit/plugins/mcollective/validator/ipv6address_validator_spec.rb +19 -0
  121. data/spec/unit/plugins/mcollective/validator/length_validator_spec.rb +19 -0
  122. data/spec/unit/plugins/mcollective/validator/regex_validator_spec.rb +19 -0
  123. data/spec/unit/plugins/mcollective/validator/shellsafe_validator_spec.rb +21 -0
  124. data/spec/unit/plugins/mcollective/validator/typecheck_validator_spec.rb +23 -0
  125. data/spec/unit/registration/base_spec.rb +1 -1
  126. data/spec/unit/rpc/actionrunner_spec.rb +2 -2
  127. data/spec/unit/rpc/agent_spec.rb +41 -65
  128. data/spec/unit/rpc/client_spec.rb +430 -134
  129. data/spec/unit/rpc/reply_spec.rb +31 -1
  130. data/spec/unit/rpc/request_spec.rb +33 -12
  131. data/spec/unit/rpc/result_spec.rb +7 -0
  132. data/spec/unit/rpc/stats_spec.rb +14 -14
  133. data/spec/unit/rpc_spec.rb +16 -0
  134. data/spec/unit/security/base_spec.rb +8 -8
  135. data/spec/unit/ssl_spec.rb +20 -2
  136. data/spec/unit/string_spec.rb +15 -0
  137. data/spec/unit/util_spec.rb +141 -21
  138. data/spec/unit/validator_spec.rb +67 -0
  139. metadata +145 -7
  140. data/lib/mcollective/rpc/ddl.rb +0 -258
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ module DDL
7
+ describe DataDDL do
8
+ before :each do
9
+ Cache.delete!(:ddl) rescue nil
10
+ @ddl = DDL.new("rspec", :data, false)
11
+ @ddl.metadata(:name => "name", :description => "description", :author => "author", :license => "license", :version => "version", :url => "url", :timeout => "timeout")
12
+ end
13
+
14
+ describe "#input" do
15
+ it "should only allow 'query' as input for data plugins" do
16
+ ddl = DDL.new("rspec", :data, false)
17
+ ddl.dataquery(:description => "rspec")
18
+ ddl.instance_variable_set("@current_entity", :query)
19
+ ddl.instance_variable_set("@plugintype", :data)
20
+
21
+ expect { ddl.input(:rspec, {}) }.to raise_error("The only valid input name for a data query is 'query'")
22
+ end
23
+ end
24
+
25
+ describe "#dataquery_interface" do
26
+ it "should return the correct data" do
27
+ input = {:prompt => "Matcher", :description => "Augeas Matcher", :type => :string, :validation => /.+/, :maxlength => 0}
28
+ output = {:description=>"rspec", :display_as=>"rspec", :default => nil}
29
+
30
+ @ddl.instance_variable_set("@plugintype", :data)
31
+ @ddl.dataquery(:description => "rspec") do
32
+ @ddl.output :rspec, output
33
+ @ddl.input :query, input
34
+ end
35
+
36
+ @ddl.dataquery_interface.should == {:description => "rspec",
37
+ :input => {:query => input.merge(:optional => nil)},
38
+ :output => {:rspec => output}}
39
+ end
40
+ end
41
+
42
+ describe "#dataquery" do
43
+ it "should ensure a description is set" do
44
+ expect { @ddl.dataquery({}) }.to raise_error("Data queries need a :description")
45
+ end
46
+
47
+ it "should ensure only one definition" do
48
+ @ddl.dataquery(:description => "rspec")
49
+
50
+ expect { @ddl.dataquery(:description => "rspec") }.to raise_error("Data queries can only have one definition")
51
+ end
52
+
53
+ it "should create the default structure" do
54
+ @ddl.dataquery(:description => "rspec")
55
+ @ddl.instance_variable_set("@plugintype", :data)
56
+ @ddl.dataquery_interface.should == {:description => "rspec", :input => {}, :output => {}}
57
+ end
58
+
59
+ it "should call the block if given" do
60
+ @ddl.dataquery(:description => "rspec") { @ddl.instance_variable_get("@current_entity").should == :data }
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ module DDL
7
+ describe DiscoveryDDL do
8
+ before :each do
9
+ Cache.delete!(:ddl) rescue nil
10
+ @ddl = DDL.new("rspec", :discovery, false)
11
+ @ddl.metadata(:name => "name", :description => "description", :author => "author", :license => "license", :version => "version", :url => "url", :timeout => "timeout")
12
+ end
13
+
14
+ describe "#discovery_interface" do
15
+ it "should return correct data" do
16
+ @ddl.instance_variable_set("@plugintype", :discovery)
17
+ @ddl.discovery do
18
+ @ddl.capabilities :identity
19
+ end
20
+
21
+ @ddl.discovery_interface.should == {:capabilities => [:identity]}
22
+ end
23
+ end
24
+
25
+ describe "#capabilities" do
26
+ it "should support non arrays" do
27
+ @ddl.instance_variable_set("@plugintype", :discovery)
28
+ @ddl.discovery do
29
+ @ddl.capabilities :identity
30
+ end
31
+ @ddl.discovery_interface.should == {:capabilities => [:identity]}
32
+ end
33
+
34
+ it "should not accept empty capability lists" do
35
+ @ddl.instance_variable_set("@plugintype", :discovery)
36
+ @ddl.discovery do
37
+ expect { @ddl.capabilities [] }.to raise_error("Discovery plugin capabilities can't be empty")
38
+ end
39
+ end
40
+
41
+ it "should only accept known capabilities" do
42
+ @ddl.instance_variable_set("@plugintype", :discovery)
43
+ @ddl.discovery do
44
+ expect { @ddl.capabilities :rspec }.to raise_error(/rspec is not a valid capability/)
45
+ end
46
+ end
47
+
48
+ it "should correctly store the capabilities" do
49
+ @ddl.instance_variable_set("@plugintype", :discovery)
50
+ @ddl.discovery do
51
+ @ddl.capabilities [:identity, :classes]
52
+ end
53
+ @ddl.discovery_interface.should == {:capabilities => [:identity, :classes]}
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ describe DDL do
7
+ before do
8
+ Cache.delete!(:ddl) rescue nil
9
+ end
10
+
11
+ describe "#new" do
12
+ it "should default to agent ddls" do
13
+ DDL::AgentDDL.expects(:new).once
14
+ DDL.new("rspec")
15
+ end
16
+
17
+ it "should return the correct plugin ddl class" do
18
+ DDL.new("rspec", :agent, false).class.should == DDL::AgentDDL
19
+ end
20
+
21
+ it "should default to base when no specific class exist" do
22
+ DDL.new("rspec", :rspec, false).class.should == DDL::Base
23
+ end
24
+ end
25
+
26
+ describe "#load_and_cache" do
27
+ it "should setup the cache" do
28
+ Cache.setup(:ddl)
29
+
30
+ Cache.expects(:setup).once.returns(true)
31
+ DDL.load_and_cache("rspec", :agent, false)
32
+ end
33
+
34
+ it "should attempt to read from the cache and return found ddl" do
35
+ Cache.expects(:setup)
36
+ Cache.expects(:read).with(:ddl, "agent/rspec").returns("rspec")
37
+ DDL.load_and_cache("rspec", :agent, false).should == "rspec"
38
+ end
39
+
40
+ it "should handle cache misses then create and save a new ddl object" do
41
+ Cache.expects(:setup)
42
+ Cache.expects(:read).with(:ddl, "agent/rspec").raises("failed")
43
+ Cache.expects(:write).with(:ddl, "agent/rspec", kind_of(DDL::AgentDDL)).returns("rspec")
44
+
45
+ DDL.load_and_cache("rspec", :agent, false).should == "rspec"
46
+ end
47
+ end
48
+
49
+ describe "#string_to_number" do
50
+ it "should turn valid strings into numbers" do
51
+ ["1", "0", "9999"].each do |i|
52
+ DDL.string_to_number(i).class.should == Fixnum
53
+ end
54
+
55
+ ["1.1", "0.0", "9999.99"].each do |i|
56
+ DDL.string_to_number(i).class.should == Float
57
+ end
58
+ end
59
+
60
+ it "should raise errors for invalid values" do
61
+ expect { DDL.string_to_number("rspec") }.to raise_error
62
+ end
63
+ end
64
+
65
+ describe "#string_to_boolean" do
66
+ it "should turn valid strings into boolean" do
67
+ ["true", "yes", "1"].each do |t|
68
+ DDL.string_to_boolean(t).should == true
69
+ DDL.string_to_boolean(t.upcase).should == true
70
+ end
71
+
72
+ ["false", "no", "0"].each do |f|
73
+ DDL.string_to_boolean(f).should == false
74
+ DDL.string_to_boolean(f.upcase).should == false
75
+ end
76
+ end
77
+
78
+ it "should raise errors for invalid values" do
79
+ expect { DDL.string_to_boolean("rspec") }.to raise_error
80
+ end
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,196 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ describe Discovery do
7
+ before do
8
+ Config.instance.stubs(:default_discovery_method).returns("mc")
9
+ @client = mock
10
+
11
+ Discovery.any_instance.stubs(:find_known_methods).returns(["mc"])
12
+ @discovery = Discovery.new(@client)
13
+ end
14
+
15
+ describe "#timeout_for_compound_filter" do
16
+ it "should return the correct time" do
17
+ ddl = mock
18
+ ddl.stubs(:meta).returns({:timeout => 1})
19
+
20
+ filter = [Matcher.create_compound_callstack("test().size=1 and rspec().size=1")]
21
+
22
+ DDL.expects(:new).with("test_data", :data).returns(ddl)
23
+ DDL.expects(:new).with("rspec_data", :data).returns(ddl)
24
+
25
+ @discovery.timeout_for_compound_filter(filter).should == 2
26
+ end
27
+ end
28
+
29
+ describe "#discover" do
30
+ before do
31
+ ddl = mock
32
+ ddl.stubs(:meta).returns({:timeout => 2})
33
+
34
+ discoverer = mock
35
+
36
+ @discovery.stubs(:force_discovery_method_by_filter).returns(false)
37
+ @discovery.stubs(:ddl).returns(ddl)
38
+ @discovery.stubs(:check_capabilities)
39
+ @discovery.stubs(:discovery_class).returns(discoverer)
40
+ end
41
+
42
+ it "should error for non fixnum limits" do
43
+ expect { @discovery.discover(nil, 0, 1.1) }.to raise_error("Limit has to be an integer")
44
+ end
45
+
46
+ it "should use the DDL timeout if none is specified" do
47
+ filter = Util.empty_filter
48
+ @discovery.discovery_class.expects(:discover).with(filter, 2, 0, @client)
49
+ @discovery.discover(filter, nil, 0)
50
+ end
51
+
52
+ it "should check the discovery method is capable of serving the filter" do
53
+ @discovery.expects(:check_capabilities).with("filter").raises("capabilities check failed")
54
+ expect { @discovery.discover("filter", nil, 0) }.to raise_error("capabilities check failed")
55
+ end
56
+
57
+ it "should call the correct discovery plugin" do
58
+ @discovery.discovery_class.expects(:discover).with("filter", 2, 0, @client)
59
+ @discovery.discover("filter", nil, 0)
60
+ end
61
+
62
+ it "should handle limits correctly" do
63
+ @discovery.discovery_class.stubs(:discover).returns([1,2,3,4,5])
64
+ @discovery.discover(Util.empty_filter, 1, 1).should == [1]
65
+ @discovery.discover(Util.empty_filter, 1, 0).should == [1,2,3,4,5]
66
+ end
67
+ end
68
+
69
+ describe "#force_discovery_method_by_filter" do
70
+ it "should force mc plugin when needed" do
71
+ options = {:discovery_method => "rspec"}
72
+
73
+ Log.expects(:info).with("Switching to mc discovery method because compound filters are used")
74
+
75
+ @discovery.expects(:discovery_method).returns("rspec")
76
+ @client.expects(:options).returns(options)
77
+ @discovery.force_discovery_method_by_filter({"compound" => ["rspec"]}).should == true
78
+
79
+ options[:discovery_method].should == "mc"
80
+ end
81
+
82
+ it "should not force mc plugin when no compound filter is used" do
83
+ options = {:discovery_method => "rspec"}
84
+
85
+ @discovery.expects(:discovery_method).returns("rspec")
86
+ @discovery.force_discovery_method_by_filter({"compound" => []}).should == false
87
+
88
+ options[:discovery_method].should == "rspec"
89
+ end
90
+ end
91
+
92
+ describe "#check_capabilities" do
93
+ before do
94
+ @ddl = mock
95
+ @discovery.stubs(:ddl).returns(@ddl)
96
+ @discovery.stubs(:discovery_method).returns("rspec")
97
+ end
98
+
99
+ it "should fail for unsupported capabilities" do
100
+ @ddl.stubs(:discovery_interface).returns({:capabilities => []})
101
+
102
+ filter = Util.empty_filter
103
+
104
+ expect { @discovery.check_capabilities(filter.merge({"cf_class" => ["filter"]})) }.to raise_error(/Cannot use class filters/)
105
+
106
+ ["fact", "identity", "compound"].each do |type|
107
+ expect { @discovery.check_capabilities(filter.merge({type => ["filter"]})) }.to raise_error(/Cannot use #{type} filters/)
108
+ end
109
+ end
110
+ end
111
+
112
+ describe "#ddl" do
113
+ before do
114
+ @ddl = mock
115
+ @ddl.stubs(:meta).returns({:name => "mc"})
116
+ end
117
+
118
+ it "should create an instance of the right ddl" do
119
+ @discovery.instance_variable_set("@ddl", nil)
120
+ @client.stubs(:options).returns({})
121
+ DDL.expects(:new).with("mc", :discovery).returns(@ddl)
122
+ @discovery.ddl
123
+ end
124
+
125
+ it "should reload the ddl if the method has changed" do
126
+ @discovery.instance_variable_set("@ddl", @ddl)
127
+ @discovery.stubs(:discovery_method).returns("rspec")
128
+ DDL.expects(:new).with("rspec", :discovery).returns(@ddl)
129
+ @discovery.ddl
130
+ end
131
+ end
132
+
133
+ describe "#discovery_class" do
134
+ it "should try to load the class if not already loaded" do
135
+ @discovery.expects(:discovery_method).returns("mc")
136
+ PluginManager.expects(:loadclass).with("MCollective::Discovery::Mc")
137
+ Discovery.expects(:const_defined?).with("Mc").returns(false)
138
+ Discovery.expects(:const_get).with("Mc").returns("rspec")
139
+ @discovery.discovery_class.should == "rspec"
140
+ end
141
+
142
+ it "should not load the class again if its already loaded" do
143
+ @discovery.expects(:discovery_method).returns("mc")
144
+ PluginManager.expects(:loadclass).never
145
+ Discovery.expects(:const_defined?).with("Mc").returns(true)
146
+ Discovery.expects(:const_get).with("Mc").returns("rspec")
147
+ @discovery.discovery_class.should == "rspec"
148
+ end
149
+ end
150
+
151
+ describe "#initialize" do
152
+ it "should load all the known methods" do
153
+ @discovery.instance_variable_get("@known_methods").should == ["mc"]
154
+ end
155
+ end
156
+
157
+ describe "#find_known_methods" do
158
+ it "should use the PluginManager to find plugins of type 'discovery'" do
159
+ @discovery.find_known_methods.should == ["mc"]
160
+ end
161
+ end
162
+
163
+ describe "#has_method?" do
164
+ it "should correctly report the availability of a discovery method" do
165
+ @discovery.has_method?("mc").should == true
166
+ @discovery.has_method?("rspec").should == false
167
+ end
168
+ end
169
+
170
+ describe "#descovery_method" do
171
+ it "should default to 'mc'" do
172
+ @client.expects(:options).returns({})
173
+ @discovery.discovery_method.should == "mc"
174
+ end
175
+
176
+ it "should give preference to the client options" do
177
+ @client.expects(:options).returns({:discovery_method => "rspec"}).twice
178
+ Config.instance.expects(:direct_addressing).returns(true)
179
+ @discovery.expects(:has_method?).with("rspec").returns(true)
180
+ @discovery.discovery_method.should == "rspec"
181
+ end
182
+
183
+ it "should validate the discovery method exists" do
184
+ @client.expects(:options).returns({:discovery_method => "rspec"}).twice
185
+ expect { @discovery.discovery_method.should == "rspec" }.to raise_error("Unknown discovery method rspec")
186
+ end
187
+
188
+ it "should only allow custom discovery methods if direct_addressing is enabled" do
189
+ @client.expects(:options).returns({:discovery_method => "rspec"}).twice
190
+ Config.instance.expects(:direct_addressing).returns(false)
191
+ @discovery.expects(:has_method?).with("rspec").returns(true)
192
+ expect { @discovery.discovery_method.should == "rspec" }.to raise_error("Custom discovery methods require direct addressing mode")
193
+ end
194
+ end
195
+ end
196
+ end
@@ -13,7 +13,7 @@ module MCollective::Facts
13
13
 
14
14
  describe "#inherited" do
15
15
  it "should add classes to the plugin manager" do
16
- MCollective::PluginManager.stubs("<<").with({:type => "facts_plugin", :class => "MCollective::Facts::Bar"})
16
+ MCollective::PluginManager.expects("<<").with({:type => "facts_plugin", :class => "MCollective::Facts::Bar"})
17
17
 
18
18
  class Bar<Base; end
19
19
  end
@@ -0,0 +1,72 @@
1
+ #! /usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ module Generators
7
+ describe AgentGenerator do
8
+
9
+ describe "#create_ddl" do
10
+
11
+ before :each do
12
+ AgentGenerator.any_instance.stubs(:create_plugin_content)
13
+ AgentGenerator.any_instance.stubs(:create_plugin_string)
14
+ AgentGenerator.any_instance.stubs(:write_plugins)
15
+ AgentGenerator.any_instance.expects(:create_metadata_string).returns("metadata\n")
16
+ end
17
+
18
+ it "should create a ddl with nothing but metadata if no actions are specified" do
19
+ result = AgentGenerator.new("foo").ddl
20
+ result.should == "metadata\n"
21
+ end
22
+
23
+ it "should add action strings to metadata if there are actions specfied" do
24
+ result = AgentGenerator.new("foo", ["action1", "action2"]).ddl
25
+ expected = File.read(File.join(File.dirname(__FILE__), "snippets", "agent_ddl"))
26
+ result.should == expected
27
+ end
28
+ end
29
+
30
+ describe "#create_plugin_content" do
31
+ before :each do
32
+ AgentGenerator.any_instance.stubs(:create_plugin_string)
33
+ AgentGenerator.any_instance.stubs(:write_plugins)
34
+ AgentGenerator.any_instance.stubs(:create_metadata_string).returns("metadata\n")
35
+ AgentGenerator.any_instance.stubs(:create_ddl)
36
+ end
37
+
38
+ it "should create the correct pluginf ile content with actions if they are specified" do
39
+ AgentGenerator.any_instance.stubs(:create_metadata_string).returns("meta\n")
40
+ result = AgentGenerator.new("foo", ["action1", "action2"]).content
41
+ result.should == " action \"action1\" do\n end\n\n action \"action2\" do\n end\n"
42
+ end
43
+ end
44
+
45
+ describe "#action_help" do
46
+ before :each do
47
+ AgentGenerator.any_instance.stubs(:create_plugin_content)
48
+ AgentGenerator.any_instance.stubs(:create_plugin_string)
49
+ AgentGenerator.any_instance.stubs(:write_plugins)
50
+ AgentGenerator.any_instance.stubs(:create_metadata_string).returns("metadata\n")
51
+ end
52
+
53
+ it "should load and return the action_help snippet" do
54
+ erb = mock
55
+ erb.stubs(:result).returns("result")
56
+ File.stubs(:dirname).returns("/tmp")
57
+ File.expects(:read).with("/tmp/templates/action_snippet.erb").returns("result")
58
+ ERB.expects(:new).with("result").returns(erb)
59
+ AgentGenerator.new("foo", ["action"])
60
+ end
61
+
62
+ it "should raise an error if the action_help snippet does not exist" do
63
+ File.stubs(:dirname).returns("/tmp")
64
+ File.stubs(:read).raises(Errno::ENOENT, "No such file or directory")
65
+ expect{
66
+ AgentGenerator.new("foo", ["action"])
67
+ }.to raise_error(Errno::ENOENT)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end