motherbrain 0.0.0.placeholder → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +9 -0
  5. data/CHANGELOG.md +196 -0
  6. data/COMMANDS.md +9 -0
  7. data/CONTRIBUTING.md +24 -0
  8. data/Dockerfile +26 -0
  9. data/Gemfile +60 -2
  10. data/Guardfile +30 -0
  11. data/LICENSE +10 -0
  12. data/MANIFESTS.md +90 -0
  13. data/OPERATORS_GUIDE.md +195 -0
  14. data/PLUGINS.md +268 -0
  15. data/README.md +304 -16
  16. data/Thorfile +123 -0
  17. data/VAGRANT.md +116 -0
  18. data/bin/boot +9 -0
  19. data/bin/mb +5 -0
  20. data/bin/mbsrv +5 -0
  21. data/config.json +32 -0
  22. data/features/cli/bootstrap_command/configurable_scripts.feature +32 -0
  23. data/features/cli/configure_command.feature +57 -0
  24. data/features/cli/environment_command/create_command.feature +22 -0
  25. data/features/cli/environment_command/destroy_command.feature +33 -0
  26. data/features/cli/environment_command/from_command.feature +29 -0
  27. data/features/cli/environment_command/list_command.feature +0 -0
  28. data/features/cli/node_limiting.feature +47 -0
  29. data/features/cli/plugin_command/list_command.feature +46 -0
  30. data/features/cli/service_command/service_command.feature +21 -0
  31. data/features/cli/template_command.feature +10 -0
  32. data/features/cli/validate_config.feature +46 -0
  33. data/features/step_definitions/bootstrap_steps.rb +57 -0
  34. data/features/step_definitions/chef_server_steps.rb +3 -0
  35. data/features/step_definitions/configuration_steps.rb +18 -0
  36. data/features/step_definitions/core_cli_steps.rb +33 -0
  37. data/features/step_definitions/environment_steps.rb +43 -0
  38. data/features/step_definitions/node_steps.rb +3 -0
  39. data/features/step_definitions/plugin_steps.rb +15 -0
  40. data/features/step_definitions/template_steps.rb +7 -0
  41. data/features/support/env.rb +68 -0
  42. data/lib/mb/api.rb +8 -0
  43. data/lib/mb/api/application.rb +7 -0
  44. data/lib/mb/api/endpoint.rb +5 -0
  45. data/lib/mb/api/helpers.rb +38 -0
  46. data/lib/mb/api/v1.rb +56 -0
  47. data/lib/mb/api/v1/config_endpoint.rb +12 -0
  48. data/lib/mb/api/v1/environments_endpoint.rb +174 -0
  49. data/lib/mb/api/v1/jobs_endpoint.rb +31 -0
  50. data/lib/mb/api/v1/plugins_endpoint.rb +90 -0
  51. data/lib/mb/api/validators.rb +5 -0
  52. data/lib/mb/api/validators/sem_ver.rb +18 -0
  53. data/lib/mb/application.rb +148 -0
  54. data/lib/mb/berkshelf.rb +50 -0
  55. data/lib/mb/bootstrap.rb +9 -0
  56. data/lib/mb/bootstrap/manager.rb +250 -0
  57. data/lib/mb/bootstrap/manifest.rb +131 -0
  58. data/lib/mb/bootstrap/routine.rb +199 -0
  59. data/lib/mb/bootstrap/template.rb +73 -0
  60. data/lib/mb/bootstrap/worker.rb +227 -0
  61. data/lib/mb/chef.rb +6 -0
  62. data/lib/mb/chef/config.rb +69 -0
  63. data/lib/mb/chef/run_list_item.rb +115 -0
  64. data/lib/mb/chef_mutex.rb +304 -0
  65. data/lib/mb/clean_room_base.rb +39 -0
  66. data/lib/mb/cli.rb +50 -0
  67. data/lib/mb/cli/base.rb +51 -0
  68. data/lib/mb/cli/shell.rb +29 -0
  69. data/lib/mb/cli/shell/basic.rb +11 -0
  70. data/lib/mb/cli/shell/color.rb +11 -0
  71. data/lib/mb/cli/shell/ext.rb +41 -0
  72. data/lib/mb/cli/sub_command.rb +95 -0
  73. data/lib/mb/cli/sub_command/component.rb +56 -0
  74. data/lib/mb/cli/sub_command/plugin.rb +232 -0
  75. data/lib/mb/cli_client.rb +178 -0
  76. data/lib/mb/cli_gateway.rb +426 -0
  77. data/lib/mb/cli_gateway/sub_commands.rb +3 -0
  78. data/lib/mb/cli_gateway/sub_commands/environment.rb +124 -0
  79. data/lib/mb/cli_gateway/sub_commands/plugin.rb +148 -0
  80. data/lib/mb/command.rb +88 -0
  81. data/lib/mb/command_invoker.rb +235 -0
  82. data/lib/mb/command_invoker/worker.rb +40 -0
  83. data/lib/mb/command_runner.rb +233 -0
  84. data/lib/mb/component.rb +245 -0
  85. data/lib/mb/config.rb +275 -0
  86. data/lib/mb/config_manager.rb +75 -0
  87. data/lib/mb/console.rb +35 -0
  88. data/lib/mb/cookbook_metadata.rb +73 -0
  89. data/lib/mb/core_ext.rb +3 -0
  90. data/lib/mb/core_ext/dir.rb +37 -0
  91. data/lib/mb/core_ext/enumerable.rb +48 -0
  92. data/lib/mb/core_ext/file.rb +24 -0
  93. data/lib/mb/core_ext/signal.rb +11 -0
  94. data/lib/mb/environment_manager.rb +195 -0
  95. data/lib/mb/error_handler.rb +212 -0
  96. data/lib/mb/errors.rb +693 -0
  97. data/lib/mb/file_system.rb +60 -0
  98. data/lib/mb/file_system/tempfile.rb +25 -0
  99. data/lib/mb/gear.rb +154 -0
  100. data/lib/mb/gears.rb +8 -0
  101. data/lib/mb/gears/dynamic_service.rb +218 -0
  102. data/lib/mb/gears/jmx.rb +24 -0
  103. data/lib/mb/gears/jmx/action.rb +46 -0
  104. data/lib/mb/gears/mysql.rb +20 -0
  105. data/lib/mb/gears/mysql/action.rb +190 -0
  106. data/lib/mb/gears/service.rb +163 -0
  107. data/lib/mb/gears/service/action.rb +58 -0
  108. data/lib/mb/gears/service/action_runner.rb +161 -0
  109. data/lib/mb/grape_ext.rb +3 -0
  110. data/lib/mb/grape_ext/endpoint.rb +13 -0
  111. data/lib/mb/group.rb +143 -0
  112. data/lib/mb/job.rb +183 -0
  113. data/lib/mb/job/state_machine.rb +34 -0
  114. data/lib/mb/job/states.rb +46 -0
  115. data/lib/mb/job_manager.rb +96 -0
  116. data/lib/mb/job_record.rb +67 -0
  117. data/lib/mb/job_ticket.rb +25 -0
  118. data/lib/mb/lock_manager.rb +116 -0
  119. data/lib/mb/logging.rb +134 -0
  120. data/lib/mb/logging/basic_format.rb +31 -0
  121. data/lib/mb/manifest.rb +128 -0
  122. data/lib/mb/mixin.rb +3 -0
  123. data/lib/mb/mixin/attribute_setting.rb +265 -0
  124. data/lib/mb/mixin/coded_exit.rb +49 -0
  125. data/lib/mb/mixin/locks.rb +54 -0
  126. data/lib/mb/mixin/services.rb +100 -0
  127. data/lib/mb/node_filter.rb +97 -0
  128. data/lib/mb/node_querier.rb +527 -0
  129. data/lib/mb/plugin.rb +300 -0
  130. data/lib/mb/plugin_manager.rb +589 -0
  131. data/lib/mb/provisioner.rb +186 -0
  132. data/lib/mb/provisioner/manager.rb +213 -0
  133. data/lib/mb/provisioner/manifest.rb +125 -0
  134. data/lib/mb/provisioner/provision_data.rb +96 -0
  135. data/lib/mb/provisioners.rb +5 -0
  136. data/lib/mb/provisioners/aws.rb +395 -0
  137. data/lib/mb/rest_gateway.rb +72 -0
  138. data/lib/mb/ridley_ext.rb +5 -0
  139. data/lib/mb/ridley_ext/cookbook_object.rb +15 -0
  140. data/lib/mb/srv_ctl.rb +183 -0
  141. data/lib/mb/test.rb +104 -0
  142. data/lib/mb/thor_ext.rb +49 -0
  143. data/lib/mb/upgrade.rb +6 -0
  144. data/lib/mb/upgrade/manager.rb +85 -0
  145. data/lib/mb/upgrade/worker.rb +149 -0
  146. data/lib/mb/version.rb +1 -1
  147. data/lib/motherbrain.rb +166 -2
  148. data/man/man_helper.rb +81 -0
  149. data/man/mb.1 +494 -0
  150. data/man/mb.1.html +300 -0
  151. data/man/mb.1.ronn.erb +62 -0
  152. data/motherbrain.gemspec +56 -20
  153. data/scripts/node_name.rb +14 -0
  154. data/spec/fixtures/cb_metadata.json +7 -0
  155. data/spec/fixtures/cb_metadata.rb +14 -0
  156. data/spec/fixtures/fake_id_rsa +27 -0
  157. data/spec/fixtures/fake_key.pem +27 -0
  158. data/spec/fixtures/myface-0.1.0/metadata.rb +14 -0
  159. data/spec/fixtures/myface-0.1.0/motherbrain.rb +0 -0
  160. data/spec/fixtures/test_env.json +15 -0
  161. data/spec/spec_helper.rb +67 -0
  162. data/spec/support/actor_mocking.rb +7 -0
  163. data/spec/support/berkshelf.rb +24 -0
  164. data/spec/support/chef_server.rb +102 -0
  165. data/spec/support/doubles.rb +11 -0
  166. data/spec/support/klass.rb +10 -0
  167. data/spec/support/matchers/each.rb +12 -0
  168. data/spec/support/matchers/error_codes.rb +5 -0
  169. data/spec/support/matchers/exit_codes.rb +57 -0
  170. data/spec/support/matchers/jobs.rb +11 -0
  171. data/spec/support/spec_helpers.rb +145 -0
  172. data/spec/unit/mb/api/application_spec.rb +11 -0
  173. data/spec/unit/mb/api/helpers_spec.rb +5 -0
  174. data/spec/unit/mb/api/v1/config_endpoint_spec.rb +19 -0
  175. data/spec/unit/mb/api/v1/environments_endpoint_spec.rb +71 -0
  176. data/spec/unit/mb/api/v1/jobs_endpoint_spec.rb +24 -0
  177. data/spec/unit/mb/api/v1/plugins_endpoint_spec.rb +298 -0
  178. data/spec/unit/mb/api/v1_spec.rb +37 -0
  179. data/spec/unit/mb/api/validators/sem_ver_spec.rb +5 -0
  180. data/spec/unit/mb/application_spec.rb +19 -0
  181. data/spec/unit/mb/berkshelf_spec.rb +38 -0
  182. data/spec/unit/mb/bootstrap/manager_spec.rb +347 -0
  183. data/spec/unit/mb/bootstrap/manifest_spec.rb +333 -0
  184. data/spec/unit/mb/bootstrap/routine_spec.rb +393 -0
  185. data/spec/unit/mb/bootstrap/template_spec.rb +100 -0
  186. data/spec/unit/mb/bootstrap/worker_spec.rb +194 -0
  187. data/spec/unit/mb/chef/config_spec.rb +33 -0
  188. data/spec/unit/mb/chef/run_list_item_spec.rb +34 -0
  189. data/spec/unit/mb/chef_mutex_spec.rb +314 -0
  190. data/spec/unit/mb/clean_room_base_spec.rb +31 -0
  191. data/spec/unit/mb/cli/base_spec.rb +43 -0
  192. data/spec/unit/mb/cli/shell/basic_spec.rb +5 -0
  193. data/spec/unit/mb/cli/shell/color_spec.rb +5 -0
  194. data/spec/unit/mb/cli/shell/ext_spec.rb +11 -0
  195. data/spec/unit/mb/cli/shell_spec.rb +38 -0
  196. data/spec/unit/mb/cli/sub_command/base_spec.rb +102 -0
  197. data/spec/unit/mb/cli/sub_command/component_spec.rb +5 -0
  198. data/spec/unit/mb/cli/sub_command/plugin_spec.rb +91 -0
  199. data/spec/unit/mb/cli/sub_command_spec.rb +43 -0
  200. data/spec/unit/mb/cli/ui.rb +0 -0
  201. data/spec/unit/mb/cli_client_spec.rb +51 -0
  202. data/spec/unit/mb/cli_gateway_spec.rb +386 -0
  203. data/spec/unit/mb/command_invoker/worker_spec.rb +43 -0
  204. data/spec/unit/mb/command_invoker_spec.rb +230 -0
  205. data/spec/unit/mb/command_runner_spec.rb +299 -0
  206. data/spec/unit/mb/command_spec.rb +76 -0
  207. data/spec/unit/mb/component_spec.rb +185 -0
  208. data/spec/unit/mb/config_manager_spec.rb +31 -0
  209. data/spec/unit/mb/config_spec.rb +408 -0
  210. data/spec/unit/mb/cookbook_metadata_spec.rb +89 -0
  211. data/spec/unit/mb/core_ext/dir_spec.rb +92 -0
  212. data/spec/unit/mb/core_ext/enumerable_spec.rb +104 -0
  213. data/spec/unit/mb/core_ext/file_spec.rb +58 -0
  214. data/spec/unit/mb/core_ext/signal_spec.rb +24 -0
  215. data/spec/unit/mb/environment_manager_spec.rb +166 -0
  216. data/spec/unit/mb/error_handler_spec.rb +173 -0
  217. data/spec/unit/mb/errors_spec.rb +132 -0
  218. data/spec/unit/mb/file_system/tempfile_spec.rb +14 -0
  219. data/spec/unit/mb/file_system_spec.rb +69 -0
  220. data/spec/unit/mb/gear_spec.rb +125 -0
  221. data/spec/unit/mb/gears/dynamic_service_spec.rb +187 -0
  222. data/spec/unit/mb/gears/jmx/action_spec.rb +34 -0
  223. data/spec/unit/mb/gears/jmx_spec.rb +32 -0
  224. data/spec/unit/mb/gears/mysql/action_spec.rb +118 -0
  225. data/spec/unit/mb/gears/mysql_spec.rb +21 -0
  226. data/spec/unit/mb/gears/service/action_runner_spec.rb +182 -0
  227. data/spec/unit/mb/gears/service/action_spec.rb +44 -0
  228. data/spec/unit/mb/gears/service_spec.rb +124 -0
  229. data/spec/unit/mb/group_spec.rb +280 -0
  230. data/spec/unit/mb/job_manager_spec.rb +56 -0
  231. data/spec/unit/mb/job_record_spec.rb +60 -0
  232. data/spec/unit/mb/job_spec.rb +201 -0
  233. data/spec/unit/mb/locks_manager_spec.rb +88 -0
  234. data/spec/unit/mb/logging_spec.rb +133 -0
  235. data/spec/unit/mb/manifest_spec.rb +105 -0
  236. data/spec/unit/mb/mixin/attribute_setting_spec.rb +180 -0
  237. data/spec/unit/mb/mixin/coded_exit_spec.rb +25 -0
  238. data/spec/unit/mb/mixin/locks_spec.rb +32 -0
  239. data/spec/unit/mb/mixin/services_spec.rb +75 -0
  240. data/spec/unit/mb/node_filter_spec.rb +86 -0
  241. data/spec/unit/mb/node_querier_spec.rb +532 -0
  242. data/spec/unit/mb/plugin_manager_spec.rb +724 -0
  243. data/spec/unit/mb/plugin_spec.rb +247 -0
  244. data/spec/unit/mb/provisioner/manager_spec.rb +141 -0
  245. data/spec/unit/mb/provisioner/manifest_spec.rb +182 -0
  246. data/spec/unit/mb/provisioner/provision_data_spec.rb +113 -0
  247. data/spec/unit/mb/provisioner_spec.rb +251 -0
  248. data/spec/unit/mb/provisioners/aws_spec.rb +392 -0
  249. data/spec/unit/mb/provisioners/environment_factory_spec.rb +108 -0
  250. data/spec/unit/mb/rest_gateway_spec.rb +13 -0
  251. data/spec/unit/mb/ridley_ext/cookbook_object_spec.rb +105 -0
  252. data/spec/unit/mb/srv_ctl_spec.rb +142 -0
  253. data/spec/unit/mb/upgrade/manager_spec.rb +37 -0
  254. data/spec/unit/mb/upgrade/worker_spec.rb +219 -0
  255. data/spec/unit/motherbrain_spec.rb +58 -0
  256. data/templates/bootstrap.json +8 -0
  257. data/templates/motherbrain.rb +44 -0
  258. metadata +694 -15
  259. data/Rakefile +0 -1
