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,187 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Gear::DynamicService do
|
4
|
+
let(:dynamic_service) { described_class.new('webapp', 'tomcat') }
|
5
|
+
let(:plugin) { double(MB::Plugin, name: "MyPlugin", component: component) }
|
6
|
+
let(:environment) { "prod" }
|
7
|
+
let(:state) { "start" }
|
8
|
+
let(:component) { double(get_service: service, group: group) }
|
9
|
+
let(:service) { double(service_group: "default", service_attribute: ["foo.bar"], service_recipe: ["tomcat_stop"]) }
|
10
|
+
let(:group) { double(nodes: nodes) }
|
11
|
+
let(:nodes) { [ node1, node2 ] }
|
12
|
+
let(:node1) { double(name: nil, reload: nil, set_chef_attribute: nil, save: nil) }
|
13
|
+
let(:node2) { double(name: nil, reload: nil, set_chef_attribute: nil, save: nil) }
|
14
|
+
let(:job) { MB::Job.new(:thejob) }
|
15
|
+
describe "ClassMethods" do
|
16
|
+
let(:service) { "webapp.tomcat" }
|
17
|
+
|
18
|
+
before do
|
19
|
+
dynamic_service.stub(:state_change)
|
20
|
+
MB::Job.should_receive(:new).and_return(job)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "::change_service_state" do
|
24
|
+
let(:change_service_state) { MB::Gear::DynamicService.change_service_state(service, plugin, environment, state) }
|
25
|
+
|
26
|
+
it "splits the service on a period" do
|
27
|
+
expect(MB::Gear::DynamicService).to receive(:new).with('webapp', 'tomcat').and_return(dynamic_service)
|
28
|
+
change_service_state
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when the service is not formatted as 'COMPONENT.SERVICE'" do
|
32
|
+
let(:service) { "foo" }
|
33
|
+
|
34
|
+
it "raises an error" do
|
35
|
+
job.should_receive(:report_failure).with(kind_of(MB::InvalidDynamicService))
|
36
|
+
change_service_state
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:job) { double(alive?: false, report_running: nil, set_status: nil, report_success: nil, ticket: nil) }
|
43
|
+
|
44
|
+
describe "#state_change" do
|
45
|
+
let(:state_change) { dynamic_service.state_change(job, plugin, environment, state, true, options) }
|
46
|
+
let(:node_querier) { double(bulk_chef_run: nil) }
|
47
|
+
let(:options) { Hash.new }
|
48
|
+
|
49
|
+
before do
|
50
|
+
dynamic_service.stub(:unset_environment_attribute)
|
51
|
+
dynamic_service.stub(:set_node_attributes)
|
52
|
+
dynamic_service.stub(:node_querier).and_return(node_querier)
|
53
|
+
MotherBrain::Job.stub(:new).and_return(job)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "starts a bulk chef run" do
|
57
|
+
expect(node_querier).to receive(:bulk_chef_run).with(job, nodes, ["tomcat_stop"])
|
58
|
+
state_change
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when you attempt to change to an unsupported state" do
|
62
|
+
let(:state) { "foobar" }
|
63
|
+
let(:log) { double( info: nil) }
|
64
|
+
|
65
|
+
before do
|
66
|
+
MB::Logging.stub(:logger).and_return(log)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "logs a warning" do
|
70
|
+
expect(log).to receive(:warn)
|
71
|
+
state_change
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when the cluster override flag is provided" do
|
76
|
+
let(:options) do
|
77
|
+
{
|
78
|
+
cluster_override: true
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
it "sets an attribute on the environment" do
|
83
|
+
expect(dynamic_service).to receive(:set_environment_attribute)
|
84
|
+
state_change
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#remove_node_state_change" do
|
90
|
+
subject { MB::Gear::DynamicService.new(component_name, service_name) }
|
91
|
+
let(:service_name) { "foo_service" }
|
92
|
+
let(:service) { double(MB::Gear::Service,
|
93
|
+
service_attribute: ["foo.service_attr"],
|
94
|
+
service_recipe: service_recipe) }
|
95
|
+
let(:component_name) { "foo_component" }
|
96
|
+
let(:plugin) { double(MB::Plugin) }
|
97
|
+
let(:component) { double(MB::Component) }
|
98
|
+
let(:node_querier) { double(MB::NodeQuerier) }
|
99
|
+
let(:node) { double(Ridley::NodeObject) }
|
100
|
+
let(:service_recipe) { "recipe[foo::service]" }
|
101
|
+
|
102
|
+
before do
|
103
|
+
plugin.stub(:component).with(component_name).and_return(component)
|
104
|
+
component.stub(:get_service).with(service_name).and_return(service)
|
105
|
+
subject.stub(:node_querier).and_return(node_querier)
|
106
|
+
subject.stub(:unset_node_attributes).with(job, [node], service.service_attribute)
|
107
|
+
node_querier.stub(:bulk_chef_run).with(job, [node], service.service_recipe)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should run chef by default" do
|
111
|
+
expect(node_querier).to receive(:bulk_chef_run).with(job, [node], service_recipe)
|
112
|
+
subject.remove_node_state_change(job, plugin, node)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should not run chef if told not to" do
|
116
|
+
expect(node_querier).not_to receive(:bulk_chef_run)
|
117
|
+
subject.remove_node_state_change(job, plugin, node, false)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should set the service node attributes to nil" do
|
121
|
+
expect(subject).to receive(:unset_node_attributes).with(job, [node], service.service_attribute)
|
122
|
+
subject.remove_node_state_change(job, plugin, node, false)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "#get_chef_environment" do
|
127
|
+
let(:get_chef_environment) { dynamic_service.get_chef_environment(environment) }
|
128
|
+
let(:result) { double() }
|
129
|
+
|
130
|
+
before do
|
131
|
+
dynamic_service.stub_chain(:chef_connection, :environment, :find).and_return(result)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "returns the chef environment object" do
|
135
|
+
expect(get_chef_environment).to eql(result)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
let(:attribute_keys) { ["foo.bar"] }
|
140
|
+
let(:state) { "start" }
|
141
|
+
let(:chef_environment_object) { double(set_override_attribute: nil, delete_override_attribute: nil, save: nil) }
|
142
|
+
|
143
|
+
describe "#set_environment_attribute" do
|
144
|
+
|
145
|
+
before do
|
146
|
+
dynamic_service.stub(:get_chef_environment).and_return(chef_environment_object)
|
147
|
+
end
|
148
|
+
|
149
|
+
let(:set_environment_attribute) { dynamic_service.set_environment_attribute(job, environment, attribute_keys, state) }
|
150
|
+
|
151
|
+
it "sets a chef attribute on the environment" do
|
152
|
+
expect(chef_environment_object).to receive(:set_override_attribute).with('foo.bar', 'start')
|
153
|
+
expect(chef_environment_object).to receive(:save)
|
154
|
+
set_environment_attribute
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "#unset_environment_attribute" do
|
159
|
+
let(:unset_environment_attribute) { dynamic_service.unset_environment_attribute(job, environment, attribute_keys) }
|
160
|
+
|
161
|
+
before do
|
162
|
+
dynamic_service.stub(:get_chef_environment).and_return(chef_environment_object)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "deletes a chef attribute on the environment" do
|
166
|
+
expect(chef_environment_object).to receive(:delete_override_attribute).with('foo.bar')
|
167
|
+
expect(chef_environment_object).to receive(:save)
|
168
|
+
unset_environment_attribute
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "#set_node_attributes" do
|
173
|
+
let(:set_node_attribute) { dynamic_service.set_node_attributes(job, nodes, attribute_keys, state) }
|
174
|
+
|
175
|
+
it "sets a chef attribute on the node" do
|
176
|
+
expect(node1).to receive(:set_chef_attribute).with("foo.bar", "start")
|
177
|
+
expect(node2).to receive(:set_chef_attribute).with("foo.bar", "start")
|
178
|
+
set_node_attribute
|
179
|
+
end
|
180
|
+
|
181
|
+
it "saves the node" do
|
182
|
+
expect(node1).to receive(:save)
|
183
|
+
expect(node2).to receive(:save)
|
184
|
+
set_node_attribute
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Gear::JMX::Action do
|
4
|
+
subject { described_class }
|
5
|
+
before { described_class.any_instance.stub(jruby?: true) }
|
6
|
+
|
7
|
+
describe "::new" do
|
8
|
+
let(:port) { 9001 }
|
9
|
+
let(:object_name) { "com.some.thing:name=thing" }
|
10
|
+
|
11
|
+
it "should set its attributes" do
|
12
|
+
obj = subject.new(port, object_name) do |mbean|
|
13
|
+
mbean.do_a_thing
|
14
|
+
end
|
15
|
+
|
16
|
+
obj.port.should == port
|
17
|
+
obj.object_name.should == object_name
|
18
|
+
obj.block.should be_a(Proc)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be given a block" do
|
22
|
+
lambda do
|
23
|
+
obj = subject.new(port, object_name)
|
24
|
+
end.should raise_error(MB::ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be given a block with 1 argument" do
|
28
|
+
lambda do
|
29
|
+
obj = subject.new(port, object_name) do
|
30
|
+
end
|
31
|
+
end.should raise_error(MB::ArgumentError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Gear::JMX do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
it "is registered with MB::Gear" do
|
7
|
+
MB::Gear.all.should include(subject)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has the inferred keyword ':jmx' from it's Class name" do
|
11
|
+
subject.keyword.should eql(:jmx)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#action" do
|
15
|
+
subject { MB::Gear::JMX.new }
|
16
|
+
before { described_class.any_instance.stub(jruby?: true) }
|
17
|
+
|
18
|
+
it "returns a Gear::JMX::Action" do
|
19
|
+
expect(subject.action(9001, "com.some.thing:name=thing") { |bean| }).to be_a(MB::Gear::JMX::Action)
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when not running under JRuby" do
|
23
|
+
before { described_class.any_instance.stub(jruby?: false) }
|
24
|
+
|
25
|
+
it "raises an ActionNotSupported error" do
|
26
|
+
expect {
|
27
|
+
subject.action(9001, "com.some.thing:name=thing")
|
28
|
+
}.to raise_error(MB::ActionNotSupported)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Gear::MySQL::Action do
|
4
|
+
subject { described_class }
|
5
|
+
let(:environment) { "rspec-test" }
|
6
|
+
let(:sql) { "select * from boxes" }
|
7
|
+
let(:base_options) { {data_bag: {name: "creds"}} }
|
8
|
+
|
9
|
+
describe "::new" do
|
10
|
+
it "should set its attributes" do
|
11
|
+
obj = subject.new(sql, base_options)
|
12
|
+
|
13
|
+
obj.sql.should == sql
|
14
|
+
obj.options.should == base_options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "options" do
|
19
|
+
it "should describe a data bag" do
|
20
|
+
options = {}
|
21
|
+
expect { subject.new(sql, options) }.to raise_error(MB::ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have a data bag name" do
|
25
|
+
options = {data_bag: {}}
|
26
|
+
expect { subject.new(sql, options) }.to raise_error(MB::ArgumentError)
|
27
|
+
|
28
|
+
options = {data_bag: {name: "creds"}}
|
29
|
+
expect { subject.new(sql, options) }.not_to raise_error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#connection_info" do
|
34
|
+
let(:node) { double("node", public_hostname: "some.node.com") }
|
35
|
+
let(:data_bag_item) { double("data_bag_item") }
|
36
|
+
let(:data_bag) { double("data_bag") }
|
37
|
+
subject { described_class.new(sql, base_options) }
|
38
|
+
|
39
|
+
before(:each) do
|
40
|
+
subject.ridley.stub_chain(:data_bag, :find).and_return(data_bag)
|
41
|
+
data_bag.stub_chain(:item, :find).and_return(data_bag_item)
|
42
|
+
end
|
43
|
+
|
44
|
+
context "the data bag is empty" do
|
45
|
+
before(:each) do
|
46
|
+
data_bag_item.stub(:decrypt).and_return({})
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should raise a GearError" do
|
50
|
+
expect { subject.connection_info(environment, node) }.to raise_error(MB::GearError)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "the data bag is not empty" do
|
55
|
+
before(:each) do
|
56
|
+
data_bag_hash = {username: "user", password: "pass", database: "db", port: 3306}
|
57
|
+
data_bag_item.stub(:decrypt).and_return(data_bag_hash)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have a host" do
|
61
|
+
connection_info = subject.connection_info(environment, node)
|
62
|
+
|
63
|
+
connection_info[:host].should == "some.node.com"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should retrieve the credentials from the data bag" do
|
67
|
+
connection_info = subject.connection_info(environment, node)
|
68
|
+
|
69
|
+
connection_info[:username].should == "user"
|
70
|
+
connection_info[:password].should == "pass"
|
71
|
+
connection_info[:database].should == "db"
|
72
|
+
connection_info[:port].should == 3306
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when the data bag does not exist" do
|
77
|
+
before do
|
78
|
+
subject.should_receive(:credentials).with(environment).and_raise(MB::DataBagNotFound.new("kittens"))
|
79
|
+
end
|
80
|
+
|
81
|
+
it "raises a GearError" do
|
82
|
+
expect {
|
83
|
+
subject.connection_info(environment, node)
|
84
|
+
}.to raise_error
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "when the data bag item does not exist" do
|
89
|
+
before do
|
90
|
+
subject.should_receive(:credentials).with(environment).
|
91
|
+
and_raise(MB::DataBagItemNotFound.new("kittens", "puppies"))
|
92
|
+
end
|
93
|
+
|
94
|
+
it "raises a GearError" do
|
95
|
+
expect {
|
96
|
+
subject.connection_info(environment, node)
|
97
|
+
}.to raise_error
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#data_bag_keys" do
|
103
|
+
let(:keys) { [:username, :password, :database, :port] }
|
104
|
+
|
105
|
+
it "should have all of the keys" do
|
106
|
+
obj = subject.new(sql, base_options)
|
107
|
+
keys.each { |key| obj.data_bag_keys.should have_key(key) }
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should prepend the base hash" do
|
111
|
+
options = base_options.dup
|
112
|
+
options[:data_bag][:location] = {hash: "some.hash"}
|
113
|
+
obj = subject.new(sql, options)
|
114
|
+
|
115
|
+
keys.each { |key| obj.data_bag_keys[key].should start_with("some.hash.") }
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Gear::MySQL do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
it "is registered with MB::Gear" do
|
7
|
+
MB::Gear.all.should include(subject)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has the inferred keyword ':mysql' from it's Class name" do
|
11
|
+
subject.keyword.should eql(:mysql)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#action" do
|
15
|
+
subject { described_class.new }
|
16
|
+
|
17
|
+
it "returns a Gear::MySQL::Action" do
|
18
|
+
subject.action("select * from boxes", data_bag: {name: "creds"}).should be_a(MB::Gear::MySQL::Action)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Gear::Service::ActionRunner do
|
4
|
+
let(:environment) { "rspec" }
|
5
|
+
let(:node_one) { double(name: 'node-one', save: nil) }
|
6
|
+
let(:node_two) { double(name: 'node-two', save: nil) }
|
7
|
+
let(:node_three) { Ridley::NodeObject.new(nil) }
|
8
|
+
let(:job) { double(set_status: nil) }
|
9
|
+
let(:nodes) { [ node_one, node_two ] }
|
10
|
+
|
11
|
+
subject { action_runner }
|
12
|
+
|
13
|
+
let(:action_runner) { MB::Gear::Service::ActionRunner.new(environment, nodes) }
|
14
|
+
|
15
|
+
before do
|
16
|
+
node_three.stub(:reload)
|
17
|
+
node_three.stub(:save)
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when an action describes a node attribute" do
|
21
|
+
let(:action_runner) {
|
22
|
+
MB::Gear::Service::ActionRunner.new(environment, nodes) do
|
23
|
+
node_attribute('tester', true, toggle: true)
|
24
|
+
end
|
25
|
+
}
|
26
|
+
|
27
|
+
it "has an item in the list of node attributes" do
|
28
|
+
expect(action_runner.node_attributes).to have(1).item
|
29
|
+
|
30
|
+
node_attribute = action_runner.node_attributes[0]
|
31
|
+
expect(node_attribute).to be_a(Hash)
|
32
|
+
expect(node_attribute[:key]).to eql('tester')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when an action describes an environment attribute" do
|
37
|
+
let(:action_runner) {
|
38
|
+
MB::Gear::Service::ActionRunner.new(environment, nodes) do
|
39
|
+
environment_attribute('tester', true, toggle: true)
|
40
|
+
end
|
41
|
+
}
|
42
|
+
|
43
|
+
it "has an item in the list of environment attributes" do
|
44
|
+
expect(action_runner.environment_attributes).to have(1).item
|
45
|
+
|
46
|
+
environment_attribute = action_runner.environment_attributes[0]
|
47
|
+
expect(environment_attribute).to be_a(Hash)
|
48
|
+
expect(environment_attribute[:key]).to eql('tester')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when an action describes a service recipe" do
|
53
|
+
let(:action_runner) {
|
54
|
+
MB::Gear::Service::ActionRunner.new(environment, nodes) do
|
55
|
+
service_recipe 'my_recipe'
|
56
|
+
end
|
57
|
+
}
|
58
|
+
|
59
|
+
it "has a service recipe set" do
|
60
|
+
expect(action_runner.service_recipe).to eql('my_recipe')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#add_environment_attribute" do
|
65
|
+
let(:key) { "ruby.application.version" }
|
66
|
+
let(:value) { "1.2.3" }
|
67
|
+
let(:options) { Hash.new }
|
68
|
+
|
69
|
+
it "adds an item to the list of #environment_attributes to set" do
|
70
|
+
subject.add_environment_attribute(key, value, options)
|
71
|
+
expect(subject.environment_attributes).to have(1).item
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#add_node_attribute" do
|
76
|
+
let(:key) { "ruby.application.version" }
|
77
|
+
let(:value) { "1.2.3" }
|
78
|
+
let(:options) { Hash.new }
|
79
|
+
|
80
|
+
it "adds an item to the list of #node_attributes to set" do
|
81
|
+
subject.add_node_attribute(key, value, options)
|
82
|
+
expect(subject.node_attributes).to have(1).item
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#set_node_attributes" do
|
87
|
+
let(:nodes) { [ node_three ] }
|
88
|
+
|
89
|
+
let(:set_node_attributes) { subject.send(:set_node_attributes, job) }
|
90
|
+
|
91
|
+
context "when force_value_to and toggle are sent" do
|
92
|
+
|
93
|
+
before do
|
94
|
+
subject.add_node_attribute('some.attr', 123, toggle: true, force_value_to: 789)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "sets the node attribute" do
|
98
|
+
node_three.should_receive(:set_chef_attribute).with('some.attr', 123)
|
99
|
+
set_node_attributes
|
100
|
+
end
|
101
|
+
|
102
|
+
it "adds a callback" do
|
103
|
+
set_node_attributes
|
104
|
+
expect(subject.toggle_callbacks.size).to eql(1)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#set_environment_attributes" do
|
110
|
+
let(:environment) { Ridley::EnvironmentObject.new(nil) }
|
111
|
+
let(:ridley) { double( 'foo', environment: environment_resource) }
|
112
|
+
let(:environment_resource) { double(find: environment) }
|
113
|
+
let(:set_environment_attributes) { subject.send(:set_environment_attributes, job) }
|
114
|
+
|
115
|
+
before do
|
116
|
+
subject.add_environment_attribute('some.env.attr', 123, toggle: true)
|
117
|
+
MB::Application.stub(:[]).and_return(ridley)
|
118
|
+
environment.stub(:save)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "sets the environment attribute" do
|
122
|
+
environment.should_receive(:set_default_attribute).with('some.env.attr', 123)
|
123
|
+
set_environment_attributes
|
124
|
+
end
|
125
|
+
|
126
|
+
it "adds a callback" do
|
127
|
+
set_environment_attributes
|
128
|
+
expect(subject.toggle_callbacks.size).to eql(1)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#reset" do
|
133
|
+
let(:nodes) { [ node_three ] }
|
134
|
+
|
135
|
+
let(:reset) { subject.reset(job) }
|
136
|
+
|
137
|
+
context "when the callback toggles a node attribute" do
|
138
|
+
|
139
|
+
before do
|
140
|
+
subject.add_node_attribute('some.attr', 123, toggle: true)
|
141
|
+
subject.send(:set_node_attributes, job)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "resets the original value" do
|
145
|
+
node_three.should_receive(:set_chef_attribute).with('some.attr', nil)
|
146
|
+
reset
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "when the callback uses force_value_to on a node attribute" do
|
151
|
+
|
152
|
+
before do
|
153
|
+
subject.add_node_attribute('some.attr', 123, toggle: true, force_value_to: 789)
|
154
|
+
subject.send(:set_node_attributes, job)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "sets the attribute to the forced value" do
|
158
|
+
node_three.should_receive(:set_chef_attribute).with('some.attr', 789)
|
159
|
+
reset
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context "when the callback toggles an environment attribute" do
|
164
|
+
let(:environment) { Ridley::EnvironmentObject.new(nil) }
|
165
|
+
let(:ridley) { double( 'foo', environment: environment_resource) }
|
166
|
+
let(:environment_resource) { double(find: environment) }
|
167
|
+
|
168
|
+
|
169
|
+
before do
|
170
|
+
MB::Application.stub(:[]).and_return(ridley)
|
171
|
+
environment.stub(:save)
|
172
|
+
subject.add_environment_attribute('some.env.attr', 123, toggle: true)
|
173
|
+
subject.send(:set_environment_attributes, job)
|
174
|
+
end
|
175
|
+
|
176
|
+
it "removes the attribute key" do
|
177
|
+
environment.should_receive(:delete_default_attribute).with('some.env.attr')
|
178
|
+
reset
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|