Skip to content

Commit

Permalink
Include settings header via concat
Browse files Browse the repository at this point in the history
Rather than including this directly via ERB (which raises a deprecation
warning), this uses more native methods.
  • Loading branch information
ekohl committed Nov 14, 2023
1 parent 56a6e3a commit 9853af7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
5 changes: 5 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
}

foreman::settings_fragment { 'header.yaml':
content => template('foreman/_header.erb'),
order => '00',
}

foreman::settings_fragment { 'base.yaml':
content => template('foreman/settings.yaml.erb'),
order => '01',
}
Expand Down
28 changes: 15 additions & 13 deletions spec/classes/foreman_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
end

it 'should set up the config' do
should contain_concat__fragment('foreman_settings+01-header.yaml')
should contain_concat__fragment('foreman_settings+00-header.yaml').with_content(/^## Module:\s+'foreman'$/)

should contain_concat__fragment('foreman_settings+01-base.yaml')
.with_content(/^:unattended:\s*true$/)
.without_content(/^:unattended_url:/)
.with_content(/^:require_ssl:\s*true$/)
Expand Down Expand Up @@ -263,15 +265,15 @@
end

it 'should configure certificates in settings.yaml' do
is_expected.to contain_concat__fragment('foreman_settings+01-header.yaml')
is_expected.to contain_concat__fragment('foreman_settings+01-base.yaml')
.with_content(%r{^:sendmail_location: "/usr/bin/mysendmail"$})
.with_content(%r{^:sendmail_arguments: "--myargument"$})
.with_content(%r{^:websockets_ssl_key: /etc/ssl/private/snakeoil-ws\.pem$})
.with_content(%r{^:websockets_ssl_cert: /etc/ssl/certs/snakeoil-ws\.pem$})
end

it 'should configure ct and fcct commands in settings.yaml' do
is_expected.to contain_concat__fragment('foreman_settings+01-header.yaml')
is_expected.to contain_concat__fragment('foreman_settings+01-base.yaml')
.with_content(%r{^:ct_location: "/usr/bin/myct"$})
.with_content(%r{^:fcct_location: "/usr/bin/myfcct"$})
end
Expand All @@ -282,7 +284,7 @@
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('foreman-journald') }
it 'should configure logging in settings.yaml' do
verify_concat_fragment_contents(catalogue, 'foreman_settings+01-header.yaml', [
verify_concat_fragment_contents(catalogue, 'foreman_settings+01-base.yaml', [
':logging:',
' :level: info',
' :production:',
Expand All @@ -305,7 +307,7 @@
end

it 'should have changed parameters' do
should contain_concat__fragment('foreman_settings+01-header.yaml')
should contain_concat__fragment('foreman_settings+01-base.yaml')
.with_content(/^:unattended:\s*false$/)
.with_content(/^:require_ssl:\s*false$/)
.with_content(/^:oauth_active:\s*false$/)
Expand All @@ -318,31 +320,31 @@
describe 'with unattended_url' do
let(:params) { super().merge(unattended_url: 'http://example.com') }
it {
should contain_concat__fragment('foreman_settings+01-header.yaml')
should contain_concat__fragment('foreman_settings+01-base.yaml')
.with_content(%r{^:unattended_url:\s*http://example.com$})
}
end

describe 'with loggers' do
let(:params) { super().merge(loggers: { ldap: true }) }
it 'should set loggers config' do
should contain_concat__fragment('foreman_settings+01-header.yaml')
should contain_concat__fragment('foreman_settings+01-base.yaml')
.with_content(/^:loggers:\n\s+:ldap:\n\s+:enabled:\s*true$/)
end
end

describe 'with rails_cache_store file' do
let(:params) { super().merge(rails_cache_store: { type: "file" }) }
it 'should set rails_cache_store config' do
should contain_concat__fragment('foreman_settings+01-header.yaml')
should contain_concat__fragment('foreman_settings+01-base.yaml')
.with_content(/^:rails_cache_store:\n\s+:type:\s*file$/)
end
end

describe 'with rails_cache_store redis' do
let(:params) { super().merge(rails_cache_store: { type: "redis" }) }
it 'should set rails_cache_store config' do
should contain_concat__fragment('foreman_settings+01-header.yaml')
should contain_concat__fragment('foreman_settings+01-base.yaml')
.with_content(%r{^:rails_cache_store:\n\s+:type:\s*redis\n\s+:urls:\n\s*- redis://localhost:6379/4\n\s+:options:\n\s+:compress:\s*true\n\s+:namespace:\s*foreman$})
end
it { is_expected.to contain_package('foreman-redis') }
Expand All @@ -357,7 +359,7 @@
describe 'with rails_cache_store redis with explicit URL' do
let(:params) { super().merge(rails_cache_store: { type: "redis", urls: [ "redis.example.com/0" ]}) }
it 'should set rails_cache_store config' do
should contain_concat__fragment('foreman_settings+01-header.yaml')
should contain_concat__fragment('foreman_settings+01-base.yaml')
.with_content(/^:rails_cache_store:\n\s+:type:\s*redis\n\s+:urls:\n\s*- redis:\/\/redis.example.com\/0\n\s+:options:\n\s+:compress:\s*true\n\s+:namespace:\s*foreman$/)
end
it { is_expected.to contain_package('foreman-redis') }
Expand All @@ -372,7 +374,7 @@
describe 'with rails_cache_store redis with options' do
let(:params) { super().merge(rails_cache_store: { type: "redis", urls: [ "redis.example.com/0", "redis2.example.com/0" ], options: {compress: "false", namespace: "katello"}}) }
it 'should set rails_cache_store config' do
should contain_concat__fragment('foreman_settings+01-header.yaml')
should contain_concat__fragment('foreman_settings+01-base.yaml')
.with_content(/^:rails_cache_store:\n\s+:type:\s*redis\n\s+:urls:\n\s*- redis:\/\/redis.example.com\/0\n\s*- redis:\/\/redis2.example.com\/0\n\s+:options:\n\s+:compress:\s*false\n\s+:namespace:\s*katello$/)
end
it { is_expected.to contain_package('foreman-redis') }
Expand All @@ -381,15 +383,15 @@
describe 'with cors domains' do
let(:params) { super().merge(cors_domains: ['https://example.com']) }
it 'should set cors config' do
should contain_concat__fragment('foreman_settings+01-header.yaml').
should contain_concat__fragment('foreman_settings+01-base.yaml').
with_content(/^:cors_domains:\n\s+- 'https:\/\/example\.com'\n$/)
end
end

describe 'with trusted proxies' do
let(:params) { super().merge(trusted_proxies: ['10.0.0.0/8', '127.0.0.1/32', '::1']) }
it 'should set trusted proxies config' do
should contain_concat__fragment('foreman_settings+01-header.yaml').
should contain_concat__fragment('foreman_settings+01-base.yaml').
with_content(/^:trusted_proxies:\n\s+- '10\.0\.0\.0\/8'\n\s+- '127\.0\.0\.1\/32'\n\s+- '::1'\n$/)
end
end
Expand Down
4 changes: 0 additions & 4 deletions templates/settings.yaml.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<% @header = ''
ERB.new(File.read(File.expand_path("_header.erb",File.dirname(file))), nil, nil, "@header").result(binding) -%>
---
<%= @header -%>
:unattended: <%= scope.lookupvar("foreman::unattended") %>
<% unless [nil, :undefined, :undef].include?(scope.lookupvar("foreman::unattended_url")) -%>
:unattended_url: <%= scope.lookupvar("foreman::unattended_url") %>
Expand Down

0 comments on commit 9853af7

Please sign in to comment.