Skip to content

Commit

Permalink
Merge pull request #13 from gizmoguy/upstream
Browse files Browse the repository at this point in the history
Stop sorting config keys for newer ruby versions.
  • Loading branch information
edestecd committed Jan 28, 2016
2 parents 6d3b7c9 + 1d37788 commit 8539c01
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 9 deletions.
3 changes: 2 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$ensure = $sssd::ensure,
$config = $sssd::config,
$config_file = $sssd::config_file,
$config_template = $sssd::config_template,
$mkhomedir = $sssd::mkhomedir,
$enable_mkhomedir_flags = $sssd::enable_mkhomedir_flags,
$disable_mkhomedir_flags = $sssd::disable_mkhomedir_flags,
Expand All @@ -14,7 +15,7 @@
owner => 'root',
group => 'root',
mode => '0600',
content => template("${module_name}/sssd.conf.erb"),
content => template($config_template),
}

case $::osfamily {
Expand Down
4 changes: 3 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
$extra_packages = $sssd::params::extra_packages,
$extra_packages_ensure = $sssd::params::extra_packages_ensure,
$config_file = $sssd::params::config_file,
$config_template = $sssd::params::config_template,
$mkhomedir = $sssd::params::mkhomedir,
$manage_oddjobd = $sssd::params::manage_oddjobd,
$service_ensure = $sssd::params::service_ensure,
Expand All @@ -85,7 +86,8 @@

validate_string(
$sssd_package,
$sssd_service
$sssd_service,
$config_template
)

validate_array(
Expand Down
8 changes: 8 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
$enable_mkhomedir_flags = ['--enablesssd', '--enablesssdauth', '--enablemkhomedir']
$disable_mkhomedir_flags = ['--enablesssd', '--enablesssdauth', '--disablemkhomedir']

# Earlier versions of ruby didn't provide ordered hashs, so we need to sort
# the configuration ourselves to ensure a consistent config file.
if versioncmp($::rubyversion, '1.9.3') >= 0 {
$config_template = "${module_name}/sssd.conf.erb"
} else {
$config_template = "${module_name}/sssd.conf.sorted.erb"
}

case $::osfamily {

'RedHat': {
Expand Down
124 changes: 120 additions & 4 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
require 'spec_helper'
describe 'sssd' do
describe 'on RedHat 5.11' do
let(:facts) { { :osfamily => 'RedHat', :operatingsystemrelease => '5.7' } }
let(:facts) do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '5.7',
:rubyversion => '1.9.3'
}
end

context 'with defaults for all parameters' do
it { is_expected.to contain_class('sssd::install') }
it { is_expected.to contain_class('sssd::config') }
it { is_expected.to contain_class('sssd::service') }

it do
is_expected.to contain_file('sssd.conf') \
.with_ensure('present') \
.with_path('/etc/sssd/sssd.conf') \
.with_content(/^# Managed by Puppet.\n\n\[sssd\]/)
end

it { is_expected.to contain_package('authconfig').with_ensure('latest') }
it { is_expected.not_to contain_package('oddjob-mkhomedir') }
it { is_expected.not_to contain_service('oddjobd') }
Expand All @@ -20,15 +33,44 @@
let(:params) { { :service_ensure => 'stopped' } }
it { is_expected.to contain_service('sssd').with_ensure('stopped') }
end

context 'with ruby without ordered hashes' do
let(:facts) do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '5.7',
:rubyversion => '1.8.7'
}
end
it do
is_expected.to contain_file('sssd.conf') \
.with_ensure('present') \
.with_path('/etc/sssd/sssd.conf') \
.with_content(%r{^# Managed by Puppet.\n\n\[domain/ad.example.com\]})
end
end
end
describe 'on RedHat 6.6' do
let(:facts) { { :osfamily => 'RedHat', :operatingsystemrelease => '6.6' } }
let(:facts) do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '6.6',
:rubyversion => '1.9.3'
}
end

context 'with defaults for all parameters' do
it { is_expected.to contain_class('sssd::install') }
it { is_expected.to contain_class('sssd::config') }
it { is_expected.to contain_class('sssd::service') }

it do
is_expected.to contain_file('sssd.conf') \
.with_ensure('present') \
.with_path('/etc/sssd/sssd.conf') \
.with_content(/^# Managed by Puppet.\n\n\[sssd\]/)
end

it { is_expected.to contain_package('authconfig').with_ensure('present') }
it { is_expected.to contain_package('oddjob-mkhomedir') }
it { is_expected.to contain_service('oddjobd') }
Expand All @@ -43,15 +85,44 @@
it { is_expected.to contain_service('sssd').with_ensure('stopped') }
it { is_expected.to contain_service('oddjobd').with_ensure('stopped') }
end

context 'with ruby without ordered hashes' do
let(:facts) do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '6.6',
:rubyversion => '1.8.7'
}
end
it do
is_expected.to contain_file('sssd.conf') \
.with_ensure('present') \
.with_path('/etc/sssd/sssd.conf') \
.with_content(%r{^# Managed by Puppet.\n\n\[domain/ad.example.com\]})
end
end
end
describe 'on RedHat 7.1' do
let(:facts) { { :osfamily => 'RedHat', :operatingsystemrelease => '7.1' } }
let(:facts) do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '7.1',
:rubyversion => '1.9.3'
}
end

context 'with defaults for all parameters' do
it { is_expected.to contain_class('sssd::install') }
it { is_expected.to contain_class('sssd::config') }
it { is_expected.to contain_class('sssd::service') }

it do
is_expected.to contain_file('sssd.conf') \
.with_ensure('present') \
.with_path('/etc/sssd/sssd.conf') \
.with_content(/^# Managed by Puppet.\n\n\[sssd\]/)
end

it { is_expected.to contain_package('authconfig').with_ensure('present') }
it { is_expected.to contain_package('oddjob-mkhomedir') }
it { is_expected.to contain_service('oddjobd') }
Expand All @@ -66,15 +137,44 @@
it { is_expected.to contain_service('sssd').with_ensure('stopped') }
it { is_expected.to contain_service('oddjobd').with_ensure('stopped') }
end

context 'with ruby without ordered hashes' do
let(:facts) do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '7.1',
:rubyversion => '1.8.7'
}
end
it do
is_expected.to contain_file('sssd.conf') \
.with_ensure('present') \
.with_path('/etc/sssd/sssd.conf') \
.with_content(%r{^# Managed by Puppet.\n\n\[domain/ad.example.com\]})
end
end
end
describe 'on Debian 8.1' do
let(:facts) { { :osfamily => 'Debian', :operatingsystemrelease => '8.1' } }
let(:facts) do
{
:osfamily => 'Debian',
:operatingsystemrelease => '8.1',
:rubyversion => '1.9.3'
}
end

context 'with defaults for all parameters' do
it { is_expected.to contain_class('sssd::install') }
it { is_expected.to contain_class('sssd::config') }
it { is_expected.to contain_class('sssd::service') }

it do
is_expected.to contain_file('sssd.conf') \
.with_ensure('present') \
.with_path('/etc/sssd/sssd.conf') \
.with_content(/^# Managed by Puppet.\n\n\[sssd\]/)
end

it { is_expected.not_to contain_package('authconfig') }
it { is_expected.not_to contain_package('oddjob-mkhomedir') }
it { is_expected.to contain_package('libpam-runtime').with_ensure('present') }
Expand All @@ -87,5 +187,21 @@
let(:params) { { :service_ensure => 'stopped' } }
it { is_expected.to contain_service('sssd').with_ensure('stopped') }
end

context 'with ruby without ordered hashes' do
let(:facts) do
{
:osfamily => 'Debian',
:operatingsystemrelease => '8.1',
:rubyversion => '1.8.7'
}
end
it do
is_expected.to contain_file('sssd.conf') \
.with_ensure('present') \
.with_path('/etc/sssd/sssd.conf') \
.with_content(%r{^# Managed by Puppet.\n\n\[domain/ad.example.com\]})
end
end
end
end
6 changes: 3 additions & 3 deletions templates/sssd.conf.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Managed by Puppet.

<% @config.sort.map do |k,v| -%>
<% @config.map do |k,v| -%>
<% if v.is_a?(Hash) -%>
[<%= k %>]
<% v.sort.map do |ki, vi| -%>
<% v.map do |ki, vi| -%>
<% if vi.is_a?(Array) -%>
<%= ki %> = <%= vi.join(', ') %>
<% elsif vi != :undef -%>
Expand All @@ -12,5 +12,5 @@
<% end -%>
<% else -%>
[<%= k %>]
<% end %>
<% end -%>
<% end -%>
16 changes: 16 additions & 0 deletions templates/sssd.conf.sorted.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Managed by Puppet.

<% @config.sort.map do |k,v| -%>
<% if v.is_a?(Hash) -%>
[<%= k %>]
<% v.sort.map do |ki, vi| -%>
<% if vi.is_a?(Array) -%>
<%= ki %> = <%= vi.join(', ') %>
<% elsif vi != :undef -%>
<%= ki %> = <%= vi %>
<% end -%>
<% end -%>
<% else -%>
[<%= k %>]
<% end -%>
<% end -%>

0 comments on commit 8539c01

Please sign in to comment.