chef 14.14.25 → 14.14.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef/knife/config_get.rb +2 -1
- data/lib/chef/provider/service/systemd.rb +16 -0
- data/lib/chef/provider/systemd_unit.rb +26 -2
- data/lib/chef/resource/service.rb +9 -0
- data/lib/chef/resource/systemd_unit.rb +1 -0
- data/lib/chef/version.rb +1 -1
- data/spec/integration/knife/config_get_spec.rb +7 -0
- data/spec/unit/provider/service/systemd_service_spec.rb +26 -2
- data/spec/unit/provider/systemd_unit_spec.rb +55 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 867f9eae7407b158cb748a5ae3c016ed1663736dafc3879cacb2cb10fa51f679
|
4
|
+
data.tar.gz: 3977733a96ee85e00cc05cb59f96dfaea3b16ef54229646aa7f6efef5ca9327f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12c98f539abdfdc1dee76c8bd94f5cb594bf9b32c4d3458dc666c760232a2c216a7e0b8ca5160583229b907527131ad5b4ec9b58ffa2fdcf7e9bfd7e4a819fb7
|
7
|
+
data.tar.gz: 17e59c3a99dfd164f987c582f671fe7b1f78270c38c7359ee4bff2641b24fde6123f94cbbf3f81dbf93b20bef84f2307f6a5c6719e73b0b5685a639caff38c25
|
@@ -47,9 +47,10 @@ class Chef
|
|
47
47
|
if wcl.config_location
|
48
48
|
loading_from("configuration", wcl.config_location)
|
49
49
|
end
|
50
|
+
|
50
51
|
if Chef::Config[:config_d_dir]
|
51
52
|
wcl.find_dot_d(Chef::Config[:config_d_dir]).each do |path|
|
52
|
-
loading_from(".d/ configuration",
|
53
|
+
loading_from(".d/ configuration", path)
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
@@ -51,6 +51,7 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
|
|
51
51
|
current_resource.running(false)
|
52
52
|
current_resource.enabled(false)
|
53
53
|
current_resource.masked(false)
|
54
|
+
current_resource.indirect(false)
|
54
55
|
end
|
55
56
|
else
|
56
57
|
current_resource.running(is_active?)
|
@@ -58,6 +59,7 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
|
|
58
59
|
|
59
60
|
current_resource.enabled(is_enabled?)
|
60
61
|
current_resource.masked(is_masked?)
|
62
|
+
current_resource.indirect(is_indirect?)
|
61
63
|
current_resource
|
62
64
|
end
|
63
65
|
|
@@ -142,11 +144,19 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
|
|
142
144
|
end
|
143
145
|
|
144
146
|
def enable_service
|
147
|
+
if current_resource.masked || current_resource.indirect
|
148
|
+
logger.trace("#{new_resource} cannot be enabled: it is masked or indirect")
|
149
|
+
return
|
150
|
+
end
|
145
151
|
options, args = get_systemctl_options_args
|
146
152
|
shell_out!("#{systemctl_path} #{args} enable #{Shellwords.escape(new_resource.service_name)}", **options)
|
147
153
|
end
|
148
154
|
|
149
155
|
def disable_service
|
156
|
+
if current_resource.masked || current_resource.indirect
|
157
|
+
logger.trace("#{new_resource} cannot be disabled: it is masked or indirect")
|
158
|
+
return
|
159
|
+
end
|
150
160
|
options, args = get_systemctl_options_args
|
151
161
|
shell_out!("#{systemctl_path} #{args} disable #{Shellwords.escape(new_resource.service_name)}", **options)
|
152
162
|
end
|
@@ -171,6 +181,12 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
|
|
171
181
|
shell_out("#{systemctl_path} #{args} is-enabled #{Shellwords.escape(new_resource.service_name)} --quiet", **options).exitstatus == 0
|
172
182
|
end
|
173
183
|
|
184
|
+
def is_indirect?
|
185
|
+
options, args = get_systemctl_options_args
|
186
|
+
s = shell_out("#{systemctl_path} #{args} is-enabled #{Shellwords.escape(new_resource.service_name)}", **options)
|
187
|
+
s.stdout.include?("indirect")
|
188
|
+
end
|
189
|
+
|
174
190
|
def is_masked?
|
175
191
|
options, args = get_systemctl_options_args
|
176
192
|
s = shell_out("#{systemctl_path} #{args} is-enabled #{Shellwords.escape(new_resource.service_name)}", **options)
|
@@ -42,6 +42,7 @@ class Chef
|
|
42
42
|
current_resource.active(active?)
|
43
43
|
current_resource.masked(masked?)
|
44
44
|
current_resource.static(static?)
|
45
|
+
current_resource.indirect(indirect?)
|
45
46
|
current_resource.triggers_reload(new_resource.triggers_reload)
|
46
47
|
|
47
48
|
current_resource
|
@@ -90,10 +91,14 @@ class Chef
|
|
90
91
|
if current_resource.static
|
91
92
|
logger.trace("#{new_resource.unit_name} is a static unit, enabling is a NOP.")
|
92
93
|
end
|
94
|
+
if current_resource.indirect
|
95
|
+
logger.trace("#{new_resource.unit_name} is an indirect unit, enabling is a NOP.")
|
96
|
+
end
|
93
97
|
|
94
|
-
unless current_resource.enabled || current_resource.static
|
98
|
+
unless current_resource.enabled || current_resource.static || current_resource.indirect
|
95
99
|
converge_by("enabling unit: #{new_resource.unit_name}") do
|
96
100
|
systemctl_execute!(:enable, new_resource.unit_name)
|
101
|
+
logger.info("#{new_resource} enabled")
|
97
102
|
end
|
98
103
|
end
|
99
104
|
end
|
@@ -103,9 +108,14 @@ class Chef
|
|
103
108
|
logger.trace("#{new_resource.unit_name} is a static unit, disabling is a NOP.")
|
104
109
|
end
|
105
110
|
|
106
|
-
if current_resource.
|
111
|
+
if current_resource.indirect
|
112
|
+
logger.trace("#{new_resource.unit_name} is an indirect unit, enabling is a NOP.")
|
113
|
+
end
|
114
|
+
|
115
|
+
if current_resource.enabled && !current_resource.static && !current_resource.indirect
|
107
116
|
converge_by("disabling unit: #{new_resource.unit_name}") do
|
108
117
|
systemctl_execute!(:disable, new_resource.unit_name)
|
118
|
+
logger.info("#{new_resource} disabled")
|
109
119
|
end
|
110
120
|
end
|
111
121
|
end
|
@@ -113,6 +123,7 @@ class Chef
|
|
113
123
|
def action_reenable
|
114
124
|
converge_by("reenabling unit: #{new_resource.unit_name}") do
|
115
125
|
systemctl_execute!(:reenable, new_resource.unit_name)
|
126
|
+
logger.info("#{new_resource} reenabled")
|
116
127
|
end
|
117
128
|
end
|
118
129
|
|
@@ -120,6 +131,7 @@ class Chef
|
|
120
131
|
unless current_resource.masked
|
121
132
|
converge_by("masking unit: #{new_resource.unit_name}") do
|
122
133
|
systemctl_execute!(:mask, new_resource.unit_name)
|
134
|
+
logger.info("#{new_resource} masked")
|
123
135
|
end
|
124
136
|
end
|
125
137
|
end
|
@@ -128,6 +140,7 @@ class Chef
|
|
128
140
|
if current_resource.masked
|
129
141
|
converge_by("unmasking unit: #{new_resource.unit_name}") do
|
130
142
|
systemctl_execute!(:unmask, new_resource.unit_name)
|
143
|
+
logger.info("#{new_resource} unmasked")
|
131
144
|
end
|
132
145
|
end
|
133
146
|
end
|
@@ -136,6 +149,7 @@ class Chef
|
|
136
149
|
unless current_resource.active
|
137
150
|
converge_by("starting unit: #{new_resource.unit_name}") do
|
138
151
|
systemctl_execute!(:start, new_resource.unit_name, default_env: false)
|
152
|
+
logger.info("#{new_resource} started")
|
139
153
|
end
|
140
154
|
end
|
141
155
|
end
|
@@ -144,6 +158,7 @@ class Chef
|
|
144
158
|
if current_resource.active
|
145
159
|
converge_by("stopping unit: #{new_resource.unit_name}") do
|
146
160
|
systemctl_execute!(:stop, new_resource.unit_name, default_env: false)
|
161
|
+
logger.info("#{new_resource} stopped")
|
147
162
|
end
|
148
163
|
end
|
149
164
|
end
|
@@ -151,6 +166,7 @@ class Chef
|
|
151
166
|
def action_restart
|
152
167
|
converge_by("restarting unit: #{new_resource.unit_name}") do
|
153
168
|
systemctl_execute!(:restart, new_resource.unit_name, default_env: false)
|
169
|
+
logger.info("#{new_resource} restarted")
|
154
170
|
end
|
155
171
|
end
|
156
172
|
|
@@ -158,6 +174,7 @@ class Chef
|
|
158
174
|
if current_resource.active
|
159
175
|
converge_by("reloading unit: #{new_resource.unit_name}") do
|
160
176
|
systemctl_execute!(:reload, new_resource.unit_name, default_env: false)
|
177
|
+
logger.info("#{new_resource} reloaded")
|
161
178
|
end
|
162
179
|
else
|
163
180
|
logger.trace("#{new_resource.unit_name} is not active, skipping reload.")
|
@@ -167,18 +184,21 @@ class Chef
|
|
167
184
|
def action_try_restart
|
168
185
|
converge_by("try-restarting unit: #{new_resource.unit_name}") do
|
169
186
|
systemctl_execute!("try-restart", new_resource.unit_name, default_env: false)
|
187
|
+
logger.info("#{new_resource} try-restarted")
|
170
188
|
end
|
171
189
|
end
|
172
190
|
|
173
191
|
def action_reload_or_restart
|
174
192
|
converge_by("reload-or-restarting unit: #{new_resource.unit_name}") do
|
175
193
|
systemctl_execute!("reload-or-restart", new_resource.unit_name, default_env: false)
|
194
|
+
logger.info("#{new_resource} reload-or-restarted")
|
176
195
|
end
|
177
196
|
end
|
178
197
|
|
179
198
|
def action_reload_or_try_restart
|
180
199
|
converge_by("reload-or-try-restarting unit: #{new_resource.unit_name}") do
|
181
200
|
systemctl_execute!("reload-or-try-restart", new_resource.unit_name, default_env: false)
|
201
|
+
logger.info("#{new_resource} reload-or-try-restarted")
|
182
202
|
end
|
183
203
|
end
|
184
204
|
|
@@ -198,6 +218,10 @@ class Chef
|
|
198
218
|
systemctl_execute("is-enabled", new_resource.unit_name).stdout.include?("static")
|
199
219
|
end
|
200
220
|
|
221
|
+
def indirect?
|
222
|
+
systemctl_execute("is-enabled", new_resource.unit_name).stdout.include?("indirect")
|
223
|
+
end
|
224
|
+
|
201
225
|
private
|
202
226
|
|
203
227
|
def unit_path
|
@@ -159,6 +159,15 @@ class Chef
|
|
159
159
|
)
|
160
160
|
end
|
161
161
|
|
162
|
+
# if the service is indirect or not
|
163
|
+
def indirect(arg = nil)
|
164
|
+
set_or_return(
|
165
|
+
:indirect,
|
166
|
+
arg,
|
167
|
+
kind_of: [ TrueClass, FalseClass ]
|
168
|
+
)
|
169
|
+
end
|
170
|
+
|
162
171
|
def options(arg = nil)
|
163
172
|
set_or_return(
|
164
173
|
:options,
|
@@ -42,6 +42,7 @@ class Chef
|
|
42
42
|
property :active, [TrueClass, FalseClass], skip_docs: true
|
43
43
|
property :masked, [TrueClass, FalseClass], skip_docs: true
|
44
44
|
property :static, [TrueClass, FalseClass], skip_docs: true
|
45
|
+
property :indirect, [TrueClass, FalseClass], skip_docs: true
|
45
46
|
|
46
47
|
# User-provided properties
|
47
48
|
property :user, String, desired_state: false,
|
data/lib/chef/version.rb
CHANGED
@@ -110,6 +110,13 @@ describe "knife config get", :workstation do
|
|
110
110
|
it { is_expected.to match(/^node_name:\s+one$/) }
|
111
111
|
end
|
112
112
|
|
113
|
+
context "with a config dot d files" do
|
114
|
+
before { file(".chef/config.d/abc.rb", "node_name 'one'\n") }
|
115
|
+
|
116
|
+
it { is_expected.to match(%r{^Loading from .d/ configuration file .*/#{File.basename(path_to("."))}/.chef/config.d/abc.rb$}) }
|
117
|
+
it { is_expected.to match(/^node_name:\s+one$/) }
|
118
|
+
end
|
119
|
+
|
113
120
|
context "with a credentials file and CHEF_HOME" do
|
114
121
|
before do
|
115
122
|
file(".chef/credentials", "[default]\nclient_name = \"three\"\n")
|
@@ -36,11 +36,11 @@ describe Chef::Provider::Service::Systemd do
|
|
36
36
|
let(:provider) { Chef::Provider::Service::Systemd.new(new_resource, run_context) }
|
37
37
|
|
38
38
|
let(:shell_out_success) do
|
39
|
-
double("shell_out", exitstatus: 0, error?: false)
|
39
|
+
double("shell_out", exitstatus: 0, error?: false, stdout: "")
|
40
40
|
end
|
41
41
|
|
42
42
|
let(:shell_out_failure) do
|
43
|
-
double("shell_out", exitstatus: 1, error?: true)
|
43
|
+
double("shell_out", exitstatus: 1, error?: true, stdout: "")
|
44
44
|
end
|
45
45
|
|
46
46
|
let(:current_resource) { Chef::Resource::Service.new(service_name) }
|
@@ -56,6 +56,7 @@ describe Chef::Provider::Service::Systemd do
|
|
56
56
|
allow(provider).to receive(:is_active?).and_return(false)
|
57
57
|
allow(provider).to receive(:is_enabled?).and_return(false)
|
58
58
|
allow(provider).to receive(:is_masked?).and_return(false)
|
59
|
+
allow(provider).to receive(:is_indirect?).and_return(false)
|
59
60
|
end
|
60
61
|
|
61
62
|
it "should create a current resource with the name of the new resource" do
|
@@ -359,6 +360,29 @@ describe Chef::Provider::Service::Systemd do
|
|
359
360
|
expect(provider.is_masked?).to be false
|
360
361
|
end
|
361
362
|
end
|
363
|
+
|
364
|
+
describe "is_indirect?" do
|
365
|
+
before(:each) do
|
366
|
+
provider.current_resource = current_resource
|
367
|
+
current_resource.service_name(service_name)
|
368
|
+
allow(provider).to receive(:which).with("systemctl").and_return(systemctl_path.to_s)
|
369
|
+
end
|
370
|
+
|
371
|
+
it "should return true if '#{systemctl_path} --system is-enabled service_name' returns 'indirect'" do
|
372
|
+
expect(provider).to receive(:shell_out).with("#{systemctl_path} --system is-enabled #{service_name_escaped}", {}).and_return(double(stdout: "indirect", exitstatus: shell_out_success))
|
373
|
+
expect(provider.is_indirect?).to be true
|
374
|
+
end
|
375
|
+
|
376
|
+
it "should return false if '#{systemctl_path} --system is-enabled service_name' returns 0 and outputs something other than 'indirect'" do
|
377
|
+
expect(provider).to receive(:shell_out).with("#{systemctl_path} --system is-enabled #{service_name_escaped}", {}).and_return(double(stdout: "enabled", exitstatus: shell_out_success))
|
378
|
+
expect(provider.is_indirect?).to be false
|
379
|
+
end
|
380
|
+
|
381
|
+
it "should return false if '#{systemctl_path} --system is-enabled service_name' returns anything except 0 and outputs somethign other than 'indirect''" do
|
382
|
+
expect(provider).to receive(:shell_out).with("#{systemctl_path} --system is-enabled #{service_name_escaped}", {}).and_return(double(stdout: "enabled", exitstatus: shell_out_failure))
|
383
|
+
expect(provider.is_indirect?).to be false
|
384
|
+
end
|
385
|
+
end
|
362
386
|
end
|
363
387
|
end
|
364
388
|
end
|
@@ -65,11 +65,19 @@ describe Chef::Provider::SystemdUnit do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
let(:shell_out_masked) do
|
68
|
-
double("shell_out",
|
68
|
+
double("shell_out", exitstatus: 0, error?: false, stdout: "masked")
|
69
69
|
end
|
70
70
|
|
71
71
|
let(:shell_out_static) do
|
72
|
-
double("shell_out",
|
72
|
+
double("shell_out", exitstatus: 0, error?: false, stdout: "static")
|
73
|
+
end
|
74
|
+
|
75
|
+
let(:shell_out_disabled) do
|
76
|
+
double("shell_out", exitstatus: 1, error?: true, stdout: "disabled")
|
77
|
+
end
|
78
|
+
|
79
|
+
let(:shell_out_indirect) do
|
80
|
+
double("shell_out", exitstatus: 0, error?: true, stdout: "indirect")
|
73
81
|
end
|
74
82
|
|
75
83
|
before(:each) do
|
@@ -858,8 +866,8 @@ describe Chef::Provider::SystemdUnit do
|
|
858
866
|
it "returns false when unit is not enabled" do
|
859
867
|
current_resource.user(user_name)
|
860
868
|
expect(provider).to receive(:shell_out_compacted)
|
861
|
-
|
862
|
-
|
869
|
+
.with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts)
|
870
|
+
.and_return(shell_out_disabled)
|
863
871
|
expect(provider.enabled?).to be false
|
864
872
|
end
|
865
873
|
end
|
@@ -874,8 +882,8 @@ describe Chef::Provider::SystemdUnit do
|
|
874
882
|
|
875
883
|
it "returns false when unit is not enabled" do
|
876
884
|
expect(provider).to receive(:shell_out_compacted)
|
877
|
-
|
878
|
-
|
885
|
+
.with(systemctl_path, "--system", "is-enabled", unit_name)
|
886
|
+
.and_return(shell_out_disabled)
|
879
887
|
expect(provider.enabled?).to be false
|
880
888
|
end
|
881
889
|
end
|
@@ -962,6 +970,47 @@ describe Chef::Provider::SystemdUnit do
|
|
962
970
|
end
|
963
971
|
end
|
964
972
|
end
|
973
|
+
|
974
|
+
describe "#indirect?" do
|
975
|
+
before(:each) do
|
976
|
+
provider.current_resource = current_resource
|
977
|
+
allow(provider).to receive(:which).with("systemctl").and_return(systemctl_path.to_s)
|
978
|
+
end
|
979
|
+
|
980
|
+
context "when a user is specified" do
|
981
|
+
it "returns true when the unit is indirect" do
|
982
|
+
current_resource.user(user_name)
|
983
|
+
expect(provider).to receive(:shell_out_compacted)
|
984
|
+
.with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts)
|
985
|
+
.and_return(shell_out_indirect)
|
986
|
+
expect(provider.indirect?).to be true
|
987
|
+
end
|
988
|
+
|
989
|
+
it "returns false when the unit is not indirect" do
|
990
|
+
current_resource.user(user_name)
|
991
|
+
expect(provider).to receive(:shell_out_compacted)
|
992
|
+
.with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts)
|
993
|
+
.and_return(shell_out_static)
|
994
|
+
expect(provider.indirect?).to be false
|
995
|
+
end
|
996
|
+
end
|
997
|
+
|
998
|
+
context "when no user is specified" do
|
999
|
+
it "returns true when the unit is indirect" do
|
1000
|
+
expect(provider).to receive(:shell_out_compacted)
|
1001
|
+
.with(systemctl_path, "--system", "is-enabled", unit_name)
|
1002
|
+
.and_return(shell_out_indirect)
|
1003
|
+
expect(provider.indirect?).to be true
|
1004
|
+
end
|
1005
|
+
|
1006
|
+
it "returns false when the unit is not indirect" do
|
1007
|
+
expect(provider).to receive(:shell_out_compacted)
|
1008
|
+
.with(systemctl_path, "--system", "is-enabled", unit_name)
|
1009
|
+
.and_return(shell_out_static)
|
1010
|
+
expect(provider.indirect?).to be false
|
1011
|
+
end
|
1012
|
+
end
|
1013
|
+
end
|
965
1014
|
end
|
966
1015
|
end
|
967
1016
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 14.14.
|
4
|
+
version: 14.14.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef-config
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 14.14.
|
19
|
+
version: 14.14.29
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 14.14.
|
26
|
+
version: 14.14.29
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mixlib-cli
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|