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

Move management of facts.d directory out of puppet::facts and into ma… #65

Merged
merged 1 commit into from
Nov 30, 2015
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
2 changes: 2 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 0 additions & 18 deletions manifests/facts.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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': }
}
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 0 additions & 27 deletions spec/classes/puppet_facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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
Expand Down
34 changes: 33 additions & 1 deletion spec/classes/puppet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down