diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index dab2be1..27d6fc7 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -36,6 +36,7 @@ jobs: ruby-version: ${{ matrix.ruby }} - name: Bundle run: | + sudo apt-get install -qq augeas-tools augeas-lenses libaugeas-dev bundle config set system 'true' bundle update --jobs 4 --retry 3 - name: Unit tests diff --git a/Gemfile b/Gemfile index ada3955..21f21cd 100644 --- a/Gemfile +++ b/Gemfile @@ -49,3 +49,4 @@ if RUBY_VERSION >= '2.5' and RUBY_VERSION < '2.8' gem 'rspec-puppet', '~> 2.8.0' end +gem 'rspec-puppet-augeas' diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 66c5145..6bcd52c 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -6,6 +6,13 @@ it { should contain_class('splunk::installed') } it { should contain_package('splunk') } it { should_not contain_file('/opt/splunk/etc/.ui_login') } + describe_augeas '/opt/splunk/etc/system/local/server.conf pass4symmkey', target: 'opt/splunk/etc/system/local/server.conf' do + it { + should execute.with_change + aug_get('target[. = "general"]/pass4SymmKey').should.nil? + should execute.idempotently + } + end end context 'with admin hash ' do @@ -82,6 +89,14 @@ } it do should contain_package('splunkforwarder') + should contain_augeas('/opt/splunkforwarder/etc/system/local/server.conf pass4symmkey') + end + describe_augeas '/opt/splunkforwarder/etc/system/local/server.conf pass4symmkey', target: 'opt/splunkforwarder/etc/system/local/server.conf' do + it { + should execute.with_change + aug_get('target[. = "general"]/pass4SymmKey').should.nil? + should execute.idempotently + } end end @@ -647,12 +662,26 @@ :dontruncmds => true, } } + let(:facts) { + { + :fqdn => 'splunk-localhost.internal.corp.example' + } + } it { should contain_class('splunk::installed') } it { should contain_package('splunk') } it { should contain_file('/opt/splunk/etc/apps/puppet_search_shcluster_base/default/server.conf').with_content(/conf_deploy_fetch_url = https:\/\/splunk-shd.internal.corp.example:8089/) } it { should contain_file('/opt/splunk/etc/apps/puppet_search_shcluster_base/default/server.conf').with_content(/\[replication_port:/) } it { should contain_file('/opt/splunk/etc/apps/puppet_search_shcluster_base/default/server.conf').with_content(/shcluster_label = SHC/) } it { should contain_file('/opt/splunk/etc/apps/puppet_search_shcluster_pass4symmkey_base/default/server.conf').with_content(/pass4SymmKey = /) } + it { should contain_augeas('/opt/splunk/etc/system/local/server.conf/shclustering') } + describe_augeas '/opt/splunk/etc/system/local/server.conf/shclustering', target: 'opt/splunk/etc/system/local/server.conf' do + it { + aug_get('target[. = "shclustering"]').should.nil? + should execute.with_change + aug_get('target[. = "shclustering"]/mgmt_uri').should == 'https://splunk-localhost.internal.corp.example:8089' + should execute.idempotently + } + end end context 'with search head deployer role' do diff --git a/spec/fixtures/augeas/opt/splunk/etc/system/local/server.conf b/spec/fixtures/augeas/opt/splunk/etc/system/local/server.conf new file mode 100644 index 0000000..88993ad --- /dev/null +++ b/spec/fixtures/augeas/opt/splunk/etc/system/local/server.conf @@ -0,0 +1,4 @@ +[general] +pass4SymmKey = $7$aTVkS01HYVNJUk5wSnR5NKR+EdOfT4t84WSiXvPFHGHsfHtbgPIL3g== + +[replication_port://8079] diff --git a/spec/fixtures/augeas/opt/splunkforwarder b/spec/fixtures/augeas/opt/splunkforwarder new file mode 120000 index 0000000..508698a --- /dev/null +++ b/spec/fixtures/augeas/opt/splunkforwarder @@ -0,0 +1 @@ +splunk/ \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cffdb1b..bf93b6d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,10 @@ require 'rspec-puppet/spec_helper' +require 'rspec-puppet-augeas' fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) RSpec.configure do |c| + c.augeas_fixtures = File.join(fixture_path, 'augeas') c.module_path = File.join(fixture_path, 'modules') c.manifest_dir = File.join(fixture_path, 'manifests') c.environmentpath = File.join(Dir.pwd, 'spec')