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,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::Manifest do
4
+ subject { manifest }
5
+ let(:manifest) { described_class.new(attributes) }
6
+
7
+ let(:valid_json) do
8
+ <<-JSON
9
+ {
10
+ "nodes": [
11
+ {
12
+ "type": "m1.large",
13
+ "groups": ["activemq::master"]
14
+ },
15
+ {
16
+ "type": "m1.large",
17
+ "count": 2,
18
+ "groups": ["activemq::slave"]
19
+ },
20
+ {
21
+ "type": "m1.small",
22
+ "groups": ["nginx::master"]
23
+ }
24
+ ]
25
+ }
26
+ JSON
27
+ end
28
+
29
+ let(:valid_hash) {
30
+ {
31
+ nodes: [
32
+ {
33
+ type: "m1.large",
34
+ groups: ["activemq::master"]
35
+ },
36
+ {
37
+ type: "m1.large",
38
+ count: 2,
39
+ groups: ["activemq::slave"]
40
+ },
41
+ {
42
+ type: "m1.small",
43
+ groups: ["nginx::master"]
44
+ }
45
+ ]
46
+ }
47
+ }
48
+
49
+ let(:attributes) { valid_hash }
50
+
51
+ it { should == valid_hash }
52
+ it { should have_key(:nodes) }
53
+
54
+ its(:node_count) { should == 4 }
55
+
56
+ context "with an empty hash" do
57
+ let(:attributes) { Hash.new }
58
+
59
+ it { should be_empty }
60
+ end
61
+
62
+ describe "#[:nodes]" do
63
+ subject { manifest[:nodes] }
64
+
65
+ it { should have(3).items }
66
+ it { should =~ valid_hash[:nodes] }
67
+ end
68
+
69
+ describe ".from_file" do
70
+ pending
71
+ end
72
+
73
+ describe ".from_json" do
74
+ pending
75
+ end
76
+
77
+ describe "#from_json" do
78
+ subject { from_json }
79
+ let(:from_json) { described_class.new.from_json(json) }
80
+
81
+ let(:json) { valid_json }
82
+
83
+ it { should == valid_hash }
84
+
85
+ context "given an empty json string" do
86
+ let(:json) { "{}" }
87
+
88
+ it { should be_empty }
89
+ end
90
+
91
+ context "given an invalid JSON string" do
92
+ let(:json) { "sdf" }
93
+
94
+ it "raises" do
95
+ expect {
96
+ from_json
97
+ }.to raise_error(MB::InvalidManifest)
98
+ end
99
+ end
100
+ end
101
+
102
+ describe "#save" do
103
+ pending
104
+ end
105
+ end
@@ -0,0 +1,180 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::Mixin::AttributeSetting do
4
+ subject do
5
+ Class.new do
6
+ include MB::Mixin::AttributeSetting
7
+ end.new
8
+ end
9
+
10
+ let(:environment) { "test-env" }
11
+
12
+ describe "#set_component_versions" do
13
+ let(:plugin) { double('plugin', name: "rspec") }
14
+ let(:component) { double('component') }
15
+
16
+ context "when the component exists" do
17
+ before(:each) { plugin.stub(:component!).with(plugin.name).and_return(component) }
18
+
19
+ context "without a version_attribute" do
20
+ before(:each) { component.stub(version_attribute: nil) }
21
+
22
+ it "raises a MB::ComponentNotVersioned error" do
23
+ expect {
24
+ subject.set_component_versions(environment, plugin, plugin.name => "1.2.3")
25
+ }.to raise_error(MB::ComponentNotVersioned)
26
+ end
27
+ end
28
+ end
29
+
30
+ context "when the component does not exist" do
31
+ before(:each) do
32
+ plugin.stub(:component!).with(plugin.name).and_raise(MB::ComponentNotFound.new(component, plugin))
33
+ end
34
+
35
+ it "raises a MB::ComponentNotFound error" do
36
+ expect {
37
+ subject.set_component_versions(environment, plugin, plugin.name => "1.2.3")
38
+ }.to raise_error(MB::ComponentNotFound)
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "#set_cookbook_versions" do
44
+ before(:each) do
45
+ subject.stub(satisfies_constraints?: true)
46
+ end
47
+
48
+ context "successful" do
49
+ let(:hash) { Hash.new }
50
+ before(:each) do
51
+ env = double('environment', name: "foo")
52
+ chef_connection = subject.chef_connection
53
+ chef_connection.stub_chain(:environment, :find).and_return(env)
54
+ chef_connection.stub_chain(:cookbook, :latest_version).and_return("1.2.4")
55
+ env.should_receive(:cookbook_versions).and_return(hash)
56
+ env.stub(:save)
57
+ end
58
+
59
+ it "saves the cookbook versions to the environment" do
60
+ subject.set_cookbook_versions "foo", {"some_book" => "= 1.2.3"}
61
+ hash["some_book"].should_not be_nil
62
+ hash["some_book"].should eq("= 1.2.3")
63
+ end
64
+
65
+ it "converts 'latest' to a (=) constraint of the latest" do
66
+ subject.set_cookbook_versions "foo", {"some_book" => "latest"}
67
+ hash["some_book"].should_not be_nil
68
+ hash["some_book"].should eq("= 1.2.4")
69
+ end
70
+ end
71
+
72
+ context "given incomplete version constraints" do
73
+ let(:constraints) do
74
+ { "some_cook" => "123" }
75
+ end
76
+
77
+ let(:env) { double('environment', name: "foo") }
78
+
79
+ before(:each) do
80
+ subject.stub(expand_latest_versions: constraints)
81
+ chef_connection = subject.chef_connection
82
+ chef_connection.stub_chain(:environment, :find).and_return(env)
83
+ env.stub(:save)
84
+ end
85
+
86
+ it "expands them to a fully qualified constraint format" do
87
+ env.stub_chain(:cookbook_versions, :merge!).with("some_cook" => "= 123.0.0")
88
+ subject.set_cookbook_versions "foo", constraints
89
+ end
90
+ end
91
+
92
+ context "when constraints could not be satisfiied" do
93
+ let(:constraints) do
94
+ { "rspec_test" => "= 1.2.3", "rspec_fail_test" => ">= 2.0.0" }
95
+ end
96
+
97
+ before(:each) do
98
+ subject.stub(expand_latest_versions: constraints)
99
+ subject.stub(:satisfies_constraints?).with(constraints).and_raise
100
+ end
101
+
102
+ it "raises an error" do
103
+
104
+ expect {
105
+ subject.set_cookbook_versions "foo", constraints
106
+ }.to raise_error
107
+ end
108
+ end
109
+ end
110
+
111
+ describe "#set_environment_attributes" do
112
+ context "successful" do
113
+ let(:hash) { Hash.new }
114
+ before(:each) do
115
+ env = double('environment', name: "foo")
116
+ chef_connection = subject.chef_connection
117
+ chef_connection.stub_chain(:environment, :find).and_return(env)
118
+ env.should_receive(:default_attributes).and_return(hash)
119
+ env.stub(:save)
120
+ end
121
+
122
+ it "should save the attributes to the environment" do
123
+ subject.set_environment_attributes "foo", {"bar.baz" => "quux"}
124
+ hash["bar"].should_not be_nil
125
+ hash["bar"]["baz"].should eq("quux")
126
+ end
127
+ end
128
+ end
129
+
130
+ describe "#set_environment_attributes_from_file" do
131
+ let(:env) { double }
132
+ let(:filepath) { tmp_path.join('attr-test-file') }
133
+ let(:contents) { double }
134
+
135
+ before(:each) { FileUtils.touch(filepath) }
136
+
137
+ context "given the type :json" do
138
+ it "delegates to set_environment_attributes_from_json" do
139
+ subject.should_receive(:set_environment_attributes_from_json).with(env, anything)
140
+
141
+ subject.set_environment_attributes_from_file(env, filepath, :json)
142
+ end
143
+
144
+ it "raises an InvalidAttributesFile error if there was a problem decoding json" do
145
+ subject.should_receive(:set_environment_attributes_from_json).and_raise(MultiJson::DecodeError)
146
+
147
+ expect {
148
+ subject.set_environment_attributes_from_file(env, filepath, :json)
149
+ }.to raise_error(MB::InvalidAttributesFile)
150
+ end
151
+ end
152
+
153
+ it "raises an MB::ArgumentError when given an unknown type" do
154
+ expect {
155
+ subject.set_environment_attributes_from_file(env, filepath, :not_known)
156
+ }.to raise_error(MB::ArgumentError)
157
+ end
158
+ end
159
+
160
+ describe "#set_environment_attributes_from_json" do
161
+ let(:env) { double }
162
+ let(:data) { double }
163
+
164
+ before(:each) { subject.stub(:set_environment_attributes_from_hash) }
165
+
166
+ it "decodes the given string to json" do
167
+ MultiJson.should_receive(:decode).with(data)
168
+
169
+ subject.set_environment_attributes_from_json(env, data)
170
+ end
171
+
172
+ it "delegates to #set_environment_attributes_from_hash with the environment and decoded json" do
173
+ decoded_json = double
174
+ MultiJson.should_receive(:decode).and_return(decoded_json)
175
+ subject.should_receive(:set_environment_attributes_from_hash).with(env, decoded_json)
176
+
177
+ subject.set_environment_attributes_from_json(env, data)
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::Mixin::CodedExit do
4
+ subject do
5
+ Class.new do
6
+ include MB::Mixin::CodedExit
7
+ end.new
8
+ end
9
+
10
+ describe "#exit_with" do
11
+ let(:constant) { MB::MBError }
12
+
13
+ it "exits with the status code for the given constant" do
14
+ expect {
15
+ subject.exit_with(constant)
16
+ }.to exit_with(constant)
17
+ end
18
+ end
19
+
20
+ describe "#exit_code_for" do
21
+ it "returns the exit status for the given constant" do
22
+ subject.exit_code_for("MBError").should eql(1)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::Mixin::Locks do
4
+ subject do
5
+ Class.new do
6
+ include MB::Mixin::Locks
7
+ end.new
8
+ end
9
+
10
+ let(:lock_manager) { MB::LockManager.instance }
11
+
12
+ before(:each) { lock_manager.reset }
13
+
14
+ describe "#chef_locks" do
15
+ it "returns a Set" do
16
+ subject.chef_locks.should be_a(Set)
17
+ end
18
+ end
19
+
20
+ describe "#find_lock" do
21
+ it "returns a Chef::Mutex if a mutex with the given name is registered" do
22
+ mutex = double('mutex', type: :chef_environment, name: "my_environment")
23
+ lock_manager.stub(:locks).and_return([mutex])
24
+
25
+ subject.find_lock(chef_environment: "my_environment").should eql(mutex)
26
+ end
27
+
28
+ it "returns nil if a mutex with the given name is not registered" do
29
+ subject.find_lock(chef_environment: "not-there-lock").should be_nil
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::Mixin::Services do
4
+ subject do
5
+ Class.new do
6
+ include MB::Mixin::Services
7
+ end.new
8
+ end
9
+
10
+ describe "#bootstrap_manager" do
11
+ it "returns an instance of MB::Bootstrap::Manager" do
12
+ subject.bootstrap_manager.should be_a(MB::Bootstrap::Manager)
13
+ end
14
+ end
15
+
16
+ describe "#command_invoker" do
17
+ it "returns an instance of MB::CommandInvoker" do
18
+ subject.command_invoker.should be_a(MB::CommandInvoker)
19
+ end
20
+ end
21
+
22
+ describe "#config_manager" do
23
+ it "returns an instance of MB::ConfigManager" do
24
+ subject.config_manager.should be_a(MB::ConfigManager)
25
+ end
26
+ end
27
+
28
+ describe "#environment_manager" do
29
+ it "returns an instance of MB::EnvironmentManager" do
30
+ subject.environment_manager.should be_a(MB::EnvironmentManager)
31
+ end
32
+ end
33
+
34
+ describe "#job_manager" do
35
+ it "returns an instance of MB::JobManager" do
36
+ subject.job_manager.should be_a(MB::JobManager)
37
+ end
38
+ end
39
+
40
+ describe "#provisioner_manager" do
41
+ it "returns an instance of MB::Provisioner::Manager" do
42
+ subject.provisioner_manager.should be_a(MB::Provisioner::Manager)
43
+ end
44
+ end
45
+
46
+ describe "#node_querier" do
47
+ it "returns an instance of MB::NodeQuerier" do
48
+ subject.node_querier.should be_a(MB::NodeQuerier)
49
+ end
50
+ end
51
+
52
+ describe "#plugin_manager" do
53
+ it "returns an instance of MB::PluginManager" do
54
+ subject.plugin_manager.should be_a(MB::PluginManager)
55
+ end
56
+ end
57
+
58
+ describe "#provisioner_manager" do
59
+ it "returns an instance of MB::Provisioner::Manager" do
60
+ subject.provisioner_manager.should be_a(MB::Provisioner::Manager)
61
+ end
62
+ end
63
+
64
+ describe "#upgrade_manager" do
65
+ it "returns an instance of MB::Upgrade::Manager" do
66
+ subject.upgrade_manager.should be_a(MB::Upgrade::Manager)
67
+ end
68
+ end
69
+
70
+ describe "#ridley" do
71
+ it "returns an instance of Ridley::Client" do
72
+ subject.ridley.should be_a(Ridley::Client)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe MB::NodeFilter do
4
+ let(:nodes) do
5
+ (1..10).to_a.collect do |i|
6
+ double("node#{i}").tap do |d|
7
+ d.stub(:public_hostname).and_return("node#{i}.test.riotgames.com")
8
+ d.stub(:public_ipv4).and_return("192.168.1.#{i}")
9
+ end
10
+ end
11
+ end
12
+
13
+ describe "ClassMethods" do
14
+ describe "::filter" do
15
+ let(:segments) { [["192.168.1.3-5"]] }
16
+ subject(:filter) { described_class.filter(segments, nodes) }
17
+
18
+ context "given an array of arrays of segments" do
19
+ it "returns the correct number of nodes" do
20
+ expect(filter).to have(3).items
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ subject { MB::NodeFilter.new(filter) }
27
+ let(:filtered) { subject.filter(nodes) }
28
+ let(:filter) {[]}
29
+
30
+ describe ":expand_iprange" do
31
+ let(:expand_ipranges) { described_class.expand_ipranges(nodes) }
32
+ let(:nodes) { ["192.168.0.2", "192.168.0.5-8"] }
33
+
34
+ it "expands any ipranges" do
35
+ expect(expand_ipranges).to eq(["192.168.0.2", "192.168.0.5", "192.168.0.6", "192.168.0.7", "192.168.0.8"])
36
+ end
37
+ end
38
+
39
+ describe "#ipaddress?" do
40
+ it "is true for valid ipaddresses" do
41
+ expect(subject.ipaddress?("192.168.1.1")).to be_true
42
+ end
43
+
44
+ it "is false for invalid ipaddresses" do
45
+ expect(subject.ipaddress?("invalid")).to be_false
46
+ expect(subject.ipaddress?("192.168.1.3-5")).to be_false
47
+ end
48
+ end
49
+
50
+ describe "#iprange" do
51
+ it "expands the range" do
52
+ expect(subject.iprange("192.168.1.1-2")).to eq(["192.168.1.1", "192.168.1.2"])
53
+ end
54
+
55
+ it "is nil when not an iprange" do
56
+ expect(subject.iprange("192.168.1.1")).to be_nil
57
+ expect(subject.iprange("invalid")).to be_nil
58
+ end
59
+ end
60
+
61
+ describe "#filter" do
62
+ context "when an ipaddress range is given" do
63
+ let(:filter) { ["192.168.1.3-5"] }
64
+
65
+ it "filters the nodes" do
66
+ expect(filtered.collect(&:public_ipv4)).to eq(["192.168.1.3", "192.168.1.4", "192.168.1.5"])
67
+ end
68
+ end
69
+
70
+ context "when a full hostname is given" do
71
+ let(:filter) { ["node2.test.riotgames.com"] }
72
+
73
+ it "filters the nodes by their full hostname" do
74
+ expect(filtered.collect(&:public_hostname)).to eq(["node2.test.riotgames.com"])
75
+ end
76
+ end
77
+
78
+ context "when just the hostname is given" do
79
+ let(:filter) { ["node2"] }
80
+
81
+ it "filters the nodes by their full hostname" do
82
+ expect(filtered.collect(&:public_hostname)).to eq(["node2.test.riotgames.com"])
83
+ end
84
+ end
85
+ end
86
+ end