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,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::Provisioner::EnvironmentFactory do
4
+ let(:manifest) {
5
+ MB::Provisioner::Manifest.new.from_json(manifest_hash.to_json)
6
+ }
7
+ let(:manifest_hash) {
8
+ {
9
+ nodes: [
10
+ {
11
+ type: "m1.large",
12
+ count: 4,
13
+ components: ["activemq::master"]
14
+ },
15
+ {
16
+ type: "m1.large",
17
+ count: 2,
18
+ components: ["activemq::slave"]
19
+ },
20
+ {
21
+ type: "m1.small",
22
+ count: 2,
23
+ components: ["nginx::server"]
24
+ }
25
+ ]
26
+ }
27
+ }
28
+
29
+ describe "ClassMethods" do
30
+ subject { described_class }
31
+
32
+ describe "::convert_manifest" do
33
+ it "returns an array of hashes" do
34
+ subject.convert_manifest(manifest).should be_a(Array)
35
+ subject.convert_manifest(manifest).should each be_a(Hash)
36
+ end
37
+
38
+ it "contains an element for the amount of each node group and instance type" do
39
+ subject.convert_manifest(manifest).should have(8).items
40
+ end
41
+
42
+ describe "with different ordering" do
43
+ let(:manifest_hash) {
44
+ {
45
+ nodes: [
46
+ { groups: "default", type: "none" },
47
+ { type: "none", groups: "default", count: 2 }
48
+ ]
49
+ }
50
+ }
51
+
52
+ it "it still works" do
53
+ subject.convert_manifest(manifest).should be_a(Array)
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ let(:options) do
60
+ {
61
+ api_url: "https://ef.riotgames.com",
62
+ api_key: "58dNU5xBxDKjR15W71Lp",
63
+ ssl: {
64
+ verify: false
65
+ }
66
+ }
67
+ end
68
+
69
+ subject { described_class.new(options) }
70
+
71
+ describe "#up" do
72
+ let(:job) { MB::Job.new(:provision) }
73
+ let(:env_name) { "mbtest" }
74
+ let(:plugin) { double('plugin') }
75
+ let(:options) { Hash.new }
76
+
77
+ it "skips the bootstrap process" do
78
+ connection = double('connection')
79
+ environment = double('environment')
80
+ converted_manifest = Hash.new
81
+
82
+ subject.should_receive(:new_connection).and_return(connection)
83
+ described_class.should_receive(:convert_manifest).with(manifest).and_return(converted_manifest)
84
+ described_class.should_receive(:handle_created).with(environment).and_return(Array.new)
85
+ described_class.should_receive(:validate_create).and_return(true)
86
+ connection.stub_chain(:environment, :create).with(env_name, converted_manifest).and_return(Hash.new)
87
+ connection.stub_chain(:environment, :created?).with(env_name).and_return(true)
88
+ connection.stub_chain(:environment, :find).with(env_name, force: true).and_return(environment)
89
+
90
+ subject.up(job, env_name, manifest, plugin, options)
91
+ end
92
+ end
93
+
94
+ describe "#down" do
95
+ let(:job) { MB::Job.new(:destroy) }
96
+ let(:env_name) { "mbtest" }
97
+
98
+ it "sends a destroy command to environment factory with the given environment" do
99
+ connection = double('connection')
100
+
101
+ subject.should_receive(:new_connection).and_return(connection)
102
+ subject.should_receive(:destroyed?).with(connection, env_name).and_return(true)
103
+ connection.stub_chain(:environment, :destroy).with(env_name).and_return(Hash.new)
104
+
105
+ subject.down(job, env_name, options)
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::RestGateway do
4
+ include Rack::Test::Methods
5
+
6
+ after { subject.terminate }
7
+
8
+ describe "#app" do
9
+ it "returns MB::API::Application" do
10
+ subject.app.should be_a(MB::API::Application)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ridley::CookbookObject do
4
+ let(:client) { double('client') }
5
+
6
+ describe "#has_motherbrain_plugin?" do
7
+ context "when a metadata.rb, metadata.json, and motherbrain.rb file are present in root_files" do
8
+ subject do
9
+ described_class.new(client,
10
+ root_files: [
11
+ {
12
+ name: "metadata.rb",
13
+ url: "https://s3.amazonaws.com/opscode-platform-production-data/organization-(...)",
14
+ checksum: "967087a09f48f234028d3aa27a094882",
15
+ path: "metadata.rb",
16
+ specificity: "default"
17
+ },
18
+ {
19
+ name: "motherbrain.rb",
20
+ url: "https://s3.amazonaws.com/opscode-platform-production-data/organization-(...)",
21
+ checksum: "d18c630c8a68ffa4852d13214d0525a6",
22
+ path: "motherbrain.rb",
23
+ specificity: "default"
24
+ }
25
+ ]
26
+ )
27
+ end
28
+
29
+ it { should have_motherbrain_plugin }
30
+ end
31
+
32
+ context "when a motherbrain.rb is present" do
33
+ let(:root_files) do
34
+ [
35
+ {
36
+ name: "motherbrain.rb",
37
+ url: "https://s3.amazonaws.com/opscode-platform-production-data/organization-(...)",
38
+ checksum: "d18c630c8a68ffa4852d13214d0525a6",
39
+ path: "motherbrain.rb",
40
+ specificity: "default"
41
+ }
42
+ ]
43
+ end
44
+
45
+ subject { described_class.new(client, root_files: root_files) }
46
+
47
+ context "when a metadata.rb is present in the root_files" do
48
+ before do
49
+ root_files << {
50
+ name: "metadata.rb",
51
+ url: "https://s3.amazonaws.com/opscode-platform-production-data/organization-(...)",
52
+ checksum: "967087a09f48f234028d3aa27a094882",
53
+ path: "metadata.rb",
54
+ specificity: "default"
55
+ }
56
+ end
57
+
58
+ it { should have_motherbrain_plugin }
59
+ end
60
+
61
+ context "when a metadata.json is present in the root_files" do
62
+ before do
63
+ root_files << {
64
+ name: "metadata.json",
65
+ url: "https://s3.amazonaws.com/opscode-platform-production-data/organization-(...)",
66
+ checksum: "44ca6f96d3f0a7299cfff2f69295bc55",
67
+ path: "metadata.json",
68
+ specificity: "default"
69
+ }
70
+ end
71
+
72
+ it { should have_motherbrain_plugin }
73
+ end
74
+
75
+ context "when there is no metadata.rb or metadata.json in the root_files" do
76
+ it { should_not have_motherbrain_plugin }
77
+ end
78
+ end
79
+
80
+ context "when missing a motherbrain.rb file" do
81
+ let(:root_files) do
82
+ [
83
+ {
84
+ name: "metadata.rb",
85
+ url: "https://s3.amazonaws.com/opscode-platform-production-data/organization-(...)",
86
+ checksum: "967087a09f48f234028d3aa27a094882",
87
+ path: "metadata.rb",
88
+ specificity: "default"
89
+ },
90
+ {
91
+ name: "metadata.json",
92
+ url: "https://s3.amazonaws.com/opscode-platform-production-data/organization-(...)",
93
+ checksum: "44ca6f96d3f0a7299cfff2f69295bc55",
94
+ path: "metadata.json",
95
+ specificity: "default"
96
+ }
97
+ ]
98
+ end
99
+
100
+ subject { described_class.new(client, root_files: root_files) }
101
+
102
+ it { should_not have_motherbrain_plugin }
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,142 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::SrvCtl do
4
+ describe "ClassMethods" do
5
+ describe "::parse" do
6
+ let(:args) { Array.new }
7
+ let(:filename) { "mbsrv" }
8
+
9
+ subject { described_class.parse(args, filename) }
10
+
11
+ it "returns a hash" do
12
+ subject.should be_a(Hash)
13
+ end
14
+
15
+ context "given -c" do
16
+ let(:args) { ["-c", "/tmp/config.json"] }
17
+
18
+ it "sets :config to the given value" do
19
+ subject[:config].should eql("/tmp/config.json")
20
+ end
21
+ end
22
+
23
+ context "given -k" do
24
+ let(:args) { ["-k"] }
25
+
26
+ it "sets :kill to true" do
27
+ subject[:kill].should be_true
28
+ end
29
+ end
30
+
31
+ context "given -v" do
32
+ let(:args) { ["-v"] }
33
+
34
+ it "sets :log_level to Logger::DEBUG" do
35
+ subject[:log_level].should eql(Logger::DEBUG)
36
+ end
37
+ end
38
+
39
+ context "given -d" do
40
+ let(:args) { ["-d"] }
41
+
42
+ it "sets :daemonize to true" do
43
+ subject[:daemonize].should be_true
44
+ end
45
+ end
46
+
47
+ context "given -P" do
48
+ let(:args) { ["-P", "/var/run/some.pid"] }
49
+
50
+ it "sets :pid_file to the given value" do
51
+ subject[:pid_file].should eql("/var/run/some.pid")
52
+ end
53
+ end
54
+
55
+ context "given -P and -d" do
56
+ let(:args) { ["-P", "/var/run/some.pid", "-d"] }
57
+
58
+ it "sets :pid_file to the given value" do
59
+ subject[:pid_file].should eql("/var/run/some.pid")
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "::new" do
65
+ before(:each) do
66
+ generate_valid_config(MB::Config.default_path)
67
+ end
68
+
69
+ let(:options) { Hash.new }
70
+ subject { described_class.new(options) }
71
+
72
+ context "given no options" do
73
+ it "sets a default value for :config" do
74
+ subject.config.should_not be_nil
75
+ end
76
+ end
77
+
78
+ context "given :daemonize is true" do
79
+ let(:options) { { daemonize: true } }
80
+
81
+ it "sets config.server.daemonize to true" do
82
+ subject.config.server.daemonize.should be_true
83
+ end
84
+ end
85
+
86
+ context "given a value for :pid_file" do
87
+ let(:options) { { pid_file: "/tmp/some.pid" } }
88
+
89
+ it "sets config.server.pid to the value" do
90
+ subject.config.server.pid.should eql("/tmp/some.pid")
91
+ end
92
+ end
93
+
94
+ context "given a value for :log_level" do
95
+ let(:options) { { log_level: 'INFO' } }
96
+
97
+ it "sets config.log.level to the value" do
98
+ subject.config.log.level.should eql("INFO")
99
+ end
100
+ end
101
+
102
+ context "given a value for :log_location" do
103
+ let(:options) { { log_location: "/tmp/logs" } }
104
+
105
+ it "sets config.log.location to the value" do
106
+ subject.config.log.location.should eql("/tmp/logs")
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ describe "#daemonize" do
113
+ let(:config) { double("config", :to_logger => nil) }
114
+ let(:ui) { double("ui", :say => nil) }
115
+
116
+ before do
117
+ MB::Config.stub(:from_file).and_return(config)
118
+ MB::Logging.stub(:setup)
119
+ MB::SrvCtl.stub(:ui).and_return(ui)
120
+ end
121
+
122
+ let(:srv_ctl) { described_class.new }
123
+ let(:daemonize) { srv_ctl.send(:daemonize) }
124
+
125
+ context "when the pid directory does not exist" do
126
+
127
+ before do
128
+ File.stub(:exist?).and_return(false)
129
+ FileUtils.stub(:mkdir_p)
130
+ srv_ctl.stub(:pid_directory).and_return("")
131
+ File.stub(:writable?).and_return(true)
132
+ Process.stub(:daemon)
133
+ srv_ctl.stub(:create_pid)
134
+ end
135
+
136
+ it "attempts to make the directory" do
137
+ FileUtils.should_receive(:mkdir_p).and_return(nil)
138
+ daemonize
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::Upgrade::Manager do
4
+ let(:environment) { "environment" }
5
+ let(:plugin) { double('plugin') }
6
+ let(:options) { Hash.new }
7
+
8
+ subject { described_class.new }
9
+
10
+ describe "#async_upgrade" do
11
+ let(:ticket) { double('ticket') }
12
+ let(:job) { double('job', ticket: ticket) }
13
+
14
+ before(:each) do
15
+ MB::Job.should_receive(:new).with(:upgrade).and_return(job)
16
+ subject.should_receive(:async).with(:upgrade, job, environment, plugin, options).and_return(ticket)
17
+ end
18
+
19
+ it "returns a job ticket" do
20
+ subject.async_upgrade(environment, plugin, options).should eql(ticket)
21
+ end
22
+ end
23
+
24
+ describe "#upgrade" do
25
+ let(:job) { double('job', alive?: true) }
26
+ let(:worker) { double('worker', alive?: true) }
27
+
28
+ it "runs the request in a worker and then terminates the job and worker" do
29
+ MB::Upgrade::Worker.should_receive(:new).with(job, environment, plugin, options).and_return(worker)
30
+ job.should_receive(:terminate)
31
+ worker.should_receive(:terminate)
32
+ worker.should_receive(:run)
33
+
34
+ subject.upgrade(job, environment, plugin, options)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,219 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::Upgrade::Worker do
4
+ subject { worker }
5
+
6
+ let(:worker) { klass.new(job, environment_name, plugin, options).wrapped_object }
7
+
8
+ let(:component1) { MB::Component.new(component_name, plugin) }
9
+ let(:component_name) { "component1" }
10
+ let(:component_versions) { { component_name => "1.2.3" } }
11
+ let(:components) { [component1] }
12
+ let(:cookbook_versions) { { "ohai" => "1.2.3" } }
13
+ let(:environment) { double }
14
+ let(:environment_name) { "rspec-test" }
15
+ let(:job) { job_double }
16
+ let(:options) { Hash.new }
17
+ let(:nodes) { %w[node1 node2 node3] }
18
+ let(:plugin) { double MB::Plugin, name: plugin_name }
19
+ let(:plugin_name) { "plugin_name" }
20
+
21
+ before do
22
+ worker.stub(
23
+ assert_environment_exists: true,
24
+ nodes: nodes,
25
+ set_component_versions: nil,
26
+ set_cookbook_versions: nil,
27
+ save_environment: true,
28
+ run_chef: true
29
+ )
30
+ plugin.stub(:component!).with(component_name).and_return(component1)
31
+ end
32
+
33
+ its(:environment_name) { should == environment_name }
34
+ its(:plugin) { should == plugin }
35
+ its(:options) { should == options }
36
+
37
+ describe "#run" do
38
+ subject(:run) { worker.run }
39
+
40
+ it "wraps the upgrade in a lock" do
41
+ MB::ChefMutex.any_instance.should_receive :synchronize
42
+
43
+ run
44
+ end
45
+
46
+ it "marks the job as 'running' and then 'success' if successful" do
47
+ job.should_receive(:report_running).ordered
48
+ job.should_receive(:report_success).ordered
49
+
50
+ run
51
+ end
52
+
53
+ context "when an environment does not exist" do
54
+ before do
55
+ worker.stub(:assert_environment_exists).and_raise(MB::EnvironmentNotFound.new(environment_name))
56
+ end
57
+
58
+ it "should set the job state to :failure" do
59
+ job.should_receive(:report_failure)
60
+ run
61
+ end
62
+ end
63
+
64
+ context "when only cookbook_versions is passed as an option" do
65
+ before do
66
+ options[:cookbook_versions] = cookbook_versions
67
+ options[:component_versions] = nil
68
+ end
69
+
70
+ it "updates only the cookbook versions and runs chef" do
71
+ worker.should_receive(:set_cookbook_versions).ordered
72
+ worker.should_receive(:run_chef).ordered
73
+
74
+ worker.should_not_receive :set_component_versions
75
+
76
+ run
77
+ end
78
+ end
79
+
80
+ context "when only component_versions is passed as an option" do
81
+ before do
82
+ options[:cookbook_versions] = nil
83
+ options[:component_versions] = component_versions
84
+ end
85
+
86
+ it "updates only the component versions and runs chef" do
87
+ worker.should_receive(:set_component_versions).ordered
88
+ worker.should_receive(:run_chef).ordered
89
+
90
+ worker.should_not_receive :set_cookbook_versions
91
+
92
+ run
93
+ end
94
+ end
95
+
96
+ context "when both component_versions and cookbook_versions are passed as options" do
97
+ before do
98
+ options[:cookbook_versions] = cookbook_versions
99
+ options[:component_versions] = component_versions
100
+ end
101
+
102
+ it "updates the versions and runs chef" do
103
+ worker.should_receive(:set_component_versions).ordered
104
+ worker.should_receive(:set_cookbook_versions).ordered
105
+ worker.should_receive(:run_chef).ordered
106
+
107
+ run
108
+ end
109
+ end
110
+
111
+ context "when no nodes exist in the environment" do
112
+ before do
113
+ options[:cookbook_versions] = cookbook_versions
114
+ options[:component_versions] = component_versions
115
+
116
+ worker.stub nodes: []
117
+ end
118
+
119
+ it "updates the versions and does not run chef" do
120
+ worker.should_receive(:set_component_versions).ordered
121
+ worker.should_receive(:set_cookbook_versions).ordered
122
+
123
+ worker.should_not_receive :run_chef
124
+
125
+ run
126
+ end
127
+ end
128
+
129
+ context "when environment_attributes_file is passed as an option" do
130
+ let(:filepath) { double }
131
+
132
+ before do
133
+ options[:environment_attributes_file] = filepath
134
+ end
135
+
136
+ it "sets environment attributes on the environment with the contents of the file" do
137
+ worker.should_receive(:set_environment_attributes_from_file).with(environment_name, filepath).ordered
138
+
139
+ run
140
+ end
141
+
142
+ context "when the environment attributes file is invalid" do
143
+ it "sets the job to failed" do
144
+ worker.should_receive(:set_environment_attributes_from_file).and_raise(MB::InvalidAttributesFile)
145
+ job.should_receive(:report_failure)
146
+
147
+ run
148
+ end
149
+ end
150
+ end
151
+
152
+ context "when environment_attributes_file is not passed as an option" do
153
+ before do
154
+ options[:environment_attributes_file] = nil
155
+ end
156
+
157
+ it "does not set the environment attributes on the environment" do
158
+ worker.should_not_receive(:set_environment_attributes_file)
159
+
160
+ run
161
+ end
162
+ end
163
+
164
+ context "when environment_attributes is passed as an option" do
165
+ let(:env_attributes) do
166
+ {
167
+ "foo" => "bar",
168
+ "baz.quux" => 42
169
+ }
170
+ end
171
+
172
+ before do
173
+ options[:environment_attributes] = env_attributes
174
+ end
175
+
176
+ it "sets environment attributes on the environment" do
177
+ worker.should_receive(:set_environment_attributes).with(environment_name, env_attributes).ordered
178
+
179
+ run
180
+ end
181
+ end
182
+
183
+ context "when environment_attributes is not passed as an option" do
184
+ before do
185
+ options[:environment_attributes] = nil
186
+ end
187
+
188
+ it "does not set the environment attributes on the environment" do
189
+ worker.should_not_receive(:set_environment_attributes)
190
+
191
+ run
192
+ end
193
+ end
194
+ end
195
+
196
+ describe "#nodes" do
197
+ pending "This should not be the responsibility of MB::Upgrade"
198
+ end
199
+
200
+ describe "#run_chef" do
201
+ subject(:run_chef) { worker.send :run_chef }
202
+
203
+ let(:nodes) { %w[node1 node2 node3] }
204
+
205
+ before do
206
+ worker.unstub :run_chef
207
+
208
+ worker.stub nodes: nodes
209
+ end
210
+
211
+ it "runs chef on the nodes" do
212
+ nodes.each do |node|
213
+ MB::Application.node_querier.should_receive(:chef_run).with(node)
214
+ end
215
+
216
+ run_chef
217
+ end
218
+ end
219
+ end