From 1b8737d5a4f6f79ad28d38b65245b825e94a7006 Mon Sep 17 00:00:00 2001 From: Scott Garman Date: Fri, 30 Jan 2015 14:17:27 -0800 Subject: [PATCH] (PUP-3927) Ensure Fedora uses the systemd service provider Recent changes to the redhat (chkconfig) service provider requires features that the chkconfig shim doesn't support (specifically, --add). Besides, the systemd provider should be the default for Fedora anyway. --- ...3927_redhat_systemd_vs_service_provider.rb | 46 +++++++++++++++++++ lib/puppet/provider/service/systemd.rb | 1 + spec/unit/provider/service/systemd_spec.rb | 20 ++++++-- 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 acceptance/tests/resource/service/ticket_3927_redhat_systemd_vs_service_provider.rb diff --git a/acceptance/tests/resource/service/ticket_3927_redhat_systemd_vs_service_provider.rb b/acceptance/tests/resource/service/ticket_3927_redhat_systemd_vs_service_provider.rb new file mode 100644 index 00000000000..eb5688241a1 --- /dev/null +++ b/acceptance/tests/resource/service/ticket_3927_redhat_systemd_vs_service_provider.rb @@ -0,0 +1,46 @@ +test_name 'RedHat Service vs. Systemd Provider Validation' + +# A simple acceptance test to ensure basic usage of the service +# provider works for a mix of sysV and systemd RedHat Linux platforms +confine :to, :platform => /el|centos|fedora/ + +manifest_install_httpd = %Q{ + package { 'httpd': + ensure => present, + } +} + +manifest_httpd_enabled = %Q{ + service { 'httpd': + enable => true, + } +} + +manifest_httpd_disabled = %Q{ + service { 'httpd': + enable => false, + } +} + +agents.each do |agent| + distro = on(agent, facter('operatingsystem')).stdout.chomp + if distro == 'fedora' + majrelease = on(agent, facter('operatingsystemmajrelease')).stdout.chomp.to_i + if majrelease < 17 + skip_test "Test not applicable to Fedora #{majrelease}" + elsif majrelease > 21 + # This is a reminder so we update the provider's defaultfor when new + # versions of Fedora are released (then update this test) + fail_test "Provider needs manual update to support Fedora #{majrelease}" + end + end + + step "installing httpd" + apply_manifest_on(agent, manifest_install_httpd, :catch_failures => true) + + step "enabling httpd" + apply_manifest_on(agent, manifest_httpd_enabled, :catch_failures => true) + + step "disabling httpd" + apply_manifest_on(agent, manifest_httpd_disabled, :catch_failures => true) +end diff --git a/lib/puppet/provider/service/systemd.rb b/lib/puppet/provider/service/systemd.rb index eb6df2927e7..94443e45b3a 100644 --- a/lib/puppet/provider/service/systemd.rb +++ b/lib/puppet/provider/service/systemd.rb @@ -7,6 +7,7 @@ defaultfor :osfamily => [:archlinux] defaultfor :osfamily => :redhat, :operatingsystemmajrelease => "7" + defaultfor :osfamily => :redhat, :operatingsystem => :fedora, :operatingsystemmajrelease => ["17", "18", "19", "20", "21"] def self.instances i = [] diff --git a/spec/unit/provider/service/systemd_spec.rb b/spec/unit/provider/service/systemd_spec.rb index 54c95da9614..2697b9c3042 100755 --- a/spec/unit/provider/service/systemd_spec.rb +++ b/spec/unit/provider/service/systemd_spec.rb @@ -30,10 +30,22 @@ described_class.default?.should be_true end - it "should not be the default provider on rhel6" do - Facter.expects(:value).with(:osfamily).at_least_once.returns(:redhat) - Facter.expects(:value).with(:operatingsystemmajrelease).returns("6") - described_class.default?.should_not be_true + [ 4, 5, 6 ].each do |ver| + it "should not be the default provider on rhel#{ver}" do + Facter.expects(:value).with(:osfamily).at_least_once.returns(:redhat) + Facter.expects(:value).with(:operatingsystem).returns(:redhat) + Facter.expects(:value).with(:operatingsystemmajrelease).at_least_once.returns("#{ver}") + described_class.default?.should_not be_true + end + end + + [ 17, 18, 19, 20, 21 ].each do |ver| + it "should be the default provider on fedora#{ver}" do + Facter.expects(:value).with(:osfamily).at_least_once.returns(:redhat) + Facter.expects(:value).with(:operatingsystem).at_least_once.returns(:fedora) + Facter.expects(:value).with(:operatingsystemmajrelease).at_least_once.returns("#{ver}") + described_class.default?.should be_true + end end [:enabled?, :enable, :disable, :start, :stop, :status, :restart].each do |method|