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,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Gear::Service::Action do
|
4
|
+
let(:component) { double('component', name: 'test-component') }
|
5
|
+
let(:job) { double('job', set_status: nil) }
|
6
|
+
let(:klass) { described_class }
|
7
|
+
|
8
|
+
let(:environment) { "rspec-test" }
|
9
|
+
let(:node_1) { double('node_1', name: 'reset', public_hostname: 'reset.riotgames.com') }
|
10
|
+
let(:node_2) { double('node_2', name: 'jwinsor', public_hostname: 'jwinsor.riotgames.com') }
|
11
|
+
let(:node_3) { double('node_3', name: 'jwinsor-2', public_hostname: 'jwinsor-2.riotgames.com') }
|
12
|
+
let(:nodes) { [ node_1, node_2, node_3 ] }
|
13
|
+
|
14
|
+
describe "#run" do
|
15
|
+
subject do
|
16
|
+
klass.new(:start, component) do
|
17
|
+
# block
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:runner) { double('action_runner', reset: nil, run: nil, service_recipe: nil) }
|
22
|
+
let(:key) { "some.attr" }
|
23
|
+
let(:value) { "val" }
|
24
|
+
let(:chef_success) { double('success-response', error?: false, host: nil) }
|
25
|
+
let(:chef_run_options) { { override_recipe: nil } }
|
26
|
+
let(:node_querier) { double('node_querier', bulk_chef_run: nil) }
|
27
|
+
|
28
|
+
before(:each) do
|
29
|
+
MB::Gear::Service::ActionRunner.stub(:new).and_return(runner)
|
30
|
+
MB::Gear::Service::Action.any_instance.stub(:node_querier).and_return(node_querier)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "runs Chef on every node" do
|
34
|
+
expect(node_querier).to receive(:bulk_chef_run).with(job, nodes, nil)
|
35
|
+
subject.run(job, environment, nodes)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "resets the ActionRunner" do
|
39
|
+
runner.should_receive(:reset)
|
40
|
+
|
41
|
+
subject.run(job, environment, [])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Gear::Service do
|
4
|
+
let(:component) { double('component', name: 'test-component') }
|
5
|
+
let(:job) { double('job', set_status: nil) }
|
6
|
+
|
7
|
+
describe "Class" do
|
8
|
+
subject { MB::Gear::Service }
|
9
|
+
|
10
|
+
it "is registered with MB::Gear" do
|
11
|
+
MB::Gear.all.should include(subject)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has the inferred keyword ':service' from it's Class name" do
|
15
|
+
subject.keyword.should eql(:service)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "::new" do
|
19
|
+
it "sets the given name attribute" do
|
20
|
+
obj = subject.new(component, "activemq") do
|
21
|
+
# block
|
22
|
+
end
|
23
|
+
|
24
|
+
obj.name.should eql("activemq")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
subject do
|
30
|
+
MB::Gear::Service.new("service", component) do
|
31
|
+
# block
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#actions" do
|
36
|
+
subject do
|
37
|
+
MB::Gear::Service.new("service", component) do
|
38
|
+
action :start do
|
39
|
+
node_attribute("key.one", true)
|
40
|
+
end
|
41
|
+
|
42
|
+
action :stop do
|
43
|
+
# block
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns a Set of Gear::Action::Service objects for each defined action" do
|
49
|
+
subject.actions.should be_a(Set)
|
50
|
+
subject.actions.should have(2).items
|
51
|
+
subject.actions.should each be_a(MB::Gear::Service::Action)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#action!" do
|
56
|
+
subject do
|
57
|
+
MB::Gear::Service.new("activemq", component) do
|
58
|
+
action :start do
|
59
|
+
node_attribute("key.one", true)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns a Gear::Service::Action" do
|
65
|
+
subject.action!(:start).should be_a(MB::Gear::Service::Action)
|
66
|
+
end
|
67
|
+
|
68
|
+
context "given an action that does not exist" do
|
69
|
+
it "raises an ActionNotFound error" do
|
70
|
+
lambda {
|
71
|
+
subject.action!(:stop)
|
72
|
+
}.should raise_error(MB::ActionNotFound)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#action" do
|
78
|
+
subject do
|
79
|
+
MB::Gear::Service.new("activemq", component) do
|
80
|
+
action :start do
|
81
|
+
node_attribute("key.one", true)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns a Gear::Service::Action" do
|
87
|
+
subject.action(:start).should be_a(MB::Gear::Service::Action)
|
88
|
+
end
|
89
|
+
|
90
|
+
context "given an action that does not exist" do
|
91
|
+
it "returns nil" do
|
92
|
+
expect(subject.action(:stop)).to be_nil
|
93
|
+
end
|
94
|
+
|
95
|
+
it "does not raise an ActionNotFound error" do
|
96
|
+
lambda {
|
97
|
+
subject.action(:stop)
|
98
|
+
}.should_not raise_error
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#add_action" do
|
104
|
+
let(:action_1) { double('action_1', name: "start") }
|
105
|
+
let(:action_2) { double('action_2', name: "stop") }
|
106
|
+
|
107
|
+
it "adds the given action to the set of actions" do
|
108
|
+
subject.add_action(action_1)
|
109
|
+
|
110
|
+
subject.actions.should have(1).item
|
111
|
+
subject.action!("start").should eql(action_1)
|
112
|
+
end
|
113
|
+
|
114
|
+
context "when an action of the given name has already been defined" do
|
115
|
+
it "raises a DuplicateAction error" do
|
116
|
+
lambda {
|
117
|
+
subject.add_action(action_1)
|
118
|
+
subject.add_action(action_1)
|
119
|
+
}.should raise_error(MB::DuplicateAction)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
@@ -0,0 +1,280 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Group do
|
4
|
+
let(:environment) { "mb-test" }
|
5
|
+
|
6
|
+
describe "ClassMethods" do
|
7
|
+
subject { MB::Group }
|
8
|
+
|
9
|
+
describe "::new" do
|
10
|
+
context "given a block with multiple recipe calls" do
|
11
|
+
it "adds each recipe to the array of recipes on the instantiated Group" do
|
12
|
+
obj = subject.new("bacon") do
|
13
|
+
recipe "bacon::default"
|
14
|
+
recipe "bacon::database"
|
15
|
+
end
|
16
|
+
|
17
|
+
obj.recipes.should have(2).items
|
18
|
+
obj.recipes.should include("bacon::default")
|
19
|
+
obj.recipes.should include("bacon::database")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "given a block with multiple role calls" do
|
24
|
+
it "adds each role to the array of roles on the instantiated Group" do
|
25
|
+
obj = subject.new("roles_are_poopy") do
|
26
|
+
role "roles_are_evil"
|
27
|
+
role "stop_using_roles"
|
28
|
+
end
|
29
|
+
|
30
|
+
obj.roles.should have(2).items
|
31
|
+
obj.roles.should include("roles_are_evil")
|
32
|
+
obj.roles.should include("stop_using_roles")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when an attribute of the same name is defined" do
|
37
|
+
it "raises a DuplicateGroup error" do
|
38
|
+
lambda {
|
39
|
+
subject.new("db_master") do
|
40
|
+
chef_attribute "pvpnet.database.master", true
|
41
|
+
chef_attribute "pvpnet.database.master", false
|
42
|
+
end
|
43
|
+
}.should raise_error(MB::DuplicateChefAttribute)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#name" do
|
50
|
+
subject do
|
51
|
+
MB::Group.new("master_database") do
|
52
|
+
# block
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns the name of the Group" do
|
57
|
+
subject.name.should eql("master_database")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#recipes" do
|
62
|
+
subject do
|
63
|
+
MB::Group.new("pvpnet") do
|
64
|
+
recipe "pvpnet::default"
|
65
|
+
recipe "pvpnet::database"
|
66
|
+
recipe "pvpnet::app"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns a Set of recipes" do
|
71
|
+
subject.recipes.should be_a(Set)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "includes all of the recipes from the block passed to Group.new" do
|
75
|
+
subject.recipes.should have(3).items
|
76
|
+
subject.recipes.should include("pvpnet::default")
|
77
|
+
subject.recipes.should include("pvpnet::database")
|
78
|
+
subject.recipes.should include("pvpnet::app")
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when a recipe of the same name is defined" do
|
82
|
+
subject do
|
83
|
+
MB::Group.new("pvpnet") do
|
84
|
+
recipe "pvpnet::default"
|
85
|
+
recipe "pvpnet::default"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it "does not add a duplicate recipe" do
|
90
|
+
subject.recipes.should have(1).item
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#roles" do
|
96
|
+
subject do
|
97
|
+
MB::Group.new("roles_are_poopy") do
|
98
|
+
role "stop"
|
99
|
+
role "fucking"
|
100
|
+
role "using"
|
101
|
+
role "roles"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it "returns a Set of roles" do
|
106
|
+
subject.roles.should be_a(Set)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "includes all of the roles from the block passed to Group.new" do
|
110
|
+
subject.roles.should have(4).items
|
111
|
+
subject.roles.should include("stop")
|
112
|
+
subject.roles.should include("fucking")
|
113
|
+
subject.roles.should include("using")
|
114
|
+
subject.roles.should include("roles")
|
115
|
+
end
|
116
|
+
|
117
|
+
context "when a role of the same name is defined" do
|
118
|
+
subject do
|
119
|
+
MB::Group.new("roles_are_poopy") do
|
120
|
+
role "asshole_role"
|
121
|
+
role "asshole_role"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "does not add a duplicate role" do
|
126
|
+
subject.roles.should have(1).item
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#chef_attributes" do
|
132
|
+
subject do
|
133
|
+
MB::Group.new("db_master") do
|
134
|
+
chef_attribute "pvpnet.database.master", true
|
135
|
+
chef_attribute "pvpnet.database.slave", false
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
it "returns a Hash" do
|
140
|
+
subject.chef_attributes.should be_a(Hash)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "has a key for every chef_attribute" do
|
144
|
+
subject.chef_attributes.should have_key("pvpnet.database.master")
|
145
|
+
subject.chef_attributes.should have_key("pvpnet.database.slave")
|
146
|
+
end
|
147
|
+
|
148
|
+
it "has the value for every chef_attribute" do
|
149
|
+
subject.chef_attributes["pvpnet.database.master"].should eql(true)
|
150
|
+
subject.chef_attributes["pvpnet.database.slave"].should eql(false)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "#search_query" do
|
155
|
+
let(:group) { double('group') }
|
156
|
+
subject { group.search_query(environment) }
|
157
|
+
|
158
|
+
context "with one chef attribute" do
|
159
|
+
let(:group) do
|
160
|
+
MB::Group.new("db_master") do
|
161
|
+
chef_attribute "pvpnet.database.master", true
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it "returns one key:value search string" do
|
166
|
+
expect(subject).to eql("chef_environment:#{environment} AND pvpnet_database_master:true")
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context "with multiple chef attributes" do
|
171
|
+
let(:group) do
|
172
|
+
MB::Group.new("db_master") do
|
173
|
+
chef_attribute "pvpnet.database.master", true
|
174
|
+
chef_attribute "pvpnet.database.slave", false
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
it "returns them escaped and joined together by AND" do
|
179
|
+
expect(subject).to eql("chef_environment:#{environment} AND pvpnet_database_master:true AND pvpnet_database_slave:false")
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context "with multiple recipes" do
|
184
|
+
let(:group) do
|
185
|
+
MB::Group.new("pvpnet") do
|
186
|
+
recipe "pvpnet::default"
|
187
|
+
recipe "pvpnet::database"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
it "returns them escaped and joined together by AND" do
|
192
|
+
expect(subject).to eql("chef_environment:#{environment} AND recipes:pvpnet\\:\\:default AND recipes:pvpnet\\:\\:database")
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context "with dash-separated recipes" do
|
197
|
+
let(:group) do
|
198
|
+
MB::Group.new("pvpnet") do
|
199
|
+
recipe "build-essential"
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
it "does not escape the dash" do
|
204
|
+
expect(subject).to eql("chef_environment:#{environment} AND recipes:build-essential")
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context "with multiple roles" do
|
209
|
+
let(:group) do
|
210
|
+
MB::Group.new("roles") do
|
211
|
+
role "app_server"
|
212
|
+
role "database_server"
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
it "returns them escaped and joined together by AND" do
|
217
|
+
expect(subject).to eql("chef_environment:#{environment} AND roles:app_server AND roles:database_server")
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
subject { MB::Group.new("test-group") }
|
223
|
+
|
224
|
+
describe "#run_list" do
|
225
|
+
subject do
|
226
|
+
MB::Group.new("test-group") do
|
227
|
+
role "role_one"
|
228
|
+
role "role_two"
|
229
|
+
recipe "test::default"
|
230
|
+
recipe "test::special"
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
it "returns an array" do
|
235
|
+
subject.run_list.should be_a(Array)
|
236
|
+
end
|
237
|
+
|
238
|
+
it "contains an item for each role and recipe on the group" do
|
239
|
+
subject.run_list.should have(4).items
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "each role element" do
|
243
|
+
it "is wrapped in the string 'role[]'" do
|
244
|
+
subject.run_list[0].should eql("role[role_one]")
|
245
|
+
subject.run_list[1].should eql("role[role_two]")
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
describe "each recipe element" do
|
250
|
+
it "is wrapped in the string 'recipe[]'" do
|
251
|
+
subject.run_list[2].should eql("recipe[test::default]")
|
252
|
+
subject.run_list[3].should eql("recipe[test::special]")
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe "#includes_recipe?" do
|
258
|
+
subject do
|
259
|
+
MB::Group.new("test-group") do
|
260
|
+
role "role_one"
|
261
|
+
role "role_two"
|
262
|
+
recipe "test::default"
|
263
|
+
recipe "test::special"
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should return true when the recipe is included directly" do
|
268
|
+
expect(subject.includes_recipe?("recipe[test::default]")).to be_true
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should return true when the recipe is included in a role" do
|
272
|
+
pending "write role expansion"
|
273
|
+
expect(subject.includes_recipe?("recipe[role_one_recipe::default]")).to be_true
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should return false when the recipe is not included" do
|
277
|
+
expect(subject.includes_recipe?("recipe[test::doesnt_exist]")).to be_false
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|