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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-version +1 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +196 -0
- data/COMMANDS.md +9 -0
- data/CONTRIBUTING.md +24 -0
- data/Dockerfile +26 -0
- data/Gemfile +60 -2
- data/Guardfile +30 -0
- data/LICENSE +10 -0
- data/MANIFESTS.md +90 -0
- data/OPERATORS_GUIDE.md +195 -0
- data/PLUGINS.md +268 -0
- data/README.md +304 -16
- data/Thorfile +123 -0
- data/VAGRANT.md +116 -0
- data/bin/boot +9 -0
- data/bin/mb +5 -0
- data/bin/mbsrv +5 -0
- data/config.json +32 -0
- data/features/cli/bootstrap_command/configurable_scripts.feature +32 -0
- data/features/cli/configure_command.feature +57 -0
- data/features/cli/environment_command/create_command.feature +22 -0
- data/features/cli/environment_command/destroy_command.feature +33 -0
- data/features/cli/environment_command/from_command.feature +29 -0
- data/features/cli/environment_command/list_command.feature +0 -0
- data/features/cli/node_limiting.feature +47 -0
- data/features/cli/plugin_command/list_command.feature +46 -0
- data/features/cli/service_command/service_command.feature +21 -0
- data/features/cli/template_command.feature +10 -0
- data/features/cli/validate_config.feature +46 -0
- data/features/step_definitions/bootstrap_steps.rb +57 -0
- data/features/step_definitions/chef_server_steps.rb +3 -0
- data/features/step_definitions/configuration_steps.rb +18 -0
- data/features/step_definitions/core_cli_steps.rb +33 -0
- data/features/step_definitions/environment_steps.rb +43 -0
- data/features/step_definitions/node_steps.rb +3 -0
- data/features/step_definitions/plugin_steps.rb +15 -0
- data/features/step_definitions/template_steps.rb +7 -0
- data/features/support/env.rb +68 -0
- data/lib/mb/api.rb +8 -0
- data/lib/mb/api/application.rb +7 -0
- data/lib/mb/api/endpoint.rb +5 -0
- data/lib/mb/api/helpers.rb +38 -0
- data/lib/mb/api/v1.rb +56 -0
- data/lib/mb/api/v1/config_endpoint.rb +12 -0
- data/lib/mb/api/v1/environments_endpoint.rb +174 -0
- data/lib/mb/api/v1/jobs_endpoint.rb +31 -0
- data/lib/mb/api/v1/plugins_endpoint.rb +90 -0
- data/lib/mb/api/validators.rb +5 -0
- data/lib/mb/api/validators/sem_ver.rb +18 -0
- data/lib/mb/application.rb +148 -0
- data/lib/mb/berkshelf.rb +50 -0
- data/lib/mb/bootstrap.rb +9 -0
- data/lib/mb/bootstrap/manager.rb +250 -0
- data/lib/mb/bootstrap/manifest.rb +131 -0
- data/lib/mb/bootstrap/routine.rb +199 -0
- data/lib/mb/bootstrap/template.rb +73 -0
- data/lib/mb/bootstrap/worker.rb +227 -0
- data/lib/mb/chef.rb +6 -0
- data/lib/mb/chef/config.rb +69 -0
- data/lib/mb/chef/run_list_item.rb +115 -0
- data/lib/mb/chef_mutex.rb +304 -0
- data/lib/mb/clean_room_base.rb +39 -0
- data/lib/mb/cli.rb +50 -0
- data/lib/mb/cli/base.rb +51 -0
- data/lib/mb/cli/shell.rb +29 -0
- data/lib/mb/cli/shell/basic.rb +11 -0
- data/lib/mb/cli/shell/color.rb +11 -0
- data/lib/mb/cli/shell/ext.rb +41 -0
- data/lib/mb/cli/sub_command.rb +95 -0
- data/lib/mb/cli/sub_command/component.rb +56 -0
- data/lib/mb/cli/sub_command/plugin.rb +232 -0
- data/lib/mb/cli_client.rb +178 -0
- data/lib/mb/cli_gateway.rb +426 -0
- data/lib/mb/cli_gateway/sub_commands.rb +3 -0
- data/lib/mb/cli_gateway/sub_commands/environment.rb +124 -0
- data/lib/mb/cli_gateway/sub_commands/plugin.rb +148 -0
- data/lib/mb/command.rb +88 -0
- data/lib/mb/command_invoker.rb +235 -0
- data/lib/mb/command_invoker/worker.rb +40 -0
- data/lib/mb/command_runner.rb +233 -0
- data/lib/mb/component.rb +245 -0
- data/lib/mb/config.rb +275 -0
- data/lib/mb/config_manager.rb +75 -0
- data/lib/mb/console.rb +35 -0
- data/lib/mb/cookbook_metadata.rb +73 -0
- data/lib/mb/core_ext.rb +3 -0
- data/lib/mb/core_ext/dir.rb +37 -0
- data/lib/mb/core_ext/enumerable.rb +48 -0
- data/lib/mb/core_ext/file.rb +24 -0
- data/lib/mb/core_ext/signal.rb +11 -0
- data/lib/mb/environment_manager.rb +195 -0
- data/lib/mb/error_handler.rb +212 -0
- data/lib/mb/errors.rb +693 -0
- data/lib/mb/file_system.rb +60 -0
- data/lib/mb/file_system/tempfile.rb +25 -0
- data/lib/mb/gear.rb +154 -0
- data/lib/mb/gears.rb +8 -0
- data/lib/mb/gears/dynamic_service.rb +218 -0
- data/lib/mb/gears/jmx.rb +24 -0
- data/lib/mb/gears/jmx/action.rb +46 -0
- data/lib/mb/gears/mysql.rb +20 -0
- data/lib/mb/gears/mysql/action.rb +190 -0
- data/lib/mb/gears/service.rb +163 -0
- data/lib/mb/gears/service/action.rb +58 -0
- data/lib/mb/gears/service/action_runner.rb +161 -0
- data/lib/mb/grape_ext.rb +3 -0
- data/lib/mb/grape_ext/endpoint.rb +13 -0
- data/lib/mb/group.rb +143 -0
- data/lib/mb/job.rb +183 -0
- data/lib/mb/job/state_machine.rb +34 -0
- data/lib/mb/job/states.rb +46 -0
- data/lib/mb/job_manager.rb +96 -0
- data/lib/mb/job_record.rb +67 -0
- data/lib/mb/job_ticket.rb +25 -0
- data/lib/mb/lock_manager.rb +116 -0
- data/lib/mb/logging.rb +134 -0
- data/lib/mb/logging/basic_format.rb +31 -0
- data/lib/mb/manifest.rb +128 -0
- data/lib/mb/mixin.rb +3 -0
- data/lib/mb/mixin/attribute_setting.rb +265 -0
- data/lib/mb/mixin/coded_exit.rb +49 -0
- data/lib/mb/mixin/locks.rb +54 -0
- data/lib/mb/mixin/services.rb +100 -0
- data/lib/mb/node_filter.rb +97 -0
- data/lib/mb/node_querier.rb +527 -0
- data/lib/mb/plugin.rb +300 -0
- data/lib/mb/plugin_manager.rb +589 -0
- data/lib/mb/provisioner.rb +186 -0
- data/lib/mb/provisioner/manager.rb +213 -0
- data/lib/mb/provisioner/manifest.rb +125 -0
- data/lib/mb/provisioner/provision_data.rb +96 -0
- data/lib/mb/provisioners.rb +5 -0
- data/lib/mb/provisioners/aws.rb +395 -0
- data/lib/mb/rest_gateway.rb +72 -0
- data/lib/mb/ridley_ext.rb +5 -0
- data/lib/mb/ridley_ext/cookbook_object.rb +15 -0
- data/lib/mb/srv_ctl.rb +183 -0
- data/lib/mb/test.rb +104 -0
- data/lib/mb/thor_ext.rb +49 -0
- data/lib/mb/upgrade.rb +6 -0
- data/lib/mb/upgrade/manager.rb +85 -0
- data/lib/mb/upgrade/worker.rb +149 -0
- data/lib/mb/version.rb +1 -1
- data/lib/motherbrain.rb +166 -2
- data/man/man_helper.rb +81 -0
- data/man/mb.1 +494 -0
- data/man/mb.1.html +300 -0
- data/man/mb.1.ronn.erb +62 -0
- data/motherbrain.gemspec +56 -20
- data/scripts/node_name.rb +14 -0
- data/spec/fixtures/cb_metadata.json +7 -0
- data/spec/fixtures/cb_metadata.rb +14 -0
- data/spec/fixtures/fake_id_rsa +27 -0
- data/spec/fixtures/fake_key.pem +27 -0
- data/spec/fixtures/myface-0.1.0/metadata.rb +14 -0
- data/spec/fixtures/myface-0.1.0/motherbrain.rb +0 -0
- data/spec/fixtures/test_env.json +15 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/actor_mocking.rb +7 -0
- data/spec/support/berkshelf.rb +24 -0
- data/spec/support/chef_server.rb +102 -0
- data/spec/support/doubles.rb +11 -0
- data/spec/support/klass.rb +10 -0
- data/spec/support/matchers/each.rb +12 -0
- data/spec/support/matchers/error_codes.rb +5 -0
- data/spec/support/matchers/exit_codes.rb +57 -0
- data/spec/support/matchers/jobs.rb +11 -0
- data/spec/support/spec_helpers.rb +145 -0
- data/spec/unit/mb/api/application_spec.rb +11 -0
- data/spec/unit/mb/api/helpers_spec.rb +5 -0
- data/spec/unit/mb/api/v1/config_endpoint_spec.rb +19 -0
- data/spec/unit/mb/api/v1/environments_endpoint_spec.rb +71 -0
- data/spec/unit/mb/api/v1/jobs_endpoint_spec.rb +24 -0
- data/spec/unit/mb/api/v1/plugins_endpoint_spec.rb +298 -0
- data/spec/unit/mb/api/v1_spec.rb +37 -0
- data/spec/unit/mb/api/validators/sem_ver_spec.rb +5 -0
- data/spec/unit/mb/application_spec.rb +19 -0
- data/spec/unit/mb/berkshelf_spec.rb +38 -0
- data/spec/unit/mb/bootstrap/manager_spec.rb +347 -0
- data/spec/unit/mb/bootstrap/manifest_spec.rb +333 -0
- data/spec/unit/mb/bootstrap/routine_spec.rb +393 -0
- data/spec/unit/mb/bootstrap/template_spec.rb +100 -0
- data/spec/unit/mb/bootstrap/worker_spec.rb +194 -0
- data/spec/unit/mb/chef/config_spec.rb +33 -0
- data/spec/unit/mb/chef/run_list_item_spec.rb +34 -0
- data/spec/unit/mb/chef_mutex_spec.rb +314 -0
- data/spec/unit/mb/clean_room_base_spec.rb +31 -0
- data/spec/unit/mb/cli/base_spec.rb +43 -0
- data/spec/unit/mb/cli/shell/basic_spec.rb +5 -0
- data/spec/unit/mb/cli/shell/color_spec.rb +5 -0
- data/spec/unit/mb/cli/shell/ext_spec.rb +11 -0
- data/spec/unit/mb/cli/shell_spec.rb +38 -0
- data/spec/unit/mb/cli/sub_command/base_spec.rb +102 -0
- data/spec/unit/mb/cli/sub_command/component_spec.rb +5 -0
- data/spec/unit/mb/cli/sub_command/plugin_spec.rb +91 -0
- data/spec/unit/mb/cli/sub_command_spec.rb +43 -0
- data/spec/unit/mb/cli/ui.rb +0 -0
- data/spec/unit/mb/cli_client_spec.rb +51 -0
- data/spec/unit/mb/cli_gateway_spec.rb +386 -0
- data/spec/unit/mb/command_invoker/worker_spec.rb +43 -0
- data/spec/unit/mb/command_invoker_spec.rb +230 -0
- data/spec/unit/mb/command_runner_spec.rb +299 -0
- data/spec/unit/mb/command_spec.rb +76 -0
- data/spec/unit/mb/component_spec.rb +185 -0
- data/spec/unit/mb/config_manager_spec.rb +31 -0
- data/spec/unit/mb/config_spec.rb +408 -0
- data/spec/unit/mb/cookbook_metadata_spec.rb +89 -0
- data/spec/unit/mb/core_ext/dir_spec.rb +92 -0
- data/spec/unit/mb/core_ext/enumerable_spec.rb +104 -0
- data/spec/unit/mb/core_ext/file_spec.rb +58 -0
- data/spec/unit/mb/core_ext/signal_spec.rb +24 -0
- data/spec/unit/mb/environment_manager_spec.rb +166 -0
- data/spec/unit/mb/error_handler_spec.rb +173 -0
- data/spec/unit/mb/errors_spec.rb +132 -0
- data/spec/unit/mb/file_system/tempfile_spec.rb +14 -0
- data/spec/unit/mb/file_system_spec.rb +69 -0
- data/spec/unit/mb/gear_spec.rb +125 -0
- data/spec/unit/mb/gears/dynamic_service_spec.rb +187 -0
- data/spec/unit/mb/gears/jmx/action_spec.rb +34 -0
- data/spec/unit/mb/gears/jmx_spec.rb +32 -0
- data/spec/unit/mb/gears/mysql/action_spec.rb +118 -0
- data/spec/unit/mb/gears/mysql_spec.rb +21 -0
- data/spec/unit/mb/gears/service/action_runner_spec.rb +182 -0
- data/spec/unit/mb/gears/service/action_spec.rb +44 -0
- data/spec/unit/mb/gears/service_spec.rb +124 -0
- data/spec/unit/mb/group_spec.rb +280 -0
- data/spec/unit/mb/job_manager_spec.rb +56 -0
- data/spec/unit/mb/job_record_spec.rb +60 -0
- data/spec/unit/mb/job_spec.rb +201 -0
- data/spec/unit/mb/locks_manager_spec.rb +88 -0
- data/spec/unit/mb/logging_spec.rb +133 -0
- data/spec/unit/mb/manifest_spec.rb +105 -0
- data/spec/unit/mb/mixin/attribute_setting_spec.rb +180 -0
- data/spec/unit/mb/mixin/coded_exit_spec.rb +25 -0
- data/spec/unit/mb/mixin/locks_spec.rb +32 -0
- data/spec/unit/mb/mixin/services_spec.rb +75 -0
- data/spec/unit/mb/node_filter_spec.rb +86 -0
- data/spec/unit/mb/node_querier_spec.rb +532 -0
- data/spec/unit/mb/plugin_manager_spec.rb +724 -0
- data/spec/unit/mb/plugin_spec.rb +247 -0
- data/spec/unit/mb/provisioner/manager_spec.rb +141 -0
- data/spec/unit/mb/provisioner/manifest_spec.rb +182 -0
- data/spec/unit/mb/provisioner/provision_data_spec.rb +113 -0
- data/spec/unit/mb/provisioner_spec.rb +251 -0
- data/spec/unit/mb/provisioners/aws_spec.rb +392 -0
- data/spec/unit/mb/provisioners/environment_factory_spec.rb +108 -0
- data/spec/unit/mb/rest_gateway_spec.rb +13 -0
- data/spec/unit/mb/ridley_ext/cookbook_object_spec.rb +105 -0
- data/spec/unit/mb/srv_ctl_spec.rb +142 -0
- data/spec/unit/mb/upgrade/manager_spec.rb +37 -0
- data/spec/unit/mb/upgrade/worker_spec.rb +219 -0
- data/spec/unit/motherbrain_spec.rb +58 -0
- data/templates/bootstrap.json +8 -0
- data/templates/motherbrain.rb +44 -0
- metadata +694 -15
- data/Rakefile +0 -1
@@ -0,0 +1,393 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Bootstrap::Routine do
|
4
|
+
describe "ClassMethods" do
|
5
|
+
describe "::map_instructions" do
|
6
|
+
let(:task_one) { described_class::Task.new("app_server::default") }
|
7
|
+
let(:tasks) { [ task_one ] }
|
8
|
+
let(:manifest) do
|
9
|
+
MB::Bootstrap::Manifest.new(
|
10
|
+
nodes: [
|
11
|
+
{
|
12
|
+
groups: ["app_server::default"],
|
13
|
+
hosts: [
|
14
|
+
"euca-10-20-37-171.eucalyptus.cloud.riotgames.com",
|
15
|
+
"euca-10-20-37-172.eucalyptus.cloud.riotgames.com"
|
16
|
+
]
|
17
|
+
},
|
18
|
+
{
|
19
|
+
groups: ["database_master::default"],
|
20
|
+
hosts: [
|
21
|
+
"euca-10-20-37-168.eucalyptus.cloud.riotgames.com"
|
22
|
+
]
|
23
|
+
}
|
24
|
+
]
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
subject { described_class.map_instructions(tasks, manifest) }
|
29
|
+
|
30
|
+
it "returns a Hash" do
|
31
|
+
expect(subject).to be_a(Hash)
|
32
|
+
end
|
33
|
+
|
34
|
+
context "given a Task matching a node group in the manifest" do
|
35
|
+
let(:task_one) do
|
36
|
+
described_class::Task.new("app_server::default",
|
37
|
+
run_list: ["recipe[one]", "recipe[two]"],
|
38
|
+
chef_attributes: { deep: { nested: { one: "value" } } }
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "has a key for every host in the matched node group" do
|
43
|
+
expect(subject.keys).to have(2).items
|
44
|
+
end
|
45
|
+
|
46
|
+
it "each item has a groups key containing an array with an entry for each matching node group" do
|
47
|
+
subject.each do |host, info|
|
48
|
+
expect(info[:groups]).to have(1).item
|
49
|
+
expect(info[:groups]).to include(task_one.group_name)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "each item has an options key with a run_list matching the Task's run_list" do
|
54
|
+
subject.each do |host, info|
|
55
|
+
expect(info[:options][:run_list]).to eql(task_one.run_list)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "each item has an options key with a chef_attributes matching the Task's chef_attributes" do
|
60
|
+
subject.each do |host, info|
|
61
|
+
expect(info[:options][:chef_attributes]).to eql(Hashie::Mash.new(task_one.chef_attributes))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "has a Hashie::Mash value for options[:chef_attributes]" do
|
66
|
+
subject.each do |host, info|
|
67
|
+
expect(info[:options][:chef_attributes]).to be_a(Hashie::Mash)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "given two Tasks matching the same node group in the manifest" do
|
73
|
+
let(:task_one) do
|
74
|
+
described_class::Task.new("app_server::default",
|
75
|
+
run_list: ["recipe[one]", "recipe[two]"],
|
76
|
+
chef_attributes: { deep: { nested: { one: "value" } } }
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
let(:task_two) do
|
81
|
+
described_class::Task.new("database_master::default",
|
82
|
+
run_list: ["recipe[one]", "recipe[three]"],
|
83
|
+
chef_attributes: { deep: { nested: { two: "value" } } }
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
let(:manifest) do
|
88
|
+
MB::Bootstrap::Manifest.new(
|
89
|
+
nodes: [
|
90
|
+
{
|
91
|
+
groups: ["app_server::default", "database_master::default"],
|
92
|
+
hosts: [
|
93
|
+
"euca-10-20-37-171.eucalyptus.cloud.riotgames.com",
|
94
|
+
"euca-10-20-37-172.eucalyptus.cloud.riotgames.com"
|
95
|
+
]
|
96
|
+
}
|
97
|
+
]
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
let(:tasks) { [ task_one, task_two ] }
|
102
|
+
|
103
|
+
it "has a key for every host in the matched node group" do
|
104
|
+
expect(subject.keys).to have(2).items
|
105
|
+
end
|
106
|
+
|
107
|
+
it "each item has a groups key containing an array with an entry for each matching node group" do
|
108
|
+
subject.each do |host, info|
|
109
|
+
expect(info[:groups]).to have(2).item
|
110
|
+
expect(info[:groups]).to include(task_one.group_name)
|
111
|
+
expect(info[:groups]).to include(task_two.group_name)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it "each item has an options key with a run_list including each Task's run_list with no duplicates" do
|
116
|
+
subject.each do |host, info|
|
117
|
+
expect(info[:options][:run_list]).to include(*task_one.run_list)
|
118
|
+
expect(info[:options][:run_list]).to include(*task_two.run_list)
|
119
|
+
expect(info[:options][:run_list]).to have(3).items
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it "each item has an options key with a chef_attributes including each Task's chef_attributes" do
|
124
|
+
new_attributes = task_one.chef_attributes.deep_merge(task_two.chef_attributes)
|
125
|
+
|
126
|
+
subject.each do |host, info|
|
127
|
+
expect(info[:options][:chef_attributes]).to eql(Hashie::Mash.new(new_attributes))
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "given two Tasks matching different node groups in the manifest" do
|
133
|
+
let(:task_one) { described_class::Task.new("app_server::default") }
|
134
|
+
let(:task_two) { described_class::Task.new("database_master::default") }
|
135
|
+
let(:manifest) do
|
136
|
+
MB::Bootstrap::Manifest.new(
|
137
|
+
nodes: [
|
138
|
+
{
|
139
|
+
groups: ["app_server::default"],
|
140
|
+
hosts: [
|
141
|
+
"euca-10-20-37-171.eucalyptus.cloud.riotgames.com",
|
142
|
+
"euca-10-20-37-172.eucalyptus.cloud.riotgames.com"
|
143
|
+
]
|
144
|
+
},
|
145
|
+
{
|
146
|
+
groups: ["database_master::default"],
|
147
|
+
hosts: [
|
148
|
+
"euca-10-20-37-168.eucalyptus.cloud.riotgames.com"
|
149
|
+
]
|
150
|
+
}
|
151
|
+
]
|
152
|
+
)
|
153
|
+
end
|
154
|
+
let(:tasks) { [ task_one, task_two ] }
|
155
|
+
|
156
|
+
it "has a key for every host in the matched node group" do
|
157
|
+
expect(subject.keys).to have(3).items
|
158
|
+
end
|
159
|
+
|
160
|
+
it "each item has a groups key containing an array with an entry for each matching node group" do
|
161
|
+
subject.each do |host, info|
|
162
|
+
expect(info[:groups]).to have(1).item
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "given a Task that matches no node groups in the manifest" do
|
168
|
+
let(:task_one) { described_class::Task.new("database_slave::default") }
|
169
|
+
let(:tasks) { [ task_one ] }
|
170
|
+
|
171
|
+
it "returns an empty Hash" do
|
172
|
+
expect(subject).to be_empty
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "given an empty array of tasks" do
|
177
|
+
let(:tasks) { Array.new }
|
178
|
+
|
179
|
+
it "returns an empty Hash" do
|
180
|
+
expect(subject).to be_empty
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "given an empty manifest" do
|
185
|
+
let(:manifest) { MB::Bootstrap::Manifest.new }
|
186
|
+
|
187
|
+
it "returns an empty Hash" do
|
188
|
+
expect(subject).to be_empty
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
let(:plugin) do
|
195
|
+
metadata = MB::CookbookMetadata.new do
|
196
|
+
name "motherbrain"
|
197
|
+
version "0.1.0"
|
198
|
+
end
|
199
|
+
|
200
|
+
MB::Plugin.new(metadata)
|
201
|
+
end
|
202
|
+
|
203
|
+
let(:activemq) { MB::Component.new('activemq', plugin) }
|
204
|
+
let(:mysql) { MB::Component.new('mysql', plugin) }
|
205
|
+
let(:nginx) { MB::Component.new('nginx', plugin) }
|
206
|
+
|
207
|
+
let(:amq_master) { MB::Group.new('master') }
|
208
|
+
let(:amq_slave) { MB::Group.new('slave') }
|
209
|
+
let(:mysql_master) { MB::Group.new('master') }
|
210
|
+
let(:mysql_slave) { MB::Group.new('slave') }
|
211
|
+
let(:nginx_master) { MB::Group.new('master') }
|
212
|
+
|
213
|
+
before(:each) do
|
214
|
+
plugin.stub(:components).and_return([activemq, mysql, nginx])
|
215
|
+
activemq.stub(:groups).and_return([amq_master, amq_slave])
|
216
|
+
mysql.stub(:groups).and_return([mysql_master, mysql_slave])
|
217
|
+
nginx.stub(:groups).and_return([nginx_master])
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "DSL evaluation" do
|
221
|
+
subject do
|
222
|
+
described_class.new(plugin) do
|
223
|
+
async do
|
224
|
+
bootstrap("activemq::master")
|
225
|
+
bootstrap("activemq::slave")
|
226
|
+
end
|
227
|
+
|
228
|
+
async do
|
229
|
+
bootstrap("mysql::master")
|
230
|
+
bootstrap("mysql::slave")
|
231
|
+
end
|
232
|
+
|
233
|
+
bootstrap("nginx::master")
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
it "has an entry for each bootstrap or async function call" do
|
238
|
+
subject.task_queue.should have(3).items
|
239
|
+
end
|
240
|
+
|
241
|
+
context "each entry" do
|
242
|
+
it "is in FIFO order" do
|
243
|
+
expect(subject.task_queue[0]).to be_a(Array)
|
244
|
+
expect(subject.task_queue[0][0].group_name).to eql("activemq::master")
|
245
|
+
expect(subject.task_queue[0][1].group_name).to eql("activemq::slave")
|
246
|
+
expect(subject.task_queue[1]).to be_a(Array)
|
247
|
+
expect(subject.task_queue[1][0].group_name).to eql("mysql::master")
|
248
|
+
expect(subject.task_queue[1][1].group_name).to eql("mysql::slave")
|
249
|
+
expect(subject.task_queue[2].group_name).to eql("nginx::master")
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
let(:manifest) {
|
255
|
+
{
|
256
|
+
nodes: [
|
257
|
+
{
|
258
|
+
groups: ["activemq::master"],
|
259
|
+
hosts: ["amq1.riotgames.com", "amq2.riotgames.com"]
|
260
|
+
},
|
261
|
+
{
|
262
|
+
groups: ["activemq::slave"],
|
263
|
+
hosts: ["amqs1.riotgames.com", "amqs2.riotgames.com"]
|
264
|
+
},
|
265
|
+
{
|
266
|
+
groups: ["nginx::master"],
|
267
|
+
hosts: ["nginx1.riotgames.com"]
|
268
|
+
}
|
269
|
+
]
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
subject { described_class.new(plugin) }
|
274
|
+
|
275
|
+
describe "#task_queue" do
|
276
|
+
it "returns an array" do
|
277
|
+
subject.task_queue.should be_a(Array)
|
278
|
+
end
|
279
|
+
|
280
|
+
context "given a routine with async tasks" do
|
281
|
+
subject do
|
282
|
+
described_class.new(plugin) do
|
283
|
+
async do
|
284
|
+
bootstrap("activemq::master")
|
285
|
+
bootstrap("activemq::slave")
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
it "returns an array of arrays of bootstrap routine tasks" do
|
291
|
+
subject.task_queue.should have(1).item
|
292
|
+
subject.task_queue[0].should have(2).items
|
293
|
+
subject.task_queue[0].should each be_a(MB::Bootstrap::Routine::Task)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context "given a routine with syncronous tasks" do
|
298
|
+
subject do
|
299
|
+
described_class.new(plugin) do
|
300
|
+
bootstrap("activemq::master")
|
301
|
+
bootstrap("activemq::slave")
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
it "returns an array of bootstrap routine tasks" do
|
306
|
+
subject.task_queue.should have(2).items
|
307
|
+
subject.task_queue.should each be_a(MB::Bootstrap::Routine::Task)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
describe "#has_task?" do
|
313
|
+
subject do
|
314
|
+
described_class.new(plugin) do
|
315
|
+
bootstrap("activemq::master")
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
it "returns true if a bootstrap routine task with the matching ID is present" do
|
320
|
+
expect(subject).to have_task("activemq::master")
|
321
|
+
end
|
322
|
+
|
323
|
+
it "returns nil if a task with a matching ID is not present" do
|
324
|
+
expect(subject).to_not have_task("not::defined")
|
325
|
+
end
|
326
|
+
|
327
|
+
context "given a routine with async tasks" do
|
328
|
+
subject do
|
329
|
+
described_class.new(plugin) do
|
330
|
+
async do
|
331
|
+
bootstrap("activemq::master")
|
332
|
+
bootstrap("activemq::slave")
|
333
|
+
end
|
334
|
+
bootstrap("nginx::master")
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
it "has the nested async tasks and the top level tasks" do
|
339
|
+
subject.should have_task("activemq::master")
|
340
|
+
subject.should have_task("activemq::slave")
|
341
|
+
subject.should have_task("nginx::master")
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
describe MB::Bootstrap::Routine::Task do
|
348
|
+
describe "::from_group_path" do
|
349
|
+
let(:plugin) do
|
350
|
+
metadata = MB::CookbookMetadata.new do
|
351
|
+
name "motherbrain"
|
352
|
+
version "0.1.0"
|
353
|
+
end
|
354
|
+
|
355
|
+
MB::Plugin.new(metadata)
|
356
|
+
end
|
357
|
+
|
358
|
+
let(:activemq) { MB::Component.new('activemq', plugin) }
|
359
|
+
let(:amq_master) { MB::Group.new('master') }
|
360
|
+
let(:group_path) { "activemq::master" }
|
361
|
+
|
362
|
+
before(:each) do
|
363
|
+
plugin.stub(:components).and_return([activemq])
|
364
|
+
activemq.stub(:groups).and_return([amq_master])
|
365
|
+
end
|
366
|
+
|
367
|
+
subject { described_class.from_group_path(plugin, group_path) }
|
368
|
+
|
369
|
+
context "given an invalid string" do
|
370
|
+
let(:group_path) { :one_two }
|
371
|
+
|
372
|
+
it "raises a PluginSyntaxError" do
|
373
|
+
expect { subject }.to raise_error(MB::PluginSyntaxError)
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
context "when the given plugin does not contain the component in the given name" do
|
378
|
+
let(:group_path) { "something::master" }
|
379
|
+
|
380
|
+
it "raises a PluginSyntaxError" do
|
381
|
+
expect { subject }.to raise_error(MB::PluginSyntaxError)
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
context "when the given plugin does not contain the group in the given name" do
|
386
|
+
let(:group_path) { "activemq::slave" }
|
387
|
+
|
388
|
+
it "raises a PluginSyntaxError" do
|
389
|
+
expect { subject }.to raise_error(MB::PluginSyntaxError)
|
390
|
+
end
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Bootstrap::Template do
|
4
|
+
context "ClassMethods" do
|
5
|
+
describe "#find" do
|
6
|
+
let(:name_or_path) { "foo" }
|
7
|
+
subject { described_class.find(name_or_path) }
|
8
|
+
|
9
|
+
context "with installed template" do
|
10
|
+
before do
|
11
|
+
File.should_receive(:exists?).
|
12
|
+
with(MB::FileSystem.templates.join("#{name_or_path}.erb").to_s).
|
13
|
+
and_return(true)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be the path to the installed template" do
|
17
|
+
expect(subject).to eq(MB::FileSystem.templates.join("foo.erb").to_s)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with no installed template" do
|
22
|
+
before do
|
23
|
+
File.should_receive(:exists?).
|
24
|
+
with(MB::FileSystem.templates.join("#{name_or_path}.erb").to_s).
|
25
|
+
and_return(false)
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with an existing path" do
|
29
|
+
let(:name_or_path) { "/some/path/bar.erb" }
|
30
|
+
|
31
|
+
before do
|
32
|
+
File.should_receive(:exists?).
|
33
|
+
with(name_or_path).and_return(true)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should be the passed in path" do
|
37
|
+
expect(subject).to eq(name_or_path)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with a non-existant path" do
|
42
|
+
let(:name_or_path) { "/some/path/baz.erb" }
|
43
|
+
|
44
|
+
before do
|
45
|
+
File.should_receive(:exists?).
|
46
|
+
with(name_or_path).and_return(false)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should raise" do
|
50
|
+
expect { subject }.to raise_error(MB::BootstrapTemplateNotFound)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with no name or path" do
|
56
|
+
let(:name_or_path) { nil }
|
57
|
+
|
58
|
+
context "with a default in config" do
|
59
|
+
before do
|
60
|
+
MB::Application.config.bootstrap.default_template = "quux"
|
61
|
+
File.should_receive(:exists?).
|
62
|
+
with(MB::FileSystem.templates.join("quux.erb").to_s).
|
63
|
+
and_return(true)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should get the default" do
|
67
|
+
expect(subject).to eq(MB::FileSystem.templates.join("quux.erb").to_s)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#install" do
|
74
|
+
subject { described_class }
|
75
|
+
|
76
|
+
it "should install a file" do
|
77
|
+
File.should_receive(:exists?).with("/path/to/file.erb").and_return(true)
|
78
|
+
FileUtils.should_receive(:copy).
|
79
|
+
with("/path/to/file.erb",MB::FileSystem.templates.join("file.erb").to_s)
|
80
|
+
subject.install("file", "/path/to/file.erb")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should install from a URL" do
|
84
|
+
faraday = Faraday.new do |builder|
|
85
|
+
builder.adapter :test do |stub|
|
86
|
+
stub.get('/gist') {[ 200, {}, 'example' ]}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
Faraday.should_receive(:new).and_return(faraday)
|
90
|
+
subject.install("fromurl", "http://example.com/gist")
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should error when file doesn't exist" do
|
94
|
+
File.should_receive(:exists?).with("/path/to/badfile.erb").and_return(false)
|
95
|
+
FileUtils.should_not_receive(:copy)
|
96
|
+
expect { subject.install("file", "/path/to/badfile.erb") }.to raise_error(MB::BootstrapTemplateNotFound)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|