From 4d86b3237c90331f4f7e1a0864a0f41d8ddebc6c Mon Sep 17 00:00:00 2001 From: Pete Brown Date: Mon, 30 Nov 2015 14:46:17 +1000 Subject: [PATCH] Move management of facts.d directory out of puppet::facts and into main class. Issue #56 --- manifests/config.pp | 2 ++ manifests/facts.pp | 18 ---------------- manifests/init.pp | 21 +++++++++++++++++++ spec/classes/puppet_facts_spec.rb | 27 ------------------------ spec/classes/puppet_spec.rb | 34 ++++++++++++++++++++++++++++++- 5 files changed, 56 insertions(+), 46 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 0be4a52..3d03246 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -16,6 +16,8 @@ $reports = $::puppet::reports $runinterval = $::puppet::runinterval $structured_facts = $::puppet::structured_facts + $manage_etc_facter = $::puppet::manage_etc_facter + $manage_etc_facter_facts_d = $::puppet::manage_etc_facter_facts_d $stringify_facts = $structured_facts ? { default => true, diff --git a/manifests/facts.pp b/manifests/facts.pp index d5052cb..fb75659 100644 --- a/manifests/facts.pp +++ b/manifests/facts.pp @@ -16,24 +16,6 @@ validate_hash($custom_facts) } - if $::puppet::manage_etc_facter { - file { $facterbasepath: - ensure => directory, - owner => 'root', - group => 'puppet', - mode => '0755', - } - } - - if $::puppet::manage_etc_facter_facts_d { - file { "${facterbasepath}/facts.d": - ensure => directory, - owner => 'root', - group => 'puppet', - mode => '0755', - } - } - file { "${facterbasepath}/facts.d/local.yaml": ensure => file, owner => 'root', diff --git a/manifests/init.pp b/manifests/init.pp index 8ad54e1..272d05e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -132,6 +132,9 @@ $supported_mechanisms = ['service', 'cron'] validate_re($enable_mechanism, $supported_mechanisms) + include ::puppet::defaults + $facterbasepath = $::puppet::defaults::facterbasepath + if $devel_repo == true { notify { 'Deprecation notice: puppet::devel_repo is deprecated, use puppet::enable_devel_repo instead': } } @@ -171,6 +174,24 @@ include ::puppet::repo Class['::puppet::repo'] -> Class['::puppet::install'] } + if $::puppet::manage_etc_facter { + file { $facterbasepath: + ensure => directory, + owner => 'root', + group => 'puppet', + mode => '0755', + } + } + + if $::puppet::manage_etc_facter_facts_d { + file { "${facterbasepath}/facts.d": + ensure => directory, + owner => 'root', + group => 'puppet', + mode => '0755', + } + } + if $custom_facts { class { '::puppet::facts': custom_facts => $custom_facts, diff --git a/spec/classes/puppet_facts_spec.rb b/spec/classes/puppet_facts_spec.rb index 992be6b..337dabe 100644 --- a/spec/classes/puppet_facts_spec.rb +++ b/spec/classes/puppet_facts_spec.rb @@ -87,21 +87,6 @@ facterbasepath = '/etc/facter' end context 'when fed no parameters' do - it 'should manage the facts directories' do - #binding.pry; - should contain_file("#{facterbasepath}").with({ - :ensure=>"directory", - :owner=>"root", - :group=>"puppet", - :mode=>"0755" - }) - should contain_file("#{facterbasepath}/facts.d").with({ - :ensure=>"directory", - :owner=>"root", - :group=>"puppet", - :mode=>"0755" - }) - end it "should lay down #{facterbasepath}/facts.d/local.yaml" do should contain_file("#{facterbasepath}/facts.d/local.yaml").with_content( /facts for my.client.cert/ @@ -112,18 +97,6 @@ ) end end#no params - context 'when ::puppet::manage_etc_facter is false' do - let(:pre_condition){"class{'puppet': manage_etc_facter => false}"} - it 'should not try to lay down the directory' do - should_not contain_file("#{facterbasepath}") - end - end - context 'when ::puppet::manage_etc_facter_facts_d is false' do - let(:pre_condition){"class{'puppet': manage_etc_facter_facts_d => false}"} - it 'should not try to lay down the directory' do - should_not contain_file("#{facterbasepath}/facts.d") - end - end context 'when the custom_facts parameter is properly set' do let(:params) {{'custom_facts' => {'key1' => 'val1', 'key2' => 'val2'}}} it 'should iterate through the hash and properly populate the local_facts.yaml file' do diff --git a/spec/classes/puppet_spec.rb b/spec/classes/puppet_spec.rb index bcf26c4..749145b 100644 --- a/spec/classes/puppet_spec.rb +++ b/spec/classes/puppet_spec.rb @@ -104,7 +104,11 @@ }) end it { is_expected.to compile.with_all_deps } - + if Puppet.version.to_f >= 4.0 + facterbasepath = '/opt/puppetlabs/facter' + else + facterbasepath = '/etc/facter' + end context 'when fed no parameters' do it 'should instantiate the puppet::repo class with the default params' do should contain_class('puppet::repo') @@ -118,8 +122,36 @@ it 'should instantiate the puppet::agent class' do should contain_class('puppet::agent') end + it 'should manage the facts directories' do + #binding.pry; + should contain_file("#{facterbasepath}").with({ + :ensure=>"directory", + :owner=>"root", + :group=>"puppet", + :mode=>"0755" + }) + should contain_file("#{facterbasepath}/facts.d").with({ + :ensure=>"directory", + :owner=>"root", + :group=>"puppet", + :mode=>"0755" + }) + end end#no params + context 'when ::puppet::manage_etc_facter is false' do + let(:pre_condition){"class{'puppet': manage_etc_facter => false}"} + it 'should not try to lay down the directory' do + should_not contain_file("#{facterbasepath}") + end + end + context 'when ::puppet::manage_etc_facter_facts_d is false' do + let(:pre_condition){"class{'puppet': manage_etc_facter_facts_d => false}"} + it 'should not try to lay down the directory' do + should_not contain_file("#{facterbasepath}/facts.d") + end + end + # context 'when the agent_version param is something other than installed' do # let(:params) {{'agent_version' => 'BOGON'}} # it 'should instantiate the puppet::install class apropriately' do