Skip to content

Commit

Permalink
add service resource management
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hoblitt committed Feb 3, 2014
1 parent 6112159 commit e8ea305
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 15 deletions.
12 changes: 12 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,25 @@
Port389::Instance<| |> ->
Anchor['port389::end']
}
# the global 'dirsrv' service is only managed for uninstall
# otherwise, each instance manages it's own 'sub' dirsrv service instance
'absent': {
Anchor['port389::begin'] ->
service { 'dirsrv':
ensure => 'stopped',
enable => false,
} ->
class { 'port389::install': ensure => $ensure } ->
Anchor['port389::end']
}
'purged': {
Anchor['port389::begin'] ->
service { 'dirsrv':
ensure => 'stopped',
enable => false,
hasstatus => true,
hasrestart => true,
} ->
class { 'port389::install': ensure => $ensure } ->
file { $setup_dir:
ensure => absent,
Expand Down
11 changes: 11 additions & 0 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
command => "setup-ds-admin.pl --file=${setup_inf_path} --silent",
unless => "/usr/bin/test -e /etc/dirsrv/slapd-${title}",
logoutput => true,
notify => Service[$title],
}

if $enable_ssl {
Expand All @@ -125,8 +126,18 @@
ssl_cert => $ssl_cert,
ssl_key => $ssl_key,
ssl_ca_certs => $ssl_ca_certs,
notify => Service[$title],
}
}

# XXX this is extremely RedHat specific
service { $title:
ensure => 'running',
control => 'dirsrv',
hasstatus => true,
hasrestart => true,
provider => 'redhat_instance',
}
}
default: {
warning("it is meaningless to declare Port389::Instance[${name}] while Class[port389]{ ensure => 'absent|purged' }")
Expand Down
44 changes: 29 additions & 15 deletions spec/classes/port389_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
:mode => '0700',
})
end
end
end # present

context 'latest' do
let(:params) {{ :ensure => 'latest' }}
Expand All @@ -83,31 +83,39 @@
:mode => '0700',
})
end
end
end # latest

context 'absent' do
let(:params) {{ :ensure => 'absent' }}

it { should_not contain_class('port389::tune') }
it do
# XXX implimentation specific
should contain_service('dirsrv').with({
:ensure => 'stopped',
:enable => false,
}).that_comes_before('Class[port389::install]')
end
redhat_packages.each do |pkg|
it { should contain_package(pkg).with_ensure('absent') }
end
it { should_not contain_file('/var/lib/dirsrv/setup') }
end
end # absent

context 'purged' do
let(:params) {{ :ensure => 'purged' }}

it { should_not contain_class('port389::tune') }
it do
# XXX implimentation specific
should contain_service('dirsrv').with({
:ensure => 'stopped',
:enable => false,
}).that_comes_before('Class[port389::install]')
end
redhat_packages.each do |pkg|
it { should contain_package(pkg).with_ensure('absent') }
end
it do
should contain_file('/var/lib/dirsrv/setup').with({
:ensure => 'absent',
:force => true,
})
end
[
'rm -f /etc/sysconfig/dirsrv*',
'rm -rf /etc/dirsrv/',
Expand All @@ -125,8 +133,14 @@
].each do |cmd|
it { should contain_exec(cmd) }
end

end
it do
# XXX implimentation specific
should contain_file('/var/lib/dirsrv/setup').with({
:ensure => 'absent',
:force => true,
}).that_requires('Class[port389::install]')
end
end # purged

context 'foo' do
let(:params) {{ :ensure => 'foo' }}
Expand All @@ -136,7 +150,7 @@
should compile
}.to raise_error(/"foo" does not match/)
end
end
end # foo
end # ensure =>

context 'enable_tuning =>' do
Expand All @@ -145,13 +159,13 @@

it { should contain_class('port389::tune') }
it_should_behave_like 'been_tuned'
end
end # true

context 'false' do
let(:params) {{ :enable_tuning => false }}

it { should_not contain_class('port389::tune') }
end
end # false

context '[]' do
let(:params) {{ :enable_tuning =>[] }}
Expand All @@ -161,7 +175,7 @@
should compile
}.to raise_error(/is not a boolean/)
end
end
end # []
end # enable_tuning =>
end # on osfamily RedHat

Expand Down
10 changes: 10 additions & 0 deletions spec/defines/port389_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@
:command => 'setup-ds-admin.pl --file=/var/lib/dirsrv/setup/setup_ldap1.inf --silent',
:unless => '/usr/bin/test -e /etc/dirsrv/slapd-ldap1',
:logoutput => true,
}).that_notifies('Service[ldap1]')
end

it do
should contain_service('ldap1').with({
:ensure => 'running',
:control => 'dirsrv',
:hasstatus => true,
:hasrestart => true,
:provider => 'redhat_instance',
})
end

Expand Down
6 changes: 6 additions & 0 deletions spec/defines/port389_instance_ssl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
:cert => '/tmp/globalsign_root.pem',
})
end

# XXX highly internal implimentation specific
it do
should contain_port389__instance__ssl('ldap1').
that_notifies('Service[ldap1]')
end
end # true

context 'false' do
Expand Down

0 comments on commit e8ea305

Please sign in to comment.