@@ -0,0 +1,299 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::CommandRunner do
4
+ subject { command_runner }
5
+
6
+ let(:command_runner) {
7
+ described_class.new(job, environment, scope, command_block, node_filter)
8
+ }
9
+
10
+ let(:scope) { MB::Plugin.new(double(valid?: true)) }
11
+
12
+ let(:action_1) { double('action_1', name: "action 1", run: nil) }
13
+ let(:action_2) { double('action_2', name: "action 2", run: nil) }
14
+
15
+ let(:actions) { [action_1, action_2] }
16
+
17
+ let(:node_1) { double('node_1', name: 'a.riotgames.com', public_hostname: 'a.riotgames.com') }
18
+ let(:node_2) { double('node_2', name: 'b.riotgames.com', public_hostname: 'b.riotgames.com') }
19
+ let(:node_3) { double('node_3', name: 'c.riotgames.com', public_hostname: 'c.riotgames.com') }
20
+ let(:nodes) { [node_1, node_2, node_3] }
21
+ let(:node_filter) { nil }
22
+
23
+ let(:master_group) { double('master_group', nodes: [node_1, node_2]) }
24
+ let(:slave_group) { double('slave_group', nodes: [node_3]) }
25
+
26
+ let(:environment) { "rspec-test" }
27
+ let(:job) { double('job', set_status: nil) }
28
+ let(:component) { double('component', name: "foo") }
29
+ let(:args) { }
30
+ let(:command_block) {
31
+ proc {
32
+ on("master_group") do
33
+ # block
34
+ end
35
+ }
36
+ }
37
+
38
+ before(:each) do
39
+ MB::CommandRunner::CleanRoom.stub_chain(:new, :actions).and_return(actions)
40
+
41
+ scope.stub(:group!).with("master_group").and_return(master_group)
42
+ end
43
+
44
+ describe "#on" do
45
+ context "with no block" do
46
+ let(:command_block) {
47
+ proc { on("master_group") }
48
+ }
49
+
50
+ it "should raise an exception" do
51
+ -> { command_runner }.should raise_error(MB::PluginSyntaxError)
52
+ end
53
+ end
54
+
55
+ it "has a single group" do
56
+ scope.should_receive(:group!).with("master_group").and_return(master_group)
57
+
58
+ actions.each do |action|
59
+ action.
60
+ should_receive(:run).
61
+ with(job, environment, master_group.nodes, true)
62
+ end
63
+
64
+ command_runner
65
+ end
66
+
67
+ context "with multiple groups" do
68
+ let(:command_block) {
69
+ proc {
70
+ on("master_group", "slave_group") do
71
+ # block
72
+ end
73
+ }
74
+ }
75
+
76
+ it "works" do
77
+ scope.should_receive(:group!).with("master_group").and_return(master_group)
78
+ scope.should_receive(:group!).with("slave_group").and_return(slave_group)
79
+
80
+ actions.each do |action|
81
+ action.should_receive(:run).with(job, environment, nodes, true)
82
+ end
83
+
84
+ command_runner
85
+ end
86
+ end
87
+
88
+ context "with multiple groups and an option" do
89
+ let(:command_block) {
90
+ proc {
91
+ on("master_group", "slave_group", max_concurrent: 1) do
92
+ # block
93
+ end
94
+ }
95
+ }
96
+
97
+ it "works" do
98
+ scope.should_receive(:group!).with("master_group").and_return(master_group)
99
+ scope.should_receive(:group!).with("slave_group").and_return(slave_group)
100
+
101
+ actions.each do |action|
102
+ action.should_receive(:run).with(job, environment, [anything()], true).exactly(3).times
103
+ end
104
+
105
+ command_runner
106
+ end
107
+ end
108
+
109
+ context "with any: 1" do
110
+ let(:command_block) {
111
+ proc {
112
+ on("master_group", any: 1) do
113
+ # block
114
+ end
115
+ }
116
+ }
117
+
118
+ it "works" do
119
+ scope.should_receive(:group!).with("master_group").and_return(master_group)
120
+
121
+ actions.each do |action|
122
+ action.should_receive(:run).with(job, environment, [anything()], true)
123
+ end
124
+
125
+ command_runner
126
+ end
127
+ end
128
+
129
+ context "with max_concurrent: 1" do
130
+ let(:command_block) {
131
+ proc {
132
+ on("master_group", max_concurrent: 1) do
133
+ # block
134
+ end
135
+ }
136
+ }
137
+
138
+ it "runs only on one node at a time" do
139
+ scope.should_receive(:group!).with("master_group").and_return(master_group)
140
+
141
+ actions.each do |action|
142
+ action.should_receive(:run).with(job, environment, [node_1], true)
143
+ action.should_receive(:run).with(job, environment, [node_2], true)
144
+ end
145
+
146
+ command_runner
147
+ end
148
+ end
149
+
150
+ context "with multiple on blocks" do
151
+ let(:command_block) {
152
+ proc {
153
+ on("master_group", max_concurrent: 1) do
154
+ # block
155
+ end
156
+
157
+ on("slave_group") do
158
+ # block
159
+ end
160
+ }
161
+ }
162
+
163
+ it "works" do
164
+ scope.should_receive(:group!).with("master_group").and_return(master_group)
165
+ scope.should_receive(:group!).with("slave_group").and_return(slave_group)
166
+
167
+ actions.each do |action|
168
+ action.should_receive(:run).with(job, environment, [node_1], true).once
169
+ action.should_receive(:run).with(job, environment, [node_2], true).once
170
+ action.should_receive(:run).with(job, environment, [node_3], true).once
171
+ end
172
+
173
+ command_runner
174
+ end
175
+ end
176
+ end
177
+
178
+ describe "#async" do
179
+ let(:command_block) {
180
+ proc {
181
+ async do
182
+ on("master_group", max_concurrent: 1) do
183
+ # block
184
+ end
185
+
186
+ on("slave_group") do
187
+ # block
188
+ end
189
+ end
190
+ }
191
+ }
192
+
193
+ it "is ran asynchronously" do
194
+ scope.should_receive(:group!).with("master_group").and_return(master_group)
195
+ scope.should_receive(:group!).with("slave_group").and_return(slave_group)
196
+
197
+ actions.each { |action| action.should_receive(:run).exactly(3).times }
198
+
199
+ node_querier.should_receive(:bulk_chef_run)
200
+
201
+ command_runner
202
+ end
203
+
204
+ context "when there are no nodes in the target groups" do
205
+ let(:empty_group) { double('empty_group', nodes: Array.new) }
206
+ let(:command_block) {
207
+ proc {
208
+ async do
209
+ on("empty_group") do
210
+ # block
211
+ end
212
+ end
213
+ }
214
+ }
215
+
216
+ it "runs no actions" do
217
+ scope.should_receive(:group!).with("empty_group").and_return(empty_group)
218
+
219
+ actions.each { |action| action.should_not_receive(:run) }
220
+
221
+ command_runner
222
+ end
223
+ end
224
+
225
+ context "with a wait command" do
226
+ let(:empty_group) { double('empty_group', nodes: Array.new) }
227
+ let(:command_block) {
228
+ proc {
229
+ on("empty_group") do
230
+ wait 1
231
+ end
232
+ }
233
+ }
234
+
235
+ it "sleeps" do
236
+ pending "Unsure which mock is receiving #wait"
237
+
238
+ Celluloid.should_receive(:sleep).with(1)
239
+
240
+ command_runner
241
+ end
242
+ end
243
+ end
244
+
245
+ describe "#component" do
246
+ let(:proxy) { command_runner.component("foo") }
247
+
248
+ before do
249
+ scope.should_receive(:component).with("foo").and_return(component)
250
+ end
251
+
252
+ it "returns a proxy" do
253
+ proxy.should be_an_instance_of(MB::CommandRunner::InvokableComponent)
254
+ end
255
+
256
+ it "sets the component on the proxy" do
257
+ proxy.component.should eq(component)
258
+ end
259
+
260
+ it "invokes the real component" do
261
+ component.should_receive(:invoke).with(job, environment, "bar", [])
262
+ proxy.invoke("bar")
263
+ end
264
+ end
265
+
266
+ describe "#command" do
267
+ let(:command) do
268
+ MB::Command.new("foo", scope) do
269
+ description "test command"
270
+ execute do
271
+ # nothing
272
+ end
273
+ end
274
+ end
275
+
276
+ it "is invoked" do
277
+ scope.should_receive(:group!).with("master_group").and_return(master_group)
278
+ scope.should_receive(:command!).with("foo").and_return(command)
279
+
280
+ command_runner.command("foo")
281
+ end
282
+ end
283
+
284
+ describe MB::CommandRunner::InvokableComponent do
285
+ subject { invokable_component }
286
+
287
+ let(:invokable_component) {
288
+ MB::CommandRunner::InvokableComponent.new(job, environment, component)
289
+ }
290
+
291
+ describe "#invoke" do
292
+ it "invokes the component" do
293
+ component.should_receive :invoke
294
+
295
+ invokable_component.invoke("test")
296
+ end
297
+ end
298
+ end
299
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::Command do
4
+ describe "ClassMethods" do
5
+ subject { described_class }
6
+
7
+ describe "::new" do
8
+ let(:name) { "stop" }
9
+ let(:scope) { double }
10
+ let(:plugin) { MB::Plugin.new(double(valid?: true)) }
11
+ let(:component) { MB::Component.new("default", plugin) }
12
+
13
+ subject { described_class.new(name, scope) }
14
+
15
+ context "given an instance of MB::Component for scope" do
16
+ let(:scope) { component }
17
+
18
+ it "has a command type of :component" do
19
+ subject.type.should eql(:component)
20
+ end
21
+
22
+ it "has a plugin matching the component's plugin" do
23
+ subject.plugin.should eql(component.plugin)
24
+ end
25
+ end
26
+
27
+ context "given an instance of MB::Plugin for scope" do
28
+ let(:scope) { plugin }
29
+
30
+ it "has a command type of :plugin" do
31
+ subject.type.should eql(:plugin)
32
+ end
33
+
34
+ it "has a plugin matching the given scope" do
35
+ subject.plugin.should eql(plugin)
36
+ end
37
+ end
38
+
39
+ context "given an instance of an object that does not fit into a scope type" do
40
+ let(:scope) { double }
41
+
42
+ it "raises a RuntimeError" do
43
+ expect {
44
+ subject
45
+ }.to raise_error(RuntimeError)
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ subject { command }
52
+
53
+ let(:command) do
54
+ described_class.new("start", scope) do
55
+ description "start all services"
56
+ execute do; true; end
57
+ end
58
+ end
59
+
60
+ let(:metadata) do
61
+ double('metadata',
62
+ name: "rspec-test",
63
+ version: "1.2.3"
64
+ )
65
+ end
66
+
67
+ let(:scope) { MB::Plugin.new(metadata) }
68
+
69
+ its(:name) { should eql("start") }
70
+ its(:description) { should eql("start all services") }
71
+ its(:execute) { should be_a Proc }
72
+
73
+ describe "#invoke" do
74
+ pending
75
+ end
76
+ end
@@ -0,0 +1,185 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::Component do
4
+ let(:environment) { 'mb-test' }
5
+ let(:chef_conn) { double('chef_conn') }
6
+ let(:plugin) { double(MB::Plugin) }
7
+
8
+ subject { component }
9
+
10
+ let(:component) {
11
+ MB::Component.new("activemq", plugin) do
12
+ group "masters" do
13
+ # block
14
+ end
15
+ end
16
+ }
17
+
18
+ describe "#command" do
19
+ let(:component) do
20
+ MB::Component.new("activemq", plugin) do
21
+ command "existing" do
22
+ # block
23
+ end
24
+ end
25
+ end
26
+
27
+ subject { component.command(name) }
28
+
29
+ context "when the component has a command matching the given name" do
30
+ let(:name) { "existing" }
31
+
32
+ it { should be_a(MB::Command) }
33
+ it { name.should eql("existing") }
34
+ end
35
+
36
+ context "when the component does not have a command matching the given name" do
37
+ let(:name) { "not-there" }
38
+
39
+ it { should be_nil }
40
+ end
41
+ end
42
+
43
+ describe "#command!" do
44
+ before do
45
+ subject.stub(command: nil)
46
+ end
47
+
48
+ it "raises a CommandNotFound error when no matching command is present" do
49
+ expect {
50
+ subject.command!("stop")
51
+ }.to raise_error(MB::CommandNotFound)
52
+ end
53
+ end
54
+
55
+ describe "#description" do
56
+ subject { component.description }
57
+
58
+ it { should eq("activemq component commands") }
59
+
60
+ context "with a description" do
61
+ let(:component) {
62
+ MB::Component.new("activemq", plugin) do
63
+ description "ActiveMQ"
64
+ end
65
+ }
66
+
67
+ it { should eq("ActiveMQ") }
68
+ end
69
+ end
70
+
71
+ describe "#groups" do
72
+ subject do
73
+ MB::Component.new("activemq", plugin) do
74
+ group "masters" do
75
+ # block
76
+ end
77
+ end
78
+ end
79
+
80
+ it "returns a Set of Group objects" do
81
+ subject.groups.should be_a(Set)
82
+ subject.groups.should each be_a(MB::Group)
83
+ end
84
+ end
85
+
86
+ describe "#group" do
87
+ subject do
88
+ MB::Component.new("activemq", plugin) do
89
+ group "masters" do
90
+ # block
91
+ end
92
+ end
93
+ end
94
+
95
+ it "returns the group matching the given name" do
96
+ subject.group("masters").name.should eql("masters")
97
+ end
98
+ end
99
+
100
+ describe "#group!" do
101
+ subject do
102
+ MB::Component.new("activemq", plugin) do
103
+ group "masters" do
104
+ # block
105
+ end
106
+ end
107
+ end
108
+
109
+ it "returns the group matching the given name" do
110
+ subject.group!("masters").name.should eql("masters")
111
+ end
112
+
113
+ it "raises an exception on a missing group" do
114
+ lambda { subject.group!("slaves") }.should raise_error(MB::GroupNotFound)
115
+ end
116
+ end
117
+
118
+ describe "#nodes" do
119
+ pending
120
+ end
121
+
122
+ describe "#add_group" do
123
+ pending
124
+ end
125
+
126
+ describe "#service" do
127
+ subject { MB::Component }
128
+
129
+ it "returns a Set of services" do
130
+ component = subject.new("activemq", plugin) do
131
+ service "masters" do
132
+ # block
133
+ end
134
+ end
135
+
136
+ component.gears(MB::Gear::Service).should be_a(Set)
137
+ end
138
+
139
+ it "contains each service defined" do
140
+ component = subject.new("activemq", plugin) do
141
+ service "masters" do
142
+ # block
143
+ end
144
+ end
145
+
146
+ component.gears(MB::Gear::Service).should have(1).item
147
+ end
148
+
149
+ it "does not allow duplicate services" do
150
+ lambda do
151
+ subject.new("activemq", plugin) do
152
+ service "masters" do
153
+ # block
154
+ end
155
+
156
+ service "masters" do
157
+ # block
158
+ end
159
+ end
160
+ end.should raise_error(MB::DuplicateGear)
161
+ end
162
+ end
163
+
164
+ describe "#versioned" do
165
+ context "when passed nothing" do
166
+ subject {
167
+ klass.new("component_name", plugin) do
168
+ versioned
169
+ end
170
+ }
171
+
172
+ its(:version_attribute) { should == "component_name.version" }
173
+ end
174
+
175
+ context "when passed an attribute name" do
176
+ subject {
177
+ klass.new("versioned_component", plugin) do
178
+ versioned_with "my.custom.attribute"
179
+ end
180
+ }
181
+
182
+ its(:version_attribute) { should == "my.custom.attribute" }
183
+ end
184
+ end
185
+ end