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-7480) Set default collection in params.pp using PE version #301

Merged
merged 1 commit into from
Jul 25, 2018
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: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#
class puppet_agent (
$arch = $::architecture,
$collection = 'PC1',
$collection = $::puppet_agent::params::collection,
$is_pe = $::puppet_agent::params::_is_pe,
$manage_pki_dir = true,
$manage_repo = true,
Expand Down
18 changes: 18 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@
$package_version = undef
}

# Calculate the default collection
$_pe_version = $_is_pe ? {
true => pe_build_version(),
default => undef
}
# Not PE or pe_version < 2018.1.3, use PC1
if ($_pe_version == undef or versioncmp("${_pe_version}", '2018.1.3') < 0) {
$collection = 'PC1'
}
# 2018.1.3 <= pe_version < 2018.2, use puppet5
elsif versioncmp("${_pe_version}", '2018.2') < 0 {
$collection = 'puppet5'
}
# pe_version >= 2018.2, use puppet6
else {
$collection = 'puppet6'
}

$ssldir = "${confdir}/ssl"
$config = "${confdir}/puppet.conf"

Expand Down
77 changes: 77 additions & 0 deletions spec/classes/puppet_agent_params_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
require 'spec_helper'

describe 'puppet_agent::params' do
let(:facts) do
{
is_pe: true,
clientversion: '5.5.3',
osfamily: 'Debian',
operatingsystem: 'Debian',
servername: 'server',
# custom fact meant to be used only for tests in this file
custom_fact__pe_version: '2018.1.3'
}
end

before(:each) do
Puppet::Parser::Functions.newfunction(:pe_build_version, type: :rvalue, doc: '') do |args|
lookupvar('::custom_fact__pe_version')
end
end

context 'collection' do
# rspec-puppet lets us query the compiled catalog only, so we can only check if any specific resources
# have been declared. We cannot query for a class' variables, so we cannot query for the collection
# variable's value. But we can use a workaround by creating a notify resource whose message contains
# the value and query that instead since it will be added as part of the catalog. post_condition tells
# rspec-puppet to include this resource only after our class has been compiled, which is what we want.
let(:notify_title) { "check puppet_agent::params::collection's value" }
let(:post_condition) do
<<-NOTIFY_RESOURCE
notify { "#{notify_title}":
message => "${::puppet_agent::params::collection}"
}
NOTIFY_RESOURCE
end

def sets_collection_to(collection)
is_expected.to contain_notify(notify_title).with_message(collection)
end

context 'not in PE' do
let(:facts) { super().merge(is_pe: false, custom_fact__pe_version: '') }

it { sets_collection_to('PC1') }
end

context 'pe_version < 2018.1.3' do
let(:facts) { super().merge(custom_fact__pe_version: '2018.1.2') }

it { sets_collection_to('PC1') }
end

context 'pe_version == 2018.1.3' do
let(:facts) { super().merge(custom_fact__pe_version: '2018.1.3') }

it { sets_collection_to('puppet5') }
end

context '2018.1.3 < pe_version < 2018.2' do
let(:facts) { super().merge(custom_fact__pe_version: '2018.1.5') }

it { sets_collection_to('puppet5') }
end

context 'pe_version == 2018.2' do
let(:facts) { super().merge(custom_fact__pe_version: '2018.2') }

it { sets_collection_to('puppet6') }
end

context 'pe_version > 2018.2' do
let(:facts) { super().merge(custom_fact__pe_version: '2018.3') }

it { sets_collection_to('puppet6') }
end
end
end
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
end
end

RSpec.configure do |c|
c.before :each do
Puppet::Parser::Functions.newfunction(:pe_build_version, type: :rvalue, doc: '') do |args|
'2018.1.0'
end
end
end

# put local configuration and setup into spec_helper_local
begin
require 'spec_helper_local'
Expand Down