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,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::JobManager do
|
4
|
+
let(:fake_job) do
|
5
|
+
Class.new do
|
6
|
+
include Celluloid
|
7
|
+
|
8
|
+
attr_reader :id, :type, :state, :status, :status_buffer, :result
|
9
|
+
attr_reader :time_start, :time_end
|
10
|
+
|
11
|
+
@id = 1
|
12
|
+
@type = 'fake'
|
13
|
+
@state = :pending
|
14
|
+
@status = ""
|
15
|
+
@status_buffer = [""]
|
16
|
+
@result = nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
before(:each) { @fake_job = fake_job.new }
|
21
|
+
|
22
|
+
describe "#add" do
|
23
|
+
it "adds a job to the active jobs list" do
|
24
|
+
subject.add(@fake_job)
|
25
|
+
|
26
|
+
subject.active.should have(1).item
|
27
|
+
subject.active[0].id.should == @fake_job.id
|
28
|
+
subject.active[0].should be_a(MB::JobRecord)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "monitors the given job" do
|
32
|
+
subject.add(@fake_job)
|
33
|
+
|
34
|
+
subject.should be_monitoring(@fake_job)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#find" do
|
39
|
+
it "returns a record of the job" do
|
40
|
+
subject.add(@fake_job)
|
41
|
+
|
42
|
+
subject.find(@fake_job.id).should be_a(MB::JobRecord)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#complete_job" do
|
47
|
+
before(:each) do
|
48
|
+
subject.add(@fake_job)
|
49
|
+
subject.complete_job(@fake_job)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "removes the given job from the active job list" do
|
53
|
+
subject.active.should have(0).items
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::JobRecord do
|
4
|
+
let(:job) do
|
5
|
+
double('job',
|
6
|
+
id: '123',
|
7
|
+
type: 'bootstrap',
|
8
|
+
state: 'pending',
|
9
|
+
status: 'just starting',
|
10
|
+
status_buffer: ['just starting'],
|
11
|
+
result: 'finished',
|
12
|
+
time_start: Time.now,
|
13
|
+
time_end: Time.now
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#to_hash" do
|
18
|
+
subject { described_class.new(job).to_hash }
|
19
|
+
|
20
|
+
it "has the 'id' of the given Job" do
|
21
|
+
subject[:id].should eql(job.id)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has the 'type' of the given Job" do
|
25
|
+
subject[:type].should eql(job.type)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has the 'state' of the given Job" do
|
29
|
+
subject[:state].should eql(job.state)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has the 'status' of the given Job" do
|
33
|
+
subject[:status].should eql(job.status)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has the 'result' of the given Job" do
|
37
|
+
subject[:result].should eql(job.result)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has the 'time_start' of the given Job" do
|
41
|
+
subject[:time_start].should eql(job.time_start)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "has the 'time_end' of the given Job" do
|
45
|
+
subject[:time_end].should eql(job.time_end)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#to_json" do
|
50
|
+
subject { described_class.new(job).to_json }
|
51
|
+
|
52
|
+
it { should have_json_path("id") }
|
53
|
+
it { should have_json_path("type") }
|
54
|
+
it { should have_json_path("state") }
|
55
|
+
it { should have_json_path("status") }
|
56
|
+
it { should have_json_path("result") }
|
57
|
+
it { should have_json_path("time_start") }
|
58
|
+
it { should have_json_path("time_end") }
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Job do
|
4
|
+
let(:type) { :provision }
|
5
|
+
|
6
|
+
describe "ClassMethods" do
|
7
|
+
subject { described_class }
|
8
|
+
|
9
|
+
describe "::new" do
|
10
|
+
subject { described_class.new(type) }
|
11
|
+
|
12
|
+
before(:each) { subject }
|
13
|
+
after(:each) { subject.terminate if subject.alive? }
|
14
|
+
|
15
|
+
it "starts in PENDING state" do
|
16
|
+
subject.should be_pending
|
17
|
+
end
|
18
|
+
|
19
|
+
it "starts with a nil result" do
|
20
|
+
subject.result.should be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has a value for id" do
|
24
|
+
subject.id.should_not be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "registers a job with JobManager" do
|
28
|
+
MB::JobManager.instance.active.should have(1).item
|
29
|
+
MB::JobManager.instance.active[0].id.should == subject.id
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
subject { described_class.new(type) }
|
35
|
+
|
36
|
+
describe "#completed?" do
|
37
|
+
it "should be completed if status is 'success'" do
|
38
|
+
subject.transition(:running)
|
39
|
+
subject.transition(:success)
|
40
|
+
|
41
|
+
subject.should be_completed
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be completed if status is 'failure'" do
|
45
|
+
subject.transition(:running)
|
46
|
+
subject.transition(:failure)
|
47
|
+
|
48
|
+
subject.should be_completed
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should not be completed if status is 'pending'" do
|
52
|
+
subject.should_not be_completed
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not be completed if status is 'running'" do
|
56
|
+
subject.transition(:running)
|
57
|
+
|
58
|
+
subject.should_not be_completed
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#failure?" do
|
63
|
+
it "should be a failure if status is 'failure'" do
|
64
|
+
subject.transition(:running)
|
65
|
+
subject.transition(:failure)
|
66
|
+
|
67
|
+
subject.should be_failure
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not be a failure if status is not 'failure'" do
|
71
|
+
subject.transition(:running)
|
72
|
+
subject.transition(:success)
|
73
|
+
|
74
|
+
subject.should_not be_failure
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#pending?" do
|
79
|
+
it "should be pending if status is 'pending'" do
|
80
|
+
subject.should be_pending
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should not be a pending if status is not 'pending'" do
|
84
|
+
subject.transition(:running)
|
85
|
+
|
86
|
+
subject.should_not be_pending
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#running?" do
|
91
|
+
it "should be running if status is 'running'" do
|
92
|
+
subject.transition(:running)
|
93
|
+
|
94
|
+
subject.should be_running
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should not be running if status is not 'running'" do
|
98
|
+
subject.transition(:running)
|
99
|
+
subject.transition(:success)
|
100
|
+
|
101
|
+
subject.should_not be_running
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#success?" do
|
106
|
+
it "should be a success if status is 'success'" do
|
107
|
+
subject.transition(:running)
|
108
|
+
subject.transition(:success)
|
109
|
+
|
110
|
+
subject.should be_success
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should not be success if status is not 'success'" do
|
114
|
+
subject.transition(:running)
|
115
|
+
subject.transition(:failure)
|
116
|
+
|
117
|
+
subject.should_not be_success
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#transition" do
|
122
|
+
it "returns self" do
|
123
|
+
expect(subject.transition(:running)).to eq(subject)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "accepts and sets a result/reason" do
|
127
|
+
subject.transition(:running, "a reason")
|
128
|
+
|
129
|
+
subject.result.should eql("a reason")
|
130
|
+
subject.should be_running
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "to pending" do
|
134
|
+
it "has a nil time_start field" do
|
135
|
+
subject.transition(:pending)
|
136
|
+
|
137
|
+
subject.time_start.should be_nil
|
138
|
+
end
|
139
|
+
|
140
|
+
it "has a nil time_end field" do
|
141
|
+
subject.transition(:pending)
|
142
|
+
|
143
|
+
subject.time_end.should be_nil
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "to running" do
|
148
|
+
before(:each) { subject.transition(:pending) }
|
149
|
+
|
150
|
+
it "has a Time value for time_start" do
|
151
|
+
subject.transition(:running)
|
152
|
+
|
153
|
+
subject.time_start.should be_a(Time)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "has a nil time_end field" do
|
157
|
+
subject.time_end.should be_nil
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "to success" do
|
162
|
+
before(:each) do
|
163
|
+
subject.transition(:pending)
|
164
|
+
subject.transition(:running)
|
165
|
+
@time_start = subject.time_start
|
166
|
+
end
|
167
|
+
|
168
|
+
it "doesn't modify the value for time_start" do
|
169
|
+
subject.transition(:success)
|
170
|
+
|
171
|
+
subject.time_start.should eql(@time_start)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "has a Time value for time_end" do
|
175
|
+
subject.transition(:success)
|
176
|
+
|
177
|
+
subject.time_end.should be_a(Time)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "to failure" do
|
182
|
+
before(:each) do
|
183
|
+
subject.transition(:pending)
|
184
|
+
subject.transition(:running)
|
185
|
+
@time_start = subject.time_start
|
186
|
+
end
|
187
|
+
|
188
|
+
it "doesn't modify the value for time_start" do
|
189
|
+
subject.transition(:failure)
|
190
|
+
|
191
|
+
subject.time_start.should eql(@time_start)
|
192
|
+
end
|
193
|
+
|
194
|
+
it "has a Time value for time_end" do
|
195
|
+
subject.transition(:failure)
|
196
|
+
|
197
|
+
subject.time_end.should be_a(Time)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::LockManager do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe "#locks" do
|
7
|
+
it "returns a Set" do
|
8
|
+
subject.locks.should be_a(Set)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#find" do
|
13
|
+
it "returns a Chef::Mutex if a mutex is registered" do
|
14
|
+
mutex = double('mutex', type: :chef_environment, name: "my_environment")
|
15
|
+
subject.stub(:locks).and_return([mutex])
|
16
|
+
|
17
|
+
subject.find(chef_environment: "my_environment").should eql(mutex)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns nil if a mutex with the given name is not registered" do
|
21
|
+
subject.find(chef_environment: "not-there-lock").should be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#register_lock" do
|
26
|
+
let(:mutex) { double('lock') }
|
27
|
+
|
28
|
+
it "adds the given lock to the list of locks" do
|
29
|
+
subject.register(mutex)
|
30
|
+
|
31
|
+
subject.locks.should have(1).item
|
32
|
+
subject.locks.should include(mutex)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#unregister_lock" do
|
37
|
+
let(:mutex) { double('lock') }
|
38
|
+
before(:each) { subject.register(mutex) }
|
39
|
+
|
40
|
+
it "removes the given lock from the list of locks" do
|
41
|
+
subject.unregister(mutex)
|
42
|
+
|
43
|
+
subject.locks.should have(0).items
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#lock" do
|
48
|
+
let(:environment) { "rspec-test" }
|
49
|
+
let(:job) { MB::Job.new(:lock) }
|
50
|
+
|
51
|
+
it "creates a new ChefMutex and locks it" do
|
52
|
+
mutex = double('mutex')
|
53
|
+
mutex.should_receive(:lock)
|
54
|
+
MB::ChefMutex.should_receive(:new).and_return(mutex)
|
55
|
+
|
56
|
+
subject.lock(job, environment)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#async_lock" do
|
61
|
+
let(:environment) { "rspec-test" }
|
62
|
+
|
63
|
+
it "returns a JobRecord" do
|
64
|
+
expect(subject.async_lock(environment)).to be_a(MB::JobRecord)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "unlock" do
|
69
|
+
let(:environment) { "rspec-test" }
|
70
|
+
let(:job) { MB::Job.new(:unlock) }
|
71
|
+
|
72
|
+
it "creates a new ChefMutex and unlocks it" do
|
73
|
+
mutex = double('mutex')
|
74
|
+
mutex.should_receive(:unlock)
|
75
|
+
MB::ChefMutex.should_receive(:new).and_return(mutex)
|
76
|
+
|
77
|
+
subject.unlock(job, environment)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#async_unlock" do
|
82
|
+
let(:environment) { "rspec-test" }
|
83
|
+
|
84
|
+
it "returns a JobRecord" do
|
85
|
+
expect(subject.async_unlock(environment)).to be_a(MB::JobRecord)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Logging do
|
4
|
+
before :each do
|
5
|
+
klass.reset
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "ClassMethods" do
|
9
|
+
subject { MB::Logging }
|
10
|
+
|
11
|
+
describe "::logger" do
|
12
|
+
it "returns a Logger class" do
|
13
|
+
subject.logger.should be_a(Logger)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "::setup" do
|
18
|
+
subject(:logger) { MB::Logging.logger }
|
19
|
+
|
20
|
+
let(:options) { Hash.new }
|
21
|
+
|
22
|
+
it "remembers options when called multiple times" do
|
23
|
+
klass.setup level: Logger::DEBUG, location: STDERR
|
24
|
+
klass.setup Hash.new
|
25
|
+
|
26
|
+
logger.instance_variable_get(:@logdev).dev.should == STDERR
|
27
|
+
logger.debug?.should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
before :each do
|
31
|
+
klass.setup options
|
32
|
+
end
|
33
|
+
|
34
|
+
it "defaults to WARN" do
|
35
|
+
logger.warn?.should be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with level: INFO" do
|
39
|
+
let(:options) { { level: Logger::INFO } }
|
40
|
+
|
41
|
+
its(:info?) { should be_true }
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when passed 'INFO' as string" do
|
45
|
+
let(:options) { { level: 'INFO' } }
|
46
|
+
|
47
|
+
its(:info?) { should be_true }
|
48
|
+
end
|
49
|
+
|
50
|
+
context "with level: Logger::DEBUG" do
|
51
|
+
let(:options) { { level: Logger::DEBUG } }
|
52
|
+
|
53
|
+
its(:debug?) { should be_true }
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when passed 'DEBUG' as string" do
|
57
|
+
let(:options) { { level: 'DEBUG' } }
|
58
|
+
|
59
|
+
its(:debug?) { should be_true }
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when passed 'WARN' as string" do
|
63
|
+
let(:options) { { level: 'WARN' } }
|
64
|
+
|
65
|
+
its(:warn?) { should be_true }
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when passed 'ERROR' as string" do
|
69
|
+
let(:options) { { level: 'ERROR' } }
|
70
|
+
|
71
|
+
its(:error?) { should be_true }
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when passed 'FATAL' as string" do
|
75
|
+
let(:options) { { level: 'FATAL' } }
|
76
|
+
|
77
|
+
its(:fatal?) { should be_true }
|
78
|
+
end
|
79
|
+
|
80
|
+
it "defaults to 'application.log' in the MB Logs directory" do
|
81
|
+
logger.instance_variable_get(:@logdev).dev.path.should == MB::FileSystem.logs.join('application.log').to_s
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when passed STDOUT as a string" do
|
85
|
+
let(:options) { { location: "STDOUT" } }
|
86
|
+
|
87
|
+
it "constantizes STDOUT" do
|
88
|
+
logger.instance_variable_get(:@logdev).dev.should == STDOUT
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "when passed STDERR as a string" do
|
93
|
+
let(:options) { { location: "STDERR" } }
|
94
|
+
|
95
|
+
it "constantizes STDERR" do
|
96
|
+
logger.instance_variable_get(:@logdev).dev.should == STDERR
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "with a path" do
|
101
|
+
let(:location) { File.join tmp_path, "log.txt" }
|
102
|
+
let(:options) { { location: location } }
|
103
|
+
|
104
|
+
it "logs to the path" do
|
105
|
+
logger.instance_variable_get(:@logdev).dev.path.should == location
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "::set_logger" do
|
111
|
+
it "sets the logger to the given instance" do
|
112
|
+
new_logger = Logger.new('/dev/null')
|
113
|
+
subject.set_logger(new_logger)
|
114
|
+
|
115
|
+
subject.logger.should eql(new_logger)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
subject do
|
121
|
+
Class.new do
|
122
|
+
include MB::Logging
|
123
|
+
end.new
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "#logger" do
|
127
|
+
it "delegates to MB::Logging.logger" do
|
128
|
+
MB::Logging.should_receive(:logger)
|
129
|
+
|
130
|
+
subject.logger
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|