From 37bded7b92c4e1cce9244488b11f2605509c6ff6 Mon Sep 17 00:00:00 2001 From: Tomas Barton Date: Thu, 31 Aug 2017 08:45:58 +0200 Subject: [PATCH] fix systemd Wants (#103) --- spec/classes/service_spec.rb | 124 ++++++++++++++++++++++++++------ templates/zookeeper.service.erb | 2 +- 2 files changed, 104 insertions(+), 22 deletions(-) diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb index 1985bc5..47f11bf 100644 --- a/spec/classes/service_spec.rb +++ b/spec/classes/service_spec.rb @@ -6,7 +6,7 @@ :operatingsystem => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', - :operatingsystemmajrelease => '6', + :operatingsystemmajrelease => '7', :puppetversion => Puppet.version, } end @@ -18,9 +18,9 @@ }' end - it { should contain_package('zookeeperd') } + it { is_expected.to contain_package('zookeeperd') } it do - should contain_service('zookeeper').with( + is_expected.to contain_service('zookeeper').with( :ensure => 'running', :enable => true ) @@ -56,7 +56,7 @@ it { should contain_package('zookeeper') } it do - should contain_file( + is_expected.to contain_file( '/usr/lib/systemd/system/zookeeper-server.service' ).with({ 'ensure' => 'present', @@ -64,13 +64,13 @@ end it do - should contain_file( + is_expected.to contain_file( '/usr/lib/systemd/system/zookeeper-server.service' ).with_content(/zookeeper\.jar/) end it do - should contain_service('zookeeper-server').with( + is_expected.to contain_service('zookeeper-server').with( :ensure => 'running', :enable => true ) @@ -85,20 +85,20 @@ }' end - it do - is_expected.to contain_file( - '/etc/systemd/system/my-zookeeper.service' - ).with({ - 'ensure' => 'present', - }) - end + it do + is_expected.to contain_file( + '/etc/systemd/system/my-zookeeper.service' + ).with({ + 'ensure' => 'present', + }) + end - it do - is_expected.to contain_service('my-zookeeper').with( - :ensure => 'running', - :enable => true - ) - end + it do + is_expected.to contain_service('my-zookeeper').with( + :ensure => 'running', + :enable => true + ) + end end context 'install from archive' do @@ -144,6 +144,39 @@ }) end end + + context 'systemd dependencies' do + let :pre_condition do + 'class {"zookeeper": + service_provider => "systemd", + manage_service_file => true, + manage_service => true, + systemd_unit_after => "network-online.target openvpn-client@.service", + systemd_unit_want => "network-online.target openvpn-client@.service", + }' + end + + it do + is_expected.to contain_file( + '/etc/systemd/system/zookeeper-server.service' + ).with({ + 'ensure' => 'present', + }) + end + + it do + is_expected.to contain_file( + '/etc/systemd/system/zookeeper-server.service' + ).with_content(/Wants=network-online.target openvpn-client@.service/) + end + + it do + is_expected.to contain_service('zookeeper-server').with( + :ensure => 'running', + :enable => true + ) + end + end end context 'Debian 7' do @@ -173,7 +206,7 @@ end it do - should contain_file( + is_expected.to contain_file( '/etc/init.d/zookeeper' ).with({ 'ensure' => 'present', @@ -181,11 +214,60 @@ end it do - should contain_service('zookeeper').with( + is_expected.to contain_service('zookeeper').with( :ensure => 'running', :enable => true, :provider => 'init', ) end end + + context 'Debian 9' do + puppet = Puppet.version + let(:facts) do + { + :operatingsystem => 'Debian', + :osfamily => 'Debian', + :lsbdistcodename => 'stretch', + :operatingsystemmajrelease => '9', + :puppetversion => puppet, + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + :puppetversion => Puppet.version, + } + end + + let(:user) { 'zookeeper' } + let(:group) { 'zookeeper' } + + let :pre_condition do + 'class {"zookeeper": + service_provider => "systemd", + manage_service_file => true, + manage_service => true, + systemd_unit_after => "network-online.target openvpn-client@.service", + systemd_unit_want => "network-online.target openvpn-client@.service", + }' + end + + it do + is_expected.to contain_file( + '/etc/systemd/system/zookeeper.service' + ).with({ + 'ensure' => 'present', + }) + end + + it do + is_expected.to contain_file( + '/etc/systemd/system/zookeeper.service' + ).with_content(/Wants=network-online.target openvpn-client@.service/) + end + + it do + is_expected.to contain_service('zookeeper').with( + :ensure => 'running', + :enable => true + ) + end + end end diff --git a/templates/zookeeper.service.erb b/templates/zookeeper.service.erb index fe745a3..78e5fc5 100644 --- a/templates/zookeeper.service.erb +++ b/templates/zookeeper.service.erb @@ -4,7 +4,7 @@ [Unit] Description=Apache ZooKeeper <%if ! [nil, :undefined, :undef].include?(scope.lookupvar("zookeeper::systemd_unit_want")) -%> -Want=<%= scope.lookupvar("zookeeper::systemd_unit_want")%> +Wants=<%= scope.lookupvar("zookeeper::systemd_unit_want")%> <% end -%> <%if ! [nil, :undefined, :undef].include?(scope.lookupvar("zookeeper::systemd_unit_after")) -%> After=<%= scope.lookupvar("zookeeper::systemd_unit_after") %>