Skip to content

Commit

Permalink
fix systemd Wants (deric#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
deric committed Aug 31, 2017
1 parent 02c9f66 commit 37bded7
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 22 deletions.
124 changes: 103 additions & 21 deletions spec/classes/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:operatingsystem => 'Debian',
:osfamily => 'Debian',
:lsbdistcodename => 'wheezy',
:operatingsystemmajrelease => '6',
:operatingsystemmajrelease => '7',
:puppetversion => Puppet.version,
}
end
Expand All @@ -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
)
Expand Down Expand Up @@ -56,21 +56,21 @@
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',
})
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
)
Expand All @@ -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
Expand Down Expand Up @@ -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 [email protected]",
systemd_unit_want => "network-online.target [email protected]",
}'
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 [email protected]/)
end

it do
is_expected.to contain_service('zookeeper-server').with(
:ensure => 'running',
:enable => true
)
end
end
end

context 'Debian 7' do
Expand Down Expand Up @@ -173,19 +206,68 @@
end

it do
should contain_file(
is_expected.to contain_file(
'/etc/init.d/zookeeper'
).with({
'ensure' => 'present',
})
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 [email protected]",
systemd_unit_want => "network-online.target [email protected]",
}'
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 [email protected]/)
end

it do
is_expected.to contain_service('zookeeper').with(
:ensure => 'running',
:enable => true
)
end
end
end
2 changes: 1 addition & 1 deletion templates/zookeeper.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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") %>
Expand Down

0 comments on commit 37bded7

Please sign in to comment.