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,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::ConfigManager do
|
4
|
+
subject { described_class.new(@config) }
|
5
|
+
|
6
|
+
describe "update" do
|
7
|
+
let(:listener) do
|
8
|
+
Class.new do
|
9
|
+
include Celluloid
|
10
|
+
include Celluloid::Notifications
|
11
|
+
end.new
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:new_config) do
|
15
|
+
double('config', validate!: true)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "sends the 'config_manager.configure' notification" do
|
19
|
+
listener.subscribe('config_manager.configure', :trigger)
|
20
|
+
listener.should_receive(:trigger).once
|
21
|
+
|
22
|
+
subject.update(new_config)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "updates the config attribute with the given config" do
|
26
|
+
subject.update(new_config)
|
27
|
+
|
28
|
+
subject.config.should eql(new_config)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,408 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::Config do
|
4
|
+
describe "ClassMethods" do
|
5
|
+
subject { MB::Config }
|
6
|
+
|
7
|
+
describe "::new" do
|
8
|
+
before(:each) do
|
9
|
+
@config = subject.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a default value for 'berkshelf.path'" do
|
13
|
+
@config.berkshelf.path.should_not be_nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "::validate!" do
|
18
|
+
it "raises an InvalidConfig error if the given config is invalid" do
|
19
|
+
invalid_config = double('config', valid?: false, errors: [])
|
20
|
+
|
21
|
+
expect {
|
22
|
+
subject.validate!(invalid_config)
|
23
|
+
}.to raise_error(MB::InvalidConfig)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "::manager" do
|
28
|
+
it "returns an instance of MB::ConfigManager" do
|
29
|
+
subject.manager.should be_a(MB::ConfigManager)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
subject do
|
35
|
+
MB::Config.new.tap do |o|
|
36
|
+
o.chef.api_url = "https://api.opscode.com/organizations/vialstudio"
|
37
|
+
o.chef.api_client = "reset"
|
38
|
+
o.chef.api_key = "/Users/reset/.chef/reset.pem"
|
39
|
+
o.ssh.user = "root"
|
40
|
+
o.ssh.password = "something"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#log.level" do
|
45
|
+
it "converts the string 'info' to 'INFO'" do
|
46
|
+
subject.log.level = 'info'
|
47
|
+
|
48
|
+
subject.log.level.should eql('INFO')
|
49
|
+
end
|
50
|
+
|
51
|
+
it "converts the string 'debug' to 'DEBUG'" do
|
52
|
+
subject.log.level = 'debug'
|
53
|
+
|
54
|
+
subject.log.level.should eql('DEBUG')
|
55
|
+
end
|
56
|
+
|
57
|
+
it "converts the string 'warn' to 'WARN'" do
|
58
|
+
subject.log.level = 'warn'
|
59
|
+
|
60
|
+
subject.log.level.should eql('WARN')
|
61
|
+
end
|
62
|
+
|
63
|
+
it "converts the string 'fatal' to 'FATAL'" do
|
64
|
+
subject.log.level = 'fatal'
|
65
|
+
|
66
|
+
subject.log.level.should eql('FATAL')
|
67
|
+
end
|
68
|
+
|
69
|
+
it "accepts the Logger::DEBUG constant" do
|
70
|
+
subject.log.level = Logger::DEBUG
|
71
|
+
|
72
|
+
subject.log.level.should eql('DEBUG')
|
73
|
+
end
|
74
|
+
|
75
|
+
it "accepts the Logger::INFO constant" do
|
76
|
+
subject.log.level = Logger::INFO
|
77
|
+
|
78
|
+
subject.log.level.should eql('INFO')
|
79
|
+
end
|
80
|
+
|
81
|
+
it "accepts the Logger::WARN constant" do
|
82
|
+
subject.log.level = Logger::WARN
|
83
|
+
|
84
|
+
subject.log.level.should eql('WARN')
|
85
|
+
end
|
86
|
+
|
87
|
+
it "accepts the Logger::FATAL constant" do
|
88
|
+
subject.log.level = Logger::FATAL
|
89
|
+
|
90
|
+
subject.log.level.should eql('FATAL')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#log.location" do
|
95
|
+
it "accepts the string 'stdout'" do
|
96
|
+
subject.log.location = 'stdout'
|
97
|
+
|
98
|
+
subject.log.location.should eql('STDOUT')
|
99
|
+
end
|
100
|
+
|
101
|
+
it "accepts the string 'stderr'" do
|
102
|
+
subject.log.location = 'stderr'
|
103
|
+
|
104
|
+
subject.log.location.should eql('STDERR')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "validations" do
|
109
|
+
context "given a valid configuration" do
|
110
|
+
it "should be valid" do
|
111
|
+
subject.should be_valid
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it "is invalid if berkshelf.path is blank" do
|
116
|
+
subject.berkshelf.path = nil
|
117
|
+
|
118
|
+
subject.should_not be_valid
|
119
|
+
end
|
120
|
+
|
121
|
+
it "is invalid if chef.api_url is blank" do
|
122
|
+
subject.chef.api_url = nil
|
123
|
+
|
124
|
+
subject.should_not be_valid
|
125
|
+
end
|
126
|
+
|
127
|
+
it "is invalid if chef.api_url is not a valid HTTP or HTTPS url" do
|
128
|
+
pending
|
129
|
+
|
130
|
+
subject.chef.api_url = 'not_a_uri'
|
131
|
+
|
132
|
+
subject.should_not be_valid
|
133
|
+
end
|
134
|
+
|
135
|
+
it "is invalid if chef.api_client is blank" do
|
136
|
+
subject.chef.api_client = nil
|
137
|
+
|
138
|
+
subject.should_not be_valid
|
139
|
+
end
|
140
|
+
|
141
|
+
it "is invalid if chef.api_key is blank" do
|
142
|
+
subject.chef.api_key = nil
|
143
|
+
|
144
|
+
subject.should_not be_valid
|
145
|
+
end
|
146
|
+
|
147
|
+
it "is invalid if ssh_keys is blank or empty and ssh_password is blank" do
|
148
|
+
pending
|
149
|
+
|
150
|
+
subject.ssh.keys = []
|
151
|
+
subject.ssh.password = ''
|
152
|
+
|
153
|
+
subject.should_not be_valid
|
154
|
+
subject.errors[:ssh_password].should =~ ["You must specify an SSH password or an SSH key"]
|
155
|
+
subject.errors[:ssh_keys].should =~ ["You must specify an SSH password or an SSH key"]
|
156
|
+
end
|
157
|
+
|
158
|
+
it "is invalid if ssh_timeout is a non-integer non-float" do
|
159
|
+
subject.ssh.timeout = "string"
|
160
|
+
|
161
|
+
subject.should_not be_valid
|
162
|
+
end
|
163
|
+
|
164
|
+
it "is valid if ssh_timeout is an integer" do
|
165
|
+
subject.ssh.timeout = 1
|
166
|
+
|
167
|
+
subject.should be_valid
|
168
|
+
end
|
169
|
+
|
170
|
+
it "is valid if ssh_timeout is a float" do
|
171
|
+
subject.ssh.timeout = 1.0
|
172
|
+
|
173
|
+
subject.should be_valid
|
174
|
+
end
|
175
|
+
|
176
|
+
it "is valid if boostrap_default_template is a name" do
|
177
|
+
subject.bootstrap.default_template = "internal"
|
178
|
+
|
179
|
+
expect(subject).to be_valid
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
let(:json) do
|
184
|
+
%(
|
185
|
+
{
|
186
|
+
"chef": {
|
187
|
+
"api_client": "reset"
|
188
|
+
}
|
189
|
+
}
|
190
|
+
)
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "ClassMethods" do
|
194
|
+
subject { MB::Config }
|
195
|
+
|
196
|
+
describe "::from_json" do
|
197
|
+
it "returns an instance of MB::Config" do
|
198
|
+
subject.from_json(json).should be_a(MB::Config)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "::from_file" do
|
203
|
+
let(:file) { tmp_path.join("test-config.json").to_s }
|
204
|
+
|
205
|
+
before(:each) do
|
206
|
+
File.write(file, json)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "returns an instance of MB::Config" do
|
210
|
+
subject.from_file(file).should be_a(MB::Config)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "sets the object's path to the path of the loaded file" do
|
214
|
+
subject.from_file(file).path.should eql(file)
|
215
|
+
end
|
216
|
+
|
217
|
+
context "given a file that does not exist" do
|
218
|
+
it "raises a MB::ConfigNotFound error" do
|
219
|
+
lambda {
|
220
|
+
subject.from_file(tmp_path.join("asdf.txt"))
|
221
|
+
}.should raise_error(MB::ConfigNotFound)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
describe "::default_path" do
|
227
|
+
after(:each) do
|
228
|
+
ENV['MB_CONFIG'] = nil
|
229
|
+
end
|
230
|
+
|
231
|
+
subject { described_class.default_path }
|
232
|
+
|
233
|
+
it "returns a string" do
|
234
|
+
subject.should be_a(String)
|
235
|
+
end
|
236
|
+
|
237
|
+
it "is located within the motherbrain file system" do
|
238
|
+
subject.should include(MB::FileSystem.root.to_s)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "#from_json" do
|
244
|
+
it "sets the attributes found in the json" do
|
245
|
+
subject.from_json(json).chef.api_client.should eql("reset")
|
246
|
+
end
|
247
|
+
|
248
|
+
context "given JSON containing undefined attributes" do
|
249
|
+
let(:json) do
|
250
|
+
%(
|
251
|
+
{
|
252
|
+
"not_a_valid_attribute": "failure!"
|
253
|
+
}
|
254
|
+
)
|
255
|
+
end
|
256
|
+
|
257
|
+
it "ignores the additional configuration options" do
|
258
|
+
subject.from_json(json).should_not respond_to(:not_a_valid_attribute)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context "given malformed JSON" do
|
263
|
+
let(:json) do
|
264
|
+
%(
|
265
|
+
{
|
266
|
+
"firstkey": "firstval"
|
267
|
+
"missing": "a comma"
|
268
|
+
}
|
269
|
+
)
|
270
|
+
end
|
271
|
+
|
272
|
+
it "raises an InvalidConfiguration error" do
|
273
|
+
lambda {
|
274
|
+
subject.from_json(json).attributes
|
275
|
+
}.should raise_error(Buff::Errors::InvalidConfig)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
describe "#winrm" do
|
281
|
+
subject { winrm }
|
282
|
+
|
283
|
+
let(:winrm) { mb_config[:winrm] }
|
284
|
+
let(:mb_config) {
|
285
|
+
MB::Config.new.tap do |o|
|
286
|
+
o.winrm.user = "Administrator"
|
287
|
+
o.winrm.password = "secret"
|
288
|
+
end
|
289
|
+
}
|
290
|
+
|
291
|
+
it { should eq(mb_config.winrm) }
|
292
|
+
|
293
|
+
it "has valid config options" do
|
294
|
+
expect(winrm.user).to eq("Administrator")
|
295
|
+
expect(winrm.password).to eq("secret")
|
296
|
+
expect(winrm.port).to eq(5985)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
describe "#to_json" do
|
301
|
+
it "should not include the 'id' attribute" do
|
302
|
+
subject.to_json.should_not have_json_path('id')
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
describe "#save" do
|
307
|
+
let(:config_path) { tmp_path.join("config.json") }
|
308
|
+
|
309
|
+
before(:each) { subject.path = config_path }
|
310
|
+
|
311
|
+
it "creates a new file at the instance's path" do
|
312
|
+
subject.save
|
313
|
+
|
314
|
+
config_path.should exist
|
315
|
+
end
|
316
|
+
|
317
|
+
it "writes the evaluation of to_json as the content of the file" do
|
318
|
+
subject.save
|
319
|
+
|
320
|
+
File.read(config_path).should be_json_eql(subject.to_json)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
describe "#to_ridley" do
|
325
|
+
let(:config) do
|
326
|
+
MB::Config.new.tap do |o|
|
327
|
+
o.chef.api_url = "https://api.opscode.com/organizations/vialstudios"
|
328
|
+
o.chef.api_client = "reset"
|
329
|
+
o.chef.api_key = "/Users/reset/.chef/reset.pem"
|
330
|
+
o.chef.encrypted_data_bag_secret_path = File.join(fixtures_path, "fake_key.pem")
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
subject do
|
335
|
+
config.to_ridley
|
336
|
+
end
|
337
|
+
|
338
|
+
it "returns a hash with a 'server_url' key mapping to chef.api_url" do
|
339
|
+
subject.should have_key(:server_url)
|
340
|
+
subject[:server_url].should eql(config.chef.api_url)
|
341
|
+
end
|
342
|
+
|
343
|
+
it "returns a hash with a 'client_name' key mapping to chef.api_client" do
|
344
|
+
subject.should have_key(:client_name)
|
345
|
+
subject[:client_name].should eql(config.chef.api_client)
|
346
|
+
end
|
347
|
+
|
348
|
+
it "returns a hash with a 'client_key' key mapping to chef.api_key" do
|
349
|
+
subject.should have_key(:client_key)
|
350
|
+
subject[:client_key].should eql(config.chef.api_key)
|
351
|
+
end
|
352
|
+
|
353
|
+
it "returns a hash with a 'encrypted_data_bag_secret_path' key mapping to chef.encrypted_data_bag_secret_path" do
|
354
|
+
subject.should have_key(:encrypted_data_bag_secret_path)
|
355
|
+
subject[:encrypted_data_bag_secret_path].should eql(config.chef.encrypted_data_bag_secret_path)
|
356
|
+
end
|
357
|
+
|
358
|
+
it "returns a hash with a 'ssl.verify' key" do
|
359
|
+
subject.should have_key(:ssl)
|
360
|
+
subject[:ssl][:verify].should_not be_nil
|
361
|
+
end
|
362
|
+
|
363
|
+
it "returns a hash with a 'ssh' key" do
|
364
|
+
subject.should have_key(:ssh)
|
365
|
+
end
|
366
|
+
|
367
|
+
it "returns a hash with a 'winrm' key" do
|
368
|
+
subject.should have_key(:winrm)
|
369
|
+
end
|
370
|
+
|
371
|
+
describe "'ssh' key" do
|
372
|
+
it { subject[:ssh].should eql(config.ssh) }
|
373
|
+
end
|
374
|
+
|
375
|
+
it "returns a hash with a 'validator_client' key mapping to chef.validator_client" do
|
376
|
+
subject.should have_key(:validator_client)
|
377
|
+
subject[:validator_client].should eql(config.chef.validator_client)
|
378
|
+
end
|
379
|
+
|
380
|
+
context "given the config has no value for organization" do
|
381
|
+
subject do
|
382
|
+
MB::Config.new.tap do |o|
|
383
|
+
o.chef.api_url = "https://api.opscode.com"
|
384
|
+
o.chef.api_client = "reset"
|
385
|
+
o.chef.api_key = "/Users/reset/.chef/reset.pem"
|
386
|
+
end.to_ridley
|
387
|
+
end
|
388
|
+
|
389
|
+
it "returns a hash without an 'organization' key" do
|
390
|
+
subject.should_not have_key(:organization)
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
describe "#to_rest_gateway" do
|
396
|
+
subject { MB::Config.new }
|
397
|
+
|
398
|
+
it "returns a hash containing a 'host' key and value" do
|
399
|
+
subject.to_rest_gateway.should have_key(:host)
|
400
|
+
subject.to_rest_gateway[:host].should_not be_nil
|
401
|
+
end
|
402
|
+
|
403
|
+
it "returns a hash containing a 'port' key and value" do
|
404
|
+
subject.to_rest_gateway.should have_key(:port)
|
405
|
+
subject.to_rest_gateway[:port].should_not be_nil
|
406
|
+
end
|
407
|
+
end
|
408
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MotherBrain::CookbookMetadata do
|
4
|
+
describe "ClassMethods" do
|
5
|
+
subject { described_class }
|
6
|
+
|
7
|
+
describe "#load" do
|
8
|
+
it "returns an instance of CookbookMetadata" do
|
9
|
+
subject.load().should be_a(MB::CookbookMetadata)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when given a block" do
|
13
|
+
subject do
|
14
|
+
described_class.load do
|
15
|
+
name "motherbrain"
|
16
|
+
maintainer "Jamie Winsor"
|
17
|
+
maintainer_email "jamie@vialstudios.com"
|
18
|
+
license "Apache 2.0"
|
19
|
+
description "Installs/Configures motherbrain"
|
20
|
+
long_description "Installs/Configures motherbrain"
|
21
|
+
version "0.1.0"
|
22
|
+
|
23
|
+
%w{ centos }.each do |os|
|
24
|
+
supports os
|
25
|
+
end
|
26
|
+
|
27
|
+
depends "nginx", "~> 1.0.0"
|
28
|
+
depends "artifact", "~> 0.11.5"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "sets a String value for 'name'" do
|
33
|
+
subject.name.should eql("motherbrain")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "sets a String value for 'maintainer'" do
|
37
|
+
subject.maintainer.should eql("Jamie Winsor")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "sets a String value for 'maintainer_email'" do
|
41
|
+
subject.maintainer_email.should eql("jamie@vialstudios.com")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "sets a String value for 'license" do
|
45
|
+
subject.license.should eql("Apache 2.0")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "sets a String value for 'description'" do
|
49
|
+
subject.description.should eql("Installs/Configures motherbrain")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "sets a String value for 'long_description'" do
|
53
|
+
subject.long_description.should eql("Installs/Configures motherbrain")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "sets a Solve::Version value for 'version'" do
|
57
|
+
subject.version.should be_a(Solve::Version)
|
58
|
+
subject.version.to_s.should eql("0.1.0")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "doesn't complain when a value for an unknown attribute is set" do
|
62
|
+
expect {
|
63
|
+
obj = described_class.load do
|
64
|
+
unknown_keyword "asdf"
|
65
|
+
end
|
66
|
+
}.to_not raise_error
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#from_file" do
|
72
|
+
context "when the metadata is a ruby file" do
|
73
|
+
let(:path) { fixtures_path.join('cb_metadata.rb') }
|
74
|
+
|
75
|
+
it "returns an instance of CookbookMetadata" do
|
76
|
+
subject.from_file(path).should be_a(MB::CookbookMetadata)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when the metadata is a json file" do
|
81
|
+
let(:path) { fixtures_path.join('cb_metadata.json') }
|
82
|
+
|
83
|
+
it "returns an instance of CookbookMetadata" do
|
84
|
+
subject.from_file(path).should be_a(MB::CookbookMetadata)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|