From 3ddde7a60ae1fb820ec2ea7b745e35ed27395677 Mon Sep 17 00:00:00 2001 From: Yves Siegrist Date: Sun, 17 Mar 2024 21:37:38 +0100 Subject: [PATCH] Test against older versions of Splunk Also include basic testing for old versions: - 7.4.2.4 (EOL) - 8.2.9 (EOL) - 9.0.0 --- spec/acceptance/splunk_enterprise_spec.rb | 48 ++++++++++++++++++++- spec/acceptance/splunk_forwarder_spec.rb | 51 +++++++++++++++++++---- spec/spec_helper_acceptance.rb | 5 +++ 3 files changed, 96 insertions(+), 8 deletions(-) diff --git a/spec/acceptance/splunk_enterprise_spec.rb b/spec/acceptance/splunk_enterprise_spec.rb index 69713f8d..be0cbfa6 100644 --- a/spec/acceptance/splunk_enterprise_spec.rb +++ b/spec/acceptance/splunk_enterprise_spec.rb @@ -10,6 +10,51 @@ 'splunk' end + OLD_SPLUNK_VERSIONS.each do |version, build| + context "Splunk version #{version}" do + after(:all) do + pp = <<-EOS + service { '#{service_name}': ensure => stopped } + package { 'splunk': ensure => purged } + file { '/opt/splunk': ensure => absent, force => true, require => Package['splunk'] } + file { '/etc/init.d/splunk': ensure => absent, require => Package['splunk'] } + file { '/etc/systemd/system/Splunkd.service': ensure => absent, require => Package['splunk'] } + EOS + apply_manifest(pp, catch_failures: true) + end + + it 'works idempotently with no errors' do + pp = <<-EOS + class { 'splunk::params': version => '#{version}', build => '#{build}' } + class { 'splunk::enterprise': } + + # See https://community.splunk.com/t5/Installation/Why-am-I-getting-an-error-to-start-a-fresh-Splunk-instance-in-my/m-p/336938 + file_line { 'file_locking': + path => '/opt/splunk/etc/splunk-launch.conf', + line => 'OPTIMISTIC_ABOUT_FILE_LOCKING=1', + before => Exec['enable_splunk'], + require => Package['splunk'], + } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + # give splunk some time to start + sleep(10) + end + + describe package('splunk') do + it { is_expected.to be_installed } + end + + describe service(service_name) do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end + end + end + context 'default parameters' do # Using puppet_apply as a helper it 'works idempotently with no errors' do @@ -20,7 +65,8 @@ class { 'splunk::enterprise': } file_line { 'file_locking': path => '/opt/splunk/etc/splunk-launch.conf', line => 'OPTIMISTIC_ABOUT_FILE_LOCKING=1', - require => Class['splunk::enterprise'], + before => Exec['enable_splunk'], + require => Package['splunk'], } EOS diff --git a/spec/acceptance/splunk_forwarder_spec.rb b/spec/acceptance/splunk_forwarder_spec.rb index feff4e47..6a539b46 100644 --- a/spec/acceptance/splunk_forwarder_spec.rb +++ b/spec/acceptance/splunk_forwarder_spec.rb @@ -3,6 +3,50 @@ require 'spec_helper_acceptance' describe 'splunk::forwarder class' do + init = shell('/bin/readlink /sbin/init', acceptable_exit_codes: [0, 1]).stdout + service_name = if init.include? 'systemd' + 'SplunkForwarder' + else + 'splunk' + end + + OLD_SPLUNK_VERSIONS.each do |version, build| + context "Splunk forwarder version #{version}" do + after(:all) do + pp = <<-EOS + service { '#{service_name}': ensure => stopped } + package { 'splunkforwarder': ensure => purged } + file { '/opt/splunkforwarder': ensure => absent, force => true, require => Package['splunkforwarder'] } + file { '/opt/splunk': ensure => absent, force => true, require => Package['splunkforwarder'] } + file { '/etc/systemd/system/SplunkForwarder.service': ensure => absent, require => Package['splunkforwarder'] } + EOS + apply_manifest(pp, catch_failures: true) + end + + it 'works idempotently with no errors' do + pp = <<-EOS + class { 'splunk::params': version => '#{version}', build => '#{build}' } + class { 'splunk::forwarder': + splunkd_port => 8090, + } + 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_enabled } + it { is_expected.to be_running } + end + end + end + context 'default parameters' do # Using puppet_apply as a helper it 'works idempotently with no errors' do @@ -32,13 +76,6 @@ class { 'splunk::forwarder': it { is_expected.to be_installed } end - init = shell('/bin/readlink /sbin/init', acceptable_exit_codes: [0, 1]).stdout - service_name = if init.include? 'systemd' - 'SplunkForwarder' - else - 'splunk' - end - describe service(service_name) do it { is_expected.to be_enabled } it { is_expected.to be_running } diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 707feaae..a2efa3aa 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -3,6 +3,11 @@ require 'voxpupuli/acceptance/spec_helper_acceptance' require 'splunk_data' +OLD_SPLUNK_VERSIONS = [ + ['7.2.4.2', 'fb30470262e3'], + ['9.0.0', '6818ac46f2ec'], +].freeze + configure_beaker do |host| # Need to stage the Splunk/Splunkforwarder packages here.