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
@@ -550,12 +550,14 @@ module MCollective
550
550
  out = StringIO.new
551
551
  @app.stubs(:disconnect)
552
552
  @app.stubs(:exit).with(1)
553
+ @app.stubs(:options).returns({})
553
554
 
555
+ Config.instance.stubs(:color).returns(false)
554
556
  e = mock
555
557
  e.stubs(:backtrace).returns([])
556
558
  e.stubs(:to_s).returns("rspec")
557
559
 
558
- out.expects(:puts).with("#{$0} failed to run: rspec (Mocha::Mock)")
560
+ out.expects(:puts).with(regexp_matches(/rspec application failed to run/))
559
561
 
560
562
  @app.application_failure(e, out)
561
563
  end
@@ -564,14 +566,17 @@ module MCollective
564
566
  out = StringIO.new
565
567
  @app.stubs(:disconnect)
566
568
  @app.stubs(:exit).with(1)
569
+ @app.stubs(:options).returns(nil)
567
570
 
571
+ Config.instance.stubs(:color).returns(false)
568
572
  e = mock
569
573
  e.stubs(:backtrace).returns(["rspec"])
570
574
  e.stubs(:to_s).returns("rspec")
571
575
 
572
576
  @app.expects(:options).returns({:verbose => true}).twice
573
- out.expects(:puts).with("#{$0} failed to run: rspec (Mocha::Mock)")
574
- out.expects(:puts).with("\tfrom rspec")
577
+ out.expects(:puts).with(regexp_matches(/ application failed to run, use -v for full error details/))
578
+ out.expects(:puts).with(regexp_matches(/from rspec <---/))
579
+ out.expects(:puts).with(regexp_matches(/rspec.+Mocha::Mock/))
575
580
 
576
581
  @app.application_failure(e, out)
577
582
  end
@@ -111,13 +111,13 @@ module MCollective
111
111
  describe "#list" do
112
112
  it "should load the configuration" do
113
113
  Applications.expects("load_config").returns(true).once
114
- Config.any_instance.expects("libdir").returns([@tmpdir])
114
+ Config.instance.expects("libdir").returns([@tmpdir])
115
115
  Applications.list
116
116
  end
117
117
 
118
118
  it "should add found applications to the list" do
119
119
  Applications.expects("load_config").returns(true).once
120
- Config.any_instance.expects("libdir").returns([@tmpdir])
120
+ Config.instance.expects("libdir").returns([@tmpdir])
121
121
 
122
122
  Applications.list.should == ["test"]
