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,173 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MotherBrain::ErrorHandler do
|
4
|
+
subject { error_handler }
|
5
|
+
|
6
|
+
let(:error_handler) { klass.new error, options }
|
7
|
+
|
8
|
+
let(:error) { ZeroDivisionError.new }
|
9
|
+
let(:options) {
|
10
|
+
{
|
11
|
+
backtrace: backtrace,
|
12
|
+
method_name: method_name,
|
13
|
+
plugin_name: plugin_name,
|
14
|
+
file_path: file_path,
|
15
|
+
plugin_version: plugin_version,
|
16
|
+
text: text
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
let(:backtrace) { nil }
|
21
|
+
let(:method_name) { nil }
|
22
|
+
let(:plugin_name) { nil }
|
23
|
+
let(:file_path) { nil }
|
24
|
+
let(:plugin_version) { nil }
|
25
|
+
let(:text) { nil }
|
26
|
+
|
27
|
+
it { should be_a klass }
|
28
|
+
|
29
|
+
context "when passed an error class" do
|
30
|
+
let(:error) { ZeroDivisionError }
|
31
|
+
|
32
|
+
its(:error) { should be_instance_of error }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#message" do
|
36
|
+
subject(:message) { error_handler.message }
|
37
|
+
|
38
|
+
it { should be_a String }
|
39
|
+
|
40
|
+
context "with all options" do
|
41
|
+
let(:backtrace) {
|
42
|
+
["(eval):123:in `block in from_file'"]
|
43
|
+
}
|
44
|
+
let(:method_name) { :wat }
|
45
|
+
let(:plugin_name) { "abc" }
|
46
|
+
let(:file_path) { "/a/b/c.rb" }
|
47
|
+
let(:plugin_version) { "1.2.3" }
|
48
|
+
let(:text) { "There was an error" }
|
49
|
+
|
50
|
+
it {
|
51
|
+
message.should == <<-MESSAGE.gsub(/^\s+/, '')
|
52
|
+
abc (1.2.3)
|
53
|
+
/a/b/c.rb, on line 123, in 'wat'
|
54
|
+
There was an error
|
55
|
+
MESSAGE
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with a caller array" do
|
60
|
+
let(:backtrace) {
|
61
|
+
["(eval):123:in `block in from_file'"]
|
62
|
+
}
|
63
|
+
|
64
|
+
it { should include "line 123" }
|
65
|
+
end
|
66
|
+
|
67
|
+
context "with a method name" do
|
68
|
+
let(:method_name) { :wat }
|
69
|
+
|
70
|
+
it { should include method_name.to_s }
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with a name and version" do
|
74
|
+
let(:plugin_name) { "abc" }
|
75
|
+
let(:plugin_version) { "1.2.3" }
|
76
|
+
|
77
|
+
it { should include "abc (1.2.3)" }
|
78
|
+
end
|
79
|
+
|
80
|
+
context "with a path" do
|
81
|
+
let(:file_path) { "/a/b/c.rb" }
|
82
|
+
|
83
|
+
it { should include file_path }
|
84
|
+
end
|
85
|
+
|
86
|
+
context "with text" do
|
87
|
+
let(:text) { "There was an error" }
|
88
|
+
|
89
|
+
it { should include text }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe ".wrap" do
|
94
|
+
subject { klass.wrap error, options }
|
95
|
+
|
96
|
+
it { -> { subject }.should raise_error error.class }
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#line_number" do
|
100
|
+
subject { error_handler.line_number }
|
101
|
+
|
102
|
+
let(:backtrace) { [line] }
|
103
|
+
|
104
|
+
context "with an eval'd line" do
|
105
|
+
let(:line) { "(eval):123:in `block in from_file'" }
|
106
|
+
|
107
|
+
it { should == 123 }
|
108
|
+
end
|
109
|
+
|
110
|
+
context "with a sourced line" do
|
111
|
+
let(:line) { "/Users/JohnDoe/a/b/c.rb:123:in `method'" }
|
112
|
+
|
113
|
+
it { should == 123 }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "#file_contents" do
|
118
|
+
subject { error_handler.file_contents }
|
119
|
+
|
120
|
+
let(:file_contents) { "abc123" }
|
121
|
+
let(:file_path) { "/a/b/c.rb" }
|
122
|
+
|
123
|
+
before :each do
|
124
|
+
File.stub(:exist?).with(file_path).and_return(true)
|
125
|
+
File.stub(:read).with(file_path).and_return(file_contents)
|
126
|
+
end
|
127
|
+
|
128
|
+
it { should == file_contents }
|
129
|
+
|
130
|
+
context "with no file_path" do
|
131
|
+
let(:file_path) { nil }
|
132
|
+
|
133
|
+
it { should be_nil }
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "#relevant_source_lines" do
|
138
|
+
subject { error_handler.relevant_source_lines }
|
139
|
+
|
140
|
+
let(:backtrace) { ["something:6:something"] }
|
141
|
+
let(:file_contents) {
|
142
|
+
<<-FILE.gsub(/^\s{8}/, '')
|
143
|
+
require 'motherbrain'
|
144
|
+
|
145
|
+
module MyModule
|
146
|
+
class MyClass
|
147
|
+
def my_method
|
148
|
+
do :one
|
149
|
+
do :two
|
150
|
+
do :three
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
FILE
|
155
|
+
}
|
156
|
+
let(:file_path) { "/a/b/c.rb" }
|
157
|
+
|
158
|
+
before :each do
|
159
|
+
File.stub(:exist?).with(file_path).and_return(true)
|
160
|
+
File.stub(:read).with(file_path).and_return(file_contents)
|
161
|
+
end
|
162
|
+
|
163
|
+
it {
|
164
|
+
should == <<-OUTPUT.gsub(/^\s{8}/, '').rstrip
|
165
|
+
4: def my_method
|
166
|
+
5: do :one
|
167
|
+
6>> do :two
|
168
|
+
7: do :three
|
169
|
+
8: end
|
170
|
+
OUTPUT
|
171
|
+
}
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Errors do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
describe "::error_codes" do
|
7
|
+
subject { described_class.error_codes }
|
8
|
+
|
9
|
+
it "returns a Hash" do
|
10
|
+
subject.should be_a(Hash)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "::register" do
|
15
|
+
let(:err_class) do
|
16
|
+
double('error', error_code: -999)
|
17
|
+
end
|
18
|
+
|
19
|
+
before(:each) { subject.unregister(err_class) }
|
20
|
+
|
21
|
+
it "adds the error to the errors hash identified by the error_code" do
|
22
|
+
subject.register(err_class)
|
23
|
+
|
24
|
+
subject.error_codes[-999].should eql(err_class)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "raises a RuntimeError if an exception attempts to register with an in-use error code" do
|
28
|
+
subject.register(err_class)
|
29
|
+
|
30
|
+
expect {
|
31
|
+
subject.register(err_class)
|
32
|
+
}.to raise_error(RuntimeError)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe MB::MBError do
|
38
|
+
let(:error) { described_class.new("rspec test message") }
|
39
|
+
|
40
|
+
describe "#exit_code" do
|
41
|
+
subject { error.exit_code }
|
42
|
+
|
43
|
+
it { should be_a(Integer) }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#error_code" do
|
47
|
+
subject { error.error_code }
|
48
|
+
|
49
|
+
it { should be_a(Integer) }
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#message" do
|
53
|
+
subject { error.message }
|
54
|
+
|
55
|
+
it { should be_a(String) }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#to_s" do
|
59
|
+
subject { error.to_s }
|
60
|
+
|
61
|
+
it "includes the error code" do
|
62
|
+
subject.should include("[err_code]: #{error.error_code}")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "includes the error message" do
|
66
|
+
subject.should include("[message]: #{error.message}")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#to_hash" do
|
71
|
+
subject { error.to_hash }
|
72
|
+
|
73
|
+
it "contains an :code key with the exceptions error_code for it's value" do
|
74
|
+
subject.should have_key(:code)
|
75
|
+
subject[:code].should eql(error.error_code)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "contains a :message key with the exceptions message for it's value" do
|
79
|
+
subject.should have_key(:message)
|
80
|
+
subject[:message].should eql(error.message)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#to_json" do
|
85
|
+
subject { error.to_json }
|
86
|
+
|
87
|
+
it { should have_json_path("code") }
|
88
|
+
it { should have_json_path("message") }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe MB::GroupBootstrapError do
|
93
|
+
let(:bootstrap_response) do
|
94
|
+
{
|
95
|
+
"euca-10-20-37-171.eucalyptus.cloud.riotgames.com" => {
|
96
|
+
groups: ["activemq::master"],
|
97
|
+
result: {
|
98
|
+
status: :error, message: "something helpful", bootstrap_type: :full
|
99
|
+
}
|
100
|
+
},
|
101
|
+
"euca-10-20-37-172.eucalyptus.cloud.riotgames.com" => {
|
102
|
+
groups: ["activemq::master"],
|
103
|
+
result: {
|
104
|
+
status: :error, message: "something helpful", bootstrap_type: :partial
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
subject { described_class.new(bootstrap_response) }
|
111
|
+
|
112
|
+
its(:groups) { should have(1).item }
|
113
|
+
its(:host_errors) { should have(2).item }
|
114
|
+
its(:message) { should be_a(String) }
|
115
|
+
end
|
116
|
+
|
117
|
+
describe MB::ServiceRunListNotFound do
|
118
|
+
describe "with string" do
|
119
|
+
subject { described_class.new("abc") }
|
120
|
+
|
121
|
+
it "should use the string" do
|
122
|
+
expect(subject.message).to match(/abc/)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
describe "with array" do
|
126
|
+
subject { described_class.new(["a", "b", "c"]) }
|
127
|
+
|
128
|
+
it "should join the array and use the resulting string" do
|
129
|
+
expect(subject.message).to match(/a, b, c/)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::FileSystem::Tempfile do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
describe "::new" do
|
7
|
+
it "creates a new temp file within MB's temp file system" do
|
8
|
+
file = subject.new
|
9
|
+
file.close
|
10
|
+
|
11
|
+
file.path.should include(MB::FileSystem.tmp.to_s)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::FileSystem do
|
4
|
+
describe ".init" do
|
5
|
+
subject(:init) { described_class.init }
|
6
|
+
|
7
|
+
it "creates the directory structure" do
|
8
|
+
FileUtils.should_receive(:mkdir_p).exactly(5).times
|
9
|
+
|
10
|
+
init
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe ".logs" do
|
15
|
+
subject(:logs) { described_class.logs }
|
16
|
+
|
17
|
+
it { should be_a(Pathname) }
|
18
|
+
|
19
|
+
it "is a path within the root of the motherbrain filesystem" do
|
20
|
+
expect(logs.to_s).to include(MB::FileSystem.root.to_s)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".manifests" do
|
25
|
+
subject(:manifests) { described_class.manifests }
|
26
|
+
|
27
|
+
it { should be_a(Pathname) }
|
28
|
+
|
29
|
+
it "is a path within the root of the motherbrain filesystem" do
|
30
|
+
expect(manifests.to_s).to include(MB::FileSystem.root.to_s)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe ".root" do
|
35
|
+
subject(:root) { described_class.root }
|
36
|
+
|
37
|
+
it { should be_a(Pathname) }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".tmp" do
|
41
|
+
subject(:tmp) { described_class.tmp }
|
42
|
+
|
43
|
+
it { should be_a(Pathname) }
|
44
|
+
|
45
|
+
it "is a path within the root of the motherbrain filesystem" do
|
46
|
+
expect(tmp.to_s).to include(MB::FileSystem.root.to_s)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe ".tmpdir" do
|
51
|
+
subject(:tmpdir) { described_class.tmpdir }
|
52
|
+
|
53
|
+
it { should be_a(String) }
|
54
|
+
|
55
|
+
it "creates a temporary directory in the motherbrain temp filesystem" do
|
56
|
+
expect(tmpdir).to include(MB::FileSystem.tmp.to_s)
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when given a prefix" do
|
60
|
+
subject(:tmpdir) { described_class.tmpdir(prefix) }
|
61
|
+
|
62
|
+
let(:prefix) { "test" }
|
63
|
+
|
64
|
+
it "creates a directory with that prefix" do
|
65
|
+
expect(tmpdir.split(?/).last).to be_start_with(prefix)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Gear::Base do
|
4
|
+
subject do
|
5
|
+
Class.new(described_class).new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#run" do
|
9
|
+
it "raises an AbstractFunction error when not implemented" do
|
10
|
+
lambda {
|
11
|
+
subject.run(double('job'), double('environment'))
|
12
|
+
}.should raise_error(MB::AbstractFunction)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe MB::Gear do
|
18
|
+
before(:each) do
|
19
|
+
@original = MB::Gear.all
|
20
|
+
MB::Gear.clear!
|
21
|
+
end
|
22
|
+
|
23
|
+
after(:each) do
|
24
|
+
MB::Gear.clear!
|
25
|
+
@original.each do |k|
|
26
|
+
MB::Gear.register(k)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "ClassMethods" do
|
31
|
+
subject { MB::Gear }
|
32
|
+
|
33
|
+
describe "::all" do
|
34
|
+
it "returns a Set" do
|
35
|
+
subject.all.should be_a(Set)
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when no gears are registered" do
|
39
|
+
before(:each) { subject.clear! }
|
40
|
+
|
41
|
+
it "returns an empty Set" do
|
42
|
+
subject.all.should be_empty
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when a gear is registered" do
|
47
|
+
before(:each) do
|
48
|
+
@gear_1 = Class.new(MB::Gear::Base) do
|
49
|
+
register_gear :fake_one
|
50
|
+
end
|
51
|
+
|
52
|
+
@gear_2 = Class.new(MB::Gear::Base) do
|
53
|
+
register_gear :fake_two
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns an array with the registered gears" do
|
58
|
+
subject.all.should have(2).item
|
59
|
+
subject.all.should include(@gear_1)
|
60
|
+
subject.all.should include(@gear_2)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "::clear!" do
|
66
|
+
it "sets ::all to an empty Set" do
|
67
|
+
subject.clear!
|
68
|
+
|
69
|
+
subject.all.should be_empty
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "::find_by_keyword" do
|
74
|
+
before(:each) do
|
75
|
+
@klass = Class.new(MB::Gear::Base) do
|
76
|
+
register_gear :fake_gear
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns the class with the registered keyword" do
|
81
|
+
subject.find_by_keyword(:fake_gear).should eql(@klass)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "returns nil if a class with the given keyword is not registered" do
|
85
|
+
subject.find_by_keyword(:not_registered).should be_nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "::register_gear" do
|
91
|
+
it "sets the keyword class attribute" do
|
92
|
+
@klass = Class.new(MB::Gear::Base) do
|
93
|
+
register_gear :racer
|
94
|
+
end
|
95
|
+
|
96
|
+
@klass.keyword.should eql(:racer)
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when registering a keyword that has already been used" do
|
100
|
+
it "raises a DuplicateGearKeyword error" do
|
101
|
+
Class.new(MB::Gear::Base) do
|
102
|
+
register_gear :racer
|
103
|
+
end
|
104
|
+
|
105
|
+
lambda {
|
106
|
+
Class.new(MB::Gear::Base) do
|
107
|
+
register_gear :racer
|
108
|
+
end
|
109
|
+
}.should raise_error(MB::DuplicateGearKeyword)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "when registering a RESERVED_KEYWORD" do
|
114
|
+
it "raises a ReservedGearKeyword error" do
|
115
|
+
MB::Gear::RESERVED_KEYWORDS.each do |key|
|
116
|
+
lambda {
|
117
|
+
Class.new(MB::Gear::Base) do
|
118
|
+
register_gear key
|
119
|
+
end
|
120
|
+
}.should raise_error(MB::ReservedGearKeyword)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|