Skip to content

Remove special code path for Puppet Enterprise #347

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

Merged
merged 1 commit into from
Mar 1, 2021
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
27 changes: 10 additions & 17 deletions manifests/facts.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,28 @@
},
# lint:endignore
) inherits jira::params {
# Puppet Enterprise supplies its own ruby version if your using it.
# A modern ruby version is required to run the executable fact
if $facts['puppetversion'] =~ /Puppet Enterprise/ {
$ruby_bin = '/opt/puppet/bin/ruby'
$dir = 'puppetlabs/'
} elsif $facts['aio_agent_version'] =~ String[1] {
if $facts['aio_agent_version'] =~ String[1] {
$ruby_bin = '/opt/puppetlabs/puppet/bin/ruby'
$dir = 'puppetlabs/'
$dir = '/etc/puppetlabs/facter'
} else {
$ruby_bin = '/usr/bin/env ruby'
$dir = ''
$dir = '/etc/facter'

ensure_packages ($json_packages, { ensure => present })
}

if !defined(File["/etc/${dir}facter"]) {
file { "/etc/${dir}facter":
if !defined(File[$dir]) {
file { $dir:
ensure => directory,
}
}
if !defined(File["/etc/${dir}facter/facts.d"]) {
file { "/etc/${dir}facter/facts.d":
if !defined(File["${dir}/facts.d"]) {
file { "${dir}/facts.d":
ensure => directory,
}
}

if $facts['os']['family'] == 'RedHat' and $facts['puppetversion'] !~ /Puppet Enterprise/ {
ensure_packages ($json_packages, { ensure => present })
}

file { "/etc/${dir}facter/facts.d/jira_facts.rb":
file { "${dir}/facts.d/jira_facts.rb":
ensure => $ensure,
content => template('jira/facts.rb.erb'),
mode => '0755',
Expand Down
43 changes: 24 additions & 19 deletions spec/classes/jira_facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,42 @@
end
let(:pre_condition) { "class{'::jira': javahome => '/opt/java'}" }

regexp_pe = %r{^#\!/opt/puppet/bin/ruby$}
regexp_oss = %r{^#\!/opt/puppetlabs/puppet/bin/ruby$}
regexp_url = %r{http://127.0.0.1\:8080/rest/api/2/serverInfo}
pe_external_fact_file = '/etc/puppetlabs/facter/facts.d/jira_facts.rb'
external_fact_file = '/etc/puppetlabs/facter/facts.d/jira_facts.rb'

it { is_expected.to contain_file(external_fact_file).with_mode('0755') }
it { is_expected.to compile.with_all_deps }

# Test puppet enterprise shebang generated correctly
context 'with puppet enterprise' do
context 'with puppet AIO' do
let(:facts) do
facts.merge(puppetversion: '3.4.3 (Puppet Enterprise 3.2.1)')
facts.merge(aio_agent_version: 'something')
end

it do
is_expected.to contain_file(pe_external_fact_file). \
with_content(regexp_pe).
with_content(regexp_url)
is_expected.to contain_file('/etc/puppetlabs/facter/facts.d/jira_facts.rb'). \
with_content(%r{#!/opt/puppetlabs/puppet/bin/ruby}).
with_content(%r{http://127\.0\.0\.1:8080/rest/api/2/serverInfo})
end

it { is_expected.not_to contain_file('/etc/facter/facts.d/jira_facts.rb') }
it { is_expected.not_to contain_package('rubygem-json') }
it { is_expected.not_to contain_package('ruby-json') }
end
# Test puppet oss shebang generated correctly

context 'with puppet oss' do
let(:facts) do
facts.merge(puppetversion: 'all other versions')
facts.merge(aio_agent_version: nil)
end

it { is_expected.not_to contain_file('/etc/puppetlabs/facter/facts.d/jira_facts.rb') }

it do
is_expected.to contain_file(external_fact_file). \
with_content(regexp_oss). \
with_content(regexp_url)
is_expected.to contain_file('/etc/facter/facts.d/jira_facts.rb'). \
with_content(%r{#!/opt/puppet/bin/ruby}).
with_content(%r{http://127\.0\.0\.1:8080/rest/api/2/serverInfo})
end

case facts[:osfamily]
when 'RedHat'
it { is_expected.to contain_package('rubygem-json') }
when 'Debian'
it { is_expected.to contain_package('ruby-json') }
end
end

Expand All @@ -48,7 +53,7 @@
end

it do
is_expected.to contain_file(external_fact_file). \
is_expected.to contain_file('/etc/puppetlabs/facter/facts.d/jira_facts.rb'). \
with_content(%r{ url = 'http://127.0.0.1:8080/jira})
end
end
Expand Down