123
123
  end
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ describe Cache do
7
+ before do
8
+ @locks_mutex = Cache.instance_variable_set("@locks_mutex", Mutex.new)
9
+ @cache_locks = Cache.instance_variable_set("@cache_locks", {})
10
+ @cache = Cache.instance_variable_set("@cache", {})
11
+ end
12
+
13
+ describe "#setup" do
14
+ it "should use a mutex to manage access to the cache" do
15
+ @locks_mutex.expects(:synchronize).yields
16
+ Cache.setup("x").should == true
17
+ @cache.should == {"x" => {:max_age => 300.0}}
18
+ end
19
+
20
+ it "should correctly setup a new cache" do
21
+ @locks_mutex.expects(:synchronize).twice.yields
22
+ Cache.setup("rspec1", 300)
23
+ @cache["rspec1"].should == {:max_age => 300.0}
24
+
25
+ Cache.setup("rspec2")
26
+ @cache["rspec2"].should == {:max_age => 300.0}
27
+ end
28
+ end
29
+
30
+ describe "#has_cache?" do
31
+ it "should correctly report presense of a cache" do
32
+ Cache.setup("rspec")
33
+ Cache.has_cache?("rspec").should == true
34
+ Cache.has_cache?("fail").should == false
35
+ end
36
+ end
37
+
38
+ describe "#delete!" do
39
+ it "should delete the cache and return true" do
40
+ Cache.setup("rspec")
41
+ Cache.delete!("rspec").should == true
42
+ end
43
+ end
44
+
45
+ describe "#write" do
46
+ it "should detect unknown caches" do
47
+ expect { Cache.write("rspec", :key, :val) }.to raise_error("No cache called 'rspec'")
48
+ end
49
+
50
+ it "should write to the cache" do
51
+ time = Time.now
52
+ Time.expects(:now).returns(time)
53
+
54
+ Cache.setup("rspec")
55
+ Cache.write("rspec", :key, :val).should == :val
56
+
57
+ @cache["rspec"][:key][:value].should == :val
58
+ @cache["rspec"][:key][:cache_create_time].should == time
59
+ end
60
+ end
61
+
62
+ describe "#read" do
63
+ it "should read a written entry correctly" do
64
+ Cache.setup("rspec")
65
+ Cache.write("rspec", :key, :val)
66
+ Cache.read("rspec", :key).should == :val
67
+ end
68
+
69
+ it "should raise on expired reads" do
70
+ Cache.setup("rspec")
71
+ Cache.write("rspec", :key, :val)
72
+
73
+ Cache.expects(:ttl).returns(0)
74
+
75
+ expect { Cache.read("rspec", :key) }.to raise_error(/has expired/)
76
+ end
77
+ end
78
+
79
+ describe "#valid?" do
80
+ it "should return >0 for valid" do
81
+ Cache.setup("rspec", 300)
82
+ Cache.write("rspec", :key, :val)
83
+ Cache.ttl("rspec", :key).should >= 0
84
+ end
85
+
86
+ it "should return <0 for invalid" do
87
+ Cache.setup("rspec", 300)
88
+ Cache.write("rspec", :key, :val)
89
+
90
+ time = Time.now + 600
91
+ Time.expects(:now).returns(time)
92
+
93
+ Cache.ttl("rspec", :key).should <= 0
94
+ end
95
+ end
96
+
97
+ describe "#synchronize" do
98
+ it "should use the correct mutex" do
99
+ Cache.setup("rspec")
100
+
101
+ rspec_lock = @cache_locks["rspec"]
102
+ rspec_lock.expects(:synchronize).yields
103
+
104
+ @cache_locks.expects("[]").with("rspec").returns(rspec_lock)
105
+
106
+ ran = 0
107
+ Cache.synchronize("rspec") do
108
+ ran = 1
109
+ end
110
+
111
+ ran.should == 1
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ describe Client do
7
+ before do
8
+ @security = mock
9
+ @security.stubs(:initiated_by=)
10
+ @connector = mock
11
+ @connector.stubs(:connect)
12
+ @connector.stubs(:subscribe)
13
+ @connector.stubs(:unsubscribe)
14
+ @ddl = mock
15
+ @ddl.stubs(:meta).returns({:timeout => 1})
16
+ @discoverer = mock
17
+
18
+ Discovery.expects(:new).returns(@discoverer)
19
+
20
+ Config.instance.instance_variable_set("@configured", true)
21
+ PluginManager.expects("[]").with("connector_plugin").returns(@connector)
22
+ PluginManager.expects("[]").with("security_plugin").returns(@security)
23
+
24
+ @client = Client.new("/nonexisting")
25
+ @client.options = Util.default_options
26
+ end
27
+
28
+ describe "#sendreq" do
29
+ it "should send the supplied message" do
30
+ message = Message.new("rspec", nil, {:agent => "rspec", :type => :request, :collective => "mcollective", :filter => Util.empty_filter, :options => Util.default_options})
31
+
32
+ message.expects(:encode!)
33
+ @client.expects(:subscribe).with("rspec", :reply)
34
+ message.expects(:publish)
35
+ message.expects(:requestid).twice
36
+ @client.sendreq(message, "rspec")
37
+ end
38
+
39
+ it "should not subscribe to a reply queue for a message with a reply-to" do
40
+ message = Message.new("rspec", nil, {:agent => "rspec", :type => :request, :collective => "mcollective", :filter => Util.empty_filter, :options => Util.default_options})
41
+ message.reply_to = "rspec"
42
+
43
+ message.expects(:encode!)
44
+ @client.expects(:subscribe).never
45
+ message.expects(:publish)
46
+ message.expects(:requestid).twice
47
+ @client.sendreq(message, "rspec")
48
+ end
49
+ end
50
+ describe "#req" do
51
+ it "should record the requestid" do
52
+ message = Message.new("rspec", nil, {:agent => "rspec", :type => :request, :collective => "mcollective", :filter => Util.empty_filter, :options => Util.default_options})
53
+ message.discovered_hosts = ["rspec"]
54
+
55
+ reply = mock
56
+ reply.stubs("payload").returns("rspec payload")
57
+
58
+ @client.expects(:sendreq).returns("823a3419a0975c3facbde121f72ab61f")
59
+ @client.expects(:receive).returns(reply)
60
+
61
+ @discoverer.stubs(:discovery_timeout).returns(0)
62
+
63
+ Time.stubs(:now).returns(Time.at(1340621250), Time.at(1340621251))
64
+
65
+ @client.req(message){}.should == {:blocktime => 1.0, :discoverytime => 0, :noresponsefrom => [],
66
+ :requestid => "823a3419a0975c3facbde121f72ab61f", :responses => 1,
67
+ :starttime => 1340621250.0, :totaltime => 1.0}
68
+ end
69
+ end
70
+
71
+ describe "#discover" do
72
+ it "should delegate to the discovery plugins" do
73
+ @discoverer.expects(:discover).with({}, 1, 0).returns([])
74
+ @client.discover({}, 1).should == []
75
+ end
76
+ end
77
+ end
78
+ end
@@ -75,73 +75,71 @@ module MCollective
75
75
  Config.instance.loadconfig("/nonexisting")
