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,386 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::CliGateway do
|
4
|
+
let(:ui) { described_class.ui }
|
5
|
+
|
6
|
+
before do
|
7
|
+
ui.stub :error
|
8
|
+
ui.stub :info
|
9
|
+
ui.stub :say
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "ClassMethods" do
|
13
|
+
subject { described_class }
|
14
|
+
|
15
|
+
describe "::new" do
|
16
|
+
describe "specifying a configuration file" do
|
17
|
+
let(:location) { tmp_path.join('config.json').to_s }
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
generate_valid_config(location)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "loads the specified config file into the ConfigManager" do
|
24
|
+
config = MB::Config.from_file(location)
|
25
|
+
invoker = subject.new([], config: location)
|
26
|
+
|
27
|
+
MB::ConfigManager.instance.config._attributes_.should eql(config._attributes_)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "exits with a ConfigNotFound error when the specified path does not exist" do
|
31
|
+
lambda {
|
32
|
+
invoker = subject.new([], config: tmp_path.join("not_there.json"))
|
33
|
+
}.should exit_with(MB::ConfigNotFound)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "exits with a ConfigNotFound error when the specified path is a directory" do
|
37
|
+
lambda {
|
38
|
+
invoker = subject.new([], config: tmp_path)
|
39
|
+
}.should exit_with(MB::ConfigNotFound)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "::requires_environment?" do
|
45
|
+
context "no arguments" do
|
46
|
+
it "should not require an environment" do
|
47
|
+
subject.requires_environment?([]).should be_false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "base command" do
|
52
|
+
it "should not require an environment for versions" do
|
53
|
+
subject.requires_environment?(["versions"]).should be_false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "plugin argument" do
|
58
|
+
it "should not require an environment for a plugin" do
|
59
|
+
subject.requires_environment?(["myface"]).should be_false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "plugin command" do
|
64
|
+
it "should require an environment for bootstrap" do
|
65
|
+
subject.requires_environment?(["myface", "bootstrap"]).should be_true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should not require an environment for help" do
|
69
|
+
subject.requires_environment?(["myface", "help"]).should be_false
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should not require an environment for subtask help" do
|
73
|
+
subject.requires_environment?(["myface", "help", "bootstrap"]).should be_false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "::start_mb_application?" do
|
79
|
+
let(:args) {["myface"]}
|
80
|
+
|
81
|
+
context "not a config task" do
|
82
|
+
it "should be true" do
|
83
|
+
subject.start_mb_application?(args).should be_true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "is a config task" do
|
88
|
+
it "should be false" do
|
89
|
+
subject::SKIP_CONFIG_TASKS.each do |config_task|
|
90
|
+
args = [config_task]
|
91
|
+
subject.start_mb_application?(args)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "::register_plugin" do
|
98
|
+
let(:name) { "myface" }
|
99
|
+
let(:description) { "Ivey should use SublimeText 2" }
|
100
|
+
let(:plugin) { MB::Plugin.new(metadata) }
|
101
|
+
let(:metadata) do
|
102
|
+
double('metadata',
|
103
|
+
name: name,
|
104
|
+
description: description
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "registers a subcommand with self" do
|
109
|
+
subcommand = double
|
110
|
+
MB::Cli::SubCommand.should_receive(:new).with(plugin).and_return(subcommand)
|
111
|
+
subject.should_receive(:register_subcommand).with(subcommand)
|
112
|
+
|
113
|
+
subject.register_plugin(plugin)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "returns a subcommand with the plugin set as #plugin" do
|
117
|
+
subject.register_plugin(plugin).plugin.should eql(plugin)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "has a name matching the plugin" do
|
121
|
+
subject.register_plugin(plugin).name.should eql(name)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "has a description matching the plugin" do
|
125
|
+
subject.register_plugin(plugin).description.should eql(description)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "::find_plugin" do
|
130
|
+
let(:plugin_manager) { double('plugin_manager') }
|
131
|
+
let(:name) { "myface" }
|
132
|
+
let(:options) do
|
133
|
+
{
|
134
|
+
plugin_version: nil,
|
135
|
+
environment: nil
|
136
|
+
}
|
137
|
+
end
|
138
|
+
let(:plugin) { double('asdf') }
|
139
|
+
|
140
|
+
subject { described_class.find_plugin(name, options) }
|
141
|
+
|
142
|
+
before do
|
143
|
+
described_class.stub(plugin_manager: plugin_manager)
|
144
|
+
described_class.stub(local_plugin?: false)
|
145
|
+
end
|
146
|
+
|
147
|
+
context "given no value for :plugin_version or :environment" do
|
148
|
+
before do
|
149
|
+
options[:plugin_version] = nil
|
150
|
+
options[:environment] = nil
|
151
|
+
end
|
152
|
+
|
153
|
+
it "finds the installed or remote latest version of the plugin with the given name" do
|
154
|
+
plugin_manager.should_receive(:latest).with(name, remote: true).and_return(plugin)
|
155
|
+
|
156
|
+
subject.should eql(plugin)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "prints an error to the UI and exits if no plugin is found" do
|
160
|
+
plugin_manager.should_receive(:latest).with(name, remote: true).and_return(nil)
|
161
|
+
ui.should_receive(:error).with(anything)
|
162
|
+
|
163
|
+
expect {
|
164
|
+
subject
|
165
|
+
}.to raise_error(SystemExit)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "given a value for :plugin_version" do
|
170
|
+
let(:plugin_version) { "1.2.3" }
|
171
|
+
before { options[:plugin_version] = plugin_version }
|
172
|
+
|
173
|
+
it "finds a plugin on local and remote of the given name and version" do
|
174
|
+
plugin_manager.should_receive(:find).with(name, plugin_version, remote: true).and_return(plugin)
|
175
|
+
|
176
|
+
subject.should eql(plugin)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "prints an error to the UI and exits if no plugin is found" do
|
180
|
+
plugin_manager.should_receive(:find).with(name, plugin_version, remote: true).and_return(nil)
|
181
|
+
ui.should_receive(:error).with(anything)
|
182
|
+
|
183
|
+
expect {
|
184
|
+
subject
|
185
|
+
}.to raise_error(SystemExit)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context "given a value for :environment" do
|
190
|
+
let(:environment) { "rspec-test" }
|
191
|
+
before { options[:environment] = environment }
|
192
|
+
|
193
|
+
it "finds the best suitable plugin for the environment" do
|
194
|
+
plugin_manager.should_receive(:for_environment).with(name, environment, remote: true).and_return(plugin)
|
195
|
+
|
196
|
+
subject.should eql(plugin)
|
197
|
+
end
|
198
|
+
|
199
|
+
context "when an environment of the given name is not found" do
|
200
|
+
before do
|
201
|
+
plugin_manager.should_receive(:for_environment).and_raise(MB::EnvironmentNotFound.new(environment))
|
202
|
+
end
|
203
|
+
|
204
|
+
it "finds the latest plugin on local and remote of the given name" do
|
205
|
+
plugin_manager.should_receive(:latest).with(name, remote: true).and_return(plugin)
|
206
|
+
|
207
|
+
subject.should eql(plugin)
|
208
|
+
end
|
209
|
+
|
210
|
+
it "prints an error to the UI and exits if no plugin is found" do
|
211
|
+
plugin_manager.should_receive(:latest).with(name, remote: true).and_return(nil)
|
212
|
+
|
213
|
+
expect {
|
214
|
+
subject
|
215
|
+
}.to raise_error(SystemExit)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context "given both a plugin version and environment" do
|
221
|
+
let(:environment) { "rspec-test" }
|
222
|
+
let(:plugin_version) { "1.2.3" }
|
223
|
+
|
224
|
+
before do
|
225
|
+
options[:environment] = environment
|
226
|
+
options[:plugin_version] = plugin_version
|
227
|
+
end
|
228
|
+
|
229
|
+
it "finds a plugin on local and remote of the given name and version" do
|
230
|
+
plugin_manager.should_receive(:find).with(name, plugin_version, remote: true).and_return(plugin)
|
231
|
+
|
232
|
+
subject.should eql(plugin)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context "given a local plugin" do
|
237
|
+
before { described_class.stub(local_plugin?: true) }
|
238
|
+
|
239
|
+
it "should prefer the local plugin if no version was specified" do
|
240
|
+
plugin_manager.should_receive(:load_installed).and_return(plugin)
|
241
|
+
|
242
|
+
subject.should eql(plugin)
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should use the version specified version of the plugin if a version is specified" do
|
246
|
+
options[:plugin_version] = '1.2.3'
|
247
|
+
plugin_manager.should_not_receive(:load_installed)
|
248
|
+
plugin_manager.should_receive(:find).with('myface', '1.2.3', remote: true).and_return(plugin)
|
249
|
+
|
250
|
+
subject.should eql(plugin)
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should use the local version if the environment is specified" do
|
254
|
+
options[:environment] = "abc"
|
255
|
+
plugin_manager.should_receive(:load_installed).and_return(plugin)
|
256
|
+
|
257
|
+
subject.should eql(plugin)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "#validate_environment" do
|
264
|
+
subject(:validate_environment) { cli_gateway.send(:validate_environment) }
|
265
|
+
let(:cli_gateway) { described_class.new(args, options, config) }
|
266
|
+
|
267
|
+
let(:args) { Array.new }
|
268
|
+
let(:config) { { current_command: double('Config', name: "help") } }
|
269
|
+
let(:environment_name) { "my_env" }
|
270
|
+
let(:options) { { environment: environment_name } }
|
271
|
+
let(:environment_manager) { MB::EnvironmentManager.instance.wrapped_object }
|
272
|
+
|
273
|
+
before do
|
274
|
+
cli_gateway.stub :ask
|
275
|
+
cli_gateway.stub testing?: false
|
276
|
+
cli_gateway.stub(environment_manager: environment_manager)
|
277
|
+
|
278
|
+
environment_manager.stub(:find).and_return(Hash.new)
|
279
|
+
end
|
280
|
+
|
281
|
+
it "doesn't ask the user" do
|
282
|
+
cli_gateway.should_not_receive(:ask)
|
283
|
+
|
284
|
+
validate_environment
|
285
|
+
end
|
286
|
+
|
287
|
+
context "without an environment" do
|
288
|
+
let(:options) { Hash.new }
|
289
|
+
|
290
|
+
it "doesn't ask the user" do
|
291
|
+
cli_gateway.should_not_receive(:ask)
|
292
|
+
|
293
|
+
validate_environment
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context "if the environment does not exist" do
|
298
|
+
before do
|
299
|
+
environment_manager.stub(:find).and_raise(
|
300
|
+
MB::EnvironmentNotFound.new("nope")
|
301
|
+
)
|
302
|
+
end
|
303
|
+
|
304
|
+
it "doesn't ask the user and raises an error" do
|
305
|
+
cli_gateway.should_not_receive(:ask)
|
306
|
+
|
307
|
+
-> { validate_environment }.should raise_error(MB::EnvironmentNotFound)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
context "if the environment does not exist and given a create task" do
|
312
|
+
let(:args) { ["bootstrap"] }
|
313
|
+
|
314
|
+
before do
|
315
|
+
environment_manager.stub(:find).and_raise(
|
316
|
+
MB::EnvironmentNotFound.new("nope")
|
317
|
+
)
|
318
|
+
end
|
319
|
+
|
320
|
+
context "and it should 'quit' on missing environments" do
|
321
|
+
let(:options) { { environment: environment_name, on_environment_missing: "quit" } }
|
322
|
+
|
323
|
+
it "should quit without asking" do
|
324
|
+
cli_gateway.should_not_receive(:ask)
|
325
|
+
cli_gateway.should_receive(:abort)
|
326
|
+
|
327
|
+
validate_environment
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
context "and it should 'create' on missing environments" do
|
332
|
+
let(:options) { { environment: environment_name, on_environment_missing: "create" } }
|
333
|
+
|
334
|
+
it "should create the environment without asking" do
|
335
|
+
cli_gateway.should_not_receive(:ask)
|
336
|
+
cli_gateway.should_receive(:create_environment).with(environment_name)
|
337
|
+
|
338
|
+
validate_environment
|
339
|
+
end
|
340
|
+
|
341
|
+
end
|
342
|
+
|
343
|
+
|
344
|
+
context "and it should 'prompt' on missing environments" do
|
345
|
+
|
346
|
+
let(:options) { { environment: environment_name, on_environment_missing: "prompt" } }
|
347
|
+
|
348
|
+
context "if the user responds yes" do
|
349
|
+
before do
|
350
|
+
cli_gateway.stub ask: "y"
|
351
|
+
end
|
352
|
+
|
353
|
+
it "creates an environment" do
|
354
|
+
cli_gateway.should_receive(:create_environment).with(environment_name)
|
355
|
+
|
356
|
+
validate_environment
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
context "if the user responds no" do
|
361
|
+
before do
|
362
|
+
cli_gateway.stub ask: "n"
|
363
|
+
end
|
364
|
+
|
365
|
+
it "doesn't create an environment" do
|
366
|
+
environment_manager.should_not_receive(:create).with(environment_name)
|
367
|
+
|
368
|
+
validate_environment
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
context "if the user responds quit" do
|
373
|
+
before do
|
374
|
+
cli_gateway.stub ask: "q"
|
375
|
+
end
|
376
|
+
|
377
|
+
it "exits the cli" do
|
378
|
+
cli_gateway.should_receive(:abort)
|
379
|
+
|
380
|
+
validate_environment
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::CommandInvoker::Worker do
|
4
|
+
let(:component) { double('component', name: 'chat') }
|
5
|
+
let(:command) { double('command', name: 'stop', type: :component, scope: component) }
|
6
|
+
let(:environment) { "rspec-env" }
|
7
|
+
|
8
|
+
subject { described_class.new(command, environment) }
|
9
|
+
|
10
|
+
describe "#run" do
|
11
|
+
let(:job) { double('job') }
|
12
|
+
let(:arguments) { Array.new }
|
13
|
+
|
14
|
+
before do
|
15
|
+
job.stub(set_status: nil)
|
16
|
+
command.stub(invoke: nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:run) { subject.run(job, arguments) }
|
20
|
+
|
21
|
+
it "sets a status message" do
|
22
|
+
job.should_receive(:set_status)
|
23
|
+
|
24
|
+
run
|
25
|
+
end
|
26
|
+
|
27
|
+
it "invokes the command" do
|
28
|
+
command.should_receive(:invoke).with(job, environment, nil)
|
29
|
+
|
30
|
+
run
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when given additional arguments" do
|
34
|
+
let(:arguments) { [1,2,3] }
|
35
|
+
|
36
|
+
it "invokes the command with the additional arguments" do
|
37
|
+
command.should_receive(:invoke).with(job, environment, nil, *arguments)
|
38
|
+
|
39
|
+
run
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::CommandInvoker do
|
4
|
+
let(:plugin_id) { "rspec-test" }
|
5
|
+
let(:command_id) { "start" }
|
6
|
+
let(:component_id) { "default" }
|
7
|
+
let(:environment) { "rspec-testenv" }
|
8
|
+
|
9
|
+
let(:options) do
|
10
|
+
{
|
11
|
+
version: "1.0.0"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { described_class.new }
|
16
|
+
|
17
|
+
describe "#async_invoke" do
|
18
|
+
let(:job_ticket) { double(MB::JobRecord) }
|
19
|
+
let(:job) { double(MB::Job, ticket: job_ticket) }
|
20
|
+
let(:command_name) { "stop" }
|
21
|
+
let(:options) { Hash.new }
|
22
|
+
|
23
|
+
before do
|
24
|
+
MB::Job.stub(:new).and_return(job)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "asynchronously calls {#invoke}" do
|
28
|
+
subject.should_receive(:async).with(:invoke, job, command_name, options)
|
29
|
+
|
30
|
+
subject.async_invoke(command_name, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns a JobRecord" do
|
34
|
+
subject.stub(:async).with(:invoke, job, command_name, options)
|
35
|
+
|
36
|
+
subject.async_invoke(command_name, options).should eql(job_ticket)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#find" do
|
41
|
+
let(:command) { "stop" }
|
42
|
+
let(:plugin) { "test-plugin" }
|
43
|
+
let(:options) do
|
44
|
+
{
|
45
|
+
version: nil,
|
46
|
+
component: nil,
|
47
|
+
environment: nil
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
let(:run) { subject.find(command, plugin, options) }
|
52
|
+
|
53
|
+
it "delegates to #find_latest" do
|
54
|
+
subject.should_receive(:find_latest).with(command, plugin, options[:component])
|
55
|
+
run
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when given a value for :version" do
|
59
|
+
before do
|
60
|
+
options[:version] = "1.2.3"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "delegates to #for_version" do
|
64
|
+
subject.should_receive(:for_version).with(options[:version], command, plugin, options[:component])
|
65
|
+
run
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when given a value for :environment" do
|
70
|
+
before do
|
71
|
+
options[:environment] = "test-env"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "delegates to #for_environment" do
|
75
|
+
subject.should_receive(:for_environment).with(options[:environment], command, plugin, options[:component])
|
76
|
+
run
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#invoke" do
|
82
|
+
let(:command_name) { "stop" }
|
83
|
+
let(:command) { double(invoke: nil) }
|
84
|
+
let(:plugin) { "chat" }
|
85
|
+
let(:component) { "default" }
|
86
|
+
let(:environment) { "rspec-test" }
|
87
|
+
let(:version) { "1.2.3" }
|
88
|
+
let(:job) { double(MB::Job, alive?: true, set_status: nil, terminate: nil) }
|
89
|
+
let(:worker) { double('worker', alive?: true, terminate: nil) }
|
90
|
+
let(:environment_manager) { double('env-man') }
|
91
|
+
let(:options) do
|
92
|
+
{
|
93
|
+
plugin: plugin,
|
94
|
+
component: component,
|
95
|
+
environment: environment,
|
96
|
+
version: version,
|
97
|
+
arguments: Array.new
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
let(:run) { subject.invoke(job, command_name, options) }
|
102
|
+
|
103
|
+
before(:each) do
|
104
|
+
MB::CommandInvoker::Worker.stub(:new).and_return(worker)
|
105
|
+
subject.stub(find: command, environment_manager: environment_manager, plugin_manager: plugin_manager)
|
106
|
+
job.stub(set_status: nil, report_running: nil, report_failure: nil, report_success: nil)
|
107
|
+
environment_manager.stub(find: nil)
|
108
|
+
worker.stub(run: nil)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "wraps the invocation in a lock" do
|
112
|
+
MB::ChefMutex.any_instance.should_receive :synchronize
|
113
|
+
|
114
|
+
run
|
115
|
+
end
|
116
|
+
|
117
|
+
it "marks the job as running and then a success on success" do
|
118
|
+
job.should_receive(:report_running).ordered
|
119
|
+
job.should_receive(:report_success).ordered
|
120
|
+
|
121
|
+
run
|
122
|
+
end
|
123
|
+
|
124
|
+
it "terminates the running job on completion" do
|
125
|
+
job.should_receive(:terminate).once
|
126
|
+
|
127
|
+
run
|
128
|
+
end
|
129
|
+
|
130
|
+
it "creates a new worker to run the command in" do
|
131
|
+
MB::CommandInvoker::Worker.should_receive(:new).with(command, environment, nil).and_return(worker)
|
132
|
+
|
133
|
+
run
|
134
|
+
end
|
135
|
+
|
136
|
+
it "runs the worker with the job and given arguments" do
|
137
|
+
worker.should_receive(:run).with(job, options[:arguments])
|
138
|
+
|
139
|
+
run
|
140
|
+
end
|
141
|
+
|
142
|
+
it "shuts the worker down after completion" do
|
143
|
+
worker.should_receive(:terminate).once
|
144
|
+
|
145
|
+
run
|
146
|
+
end
|
147
|
+
|
148
|
+
context "when the plugin option is nil" do
|
149
|
+
before { options[:plugin] = nil }
|
150
|
+
|
151
|
+
it "sets the job to failure" do
|
152
|
+
job.should_receive(:report_failure)
|
153
|
+
run
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "when the environment option is nil" do
|
158
|
+
before { options[:environment] = nil }
|
159
|
+
|
160
|
+
it "sets the job to failure" do
|
161
|
+
job.should_receive(:report_failure)
|
162
|
+
run
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "when the target environment does not exist" do
|
167
|
+
let(:exception) { MB::EnvironmentNotFound.new(environment) }
|
168
|
+
|
169
|
+
before do
|
170
|
+
subject.should_receive(:find).
|
171
|
+
with(command_name, plugin, component: component, environment: environment, version: version).
|
172
|
+
and_raise(exception)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should set the job state to :failure" do
|
176
|
+
job.should_receive(:report_failure).with(exception)
|
177
|
+
|
178
|
+
run
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "when a plugin of the given name is not found" do
|
183
|
+
let(:exception) { MB::PluginNotFound.new(plugin) }
|
184
|
+
|
185
|
+
before do
|
186
|
+
subject.should_receive(:find).
|
187
|
+
with(command_name, plugin, component: component, environment: environment, version: version).
|
188
|
+
and_raise(exception)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "sets the job to failure with a command not found message" do
|
192
|
+
job.should_receive(:report_failure).with(exception)
|
193
|
+
|
194
|
+
run
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "when a component of the given name is not found" do
|
199
|
+
let(:exception) { MB::ComponentNotFound.new(component, plugin) }
|
200
|
+
|
201
|
+
before do
|
202
|
+
subject.should_receive(:find).
|
203
|
+
with(command_name, plugin, component: component, environment: environment, version: version).
|
204
|
+
and_raise(exception)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "sets the job to failure with a command not found message" do
|
208
|
+
job.should_receive(:report_failure).with(exception)
|
209
|
+
|
210
|
+
run
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context "when a plugin command for the given plugin is not found" do
|
215
|
+
let(:exception) { MB::CommandNotFound.new(component, plugin) }
|
216
|
+
|
217
|
+
before do
|
218
|
+
subject.should_receive(:find).
|
219
|
+
with(command_name, plugin, component: component, environment: environment, version: version).
|
220
|
+
and_raise(exception)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "completes the job as a failure with a command not found message" do
|
224
|
+
job.should_receive(:report_failure).with(exception)
|
225
|
+
|
226
|
+
run
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|