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,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dir do
4
+ describe "#has_mb_plugin?" do
5
+ let(:target) { tmp_path.join('some_directory') }
6
+ subject { described_class.has_mb_plugin?(target) }
7
+
8
+ context "when the directory does not exist" do
9
+ before { FileUtils.rm_f(target) }
10
+ it { should be_false }
11
+ end
12
+
13
+ context "when the directory exists" do
14
+ before { FileUtils.mkdir_p(target) }
15
+
16
+ before do
17
+ described_class.stub(:has_mb_file?).with(target).and_return(true)
18
+ described_class.stub(:has_chef_metadata?).with(target).and_return(true)
19
+ end
20
+
21
+ context "but does not contain a motherbrain file" do
22
+ before { described_class.stub(:has_mb_file?).with(target).and_return(false) }
23
+ it { should be_false }
24
+ end
25
+
26
+ context "but does not contain a Chef metadata file" do
27
+ before { described_class.stub(:has_mb_file?).with(target).and_return(false) }
28
+ it { should be_false }
29
+ end
30
+
31
+ context "and contains a motherbrain file and Chef metadata file" do
32
+ it { should be_true }
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "#has_mb_file?" do
38
+ let(:target) { tmp_path.join('some_directory') }
39
+ subject { described_class.has_mb_file?(target) }
40
+
41
+ context "when the directory does not exist" do
42
+ before { FileUtils.rm_f(target) }
43
+ it { should be_false }
44
+ end
45
+
46
+ context "when the directory exists" do
47
+ before { FileUtils.mkdir_p(target) }
48
+
49
+ context "but does not contain a motherbrain file" do
50
+ before { FileUtils.rm_f(target.join(MB::Plugin::PLUGIN_FILENAME)) }
51
+ it { should be_false }
52
+ end
53
+
54
+ context "and has a motherbrain file" do
55
+ before { FileUtils.touch(target.join(MB::Plugin::PLUGIN_FILENAME)) }
56
+ it { should be_true }
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "#has_chef_metadata?" do
62
+ let(:target) { tmp_path.join('some_directory') }
63
+ subject { described_class.has_chef_metadata?(target) }
64
+
65
+ context "when the directory does not exist" do
66
+ before { FileUtils.rm_f(target) }
67
+ it { should be_false }
68
+ end
69
+
70
+ context "when the directory exists" do
71
+ before { FileUtils.mkdir_p(target) }
72
+
73
+ context "but does not contain a Chef JSON or Ruby metadata file" do
74
+ before do
75
+ FileUtils.rm_f(target.join(MB::CookbookMetadata::RUBY_FILENAME))
76
+ FileUtils.rm_f(target.join(MB::CookbookMetadata::JSON_FILENAME))
77
+ end
78
+ it { should be_false }
79
+ end
80
+
81
+ context "and contains a Chef JSON metadata file" do
82
+ before { FileUtils.touch(target.join(MB::CookbookMetadata::JSON_FILENAME)) }
83
+ it { should be_true }
84
+ end
85
+
86
+ context "and contains a Chef Ruby metadata file" do
87
+ before { FileUtils.touch(target.join(MB::CookbookMetadata::RUBY_FILENAME)) }
88
+ it { should be_true }
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+
3
+ describe Enumerable do
4
+ class ObjectClass
5
+ def foo
6
+ :result
7
+ end
8
+
9
+ def bar(one, two, three)
10
+ [one, two, three]
11
+ end
12
+ end
13
+
14
+ class ActorClass < ObjectClass
15
+ include Celluloid
16
+ end
17
+
18
+ let(:actors) { [ActorClass.new, ActorClass.new] }
19
+ let(:objects) { [ObjectClass.new, ObjectClass.new] }
20
+ let(:mixed) { [ActorClass.new, ObjectClass.new] }
21
+
22
+ let(:block) { proc { |item| item.foo } }
23
+
24
+ let(:array) { actors }
25
+
26
+ let(:foo_result) { [:result, :result] }
27
+ let(:bar_result) { [[1, 2, 3], [1, 2, 3]] }
28
+
29
+ describe "#concurrent_map" do
30
+ subject { concurrent_map }
31
+
32
+ context "when passed a method" do
33
+ let(:concurrent_map) { array.concurrent_map(:foo) }
34
+
35
+ context "with actors" do
36
+ let(:array) { actors }
37
+
38
+ it { should eq(foo_result) }
39
+ end
40
+
41
+ context "with objects" do
42
+ let(:array) { objects }
43
+
44
+ it { should eq(foo_result) }
45
+ end
46
+
47
+ context "with mixed actors and objects" do
48
+ let(:array) { mixed }
49
+
50
+ it { should eq(foo_result) }
51
+ end
52
+ end
53
+
54
+ context "when passed a method and arguments" do
55
+ let(:concurrent_map) { array.concurrent_map(:bar, 1, 2, 3) }
56
+
57
+ context "with actors" do
58
+ let(:array) { actors }
59
+
60
+ it { should eq(bar_result) }
61
+ end
62
+
63
+ context "with objects" do
64
+ let(:array) { objects }
65
+
66
+ it { should eq(bar_result) }
67
+ end
68
+
69
+ context "with mixed actors and objects" do
70
+ let(:array) { mixed }
71
+
72
+ it { should eq(bar_result) }
73
+ end
74
+ end
75
+
76
+ context "when passed a block" do
77
+ let(:concurrent_map) { array.concurrent_map(&block) }
78
+
79
+ context "with actors" do
80
+ let(:array) { actors }
81
+
82
+ it { should eq(foo_result) }
83
+ end
84
+
85
+ context "with objects" do
86
+ let(:array) { objects }
87
+
88
+ it { should eq(foo_result) }
89
+ end
90
+
91
+ context "with mixed actors and objects" do
92
+ let(:array) { mixed }
93
+
94
+ it { should eq(foo_result) }
95
+ end
96
+ end
97
+
98
+ context "with no arguments or block" do
99
+ let(:concurrent_map) { array.concurrent_map }
100
+
101
+ it { expect { concurrent_map }.to raise_error(ArgumentError) }
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe File do
4
+ describe "#is_chef_metadata?" do
5
+ let(:filename) { 'metadata.rb' }
6
+ let(:target) { tmp_path.join(filename) }
7
+ subject { described_class.is_chef_metadata?(target) }
8
+
9
+ context "when the file does not exist" do
10
+ before { FileUtils.rm_f(target) }
11
+ it { should be_false }
12
+ end
13
+
14
+ context "when the file exists" do
15
+ before { FileUtils.touch(target) }
16
+
17
+ context "and the basename matches the Chef Ruby metadata filename" do
18
+ let(:filename) { MB::CookbookMetadata::RUBY_FILENAME }
19
+ it { should be_true }
20
+ end
21
+
22
+ context "and the basename matches the Chef JSON metadata filename" do
23
+ let(:filename) { MB::CookbookMetadata::JSON_FILENAME }
24
+ it { should be_true }
25
+ end
26
+
27
+ context "and the basename does not match a Chef metadata filename" do
28
+ let(:filename) { 'nothing.at.all' }
29
+ it { should be_false }
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#is_mb_plugin?" do
35
+ let(:filename) { 'motherbrain.rb' }
36
+ let(:target) { tmp_path.join(filename) }
37
+ subject { described_class.is_mb_plugin?(target) }
38
+
39
+ context "when the file does not exist" do
40
+ before { FileUtils.rm_f(target) }
41
+ it { should be_false }
42
+ end
43
+
44
+ context "when the file exists" do
45
+ before { FileUtils.touch(target) }
46
+
47
+ context "and the basename matches a motherbrain plugin filename" do
48
+ let(:filename) { MB::Plugin::PLUGIN_FILENAME }
49
+ it { should be_true }
50
+ end
51
+
52
+ context "and the basename does not match a motherbrain plugin filename" do
53
+ let(:filename) { 'something.not.real' }
54
+ it { should be_false }
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Signal do
4
+ describe "#supported?" do
5
+ let(:signal_name) { "HUP" }
6
+ subject { described_class.supported?(signal_name) }
7
+
8
+ context "when the signal is in the list of signals" do
9
+ before do
10
+ Signal.stub(list: { "HUP" => 1 })
11
+ end
12
+
13
+ it { should be_true }
14
+ end
15
+
16
+ context "when the signal is not in the list of supported signals" do
17
+ before do
18
+ Signal.stub(list: Hash.new)
19
+ end
20
+
21
+ it { should be_false }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,166 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::EnvironmentManager do
4
+ subject { environment_manager }
5
+
6
+ let(:environment_manager) { described_class.new }
7
+ let(:environment_name) { "rspec-test" }
8
+
9
+ describe "#async_configure" do
10
+ let(:options) { Hash.new }
11
+
12
+ it "asynchronously calls #configure and returns a JobRecord" do
13
+ subject.should_receive(:async).with(:configure, kind_of(MB::Job), environment_name, options)
14
+
15
+ subject.async_configure(environment_name, options).should be_a(MB::JobRecord)
16
+ end
17
+ end
18
+
19
+ describe "#configure" do
20
+ let!(:job) { MB::Job.new(:environment_configure) }
21
+ let!(:ticket) { job.ticket }
22
+ let(:options) { Hash.new }
23
+
24
+ context "when the environment exists" do
25
+ before { chef_environment(environment_name) }
26
+
27
+ it "sets the job to success" do
28
+ subject.configure(job, environment_name, options)
29
+ expect(ticket).to be_success
30
+ end
31
+ end
32
+
33
+ context "when the environment does not exist" do
34
+ before { MB::RSpec::ChefServer.clear_data }
35
+
36
+ it "sets the job to failure because of EnvironmentNotFound" do
37
+ subject.configure(job, environment_name, options)
38
+ expect(ticket).to be_failure
39
+ expect(ticket.result).to be_a(MB::EnvironmentNotFound)
40
+ end
41
+ end
42
+
43
+ context "when there are nodes in the environment" do
44
+ let(:job) { double(set_status: nil, report_running: nil, report_success: nil, report_failure: nil, alive?: false) }
45
+ let(:ticket) { nil }
46
+ let(:node_one) { double(name: "surfing", public_hostname: "surfing.riotgames.com") }
47
+ let(:node_two) { double(name: "football", public_hostname: "football.riotgames.com") }
48
+ let(:response_one) { double(value: double(host: "surfing.riotgames.com")) }
49
+ let(:response_two) { double(value: double(host: "football.riotgames.com")) }
50
+
51
+ let(:nodes) { [node_one, node_two] }
52
+
53
+ before do
54
+ chef_environment(environment_name)
55
+ environment_manager.stub(:nodes_for_environment).and_return(nodes)
56
+ nodes.stub(:collect).and_return([response_one, response_two])
57
+ end
58
+
59
+ it "attempts to run chef" do
60
+ subject.configure(job, environment_name, options)
61
+ expect(job).to have_received(:report_success).with(
62
+ "Finished chef client run on 2 node(s) - surfing.riotgames.com, football.riotgames.com")
63
+ end
64
+
65
+ context "when nodes fail" do
66
+
67
+ before do
68
+ response_one.stub(:value).and_raise(MB::RemoteCommandError.new(nil, "surfing.riotgames.com"))
69
+ response_two.stub(:value).and_raise(MB::RemoteCommandError.new(nil, "football.riotgames.com"))
70
+ end
71
+
72
+ it "describes the unsuccessful nodes" do
73
+ subject.configure(job, environment_name, options)
74
+ expect(job).to have_received(:report_failure).with(
75
+ "chef client run failed on 2 node(s) - surfing.riotgames.com, football.riotgames.com")
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ describe "#find" do
82
+ before { chef_environment(environment_name) }
83
+
84
+ it "returns a Ridley::EnvironmentObject" do
85
+ expect(subject.find(environment_name)).to be_a(Ridley::EnvironmentObject)
86
+ end
87
+
88
+ context "when the environment is not present on the remote Chef server" do
89
+ before { MB::RSpec::ChefServer.clear_data }
90
+
91
+ it "aborts an EnvironmentNotFound error" do
92
+ expect { subject.find(environment_name) }.to raise_error(MB::EnvironmentNotFound)
93
+ end
94
+ end
95
+ end
96
+
97
+ describe "#list" do
98
+ before do
99
+ chef_environment("rspec-one")
100
+ chef_environment("rspec-two")
101
+ chef_environment("rspec-three")
102
+ end
103
+
104
+ it "has an item for every environment on the Chef server +1 for _default" do
105
+ expect(subject.list).to have(4).items
106
+ end
107
+
108
+ it "includes the _default environment" do
109
+ expect(subject.list.find { |e| e.chef_id }).to_not be_nil
110
+ end
111
+ end
112
+
113
+ describe "#create" do
114
+ it "creates an environment" do
115
+ environment_manager.create environment_name
116
+
117
+ expect(ridley.environment.find(environment_name)).to be_true
118
+ end
119
+ end
120
+
121
+ describe "#create_from_file" do
122
+ it "creates an environment" do
123
+ test_file = File.join(fixtures_path, 'test_env.json')
124
+ environment_manager.create_from_file test_file
125
+
126
+ env = ridley.environment.find('test_env')
127
+ expect(env['default_attributes']['motherbrain']).to be_true
128
+ end
129
+
130
+ it "handles a missing file" do
131
+ test_file = File.join(fixtures_path, 'no_such_env.json')
132
+ expect { environment_manager.create_from_file(test_file) }.to raise_error
133
+ end
134
+ end
135
+
136
+ describe "#destroy" do
137
+ before { chef_environment(environment_name) }
138
+
139
+ it "destroys the environment" do
140
+ environment_manager.destroy environment_name
141
+
142
+ expect(ridley.environment.find(environment_name)).to be_nil
143
+ end
144
+ end
145
+
146
+ describe "#purge_nodes" do
147
+ before do
148
+ chef_environment(environment_name)
149
+ ridley.node.create(name: "test", chef_environment: environment_name)
150
+ end
151
+
152
+ it "removes the nodes" do
153
+ environment_manager.purge_nodes environment_name
154
+
155
+ expect(ridley.search(:node, "chef_environment:#{environment_name}")).to be_empty
156
+ end
157
+
158
+ it "does not remove nodes in other environments" do
159
+ ridley.node.create(name: "test2", chef_environment: "other")
160
+
161
+ environment_manager.purge_nodes environment_name
162
+
163
+ expect(ridley.search(:node, "chef_environment:other")).to_not be_empty
164
+ end
165
+ end
166
+ end