76
76
  Config.instance.rpchelptemplate.should == "/etc/mcollective/rpc-help.erb"
77
77
  end
78
+
79
+ it "should support multiple default_discovery_options" do
80
+ File.expects(:open).with("/nonexisting", "r").returns(StringIO.new("default_discovery_options = 1\ndefault_discovery_options = 2"))
81
+ File.expects(:exists?).with("/nonexisting").returns(true)
82
+ File.expects(:exists?).with(File.join(File.dirname("/nonexisting"), "rpc-help.erb")).returns(true)
83
+ PluginManager.stubs(:loadclass)
84
+ PluginManager.stubs("<<")
85
+
86
+ Config.instance.loadconfig("/nonexisting")
87
+ Config.instance.default_discovery_options.should == ["1", "2"]
88
+ end
78
89
  end
79
90
 
80
91
  describe "#read_plugin_config_dir" do
81
92
  before do
82
- tmpfile = Tempfile.new("mc_config_spec")
83
- path = tmpfile.path
84
- tmpfile.close!
85
-
86
- @tmpdir = FileUtils.mkdir_p(path)
87
- @tmpdir = @tmpdir[0] if @tmpdir.is_a?(Array) # ruby 1.9.2
93
+ @plugindir = File.join("/", "nonexisting", "plugin.d")
88
94
 
89
- @plugindir = File.join([@tmpdir, "plugin.d"])
90
- FileUtils.mkdir(@plugindir)
95
+ File.stubs(:directory?).with(@plugindir).returns(true)
91
96
 
92
97
  Config.instance.set_config_defaults("")
93
98
  end
94
99
 
95
100
  it "should not fail if the supplied directory is missing" do
96
- Config.instance.read_plugin_config_dir("/nonexisting")
101
+ File.expects(:directory?).with(@plugindir).returns(false)
102
+ Config.instance.read_plugin_config_dir(@plugindir)
97
103
  Config.instance.pluginconf.should == {}
98
104
  end
99
105
 
100
106
  it "should skip files that do not match the expected filename pattern" do
101
- File.open(File.join([@tmpdir, "plugin.d", "foo.txt"]), "w") { }
102
- IO.expects(:open).with(File.join([@tmpdir, "plugin.d", "foo.txt"])).never
107
+ Dir.expects(:new).with(@plugindir).returns(["foo.txt"])
108
+
109
+ IO.expects(:open).with(File.join(@plugindir, "foo.txt")).never
103
110
 
