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,532 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::NodeQuerier do
|
4
|
+
subject { node_querier }
|
5
|
+
|
6
|
+
let(:node_querier) { described_class.new }
|
7
|
+
let(:host) { "192.168.1.1" }
|
8
|
+
let(:response) { double('response', stderr: nil, stdout: nil, error?: nil) }
|
9
|
+
|
10
|
+
describe "#list" do
|
11
|
+
it "returns a list of nodes from the motherbrain's chef connection" do
|
12
|
+
nodes = double
|
13
|
+
MB::Application.ridley.stub_chain(:node, :all).and_return(nodes)
|
14
|
+
|
15
|
+
subject.list.should eql(nodes)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#ruby_script" do
|
20
|
+
subject(:result) { node_querier.send(:ruby_script, 'node_name', double('host')) }
|
21
|
+
before { node_querier.stub_chain(:chef_connection, :node, :ruby_script).and_return(response) }
|
22
|
+
|
23
|
+
context "when the response is a success" do
|
24
|
+
before { response.stub(stdout: 'success', error?: false) }
|
25
|
+
|
26
|
+
it "returns the response of the successfully run script" do
|
27
|
+
expect(result).to eql('success')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when the response is a failure" do
|
32
|
+
before { response.stub(stderr: 'error_message', error?: true) }
|
33
|
+
|
34
|
+
it "raises a RemoteScriptError" do
|
35
|
+
expect { result }.to raise_error(MB::RemoteScriptError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#bulk_chef_run" do
|
41
|
+
let(:job) { double(set_status: nil) }
|
42
|
+
let(:node_one) { double(name: "surfing", public_hostname: "surfing.riotgames.com") }
|
43
|
+
let(:node_two) { double(name: "football", public_hostname: "football.riotgames.com") }
|
44
|
+
let(:response_one) { double(value: double(host: "surfing.riotgames.com")) }
|
45
|
+
let(:response_two) { double(value: double(host: "football.riotgames.com")) }
|
46
|
+
|
47
|
+
let(:nodes) { [ node_one, node_two ] }
|
48
|
+
|
49
|
+
let(:bulk_chef_run) { node_querier.bulk_chef_run(job, nodes) }
|
50
|
+
|
51
|
+
before do
|
52
|
+
# Stubbing node_querier.future proved to be very difficult
|
53
|
+
nodes.stub(:map).and_return([response_one, response_two])
|
54
|
+
end
|
55
|
+
|
56
|
+
it "describes the successful nodes" do
|
57
|
+
bulk_chef_run
|
58
|
+
expect(job).to have_received(:set_status).with(
|
59
|
+
"Finished chef client run on 2 node(s) - surfing.riotgames.com, football.riotgames.com")
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when nodes fail" do
|
63
|
+
|
64
|
+
before do
|
65
|
+
response_one.stub(:value).and_raise(MB::RemoteCommandError.new(nil, "surfing.riotgames.com"))
|
66
|
+
response_two.stub(:value).and_raise(MB::RemoteCommandError.new(nil, "football.riotgames.com"))
|
67
|
+
node_querier.stub(:abort)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "describes the unsuccessful nodes" do
|
71
|
+
node_querier.should_receive(:abort).with(
|
72
|
+
MB::RemoteCommandError.new("chef client run failed on 2 node(s) - surfing.riotgames.com, football.riotgames.com"))
|
73
|
+
bulk_chef_run
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#node_name" do
|
79
|
+
subject(:node_name) { node_querier.node_name(host) }
|
80
|
+
|
81
|
+
let(:node) { "my_node" }
|
82
|
+
|
83
|
+
it "calls ruby_script with node_name and returns a response" do
|
84
|
+
node_querier.should_receive(:ruby_script).with('node_name', host, {}).and_return(node)
|
85
|
+
node_name.should eq(node)
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with a remote script error" do
|
89
|
+
before do
|
90
|
+
node_querier.stub(:ruby_script).and_raise(MB::RemoteScriptError)
|
91
|
+
end
|
92
|
+
|
93
|
+
it { should be_nil }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#chef_run" do
|
98
|
+
subject(:result) { node_querier.chef_run(host, options) }
|
99
|
+
let(:options) { Hash.new }
|
100
|
+
|
101
|
+
before { node_querier.stub_chain(:chef_connection, :node, :chef_run).and_return(response) }
|
102
|
+
|
103
|
+
context "when the response is a success" do
|
104
|
+
before { response.stub(stdout: 'success', error?: false) }
|
105
|
+
|
106
|
+
it "returns the Ridley response" do
|
107
|
+
expect(result).to eql(response)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "when the response is a failure" do
|
112
|
+
before { response.stub(stderr: 'error_message', error?: true) }
|
113
|
+
|
114
|
+
it "raises a RemoteCommandError" do
|
115
|
+
expect { result }.to raise_error(MB::RemoteCommandError)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when hostname is nil" do
|
120
|
+
let(:host) { nil }
|
121
|
+
|
122
|
+
it "raises a RemoteCommandError" do
|
123
|
+
expect { result }.to raise_error(MB::RemoteCommandError)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "when hostname is blank" do
|
128
|
+
let(:host) { "" }
|
129
|
+
|
130
|
+
it "raises a RemoteCommandError" do
|
131
|
+
expect { result }.to raise_error(MB::RemoteCommandError)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "when there are override recipes" do
|
136
|
+
let(:node_object) { double(reload: nil, automatic_attributes: auto_attr, save: nil) }
|
137
|
+
let(:auto_attr) { double(recipes: nil, :recipes= => nil) }
|
138
|
+
let(:options) do
|
139
|
+
{
|
140
|
+
override_recipes: ["default::foo"],
|
141
|
+
node_object: node_object
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
before do
|
146
|
+
node_querier.stub_chain(:chef_connection, :node, :execute_command).and_return(response)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "returns the ridley response" do
|
150
|
+
expect(result).to eql(response)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "#put_secret" do
|
156
|
+
let(:options) { { secret: File.join(fixtures_path, "fake_key.pem") } }
|
157
|
+
subject(:result) { node_querier.put_secret(host, options) }
|
158
|
+
|
159
|
+
before { node_querier.stub_chain(:chef_connection, :node, :put_secret).and_return(response) }
|
160
|
+
|
161
|
+
context "when there is no file at the secret path" do
|
162
|
+
let(:options) { Hash.new }
|
163
|
+
|
164
|
+
it { should be_nil }
|
165
|
+
end
|
166
|
+
|
167
|
+
context "when the response is a success" do
|
168
|
+
before { response.stub(stdout: 'success', error?: false) }
|
169
|
+
|
170
|
+
it "returns the Ridley response" do
|
171
|
+
expect(result).to eql(response)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context "when the response is a failure" do
|
176
|
+
before { response.stub(stderr: 'error_message', error?: true) }
|
177
|
+
|
178
|
+
it { should be_nil }
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "#execute_command" do
|
183
|
+
let(:command) { "echo 'hello!'" }
|
184
|
+
subject(:result) { node_querier.execute_command(host, command) }
|
185
|
+
before { node_querier.stub_chain(:chef_connection, :node, :execute_command).and_return(response) }
|
186
|
+
|
187
|
+
context "when the response is a success" do
|
188
|
+
before { response.stub(stdout: 'success', error?: false) }
|
189
|
+
|
190
|
+
it "returns the Ridley response" do
|
191
|
+
expect(result).to eql(response)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context "when the response is a failure" do
|
196
|
+
before { response.stub(stderr: 'error_message', error?: true) }
|
197
|
+
|
198
|
+
it "raises a RemoteCommandError" do
|
199
|
+
expect { result }.to raise_error(MB::RemoteCommandError)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe "#registered?" do
|
205
|
+
let(:node_name) { "reset.riotgames.com" }
|
206
|
+
|
207
|
+
it "returns true if the target node is registered with the Chef server" do
|
208
|
+
subject.should_receive(:registered_as).with(host).and_return(node_name)
|
209
|
+
|
210
|
+
subject.registered?(host).should be_true
|
211
|
+
end
|
212
|
+
|
213
|
+
it "returns false if the target node is not registered with the Chef server" do
|
214
|
+
subject.should_receive(:registered_as).with(host).and_return(nil)
|
215
|
+
|
216
|
+
subject.registered?(host).should be_false
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "#registered_as" do
|
221
|
+
let(:node_name) { "reset.riotgames.com" }
|
222
|
+
let(:client) { double('client', name: node_name) }
|
223
|
+
|
224
|
+
before do
|
225
|
+
subject.stub(:node_name).with(host).and_return(node_name)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "returns the name of the client the target node has registered to the Chef server" do
|
229
|
+
subject.chef_connection.stub_chain(:client, :find).with(node_name).and_return(client)
|
230
|
+
|
231
|
+
subject.registered_as(host).should eql(client.name)
|
232
|
+
end
|
233
|
+
|
234
|
+
it "returns nil if the target node does not have a client registered on the Chef server" do
|
235
|
+
subject.chef_connection.stub_chain(:client, :find).with(node_name).and_return(nil)
|
236
|
+
|
237
|
+
subject.registered_as(host).should be_nil
|
238
|
+
end
|
239
|
+
|
240
|
+
it "returns nil if we can't determine the node_name of the host" do
|
241
|
+
subject.should_receive(:node_name).with(host).and_return(nil)
|
242
|
+
|
243
|
+
subject.registered_as(host).should be_nil
|
244
|
+
end
|
245
|
+
|
246
|
+
context "when the target node's node_name cannot be resolved" do
|
247
|
+
before do
|
248
|
+
subject.stub(:node_name).with(host).and_return(nil)
|
249
|
+
end
|
250
|
+
|
251
|
+
it "returns false" do
|
252
|
+
subject.registered_as(host).should be_false
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe "#async_enable" do
|
258
|
+
let(:host) { "192.168.1.1" }
|
259
|
+
let(:options) { Hash.new }
|
260
|
+
|
261
|
+
it "creates a Job and delegates to #disable" do
|
262
|
+
ticket = double('ticket')
|
263
|
+
job = double('job', ticket: ticket)
|
264
|
+
MB::Job.should_receive(:new).and_return(job)
|
265
|
+
subject.should_receive(:async).with(:enable, job, host, {})
|
266
|
+
|
267
|
+
subject.async_enable(host)
|
268
|
+
end
|
269
|
+
|
270
|
+
it "returns a JobTicket" do
|
271
|
+
expect(subject.async_enable(host)).to be_a(MB::JobRecord)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
|
276
|
+
describe "#enable" do
|
277
|
+
let(:host) { "192.168.1.1" }
|
278
|
+
let(:job) { MB::Job.new(:disable) }
|
279
|
+
let(:future_stub) { double(Celluloid::Future, value: nil) }
|
280
|
+
let(:node_stub) {
|
281
|
+
double(Ridley::NodeObject,
|
282
|
+
run_list: ["recipe[disabled]", "recipe[foo::server]", "recipe[foo::database]"])
|
283
|
+
}
|
284
|
+
|
285
|
+
before do
|
286
|
+
subject.stub(:registered_as).with(host).and_return(nil)
|
287
|
+
end
|
288
|
+
|
289
|
+
it "terminates the job" do
|
290
|
+
begin
|
291
|
+
subject.enable(job, host)
|
292
|
+
rescue MB::NodeNotFound
|
293
|
+
# Don't care
|
294
|
+
end
|
295
|
+
expect(job).to_not be_alive
|
296
|
+
end
|
297
|
+
|
298
|
+
context "when the node is not registered" do
|
299
|
+
it "displays a warning" do
|
300
|
+
job.should_receive(:report_failure)
|
301
|
+
subject.enable(job, host)
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
context "when the node is registered" do
|
306
|
+
let(:node_name) { "foo.riotgames.com" }
|
307
|
+
let(:run_list) { ["recipe[disabled]", "recipe[foo::server]", "recipe[bar::server]"] }
|
308
|
+
let(:node) { double(Ridley::NodeObject,
|
309
|
+
name: node_name,
|
310
|
+
run_list: run_list,
|
311
|
+
save: true,
|
312
|
+
chef_environment: environment) }
|
313
|
+
let(:plugin_manager) { double(MB::PluginManager) }
|
314
|
+
|
315
|
+
%w[foo bar].each do |x|
|
316
|
+
let(:"service_#{x}_recipe") { "recipe[#{x}::service]" }
|
317
|
+
|
318
|
+
let(:"#{x}_group") { double(MB::Group,
|
319
|
+
recipes: ["#{x}::server"]) }
|
320
|
+
let(:"dynamic_#{x}_service") { double(MB::Gear::DynamicService) }
|
321
|
+
let(:"#{x}_service") { double(MB::Gear::Service,
|
322
|
+
name: "#{x}_service",
|
323
|
+
service_group: send(:"#{x}_group"),
|
324
|
+
service_recipe: send(:"service_#{x}_recipe"),
|
325
|
+
to_dynamic_service: send(:"dynamic_#{x}_service")) }
|
326
|
+
let(:"#{x}_component") { double(MB::Component,
|
327
|
+
name: "#{x}_component",
|
328
|
+
group: send(:"#{x}_group")) }
|
329
|
+
let(:"#{x}_plugin") { double(MB::Plugin,
|
330
|
+
components: [send(:"#{x}_component")]) }
|
331
|
+
let(:"environment") { "theenv" }
|
332
|
+
end
|
333
|
+
|
334
|
+
before do
|
335
|
+
subject.stub(:registered_as).and_return(node_name)
|
336
|
+
end
|
337
|
+
|
338
|
+
it "enables the node" do
|
339
|
+
subject.stub(:plugin_manager).and_return(plugin_manager)
|
340
|
+
subject.stub_chain(:chef_connection, :node, :find).with(node_name).and_return(node)
|
341
|
+
%w[foo bar].each_with_index do |x, i|
|
342
|
+
plugin_manager
|
343
|
+
.should_receive(:for_run_list_entry)
|
344
|
+
.with(run_list[i+1], environment, remote: true)
|
345
|
+
.and_return(send(:"#{x}_plugin"))
|
346
|
+
send(:"#{x}_component").should_receive(:gears).with(MB::Gear::Service).and_return([send(:"#{x}_service")])
|
347
|
+
send(:"#{x}_service").stub(:dynamic_service?).and_return(true)
|
348
|
+
send(:"#{x}_group").should_receive(:includes_recipe?).with(run_list[i+1]).and_return(true)
|
349
|
+
send(:"dynamic_#{x}_service").should_receive(:remove_node_state_change).with(job, send(:"#{x}_plugin"), node, false)
|
350
|
+
node.stub(:run_list=)
|
351
|
+
end
|
352
|
+
subject.should_receive(:bulk_chef_run).with(job, [node], %w[foo bar].collect { |x| send(:"service_#{x}_recipe") })
|
353
|
+
|
354
|
+
subject.enable(job, host)
|
355
|
+
end
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
describe "#async_purge" do
|
360
|
+
let(:host) { "192.168.1.1" }
|
361
|
+
let(:options) { Hash.new }
|
362
|
+
|
363
|
+
it "creates a Job and delegates to #purge" do
|
364
|
+
ticket = double('ticket')
|
365
|
+
job = double('job', ticket: ticket)
|
366
|
+
MB::Job.should_receive(:new).and_return(job)
|
367
|
+
subject.should_receive(:purge).with(job, host, options)
|
368
|
+
|
369
|
+
subject.async_purge(host, options)
|
370
|
+
end
|
371
|
+
|
372
|
+
it "returns a JobTicket" do
|
373
|
+
expect(subject.async_purge(host, options)).to be_a(MB::JobRecord)
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
describe "#async_disable" do
|
378
|
+
let(:host) { "192.168.1.1" }
|
379
|
+
let(:options) { Hash.new }
|
380
|
+
|
381
|
+
it "creates a Job and delegates to #disable" do
|
382
|
+
ticket = double('ticket')
|
383
|
+
job = double('job', ticket: ticket)
|
384
|
+
MB::Job.should_receive(:new).and_return(job)
|
385
|
+
subject.should_receive(:async).with(:disable, job, host, {})
|
386
|
+
|
387
|
+
subject.async_disable(host)
|
388
|
+
end
|
389
|
+
|
390
|
+
it "returns a JobTicket" do
|
391
|
+
expect(subject.async_disable(host)).to be_a(MB::JobRecord)
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
describe "#disable" do
|
396
|
+
let(:host) { "192.168.1.1" }
|
397
|
+
let(:job) { MB::Job.new(:disable) }
|
398
|
+
let(:future_stub) { double(Celluloid::Future, value: nil) }
|
399
|
+
let(:node_stub) {
|
400
|
+
double(Ridley::NodeObject,
|
401
|
+
run_list: ["recipe[foo::server]", "recipe[foo::database]"])
|
402
|
+
}
|
403
|
+
|
404
|
+
before do
|
405
|
+
subject.stub(:registered_as).with(host).and_return(nil)
|
406
|
+
end
|
407
|
+
|
408
|
+
it "terminates the job" do
|
409
|
+
subject.disable(job, host) rescue nil
|
410
|
+
expect(job).to_not be_alive
|
411
|
+
end
|
412
|
+
|
413
|
+
context "when the node is not registered" do
|
414
|
+
it "reports failure" do
|
415
|
+
msg = "Could not discover the host's node name. The host may not be " +
|
416
|
+
"registered with Chef or the embedded Ruby used to identify the " +
|
417
|
+
"node name may not be available. #{host} was not disabled!"
|
418
|
+
job.should_receive(:report_failure).with(msg).and_return { raise "exit" }
|
419
|
+
begin
|
420
|
+
subject.disable(job, host)
|
421
|
+
rescue => e
|
422
|
+
e.message.should == "exit"
|
423
|
+
end
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
context "when the node is registered" do
|
428
|
+
let(:node_name) { "foo.riotgames.com" }
|
429
|
+
let(:run_list) { ["recipe[foo::server]", "recipe[bar::server]"] }
|
430
|
+
let(:node) { double(Ridley::NodeObject,
|
431
|
+
name: node_name,
|
432
|
+
run_list: run_list,
|
433
|
+
save: true,
|
434
|
+
chef_environment: environment) }
|
435
|
+
let(:plugin_manager) { double(MB::PluginManager) }
|
436
|
+
|
437
|
+
%w[foo bar].each do |x|
|
438
|
+
let(:"service_#{x}_recipe") { "recipe[#{x}::service]" }
|
439
|
+
|
440
|
+
let(:"#{x}_group") { double(MB::Group,
|
441
|
+
recipes: ["#{x}::server"]) }
|
442
|
+
let(:"dynamic_#{x}_service") { double(MB::Gear::DynamicService) }
|
443
|
+
let(:"#{x}_service") { double(MB::Gear::Service,
|
444
|
+
name: "#{x}_service",
|
445
|
+
service_group: send(:"#{x}_group"),
|
446
|
+
service_recipe: send(:"service_#{x}_recipe"),
|
447
|
+
to_dynamic_service: send(:"dynamic_#{x}_service")) }
|
448
|
+
let(:"#{x}_component") { double(MB::Component,
|
449
|
+
name: "#{x}_component",
|
450
|
+
group: send(:"#{x}_group")) }
|
451
|
+
let(:"#{x}_plugin") { double(MB::Plugin,
|
452
|
+
components: [send(:"#{x}_component")]) }
|
453
|
+
let(:"environment") { "theenv" }
|
454
|
+
end
|
455
|
+
|
456
|
+
it "disables the node" do
|
457
|
+
subject.stub(:plugin_manager).and_return(plugin_manager)
|
458
|
+
subject.should_receive(:registered_as).with(host).and_return(node_name)
|
459
|
+
subject.stub_chain(:chef_connection, :node, :find).with(node_name).and_return(node)
|
460
|
+
%w[foo bar].each_with_index do |x, i|
|
461
|
+
plugin_manager
|
462
|
+
.should_receive(:for_run_list_entry)
|
463
|
+
.with(run_list[i], environment, remote: true)
|
464
|
+
.and_return(send(:"#{x}_plugin"))
|
465
|
+
send(:"#{x}_component").should_receive(:gears).with(MB::Gear::Service).and_return([send(:"#{x}_service")])
|
466
|
+
send(:"#{x}_service").stub(:dynamic_service?).and_return(true)
|
467
|
+
send(:"#{x}_group").should_receive(:includes_recipe?).with(run_list[i]).and_return(true)
|
468
|
+
send(:"dynamic_#{x}_service").should_receive(:node_state_change).with(job, send(:"#{x}_plugin"), node, MB::Gear::DynamicService::STOP, false)
|
469
|
+
node.should_receive(:run_list).and_return(run_list)
|
470
|
+
node.stub(:run_list=)
|
471
|
+
end
|
472
|
+
subject.should_receive(:bulk_chef_run).with(job, [node], %w[foo bar].collect { |x| send(:"service_#{x}_recipe") })
|
473
|
+
|
474
|
+
subject.disable(job, host)
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
479
|
+
describe "#async_purge" do
|
480
|
+
let(:host) { "192.168.1.1" }
|
481
|
+
let(:options) { Hash.new }
|
482
|
+
|
483
|
+
it "creates a Job and delegates to #purge" do
|
484
|
+
ticket = double('ticket')
|
485
|
+
job = double('job', ticket: ticket)
|
486
|
+
MB::Job.should_receive(:new).and_return(job)
|
487
|
+
subject.should_receive(:purge).with(job, host, options)
|
488
|
+
|
489
|
+
subject.async_purge(host, options)
|
490
|
+
end
|
491
|
+
|
492
|
+
it "returns a JobTicket" do
|
493
|
+
expect(subject.async_purge(host, options)).to be_a(MB::JobRecord)
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
describe "#purge" do
|
498
|
+
let(:host) { "192.168.1.1" }
|
499
|
+
let(:job) { MB::Job.new(:purge) }
|
500
|
+
let(:future_stub) { double(Celluloid::Future, value: nil) }
|
501
|
+
|
502
|
+
before do
|
503
|
+
subject.stub(:registered_as).with(host).and_return(nil)
|
504
|
+
subject.chef_connection.
|
505
|
+
stub_chain(:node, :future).
|
506
|
+
with(:uninstall_chef, host, skip_chef: false).
|
507
|
+
and_return(future_stub)
|
508
|
+
end
|
509
|
+
|
510
|
+
it "terminates the job" do
|
511
|
+
subject.purge(job, host)
|
512
|
+
expect(job).to_not be_alive
|
513
|
+
end
|
514
|
+
|
515
|
+
context "when the node is not registered" do
|
516
|
+
it "uninstalls chef" do
|
517
|
+
subject.purge(job, host)
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
context "when the node is registered" do
|
522
|
+
let(:node_name) { "reset.riotgames.com" }
|
523
|
+
before { subject.should_receive(:registered_as).with(host).and_return(node_name) }
|
524
|
+
|
525
|
+
it "deletes the client and node object and uninstalls chef" do
|
526
|
+
subject.chef_connection.stub_chain(:client, :future).with(:delete, node_name).and_return(future_stub)
|
527
|
+
subject.chef_connection.stub_chain(:node, :future).with(:delete, node_name).and_return(future_stub)
|
528
|
+
subject.purge(job, host)
|
529
|
+
end
|
530
|
+
end
|
531
|
+
end
|
532
|
+
end
|