chef 12.0.0.rc.0-x86-mingw32 → 12.0.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +1 -1
- data/lib/chef/api_client/registration.rb +3 -1
- data/lib/chef/chef_fs/data_handler/group_data_handler.rb +4 -0
- data/lib/chef/config.rb +46 -38
- data/lib/chef/event_loggers/windows_eventlog.rb +5 -6
- data/lib/chef/exceptions.rb +13 -1
- data/lib/chef/file_content_management/tempfile.rb +33 -5
- data/lib/chef/knife.rb +11 -3
- data/lib/chef/knife/bootstrap.rb +8 -7
- data/lib/chef/mixin/deep_merge.rb +15 -54
- data/lib/chef/mixin/which.rb +37 -0
- data/lib/chef/node.rb +14 -25
- data/lib/chef/node/attribute.rb +227 -41
- data/lib/chef/node/attribute_collections.rb +117 -3
- data/lib/chef/node/immutable_collections.rb +6 -6
- data/lib/chef/platform/provider_priority_map.rb +3 -2
- data/lib/chef/platform/service_helpers.rb +37 -8
- data/lib/chef/provider/service/aixinit.rb +1 -1
- data/lib/chef/provider/service/arch.rb +1 -1
- data/lib/chef/provider/service/debian.rb +5 -1
- data/lib/chef/provider/service/init.rb +4 -0
- data/lib/chef/provider/service/insserv.rb +5 -1
- data/lib/chef/provider/service/invokercd.rb +5 -1
- data/lib/chef/provider/service/redhat.rb +5 -1
- data/lib/chef/provider/service/systemd.rb +50 -32
- data/lib/chef/provider/service/upstart.rb +5 -2
- data/lib/chef/provider_resolver.rb +30 -16
- data/lib/chef/resource.rb +2 -1
- data/lib/chef/resources.rb +7 -0
- data/lib/chef/run_context.rb +0 -5
- data/lib/chef/run_list/run_list_expansion.rb +2 -2
- data/lib/chef/shell.rb +2 -2
- data/lib/chef/util/selinux.rb +2 -10
- data/lib/chef/version.rb +1 -1
- data/lib/chef/workstation_config_loader.rb +1 -1
- data/spec/support/shared/unit/resource/static_provider_resolution.rb +1 -6
- data/spec/unit/api_client/registration_spec.rb +22 -0
- data/spec/unit/application/knife_spec.rb +6 -2
- data/spec/unit/chef_fs/data_handler/group_handler_spec.rb +63 -0
- data/spec/unit/config_spec.rb +5 -5
- data/spec/unit/knife/bootstrap_spec.rb +27 -1
- data/spec/unit/knife_spec.rb +5 -0
- data/spec/unit/mixin/deep_merge_spec.rb +0 -40
- data/spec/unit/node/attribute_spec.rb +37 -50
- data/spec/unit/node_spec.rb +321 -13
- data/spec/unit/provider/file/content_spec.rb +23 -2
- data/spec/unit/provider/service/systemd_service_spec.rb +173 -158
- data/spec/unit/provider_resolver_spec.rb +175 -10
- data/spec/unit/resource/timestamped_deploy_spec.rb +8 -29
- data/spec/unit/runner_spec.rb +3 -1
- metadata +147 -221
- data/spec/.DS_Store +0 -0
- data/spec/data/.DS_Store +0 -0
- data/spec/data/lwrp/.DS_Store +0 -0
- data/spec/data/lwrp/providers/.DS_Store +0 -0
- data/spec/data/lwrp/resources/.DS_Store +0 -0
- data/spec/data/lwrp_override/.DS_Store +0 -0
- data/spec/data/lwrp_override/providers/.DS_Store +0 -0
- data/spec/data/lwrp_override/resources/.DS_Store +0 -0
@@ -70,12 +70,34 @@ describe Chef::Provider::File::Content do
|
|
70
70
|
expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_false
|
71
71
|
end
|
72
72
|
|
73
|
-
it "returns a tempfile in the destdir when :
|
73
|
+
it "returns a tempfile in the destdir when :file_deployment_uses_destdir is set" do
|
74
74
|
Chef::Config[:file_staging_uses_destdir] = true
|
75
75
|
expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be_false
|
76
76
|
expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_true
|
77
77
|
end
|
78
78
|
|
79
|
+
context "when creating a tempfiles in destdir fails" do
|
80
|
+
let(:enclosing_directory) {
|
81
|
+
canonicalize_path("/nonexisting/path")
|
82
|
+
}
|
83
|
+
|
84
|
+
it "returns a tempfile in the tempdir when :file_deployment_uses_destdir is set to :auto" do
|
85
|
+
Chef::Config[:file_staging_uses_destdir] = :auto
|
86
|
+
expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be_true
|
87
|
+
expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_false
|
88
|
+
end
|
89
|
+
|
90
|
+
it "fails when :file_desployment_uses_destdir is set" do
|
91
|
+
Chef::Config[:file_staging_uses_destdir] = true
|
92
|
+
expect{content.tempfile}.to raise_error
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns a tempfile in the tempdir when :file_desployment_uses_destdir is not set" do
|
96
|
+
expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be_true
|
97
|
+
expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_false
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
79
101
|
end
|
80
102
|
|
81
103
|
describe "when the resource does not have a content attribute set" do
|
@@ -90,4 +112,3 @@ describe Chef::Provider::File::Content do
|
|
90
112
|
|
91
113
|
end
|
92
114
|
end
|
93
|
-
|
@@ -19,238 +19,253 @@
|
|
19
19
|
require 'spec_helper'
|
20
20
|
|
21
21
|
describe Chef::Provider::Service::Systemd do
|
22
|
+
|
23
|
+
let(:node) { Chef::Node.new }
|
24
|
+
|
25
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
26
|
+
|
27
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
28
|
+
|
29
|
+
let(:service_name) { "rsyslog.service" }
|
30
|
+
|
31
|
+
let(:new_resource) { Chef::Resource::Service.new(service_name) }
|
32
|
+
|
33
|
+
let(:provider) { Chef::Provider::Service::Systemd.new(new_resource, run_context) }
|
34
|
+
|
35
|
+
let(:shell_out_success) do
|
36
|
+
double('shell_out_with_systems_locale', :exitstatus => 0, :error? => false)
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:shell_out_failure) do
|
40
|
+
double('shell_out_with_systems_locale', :exitstatus => 1, :error? => true)
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:current_resource) { Chef::Resource::Service.new(service_name) }
|
44
|
+
|
22
45
|
before(:each) do
|
23
|
-
|
24
|
-
@events = Chef::EventDispatch::Dispatcher.new
|
25
|
-
@run_context = Chef::RunContext.new(@node, {}, @events)
|
26
|
-
@new_resource = Chef::Resource::Service.new('rsyslog.service')
|
27
|
-
@provider = Chef::Provider::Service::Systemd.new(@new_resource, @run_context)
|
28
|
-
|
29
|
-
@shell_out_success = double('shell_out_with_systems_locale',
|
30
|
-
:exitstatus => 0, :error? => false)
|
31
|
-
@shell_out_failure = double('shell_out_with_systems_locale',
|
32
|
-
:exitstatus => 1, :error? => true)
|
46
|
+
allow(Chef::Resource::Service).to receive(:new).with(service_name).and_return(current_resource)
|
33
47
|
end
|
34
48
|
|
35
49
|
describe "load_current_resource" do
|
36
|
-
before(:each) do
|
37
|
-
@current_resource = Chef::Resource::Service.new('rsyslog.service')
|
38
|
-
allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource)
|
39
50
|
|
40
|
-
|
41
|
-
allow(
|
51
|
+
before(:each) do
|
52
|
+
allow(provider).to receive(:is_active?).and_return(false)
|
53
|
+
allow(provider).to receive(:is_enabled?).and_return(false)
|
42
54
|
end
|
43
55
|
|
44
56
|
it "should create a current resource with the name of the new resource" do
|
45
|
-
expect(Chef::Resource::Service).to receive(:new).and_return(
|
46
|
-
|
57
|
+
expect(Chef::Resource::Service).to receive(:new).with(new_resource.name).and_return(current_resource)
|
58
|
+
provider.load_current_resource
|
47
59
|
end
|
48
60
|
|
49
61
|
it "should set the current resources service name to the new resources service name" do
|
50
|
-
|
51
|
-
|
62
|
+
provider.load_current_resource
|
63
|
+
expect(current_resource.service_name).to eql(service_name)
|
52
64
|
end
|
53
65
|
|
54
66
|
it "should check if the service is running" do
|
55
|
-
expect(
|
56
|
-
|
67
|
+
expect(provider).to receive(:is_active?)
|
68
|
+
provider.load_current_resource
|
57
69
|
end
|
58
70
|
|
59
71
|
it "should set running to true if the service is running" do
|
60
|
-
allow(
|
61
|
-
|
62
|
-
|
72
|
+
allow(provider).to receive(:is_active?).and_return(true)
|
73
|
+
provider.load_current_resource
|
74
|
+
expect(current_resource.running).to be true
|
63
75
|
end
|
64
76
|
|
65
77
|
it "should set running to false if the service is not running" do
|
66
|
-
allow(
|
67
|
-
|
68
|
-
|
78
|
+
allow(provider).to receive(:is_active?).and_return(false)
|
79
|
+
provider.load_current_resource
|
80
|
+
expect(current_resource.running).to be false
|
69
81
|
end
|
70
82
|
|
71
83
|
describe "when a status command has been specified" do
|
72
84
|
before do
|
73
|
-
allow(
|
85
|
+
allow(new_resource).to receive(:status_command).and_return("/bin/chefhasmonkeypants status")
|
74
86
|
end
|
75
87
|
|
76
88
|
it "should run the services status command if one has been specified" do
|
77
|
-
allow(
|
78
|
-
|
79
|
-
|
89
|
+
allow(provider).to receive(:shell_out).and_return(shell_out_success)
|
90
|
+
provider.load_current_resource
|
91
|
+
expect(current_resource.running).to be true
|
80
92
|
end
|
81
93
|
|
82
94
|
it "should run the services status command if one has been specified and properly set status check state" do
|
83
|
-
allow(
|
84
|
-
|
85
|
-
expect(
|
95
|
+
allow(provider).to receive(:shell_out).with("/bin/chefhasmonkeypants status").and_return(shell_out_success)
|
96
|
+
provider.load_current_resource
|
97
|
+
expect(provider.status_check_success).to be true
|
86
98
|
end
|
87
99
|
|
88
100
|
it "should set running to false if a status command fails" do
|
89
|
-
allow(
|
90
|
-
|
91
|
-
|
101
|
+
allow(provider).to receive(:shell_out).and_return(shell_out_failure)
|
102
|
+
provider.load_current_resource
|
103
|
+
expect(current_resource.running).to be false
|
92
104
|
end
|
93
105
|
|
94
106
|
it "should update state to indicate status check failed when a status command fails" do
|
95
|
-
allow(
|
96
|
-
|
97
|
-
expect(
|
107
|
+
allow(provider).to receive(:shell_out).and_return(shell_out_failure)
|
108
|
+
provider.load_current_resource
|
109
|
+
expect(provider.status_check_success).to be false
|
98
110
|
end
|
99
111
|
end
|
100
112
|
|
101
113
|
it "should check if the service is enabled" do
|
102
|
-
expect(
|
103
|
-
|
114
|
+
expect(provider).to receive(:is_enabled?)
|
115
|
+
provider.load_current_resource
|
104
116
|
end
|
105
117
|
|
106
118
|
it "should set enabled to true if the service is enabled" do
|
107
|
-
allow(
|
108
|
-
|
109
|
-
|
119
|
+
allow(provider).to receive(:is_enabled?).and_return(true)
|
120
|
+
provider.load_current_resource
|
121
|
+
expect(current_resource.enabled).to be true
|
110
122
|
end
|
111
123
|
|
112
124
|
it "should set enabled to false if the service is not enabled" do
|
113
|
-
allow(
|
114
|
-
|
115
|
-
|
125
|
+
allow(provider).to receive(:is_enabled?).and_return(false)
|
126
|
+
provider.load_current_resource
|
127
|
+
expect(current_resource.enabled).to be false
|
116
128
|
end
|
117
129
|
|
118
130
|
it "should return the current resource" do
|
119
|
-
expect(
|
131
|
+
expect(provider.load_current_resource).to eql(current_resource)
|
120
132
|
end
|
121
133
|
end
|
122
134
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
@provider.current_resource = @current_resource
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should call the start command if one is specified" do
|
131
|
-
allow(@new_resource).to receive(:start_command).and_return("/sbin/rsyslog startyousillysally")
|
132
|
-
expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog startyousillysally")
|
133
|
-
@provider.start_service
|
134
|
-
end
|
135
|
+
def setup_current_resource
|
136
|
+
provider.current_resource = current_resource
|
137
|
+
current_resource.service_name(service_name)
|
138
|
+
end
|
135
139
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
+
%w{/usr/bin/systemctl /bin/systemctl}.each do |systemctl_path|
|
141
|
+
describe "when systemctl path is #{systemctl_path}" do
|
142
|
+
before(:each) do
|
143
|
+
setup_current_resource
|
144
|
+
allow(provider).to receive(:which).with("systemctl").and_return(systemctl_path)
|
145
|
+
end
|
140
146
|
|
141
|
-
|
142
|
-
allow(@current_resource).to receive(:running).and_return(true)
|
143
|
-
expect(@provider).not_to receive(:shell_out_with_systems_locale!).with("/bin/systemctl start #{@new_resource.service_name}")
|
144
|
-
@provider.start_service
|
145
|
-
end
|
147
|
+
describe "start and stop service" do
|
146
148
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
end
|
149
|
+
it "should call the start command if one is specified" do
|
150
|
+
allow(new_resource).to receive(:start_command).and_return("/sbin/rsyslog startyousillysally")
|
151
|
+
expect(provider).to receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog startyousillysally")
|
152
|
+
provider.start_service
|
153
|
+
end
|
153
154
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
end
|
155
|
+
it "should call '#{systemctl_path} start service_name' if no start command is specified" do
|
156
|
+
expect(provider).to receive(:shell_out_with_systems_locale!).with("#{systemctl_path} start #{service_name}").and_return(shell_out_success)
|
157
|
+
provider.start_service
|
158
|
+
end
|
159
159
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
allow(@new_resource).to receive(:reload_command).and_return("/sbin/rsyslog reloadyousillysally")
|
165
|
-
expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog reloadyousillysally")
|
166
|
-
@provider.reload_service
|
160
|
+
it "should not call '#{systemctl_path} start service_name' if it is already running" do
|
161
|
+
current_resource.running(true)
|
162
|
+
expect(provider).not_to receive(:shell_out_with_systems_locale!).with("#{systemctl_path} start #{service_name}")
|
163
|
+
provider.start_service
|
167
164
|
end
|
168
|
-
end
|
169
165
|
|
170
|
-
|
171
|
-
|
172
|
-
allow(
|
173
|
-
expect(
|
174
|
-
|
166
|
+
it "should call the restart command if one is specified" do
|
167
|
+
current_resource.running(true)
|
168
|
+
allow(new_resource).to receive(:restart_command).and_return("/sbin/rsyslog restartyousillysally")
|
169
|
+
expect(provider).to receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog restartyousillysally")
|
170
|
+
provider.restart_service
|
175
171
|
end
|
176
172
|
|
177
|
-
it "should
|
178
|
-
|
179
|
-
expect(
|
180
|
-
|
173
|
+
it "should call '#{systemctl_path} restart service_name' if no restart command is specified" do
|
174
|
+
current_resource.running(true)
|
175
|
+
expect(provider).to receive(:shell_out_with_systems_locale!).with("#{systemctl_path} restart #{service_name}").and_return(shell_out_success)
|
176
|
+
provider.restart_service
|
181
177
|
end
|
182
|
-
end
|
183
|
-
end
|
184
178
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
179
|
+
describe "reload service" do
|
180
|
+
context "when a reload command is specified" do
|
181
|
+
it "should call the reload command" do
|
182
|
+
current_resource.running(true)
|
183
|
+
allow(new_resource).to receive(:reload_command).and_return("/sbin/rsyslog reloadyousillysally")
|
184
|
+
expect(provider).to receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog reloadyousillysally")
|
185
|
+
provider.reload_service
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context "when a reload command is not specified" do
|
190
|
+
it "should call '#{systemctl_path} reload service_name' if the service is running" do
|
191
|
+
current_resource.running(true)
|
192
|
+
expect(provider).to receive(:shell_out_with_systems_locale!).with("#{systemctl_path} reload #{service_name}").and_return(shell_out_success)
|
193
|
+
provider.reload_service
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should start the service if the service is not running" do
|
197
|
+
current_resource.running(false)
|
198
|
+
expect(provider).to receive(:start_service).and_return(true)
|
199
|
+
provider.reload_service
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
191
203
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
204
|
+
it "should call the stop command if one is specified" do
|
205
|
+
current_resource.running(true)
|
206
|
+
allow(new_resource).to receive(:stop_command).and_return("/sbin/rsyslog stopyousillysally")
|
207
|
+
expect(provider).to receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog stopyousillysally")
|
208
|
+
provider.stop_service
|
209
|
+
end
|
197
210
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
end
|
211
|
+
it "should call '#{systemctl_path} stop service_name' if no stop command is specified" do
|
212
|
+
current_resource.running(true)
|
213
|
+
expect(provider).to receive(:shell_out_with_systems_locale!).with("#{systemctl_path} stop #{service_name}").and_return(shell_out_success)
|
214
|
+
provider.stop_service
|
215
|
+
end
|
204
216
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
217
|
+
it "should not call '#{systemctl_path} stop service_name' if it is already stopped" do
|
218
|
+
current_resource.running(false)
|
219
|
+
expect(provider).not_to receive(:shell_out_with_systems_locale!).with("#{systemctl_path} stop #{service_name}")
|
220
|
+
provider.stop_service
|
221
|
+
end
|
222
|
+
end
|
211
223
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
224
|
+
describe "enable and disable service" do
|
225
|
+
before(:each) do
|
226
|
+
provider.current_resource = current_resource
|
227
|
+
current_resource.service_name(service_name)
|
228
|
+
allow(provider).to receive(:which).with("systemctl").and_return("#{systemctl_path}")
|
229
|
+
end
|
216
230
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
end
|
231
|
+
it "should call '#{systemctl_path} enable service_name' to enable the service" do
|
232
|
+
expect(provider).to receive(:shell_out!).with("#{systemctl_path} enable #{service_name}").and_return(shell_out_success)
|
233
|
+
provider.enable_service
|
234
|
+
end
|
222
235
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
236
|
+
it "should call '#{systemctl_path} disable service_name' to disable the service" do
|
237
|
+
expect(provider).to receive(:shell_out!).with("#{systemctl_path} disable #{service_name}").and_return(shell_out_success)
|
238
|
+
provider.disable_service
|
239
|
+
end
|
240
|
+
end
|
228
241
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
242
|
+
describe "is_active?" do
|
243
|
+
before(:each) do
|
244
|
+
provider.current_resource = current_resource
|
245
|
+
current_resource.service_name(service_name)
|
246
|
+
allow(provider).to receive(:which).with("systemctl").and_return("#{systemctl_path}")
|
247
|
+
end
|
233
248
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
end
|
249
|
+
it "should return true if '#{systemctl_path} is-active service_name' returns 0" do
|
250
|
+
expect(provider).to receive(:shell_out).with("#{systemctl_path} is-active #{service_name} --quiet").and_return(shell_out_success)
|
251
|
+
expect(provider.is_active?).to be true
|
252
|
+
end
|
239
253
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
254
|
+
it "should return false if '#{systemctl_path} is-active service_name' returns anything except 0" do
|
255
|
+
expect(provider).to receive(:shell_out).with("#{systemctl_path} is-active #{service_name} --quiet").and_return(shell_out_failure)
|
256
|
+
expect(provider.is_active?).to be false
|
257
|
+
end
|
258
|
+
end
|
245
259
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
260
|
+
it "should return true if '#{systemctl_path} is-enabled service_name' returns 0" do
|
261
|
+
expect(provider).to receive(:shell_out).with("#{systemctl_path} is-enabled #{service_name} --quiet").and_return(shell_out_success)
|
262
|
+
expect(provider.is_enabled?).to be true
|
263
|
+
end
|
250
264
|
|
251
|
-
|
252
|
-
|
253
|
-
|
265
|
+
it "should return false if '#{systemctl_path} is-enabled service_name' returns anything except 0" do
|
266
|
+
expect(provider).to receive(:shell_out).with("#{systemctl_path} is-enabled #{service_name} --quiet").and_return(shell_out_failure)
|
267
|
+
expect(provider.is_enabled?).to be false
|
268
|
+
end
|
254
269
|
end
|
255
270
|
end
|
256
271
|
end
|