104
111
  Config.instance.read_plugin_config_dir(@plugindir)
105
112
  end
106
113
 
107
114
  it "should load the config files" do
108
- configfile = File.join([@tmpdir, "plugin.d", "foo.cfg"])
109
- File.open(configfile, "w") { }
110
-
111
- File.expects(:open).with(configfile, "r").returns([]).once
115
+ Dir.expects(:new).with(@plugindir).returns(["foo.cfg"])
116
+ File.expects(:open).with(File.join(@plugindir, "foo.cfg"), "r").returns([]).once
112
117
  Config.instance.read_plugin_config_dir(@plugindir)
113
118
  end
114
119
 
115
120
  it "should set config parameters correctly" do
116
- configfile = File.join([@tmpdir, "plugin.d", "foo.cfg"])
117
-
118
- File.open(configfile, "w") do |f|
119
- f.puts "bar = baz"
120
- end
121
-
122
- Config.instance.set_config_defaults(@tmpdir)
121
+ Dir.expects(:new).with(@plugindir).returns(["foo.cfg"])
122
+ File.expects(:open).with(File.join(@plugindir, "foo.cfg"), "r").returns(["rspec = test"])
123
123
  Config.instance.read_plugin_config_dir(@plugindir)
124
- Config.instance.pluginconf.should == {"foo.bar" => "baz"}
124
+ Config.instance.pluginconf.should == {"foo.rspec" => "test"}
125
125
  end
126
126
 
127
127
  it "should override main config file" do
128
- configfile = File.join([@tmpdir, "plugin.d", "foo.cfg"])
129
- servercfg = File.join(@tmpdir, "server.cfg")
130
-
131
- File.open(servercfg, "w") {|f| f.puts "plugin.foo.bar = foo"}
128
+ configfile = File.join(@plugindir, "foo.cfg")
129
+ servercfg = File.join(File.dirname(@plugindir), "server.cfg")
132
130
 
133
131
  PluginManager.stubs(:loadclass)
134
132
 
135
- Config.instance.loadconfig(servercfg)
136
- Config.instance.pluginconf.should == {"foo.bar" => "foo"}
133
+ File.stubs(:exists?).returns(true)
134
+ File.stubs(:directory?).with(@plugindir).returns(true)
135
+ File.stubs(:exists?).with(servercfg).returns(true)
136
+ File.expects(:open).with(servercfg, "r").returns(["plugin.rspec.key = default"])
137
137
 
138
- File.open(configfile, "w") do |f|
139
- f.puts "bar = baz"
140
- end
138
+ Dir.expects(:new).with(@plugindir).returns(["rspec.cfg"])
139
+ File.expects(:open).with(File.join(@plugindir, "rspec.cfg"), "r").returns(["key = overridden"])
141
140
 
142
- PluginManager.delete("global_stats")
143
141
  Config.instance.loadconfig(servercfg)
144
- Config.instance.pluginconf.should == {"foo.bar" => "baz"}
142
+ Config.instance.pluginconf.should == {"rspec.key" => "overridden"}
145
143
  end
146
144
  end
