Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #383: Add ensure and enable parameter for forwarder service #390

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,8 @@ The following parameters are available in the `splunk::forwarder` class:
* [`forwarder_homedir`](#-splunk--forwarder--forwarder_homedir)
* [`forwarder_confdir`](#-splunk--forwarder--forwarder_confdir)
* [`service_name`](#-splunk--forwarder--service_name)
* [`service_ensure`](#-splunk--forwarder--service_ensure)
* [`service_enable`](#-splunk--forwarder--service_enable)
* [`service_file`](#-splunk--forwarder--service_file)
* [`boot_start`](#-splunk--forwarder--boot_start)
* [`use_default_config`](#-splunk--forwarder--use_default_config)
Expand Down Expand Up @@ -1026,6 +1028,22 @@ The name of the Splunk Forwarder service.

Default value: `$splunk::params::forwarder_service`

##### <a name="-splunk--forwarder--service_ensure"></a>`service_ensure`

Data type: `String[1]`

Ensure passed to the splunk service resource.

Default value: `$splunk::params::forwarder_service_ensure`

##### <a name="-splunk--forwarder--service_enable"></a>`service_enable`

Data type: `String[1]`

Enable passed to the splunk service resource.

Default value: `$splunk::params::forwarder_service_enable`

##### <a name="-splunk--forwarder--service_file"></a>`service_file`

Data type: `Stdlib::Absolutepath`
Expand Down
8 changes: 8 additions & 0 deletions manifests/forwarder.pp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
# @param service_name
# The name of the Splunk Forwarder service.
#
# @param service_ensure
# Ensure passed to the splunk service resource.
#
# @param service_enable
# Enable passed to the splunk service resource.
#
# @param service_file
# The path to the Splunk Forwarder service file.
#
Expand Down Expand Up @@ -172,6 +178,8 @@
Stdlib::Absolutepath $forwarder_homedir = $splunk::params::forwarder_homedir,
Stdlib::Absolutepath $forwarder_confdir = $splunk::params::forwarder_confdir,
String[1] $service_name = $splunk::params::forwarder_service,
String[1] $service_ensure = $splunk::params::forwarder_service_ensure,
String[1] $service_enable = $splunk::params::forwarder_service_enable,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be a boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think only the ensure is a boolean i shall test this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Service enable property has different values on different OS'en possible values are true, false, manual, mask or delayed
So it can not be a boolean

Stdlib::Absolutepath $service_file = $splunk::params::forwarder_service_file,
Boolean $boot_start = $splunk::params::boot_start,
Boolean $use_default_config = true,
Expand Down
9 changes: 7 additions & 2 deletions manifests/forwarder/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
# sub-classes
#
class splunk::forwarder::service {
$provider = $facts['os']['family'] ? {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is that required? Did you run into any issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running de rspec test locally (on an ubuntu 22.04 bundle exec rake spec) the test on windows fails with the error Provider redhat must have features 'delayed_startable'
I have no idea why the provider redhat was used for the service resource in the rspec test for windows but this seems to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the code and on puppet7 with ruby 2.7 it fails
Error: splunk::forwarder supported operating systems on windows-2012-x86_64 is expected to compile into a catalogue without dependency cycles

Failure/Error: it { is_expected.to compile.with_all_deps }
error during compilation: Parameter enable failed on Service[SplunkForwarder]: Provider redhat must have features 'delayed_startable' to set 'enable' to 'delayed' (file: /home/runner/work/puppet-splunk/puppet-splunk/spec/fixtures/modules/splunk/manifests/forwarder/service.pp, line: 7)

Do you have an other suggestion to fix this or shall i put the selector back in the code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it by using $facts['service_provider'] as provider and add the fact to the rspec on windows

'windows' => 'windows',
default => undef,
}
service { $splunk::forwarder::service_name:
ensure => running,
enable => true,
ensure => $splunk::forwarder::service_ensure,
enable => $splunk::forwarder::service_enable,
hasstatus => true,
hasrestart => true,
provider => $provider,
}
}
8 changes: 8 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@
$enterprise_confdir = "${enterprise_homedir}/etc"
$forwarder_install_options = []
$enterprise_install_options = []
$forwarder_service_ensure = 'running'
$forwarder_service_enable = 'true'
# Systemd not supported until Splunk 7.2.2
if $facts['service_provider'] == 'systemd' and versioncmp($version, '7.2.2') >= 0 {
$enterprise_service = 'Splunkd'
Expand Down Expand Up @@ -198,6 +200,8 @@
$enterprise_confdir = "${enterprise_homedir}/etc"
$forwarder_install_options = []
$enterprise_install_options = []
$forwarder_service_ensure = 'running'
$forwarder_service_enable = 'true'
# Systemd not supported until Splunk 7.2.2
if $facts['service_provider'] == 'systemd' and versioncmp($version, '7.2.2') >= 0 {
$enterprise_service = 'Splunkd'
Expand Down Expand Up @@ -232,6 +236,8 @@
$enterprise_install_options = []
$enterprise_service = 'splunk'
$forwarder_service = 'splunk'
$forwarder_service_ensure = 'running'
$forwarder_service_enable = 'true'
$enterprise_service_file = '/etc/rc.d/splunk'
$forwarder_service_file = '/etc/rc.d/splunk'
$boot_start_args = ''
Expand All @@ -247,6 +253,8 @@
$forwarder_secret_file = "${forwarder_homedir}\\etc\\auth\\splunk.secret"
$enterprise_secret_file = "${enterprise_homedir}\\etc\\auth\\splunk.secret"
$forwarder_service = 'SplunkForwarder'
$forwarder_service_ensure = 'running'
$forwarder_service_enable = 'delayed'
$forwarder_service_file = "${forwarder_homedir}\\dummy" # Not used in Windows, but attribute must be defined with a valid path
$forwarder_confdir = "${forwarder_homedir}\\etc"
$enterprise_src_subdir = 'windows'
Expand Down
26 changes: 26 additions & 0 deletions spec/acceptance/splunk_forwarder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@
end
end

context 'stopped' do
# Using puppet_apply as a helper
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'splunk::params':
}
class { 'splunk::forwarder':
splunkd_port => 8090,
service_ensure => 'stopped',
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe package('splunkforwarder') do
it { is_expected.to be_installed }
end

describe service(service_name) do
it { is_expected.to be_stopped }

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - AlmaLinux 8

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - AlmaLinux 8

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - AlmaLinux 9

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - AlmaLinux 9

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Rocky 8

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Rocky 8

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Rocky 9

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Rocky 9

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - CentOS 9

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - CentOS 9

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Ubuntu 20.04

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Ubuntu 20.04

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Ubuntu 22.04

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`

Check failure on line 107 in spec/acceptance/splunk_forwarder_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Ubuntu 22.04

splunk::forwarder class stopped Service "SplunkForwarder" is expected to be stopped Failure/Error: it { is_expected.to be_stopped } expected Service "SplunkForwarder" to respond to `stopped?`
end
end

context 'purging' do
context 'purge_outputs => false' do
it 'works idempotently with no errors' do
Expand Down
24 changes: 24 additions & 0 deletions spec/classes/forwarder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/props.conf') }
it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/transforms.conf') }
it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/web.conf') }
it { is_expected.to contain_service('SplunkForwarder').with(ensure: 'running', enable: 'delayed', status: nil, restart: nil, start: nil, stop: nil) }
it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/server.conf') }
it { is_expected.not_to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/auth/splunk.secret') }
it { is_expected.not_to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/passwd') }
Expand Down Expand Up @@ -77,6 +78,29 @@
end
end

context 'when service_ensure = stopped' do
let(:params) { { 'service_ensure' => 'stopped' } }

case facts[:kernel]
when 'windows'
it { is_expected.to contain_service('SplunkForwarder').with(ensure: 'stopped', enable: 'delayed', status: nil, restart: nil, start: nil, stop: nil) }
when 'FreeBSD'
it { is_expected.to contain_service('splunk').with(ensure: 'stopped', enable: 'true', status: nil, restart: nil, start: nil, stop: nil) }
else
it { is_expected.to contain_service('SplunkForwarder').with(ensure: 'stopped', enable: 'true', status: nil, restart: nil, start: nil, stop: nil) }
end
end

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

if facts[:kernel] == 'FreeBSD'
it { is_expected.to contain_service('splunk').with(ensure: 'running', enable: false, status: nil, restart: nil, start: nil, stop: nil) }
else
it { is_expected.to contain_service('SplunkForwarder').with(ensure: 'running', enable: false, status: nil, restart: nil, start: nil, stop: nil) }
end
end

context 'with $boot_start = true (defaults)' do
if facts[:kernel] == 'Linux' || facts[:kernel] == 'SunOS'

Expand Down
Loading