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,7 @@
1
+ {"name": "motherbrain",
2
+ "maintainer": "Jamie Winsor",
3
+ "maintainer_email": "jamie@vialstudios.com",
4
+ "license": "Apache 2.0",
5
+ "description": "Installs/Configures motherbrain",
6
+ "long_description": "Installs/Configures motherbrain",
7
+ "version": "0.1.0"}
@@ -0,0 +1,14 @@
1
+ name "motherbrain"
2
+ maintainer "Jamie Winsor"
3
+ maintainer_email "jamie@vialstudios.com"
4
+ license "Apache 2.0"
5
+ description "Installs/Configures motherbrain"
6
+ long_description "Installs/Configures motherbrain"
7
+ version "0.1.0"
8
+
9
+ %w{ centos }.each do |os|
10
+ supports os
11
+ end
12
+
13
+ depends "nginx", "~> 1.0.0"
14
+ depends "artifact", "~> 0.11.5"
@@ -0,0 +1,27 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEpAIBAAKCAQEA2jE12CeifIMSlLkbqzVlS3esfZQNTU3hh5djO+KEi+10HJsO
3
+ 6P571TvbFYZT3NQ2km72zrYscNABVmvg+K36EkPQ+NzlhfX1zRLvKRs9eVoG+mBy
4
+ yXSGL3bXYB9tWC2sBEO/aOoJShk1H8rlknO8vi/9fCC4DvMrCm3CtPzLybfqF/q1
5
+ HYDXfxQtAAy3RqKQWLpKeHsjd4TnmG7LA9rFirrLdkyBPueYP20BjLN9DrPO8yFb
6
+ PLphvVM+xbrNzSw/cwOVii1bqSSOt9e8OVaKM1AiFo1t/GfAbtac2i68Amwuj5QM
7
+ 0G++UTg+BEubDw9zLiWRSmyLZo71nsY1kA/kdQIDAQABAoIBAQDT2m4ud6VkAhw7
8
+ fVQpM4or8YHw2Jzlz1XIwqwejD0oZCGWWNPsVJPGIf0B9FBfHUnzenx3jxitXLm/
9
+ wLVKoBosO96elFTjckL8oILIxeM1fb1Cw/0QL+zODzTl5v3TXV0lMuaaJotof/s9
10
+ 6FJplajQfWZBbL9p/J9w28vu0XnJW9ZawXeTQbg7XppFjcXDVfeY+AjSRFV5/+ZD
11
+ RG0QT7kS0IaRObk4MeiNix5L7nCnRPE2NZcWhUNuelRPWsi828vvC4AY+6N6bwB5
12
+ O4+Y+hX/ThgnzEThMG1zQwummIJ5M/OYzLvuEC7fpgbsOGVI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YTnJ
18
+ kaLAN8uCoLKr6JH9tq3DfXIfDIHiZ+BOIvI070fDAoGBAMDyzEDFmGruTyRLj66u
19
+ +rJnVVmqlKwxhLhrS+CTj74nlVOnt0a0KMhiM65IRqnPwcHUG5zXBPaUTHXwAS93
20
+ /nFPwQ37hLPOupPnoVNJZRZrowbyPBQtCJbDMURv64ylHqoBCQDoCd0hANnZvMMX
21
+ BrFVhfaaibaXXS542r6SD/27AoGAECadHE5kJTdOOBcwK/jo3Fa8g1J9Y/8yvum3
22
+ wBT69V9clS6T5j08geglvDnqAh7UzquKBEnFi1NKw+wmXkKLcrivaTdEfApavYb3
23
+ AfHKoGue907jC3Y5Mcquq81ds2J7qTEwz1eKLzfo1yjj32ShvrmwALIuhDn1GjUC
24
+ 6qtx938CgYEApEqvu0nocR1jmVVlLe5uKQBj949dh6NGq0R5Lztz6xufaTYzMC3d
25
+ AZG9XPPjRqSLs+ylSXJpwHEwoeyLFDaJcO+GgW1/ut4MC2HppOx6aImwDdXMHUWR
26
+ KYGIFF4AU/IYoBcanAm4s078EH/Oz01B2c7tR2TqabisPgLYe7PXSCw=
27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,14 @@
1
+ name "myface"
2
+ maintainer "Jamie Winsor"
3
+ maintainer_email "jamie@vialstudios.com"
4
+ license "Apache 2.0"
5
+ description "Installs/Configures myface"
6
+ long_description "Installs/Configures myface"
7
+ version "0.1.0"
8
+
9
+ %w{ centos }.each do |os|
10
+ supports os
11
+ end
12
+
13
+ depends "nginx", "~> 1.0.0"
14
+ depends "artifact", "~> 0.11.5"
File without changes
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "test_env",
3
+ "description": "test environment",
4
+ "cookbook_versions": {
5
+ "mb_base": "2.6.40"
6
+ },
7
+ "json_class": "Chef::Environment",
8
+ "chef_type": "environment",
9
+ "default_attributes": {
10
+ "motherbrain": true
11
+ },
12
+ "override_attributes": {
13
+ "awesome_level": 7
14
+ }
15
+ }
@@ -0,0 +1,67 @@
1
+ ENV['RUBY_ENV'] ||= 'test'
2
+ ENV['MOTHERBRAIN_PATH'] ||= File.join(File.expand_path(File.dirname(__FILE__)), "tmp/.mb")
3
+ ENV['BERKSHELF_PATH'] ||= File.join(File.expand_path(File.dirname(__FILE__)), "tmp/.berkshelf")
4
+ ENV['CHEF_API_URL'] = 'http://localhost:28890'
5
+
6
+ require 'rubygems'
7
+ require 'bundler'
8
+ require 'rspec'
9
+ require 'json_spec'
10
+ require 'webmock/rspec'
11
+ require 'rack/test'
12
+ require 'motherbrain'
13
+ require 'chef_zero/server'
14
+
15
+ def setup_rspec
16
+ Dir[File.join(File.expand_path("../../spec/support/**/*.rb", __FILE__))].each { |f| require f }
17
+
18
+ RSpec.configure do |config|
19
+ config.include JsonSpec::Helpers
20
+ config.include MotherBrain::RSpec::Doubles
21
+ config.include MotherBrain::Matchers
22
+ config.include MotherBrain::SpecHelpers
23
+ config.include MotherBrain::RSpec::Berkshelf
24
+ config.include MotherBrain::RSpec::ChefServer
25
+ config.include MotherBrain::Mixin::Services
26
+
27
+ config.mock_with :rspec
28
+ config.treat_symbols_as_metadata_keys_with_true_values = true
29
+ config.filter_run focus: true
30
+ config.run_all_when_everything_filtered = true
31
+
32
+ config.before(:suite) do
33
+ WebMock.disable_net_connect!(allow_localhost: true, net_http_connect_on_start: true)
34
+ MB::RSpec::ChefServer.start
35
+ end
36
+
37
+ config.before(:all) do
38
+ Celluloid.shutdown
39
+ @config = generate_valid_config
40
+ @app = MB::Application.run!(@config)
41
+ MB::Logging.setup(location: '/dev/null')
42
+ end
43
+
44
+ config.before(:each) do
45
+ clean_tmp_path
46
+ MB::RSpec::ChefServer.server.clear_data
47
+ end
48
+ end
49
+ end
50
+
51
+ if jruby?
52
+ setup_rspec
53
+ else
54
+ require 'spork'
55
+
56
+ Spork.prefork do
57
+ setup_rspec
58
+ end
59
+
60
+ Spork.each_run do
61
+ require 'motherbrain'
62
+
63
+ # Required to ensure Celluloid boots properly on each run
64
+ Celluloid::Notifications::Fanout.supervise_as :notifications_fanout
65
+ Celluloid::IncidentReporter.supervise_as :default_incident_reporter, STDERR
66
+ end
67
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.configuration.before(:each) do
2
+ class Celluloid::ActorProxy
3
+ [ :should_receive, :should_not_receive, :stub, :stub_chain, :should, :should_not ].each do |method|
4
+ undef_method(method) if method_defined?(method)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'spec_helpers'
2
+
3
+ module MotherBrain::RSpec
4
+ module Berkshelf
5
+ include MB::SpecHelpers
6
+
7
+ # @param [String] name
8
+ # name of the cookbook
9
+ # @param [String] version
10
+ # version of the cookbook
11
+ #
12
+ # @option options [Boolean] :with_plugin
13
+ # if this cookbook should contain a motherbrain plugin
14
+ #
15
+ # @return [String]
16
+ def install_cookbook(name, version, options = {})
17
+ options = options.reverse_merge(with_plugin: true)
18
+ options[:path] = MB::Berkshelf.path.join("cookbooks", "#{name}-#{version}")
19
+ options[:version] = version
20
+
21
+ generate_cookbook(name, options)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,102 @@
1
+ require 'chef_zero/server'
2
+ require_relative 'spec_helpers'
3
+
4
+ module MotherBrain::RSpec
5
+ module ChefServer
6
+ class << self
7
+ def clear_data
8
+ server.clear_data
9
+ end
10
+
11
+ def clear_request_log
12
+ @request_log = Array.new
13
+ end
14
+
15
+ def port
16
+ if ENV['CHEF_API_URL']
17
+ ENV['CHEF_API_URL'].split(?:).last.to_i
18
+ else
19
+ 28890
20
+ end
21
+ end
22
+
23
+ def request_log
24
+ @request_log ||= Array.new
25
+ end
26
+
27
+ def server
28
+ @server ||= ChefZero::Server.new(port: port, generate_real_keys: false)
29
+ end
30
+
31
+ def server_url
32
+ (@server && @server.url) || "http://localhost:#{port}"
33
+ end
34
+
35
+ def start
36
+ return if running?
37
+
38
+ server.start_background
39
+ server.on_response do |request, response|
40
+ request_log << [ request, response ]
41
+ end
42
+ clear_request_log
43
+
44
+ @running = true
45
+
46
+ server
47
+ end
48
+
49
+ def stop
50
+ @server.stop if @server
51
+ end
52
+
53
+ def running?
54
+ @running
55
+ end
56
+ end
57
+
58
+ include MotherBrain::SpecHelpers
59
+ include MotherBrain::RSpec::Berkshelf
60
+
61
+ def chef_client(name, hash = Hash.new)
62
+ load_data(:clients, name, hash)
63
+ end
64
+
65
+ def chef_cookbook(name, version, options = {})
66
+ options = options.reverse_merge(with_plugin: true)
67
+ options[:version] = version
68
+ options[:path] = tmp_path.join("cookbook-#{name}-#{version}")
69
+
70
+ ridley_zero do |r|
71
+ r.cookbook.upload(generate_cookbook(name, options))
72
+ end
73
+ end
74
+
75
+ def chef_data_bag(name, hash = Hash.new)
76
+ ChefServer.server.load_data({ 'data' => { name => hash }})
77
+ end
78
+
79
+ def chef_environment(name, hash = Hash.new)
80
+ load_data(:environments, name, hash)
81
+ end
82
+
83
+ def chef_node(name, hash = Hash.new)
84
+ load_data(:nodes, name, hash)
85
+ end
86
+
87
+ def chef_role(name, hash = Hash.new)
88
+ load_data(:roles, name, hash)
89
+ end
90
+
91
+ def ridley_zero(&block)
92
+ Ridley::Client.open(server_url: ChefServer.server_url, client_name: "reset",
93
+ client_key: fixtures_path.join('fake_key.pem').to_s, &block)
94
+ end
95
+
96
+ private
97
+
98
+ def load_data(key, name, hash)
99
+ ChefServer.server.load_data(key.to_s => { name => JSON.fast_generate(hash) })
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,11 @@
1
+ module MotherBrain
2
+ module RSpec
3
+ # Pre-defined commonly used doubles for testing motherbrain
4
+ module Doubles
5
+ def job_double(name = "job")
6
+ double(name, alive?: true, terminate: nil, set_status: nil, report_running: nil,
7
+ report_failure: nil, report_pending: nil, report_success: nil, report_boolean: nil)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module KlassHelper
2
+ def klass
3
+ described_class
4
+ end
5
+ end
6
+
7
+ RSpec.configure do |config|
8
+ config.include KlassHelper
9
+ end
10
+
@@ -0,0 +1,12 @@
1
+ RSpec::Matchers.define :each do |check|
2
+ match do |actual|
3
+ actual.each_with_index do |index, o|
4
+ @object = o
5
+ index.should check
6
+ end
7
+ end
8
+
9
+ failure_message_for_should do |actual|
10
+ "at[#{@object}] #{check.failure_message_for_should}"
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ RSpec::Matchers.define :be_error_code do |error_constant|
2
+ match do |actual|
3
+ error_constant.error_code == actual
4
+ end
5
+ end
@@ -0,0 +1,57 @@
1
+ module MotherBrain
2
+ module Matchers
3
+ class ExitCodes
4
+ include MB::Mixin::CodedExit
5
+
6
+ def initialize(target_err)
7
+ @target_err = target_err
8
+ @actual_err = nil
9
+ end
10
+
11
+ def matches?(given_proc)
12
+ given_proc.call
13
+ rescue SystemExit => @actual_err
14
+ return false unless target_has_exit_code?
15
+
16
+ @actual_status = @actual_err.status
17
+ @target_status = @target_err.exit_code
18
+
19
+ if @actual_status.nil? || @target_status.nil?
20
+ return false
21
+ end
22
+
23
+ return @actual_status == @target_status
24
+ end
25
+
26
+ def failure_message_for_should
27
+ unless target_has_exit_code?
28
+ msg = "the program exited but the exception the exception you you gave does not respond to" +
29
+ " #exit_code. Is it an MB::MBError?"
30
+ return msg
31
+ end
32
+
33
+ "the program exited with an exit status of #{@actual_status} but you expected it to be #{@target_status}."
34
+ end
35
+
36
+ def failure_message_for_should_not
37
+ unless target_has_exit_code?
38
+ msg = "the program exited but the exception the exception you you gave does not respond to" +
39
+ " #exit_code. Is it an MB::MBError?"
40
+ return msg
41
+ end
42
+
43
+ "the program exited with an exit status of #{@actual_status} but you expected it not to."
44
+ end
45
+
46
+ private
47
+
48
+ def target_has_exit_code?
49
+ @target_err.respond_to?(:exit_code)
50
+ end
51
+ end
52
+
53
+ def exit_with(err_const)
54
+ Matchers::ExitCodes.new(err_const)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,11 @@
1
+ RSpec::Matchers.define :complete_as do |state, message|
2
+ match do |actual|
3
+ sleep 0.1 until actual.completed?
4
+
5
+ if message.nil?
6
+ actual.state == state
7
+ else
8
+ actual.state == state && actual.result == message
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,145 @@
1
+ module MotherBrain
2
+ module SpecHelpers
3
+
4
+ def json_post(endpoint, params)
5
+ post endpoint, params, "CONTENT_TYPE" => "application/json"
6
+ end
7
+
8
+ def app_root_path
9
+ Pathname.new(File.expand_path('../../../', __FILE__))
10
+ end
11
+
12
+ def app_tmp_path
13
+ app_root_path.join('spec/tmp/.mb')
14
+ end
15
+
16
+ def berkshelf_path
17
+ MB::Berkshelf.default_path
18
+ end
19
+
20
+ def tmp_path
21
+ app_root_path.join('spec/tmp')
22
+ end
23
+
24
+ def fixtures_path
25
+ app_root_path.join('spec/fixtures')
26
+ end
27
+
28
+ def clean_tmp_path
29
+ FileUtils.rm_rf(tmp_path)
30
+ FileUtils.rm_rf(app_tmp_path)
31
+ FileUtils.mkdir_p(tmp_path)
32
+ MB::FileSystem.init
33
+ end
34
+
35
+ def mb_config
36
+ @mb_config ||= MB::Config.new(nil,
37
+ {
38
+ chef: {
39
+ api_client: "zero",
40
+ api_key: File.join(fixtures_path, "fake_key.pem"),
41
+ validator_client: "chef-validator",
42
+ validator_path: File.join(fixtures_path, "fake_key.pem")
43
+ },
44
+ ssh: {
45
+ user: 'reset',
46
+ password: 'whatever',
47
+ keys: []
48
+ },
49
+ ef: {
50
+ api_key: "asdf",
51
+ api_url: "https://ef.riotgames.com"
52
+ },
53
+ rest_gateway: {
54
+ port: 26101
55
+ },
56
+ plugin_manager: {
57
+ eager_loading: false
58
+ }
59
+ }
60
+ )
61
+ end
62
+
63
+ def mb_config_path
64
+ MB::Config.default_path
65
+ end
66
+
67
+ # @param [String] name
68
+ # name of the cookbook to generate
69
+ #
70
+ # @option options [String] :path
71
+ # path to the directory to place the cookbook in
72
+ # @option options [String] :version
73
+ # version of the cookbook to generate
74
+ # @option options [Boolean] :with_plugin
75
+ # should this cookbook include a motherbrain plugin?
76
+ #
77
+ # @return [String]
78
+ # path to the generated cookbook
79
+ def generate_cookbook(name, options = {})
80
+ options = options.reverse_merge(version: "0.1.0", with_plugin: true)
81
+
82
+ cookbook_path = options[:path] || File.join(berkshelf_path, 'cookbooks', "#{name}-#{options[:version]}")
83
+
84
+ FileUtils.mkdir_p(cookbook_path)
85
+ File.open(File.join(cookbook_path, MB::CookbookMetadata::RUBY_FILENAME), 'w+') do |f|
86
+ f.write <<-EOH
87
+ name "#{name}"
88
+ maintainer "Jamie Winsor"
89
+ maintainer_email "jamie@vialstudios.com"
90
+ license "Apache 2.0"
91
+ description "Installs/Configures #{name}"
92
+ long_description "Installs/Configures #{name}"
93
+ version "#{options[:version]}"
94
+
95
+ %w{ ubuntu centos }.each do |os|
96
+ supports os
97
+ end
98
+ EOH
99
+ end
100
+
101
+ File.open(File.join(cookbook_path, MB::Plugin::PLUGIN_FILENAME), 'w+') do |f|
102
+ f.write "# #{name} plugin\n"
103
+ if options[:with_bootstrap]
104
+ f.write <<-PLUGIN
105
+ stack_order do
106
+ bootstrap("#{name}::server")
107
+ end
108
+
109
+ component "#{name}" do
110
+ description "The #{name} service"
111
+ group "server" do
112
+ recipe "#{name}::server"
113
+ end
114
+ end
115
+ PLUGIN
116
+ end
117
+ end if options[:with_plugin]
118
+
119
+ cookbook_path
120
+ end
121
+
122
+ # @param [String] path
123
+ #
124
+ # @return [MB::Config]
125
+ def generate_valid_config(path = MB::Config.default_path)
126
+ FileUtils.rm_rf(path)
127
+ mb_config.save(path)
128
+
129
+ mb_config
130
+ end
131
+
132
+ def generate_invalid_config(path)
133
+ FileUtils.rm_rf(path)
134
+ File.write(path, "{asdf : }{")
135
+ end
136
+
137
+ def klass
138
+ described_class
139
+ end
140
+
141
+ def ridley
142
+ @ridley ||= Ridley::Client.new(mb_config.to_ridley)
143
+ end
144
+ end
145
+ end