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

(MODULES-3951) Add explicit check for stringify_facts #170

Merged
merged 3 commits into from
Oct 10, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions lib/facter/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
end
end

Facter.add('puppet_stringify_facts') do
setcode do
Puppet.settings['stringify_facts'] || false
end
end

Facter.add('puppet_sslpaths') do
setcode do
result = {}
Expand Down
4 changes: 4 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#
class puppet_agent::params {

if $::puppet_stringify_facts {
fail('The puppet_agent class requires stringify_facts to be disabled')
}

# The `is_pe` fact currently works by echoing out the puppet version
# and greping for "puppet enterprise". With Puppet 4 and PE 2015.2, there
# is no longer a "PE Puppet", and so that fact will no longer work.
Expand Down
37 changes: 15 additions & 22 deletions manifests/prepare/ssl.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,23 @@
'requestdir' => 'certificate_requests',
}

case $::puppet_sslpaths {
Hash: {
$sslpaths.each |String $setting, String $subdir| {
if $::puppet_sslpaths[$setting]['path_exists'] {
file { "${ssl_dir}/${subdir}":
ensure => directory,
source => $::puppet_sslpaths[$setting]['path'],
backup => false,
recurse => true,
}
}
}

# The only one that's a file, not a directory.
if $::puppet_sslpaths['hostcrl']['path_exists'] {
file { "${ssl_dir}/crl.pem":
ensure => file,
source => $::puppet_sslpaths['hostcrl']['path'],
backup => false
}
$sslpaths.each |String $setting, String $subdir| {
if $::puppet_sslpaths[$setting]['path_exists'] {
file { "${ssl_dir}/${subdir}":
ensure => directory,
source => $::puppet_sslpaths[$setting]['path'],
backup => false,
recurse => true,
}
}
default: {
fail('$::puppet-sslpaths is not a Hash. Is stringify_facts not set to false in the main section of the agent puppet.conf?')
}

# The only one that's a file, not a directory.
if $::puppet_sslpaths['hostcrl']['path_exists'] {
file { "${ssl_dir}/crl.pem":
ensure => file,
source => $::puppet_sslpaths['hostcrl']['path'],
backup => false
}
}
}
17 changes: 17 additions & 0 deletions spec/classes/puppet_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,21 @@ def global_facts(facts, os)
it { is_expected.to raise_error(Puppet::Error, /Nexenta not supported/) }
end
end

context 'stringify_facts is set to true' do
describe 'when puppet_stringify_facts evaluates as true ' do
# Mock a supported agent but with puppet_stringify_facts set to true
let(:facts) {{
:osfamily => 'windows',
:operatingsystem => '',
:puppet_ssldir => '/dev/null/ssl',
:puppet_config => '/dev/null/puppet.conf',
:architecture => 'i386',
:puppet_stringify_facts => true,
}}
let(:params) { global_params }

it { is_expected.to raise_error(Puppet::Error, /requires stringify_facts to be disabled/) }
end
end
end
42 changes: 42 additions & 0 deletions spec/unit/facter/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,48 @@
end
end

describe "puppet_stringify_facts fact for Puppet 4.x+", :unless => /3\./ =~ Puppet.version do
subject { Facter.fact("puppet_stringify_facts".to_sym).value }
after(:each) { Facter.clear }

describe 'should always be false' do
it { is_expected.to eq(false) }
end
end

describe "puppet_stringify_facts fact for Puppet 3.x", :if => /3\./ =~ Puppet.version do
subject { Facter.fact("puppet_stringify_facts".to_sym).value }
after(:each) { Facter.clear }

describe 'when not set in Puppet' do
before(:each) {
mocked_settings = Puppet::Settings.new
Puppet.stubs(:settings).returns(mocked_settings)
}
it { is_expected.to eq(false) }
end

describe 'when set false in Puppet' do
before(:each) {
mocked_settings = Puppet::Settings.new
mocked_settings.define_settings :main, :stringify_facts => { :default => false, :type => :boolean, :desc => 'mocked stringify_facts setting' }
Puppet.stubs(:settings).returns(mocked_settings)
}

it { is_expected.to eq(false) }
end

describe 'when set true in Puppet' do
before(:each) {
mocked_settings = Puppet::Settings.new
mocked_settings.define_settings :main, :stringify_facts => { :default => true, :type => :boolean, :desc => 'mocked stringify_facts setting' }
Puppet.stubs(:settings).returns(mocked_settings)
}

it { is_expected.to eq(true) }
end
end

describe "puppet_sslpaths fact" do
subject { Facter.fact("puppet_sslpaths".to_sym).value }
after(:each) { Facter.clear }
Expand Down