147
145
  end
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ module Data
7
+ describe Base do
8
+ before do
9
+ @ddl = mock
10
+ @ddl.stubs(:meta).returns({:timeout => 1})
11
+ end
12
+
13
+ describe "#initialize" do
14
+ it "should set the plugin name, ddl and timeout and call the startup hook" do
15
+ DDL.stubs(:new).returns(@ddl)
16
+ Base.any_instance.expects(:startup_hook).once
17
+ plugin = Base.new
18
+ plugin.name.should == "base"
19
+ plugin.timeout.should == 1
20
+ plugin.result.class.should == Result
21
+ end
22
+ end
23
+
24
+ describe "#lookup" do
25
+ before do
26
+ DDL.stubs(:new).returns(@ddl)
27
+ @plugin = Base.new
28
+ end
29
+
30
+ it "should validate the request" do
31
+ @plugin.expects(:ddl_validate).with("hello world").returns(true)
32
+ @plugin.stubs(:query_data)
33
+ @plugin.lookup("hello world")
34
+ end
35
+
36
+ it "should query the plugin" do
37
+ @plugin.stubs(:ddl_validate)
38
+ @plugin.expects(:query_data).with("hello world")
39
+ @plugin.lookup("hello world").class.should == Result
40
+ end
41
+
42
+ it "should raise MsgTTLExpired errors for Timeout errors" do
43
+ @plugin.stubs(:ddl_validate)
44
+ @plugin.expects(:query_data).raises(Timeout::Error)
45
+
46
+ msg = "Data plugin base timed out on query 'hello world'"
47
+ Log.expects(:error).with(msg)
48
+ expect { @plugin.lookup("hello world") }.to raise_error(msg)
49
+ end
50
+ end
51
+
52
+ describe "#query" do
53
+ it "should create a new method" do
54
+ class Rspec_data<Base; end
55
+ Rspec_data.query { "rspec test" }
56
+
57
+ DDL.stubs(:new).returns(@ddl)
58
+
59
+ data = Rspec_data.new
60
+ data.query_data.should == "rspec test"
61
+ end
62
+ end
63
+
64
+ describe "#ddl_validate" do
65
+ it "should validate the request using the Data class" do
66
+ DDL.stubs(:new).returns(@ddl)
67
+ plugin = Base.new
68
+ Data.expects(:ddl_validate).with(@ddl, "rspec")
69
+ plugin.ddl_validate("rspec")
70
+ end
71
+ end
72
+
73
+ describe "#activate_when" do
74
+ it "should create a new activate? method" do
75
+ class Rspec_data<Base;end
76
+
77
+ Rspec_data.activate_when { raise "rspec" }
78
+ DDL.stubs(:new).returns(@ddl)
79
+ expect { Rspec_data.activate? }.to raise_error("rspec")
80
+ end
81
+ end
82
+
83
+ describe "#activate?" do
84
+ it "should default to true" do
85
+ Base.activate?.should == true
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ module MCollective
6
+ module Data
7
+ describe Result do
8
+ before(:each) do
9
+ @result = Result.new
10
+ end
11
+
12
+ describe "#[]=" do
13
+ it "should only allow trusted types of data to be saved" do
14
+ expect { @result["rspec"] = Time.now }.to raise_error
15
+ @result["rspec"] = 1
16
+ @result["rspec"] = 1.1
17
+ @result["rspec"] = "rspec"
18
+ @result["rspec"] = true
19
+ @result["rspec"] = false
20
+ end
21
+
22
+ it "should set the correct value" do
23
+ @result["rspec"] = "rspec value"
24
+ @result.instance_variable_get("@data").should == {:rspec => "rspec value"}
25
+ end
26
+ end
27
+
28
+ describe "#include" do
29
+ it "should return the correct list of keys" do
30
+ @result["x"] = "1"
31
+ @result[:y] = "2"
32
+ @result.keys.sort.should == [:x, :y]
33
+ end
34
+ end
35
+
36
+ describe "#include?" do
37
+ it "should correctly report that a key is present or absent" do
38
+ @result.include?("rspec").should == false
39
+ @result.include?(:rspec).should == false
40
+ @result["rspec"] = "rspec"
41
+ @result.include?("rspec").should == true
42
+ @result.include?(:rspec).should == true
43
+ end
44
+ end
45
+
46
+ describe "#[]" do
47
+ it "should retrieve the correct information" do
48
+ @result["rspec"].should == nil
49
+ @result[:rspec].should == nil
50
+ @result["rspec"] = "rspec value"
51
+ @result["rspec"].should == "rspec value"
52
+ @result[:rspec].should == "rspec value"
53
+ end
54
+ end
55
+
56
+ describe "#method_missing" do
57
+ it "should retrieve the correct data" do
58
+ @result["rspec"] = "rspec value"
59
+ @result.rspec.should == "rspec value"
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end