Skip to content

Commit 807671f

Browse files
authored
Merge pull request #8584 from nmaludy/hotfix/systemd-static-mask
(PUP-11034) Allow systemd static services to be masked
2 parents 37aea06 + 3bf639d commit 807671f

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

lib/puppet/provider/service/systemd.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ def self.instances
4545
def enabled_insync?(current)
4646
case cached_enabled?[:output]
4747
when 'static'
48-
Puppet.debug("Unable to enable or disable static service #{@resource[:name]}")
49-
return true
48+
# masking static services is OK, but enabling/disabling them is not
49+
if @resource[:enable] == :mask
50+
current == @resource[:enable]
51+
else
52+
Puppet.debug("Unable to enable or disable static service #{@resource[:name]}")
53+
return true
54+
end
5055
when 'indirect'
5156
Puppet.debug("Service #{@resource[:name]} is in 'indirect' state and cannot be enabled/disabled")
5257
return true

spec/unit/provider/service/systemd_spec.rb

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -467,17 +467,39 @@
467467
context 'when service state is static' do
468468
let(:service_state) { 'static' }
469469

470-
it 'is always enabled_insync even if current value is the same as expected' do
471-
expect(provider).to be_enabled_insync(:false)
470+
context 'when enable is not mask' do
471+
it 'is always enabled_insync even if current value is the same as expected' do
472+
expect(provider).to be_enabled_insync(:false)
473+
end
474+
475+
it 'is always enabled_insync even if current value is not the same as expected' do
476+
expect(provider).to be_enabled_insync(:true)
477+
end
478+
479+
it 'logs a debug messsage' do
480+
expect(Puppet).to receive(:debug).with("Unable to enable or disable static service sshd.service")
481+
provider.enabled_insync?(:true)
482+
end
472483
end
473484

474-
it 'is always enabled_insync even if current value is not the same as expected' do
475-
expect(provider).to be_enabled_insync(:true)
476-
end
485+
context 'when enable is mask' do
486+
let(:provider) do
487+
provider_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service',
488+
:enable => 'mask'))
489+
end
477490

478-
it 'logs a debug messsage' do
479-
expect(Puppet).to receive(:debug).with("Unable to enable or disable static service sshd.service")
480-
provider.enabled_insync?(:true)
491+
it 'is enabled_insync if current value is the same as expected' do
492+
expect(provider).to be_enabled_insync(:mask)
493+
end
494+
495+
it 'is not enabled_insync if current value is not the same as expected' do
496+
expect(provider).not_to be_enabled_insync(:true)
497+
end
498+
499+
it 'logs no debug messsage' do
500+
expect(Puppet).not_to receive(:debug)
501+
provider.enabled_insync?(:true)
502+
end
481503
end
482504
end
483505

0 commit comments

Comments
 (0)