Skip to content

Commit 29a81a1

Browse files
committed
(maint) Update to PDK template 3.5.1
This commit updates this module to the latest PDK template (3.5.1). It also updates legacy facts from puppet_agent_spec, as legacy facts were removed in newer versions of FacterDB.
1 parent a82b5ec commit 29a81a1

File tree

9 files changed

+132
-69
lines changed

9 files changed

+132
-69
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@
1919
/spec/fixtures/modules/*
2020
/tmp/
2121
/vendor/
22+
/.vendor/
2223
/convert_report.txt
2324
/update_report.txt
2425
.DS_Store
2526
.project
2627
.envrc
2728
/inventory.yaml
2829
/spec/fixtures/litmus_inventory.yaml
30+
.resource_types
31+
.modules
32+
.task_cache.json
33+
.plan_cache.json
34+
.rerun.json
35+
bolt-debug.log

.pdkignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@
1919
/spec/fixtures/modules/*
2020
/tmp/
2121
/vendor/
22+
/.vendor/
2223
/convert_report.txt
2324
/update_report.txt
2425
.DS_Store
2526
.project
2627
.envrc
2728
/inventory.yaml
2829
/spec/fixtures/litmus_inventory.yaml
30+
.resource_types
31+
.modules
32+
.task_cache.json
33+
.plan_cache.json
34+
.rerun.json
35+
bolt-debug.log
2936
/.fixtures.yml
3037
/Gemfile
3138
/.gitattributes

.puppet-lint.rc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1+
--fail-on-warnings
12
--relative
3+
--no-80chars-check
4+
--no-140chars-check
5+
--no-class_inherits_from_params_class-check
6+
--no-autoloader_layout-check
7+
--no-documentation-check
8+
--no-single_quote_string_with_variables-check
29
--no-puppet_url_without_modules-check
10+
--ignore-paths=.vendor/**/*.pp,.bundle/**/*.pp,pkg/**/*.pp,spec/**/*.pp,tests/**/*.pp,types/**/*.pp,vendor/**/*.pp

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require:
55
AllCops:
66
NewCops: enable
77
DisplayCopNames: true
8-
TargetRubyVersion: '2.6'
8+
TargetRubyVersion: 2.7
99
Include:
1010
- "**/*.rb"
1111
Exclude:

.sync.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
.rubocop.yml:
33
default_configs:
4+
# Ruby 2.7 compatibility is needed til we drop Puppet 7 testing
5+
AllCops:
6+
TargetRubyVersion: 2.7
47
Layout/LineLength:
58
Max: 260
69
RSpec/NamedSubject:

Gemfile

Lines changed: 71 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,73 @@
1-
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
1+
# frozen_string_literal: true
22

3-
def location_for(place_or_version, fake_version = nil)
4-
git_url_regex = %r{\A(?<url>(https?|git)[:@][^#]*)(#(?<branch>.*))?}
5-
file_url_regex = %r{\Afile:\/\/(?<path>.*)}
3+
# For puppetcore, set GEM_SOURCE_PUPPETCORE = 'https://rubygems-puppetcore.puppet.com'
4+
gemsource_default = ENV['GEM_SOURCE'] || 'https://rubygems.org'
5+
gemsource_puppetcore = if ENV['PUPPET_FORGE_TOKEN']
6+
'https://rubygems-puppetcore.puppet.com'
7+
else
8+
ENV['GEM_SOURCE_PUPPETCORE'] || gemsource_default
9+
end
10+
source gemsource_default
11+
12+
def location_for(place_or_constraint, fake_constraint = nil, opts = {})
13+
git_url_regex = /\A(?<url>(?:https?|git)[:@][^#]*)(?:#(?<branch>.*))?/
14+
file_url_regex = %r{\Afile://(?<path>.*)}
15+
16+
if place_or_constraint && (git_url = place_or_constraint.match(git_url_regex))
17+
# Git source → ignore :source, keep fake_constraint
18+
[fake_constraint, { git: git_url[:url], branch: git_url[:branch], require: false }].compact
19+
20+
elsif place_or_constraint && (file_url = place_or_constraint.match(file_url_regex))
21+
# File source → ignore :source, keep fake_constraint or default >= 0
22+
[fake_constraint || '>= 0', { path: File.expand_path(file_url[:path]), require: false }]
623

7-
if place_or_version && (git_url = place_or_version.match(git_url_regex))
8-
[fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact
9-
elsif place_or_version && (file_url = place_or_version.match(file_url_regex))
10-
['>= 0', { path: File.expand_path(file_url[:path]), require: false }]
1124
else
12-
[place_or_version, { require: false }]
25+
# Plain version constraint → merge opts (including :source if provided)
26+
[place_or_constraint, { require: false }.merge(opts)]
27+
end
28+
end
29+
30+
# Print debug information if DEBUG_GEMS or VERBOSE is set
31+
def print_gem_statement_for(gems)
32+
puts 'DEBUG: Gem definitions that will be generated:'
33+
gems.each do |gem_name, gem_params|
34+
puts "DEBUG: gem #{([gem_name.inspect] + gem_params.map(&:inspect)).join(', ')}"
1335
end
1436
end
1537

1638
group :development do
17-
gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
18-
gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
19-
gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
20-
gem "deep_merge", '~> 1.2.2', require: false
21-
gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false
22-
gem "facterdb", '~> 1.18', require: false
23-
gem "metadata-json-lint", '~> 4.0', require: false
24-
gem "rspec-puppet-facts", '~> 3.0', require: false
25-
gem "json-schema", '< 5.1.1', require: false
26-
gem "dependency_checker", '~> 1.0.0', require: false
27-
gem "parallel_tests", '= 3.12.1', require: false
28-
gem "pry", '~> 0.10', require: false
29-
gem "simplecov-console", '~> 0.9', require: false
30-
gem "puppet-debugger", '~> 1.6', require: false
31-
gem "rubocop", '~> 1.50.0', require: false
32-
gem "rubocop-performance", '= 1.16.0', require: false
33-
gem "rubocop-rspec", '= 2.19.0', require: false
34-
gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]
39+
gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
40+
gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
41+
gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
42+
gem "deep_merge", '~> 1.2.2', require: false
43+
gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false
44+
gem "facterdb", '~> 2.1', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
45+
gem "facterdb", '~> 3.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
46+
gem "metadata-json-lint", '~> 4.0', require: false
47+
gem "json-schema", '< 5.1.1', require: false
48+
gem "rspec-puppet-facts", '~> 4.0', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
49+
gem "rspec-puppet-facts", '~> 5.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
50+
gem "dependency_checker", '~> 1.0.0', require: false
51+
gem "parallel_tests", '= 3.12.1', require: false
52+
gem "pry", '~> 0.10', require: false
53+
gem "simplecov-console", '~> 0.9', require: false
54+
gem "puppet-debugger", '~> 1.6', require: false
55+
gem "rubocop", '~> 1.50.0', require: false
56+
gem "rubocop-performance", '= 1.16.0', require: false
57+
gem "rubocop-rspec", '= 2.19.0', require: false
58+
gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]
59+
gem "bigdecimal", '< 3.2.2', require: false, platforms: [:mswin, :mingw, :x64_mingw]
3560
gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '~> 6.0')
3661
gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 1.0')
37-
gem "beaker-hostgenerator", *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'] || '~> 2')
62+
gem "beaker-hostgenerator", *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'] || '~> 2.0')
3863
gem "beaker-rspec"
39-
gem "beaker-puppet", *location_for(ENV['BEAKER_PUPPET_VERSION'] || '~> 4.0') if Gem::Requirement.create('< 3.2.0').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
40-
gem "beaker-module_install_helper", require: false
41-
gem "beaker-puppet_install_helper", require: false
42-
gem "nokogiri", require: false
43-
gem "bolt", '~> 3.0', require: false if ENV["GEM_BOLT"]
44-
gem "beaker-task_helper", '~> 1.9', require: false if ENV["GEM_BOLT"]
45-
gem "orchestrator_client", '< 0.7.1', require: false if ENV["GEM_BOLT"]
46-
gem "async", '~> 1.30', require: false
64+
gem "beaker-puppet", *location_for(ENV['BEAKER_PUPPET_VERSION'] || '~> 4.0')
65+
gem "beaker-module_install_helper", require: false
66+
gem "beaker-puppet_install_helper", require: false
67+
gem "nokogiri", require: false
68+
gem "bolt", '~> 3.0', require: false if ENV["GEM_BOLT"]
69+
gem "beaker-task_helper", '~> 1.9', require: false if ENV["GEM_BOLT"]
70+
gem "orchestrator_client", '< 0.7.1', require: false if ENV["GEM_BOLT"]
4771
end
4872
group :development, :release_prep do
4973
gem "puppet-strings", '~> 4.0', require: false
@@ -61,31 +85,27 @@ puppet_version = ENV.fetch('PUPPET_GEM_VERSION', nil)
6185
facter_version = ENV.fetch('FACTER_GEM_VERSION', nil)
6286
hiera_version = ENV.fetch('HIERA_GEM_VERSION', nil)
6387

64-
# If PUPPET_FORGE_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet
65-
# Otherwise, do as before and use location_for to fetch gems from the default source
66-
if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty?
67-
gems['puppet'] = ['~> 8.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }]
68-
gems['facter'] = ['~> 4.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }]
69-
else
70-
gems['puppet'] = location_for(puppet_version)
71-
gems['facter'] = location_for(facter_version) if facter_version
72-
end
73-
74-
gems['hiera'] = location_for(hiera_version) if hiera_version
88+
gems['puppet'] = location_for(puppet_version, nil, { source: gemsource_puppetcore })
89+
gems['facter'] = location_for(facter_version, nil, { source: gemsource_puppetcore })
90+
gems['hiera'] = location_for(hiera_version, nil, {}) if hiera_version
7591

92+
# Generate the gem definitions
93+
print_gem_statement_for(gems) if ENV['DEBUG']
7694
gems.each do |gem_name, gem_params|
7795
gem gem_name, *gem_params
7896
end
7997

8098
# Evaluate Gemfile.local and ~/.gemfile if they exist
8199
extra_gemfiles = [
82100
"#{__FILE__}.local",
83-
File.join(Dir.home, '.gemfile'),
101+
File.join(Dir.home, '.gemfile')
84102
]
85103

86104
extra_gemfiles.each do |gemfile|
87-
if File.file?(gemfile) && File.readable?(gemfile)
88-
eval(File.read(gemfile), binding)
89-
end
105+
next unless File.file?(gemfile) && File.readable?(gemfile)
106+
107+
# rubocop:disable Security/Eval
108+
eval(File.read(gemfile), binding)
109+
# rubocop:enable Security/Eval
90110
end
91111
# vim: syntax=ruby

Rakefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@ require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings'
88
require 'voxpupuli/acceptance/rake' if Gem.loaded_specs.key? 'voxpupuli-acceptance'
99

1010
PuppetLint.configuration.send('disable_relative')
11+
PuppetLint.configuration.send('disable_80chars')
12+
PuppetLint.configuration.send('disable_140chars')
13+
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
14+
PuppetLint.configuration.send('disable_autoloader_layout')
15+
PuppetLint.configuration.send('disable_documentation')
16+
PuppetLint.configuration.send('disable_single_quote_string_with_variables')
1117
PuppetLint.configuration.send('disable_puppet_url_without_modules')
18+
PuppetLint.configuration.fail_on_warnings = true
19+
PuppetLint.configuration.ignore_paths = [".vendor/**/*.pp", ".bundle/**/*.pp", "pkg/**/*.pp", "spec/**/*.pp", "tests/**/*.pp", "types/**/*.pp", "vendor/**/*.pp"]
20+

metadata.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"version_requirement": ">= 7.0.0 < 9.0.0"
8383
}
8484
],
85-
"pdk-version": "3.2.0",
86-
"template-url": "https://github.com/puppetlabs/pdk-templates#3.2.0",
87-
"template-ref": "tags/3.2.0-0-gb257ef1"
85+
"pdk-version": "3.5.1",
86+
"template-url": "https://github.com/puppetlabs/pdk-templates#3.5.1",
87+
"template-ref": "tags/3.5.1-0-g9d5b193"
8888
}

spec/classes/puppet_agent_spec.rb

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
# maps AIX release major fact value to the known AIX version
66
AIX_VERSION = {
7-
'6100': '6.1',
87
'7100': '7.2',
98
'7200': '7.2',
109
}.freeze
@@ -13,8 +12,10 @@ def redhat_familly_supported_os
1312
on_supported_os(
1413
supported_os: [
1514
{
16-
'operatingsystem' => 'RedHat',
17-
"operatingsystemrelease": ['5', '6', '7', '8'],
15+
'os' => {
16+
'name' => 'RedHat',
17+
'release' => ['6', '7', '8', '9', '10'],
18+
}
1819
},
1920
],
2021
)
@@ -30,7 +31,6 @@ def global_facts(facts, os)
3031
{
3132
is_pe: true,
3233
env_temp_variable: '/tmp',
33-
operatingsystemmajrelease: facts[:operatingsystemrelease].split('.')[0],
3434
}
3535
elsif %r{redhat|centos|fedora|scientific|oracle}.match?(os)
3636
{
@@ -120,12 +120,21 @@ def global_facts(facts, os)
120120
end
121121

122122
context 'package provider' do
123-
# module is still pinned to older rspec-puppet and facterdb
124-
os_name = 'fedora-41-x86_64'
125-
os_facts = {
126-
os_name => on_supported_os['fedora-39-x86_64'],
127-
}
128-
os_facts.values.first[:os]['release'] = { 'full' => '41', 'major' => '41' }
123+
# Package provider behavior changes on Fedora in >= 41
124+
# Fedora 41 facts were introduced to FacterDB in 3.8.0, the PDK template
125+
# pins FacterDB to 2.1.0 in Ruby < 3.0.
126+
# Once we drop tests for Puppet 7, we can use just the first conditional
127+
if on_supported_os['fedora-41-x86_64']
128+
os_facts = {
129+
'fedora-41-x86_64' => on_supported_os['fedora-41-x86_64']
130+
}
131+
else
132+
os_name = 'fedora-41-x86_64'
133+
os_facts = {
134+
os_name => on_supported_os['fedora-38-x86_64'],
135+
}
136+
os_facts.values.first[:os]['release'] = { 'full' => '41', 'major' => '41' }
137+
end
129138
os_facts.each do |os, facts|
130139
context "on #{os}" do
131140
let(:facts) do
@@ -349,10 +358,10 @@ def global_facts(facts, os)
349358
it { is_expected.to contain_class('puppet_agent::prepare') }
350359
it { is_expected.to contain_class('puppet_agent::install').that_requires('Class[puppet_agent::prepare]') }
351360

352-
if facts[:osfamily] == 'Debian'
361+
if facts[:os]['family'] == 'Debian'
353362
deb_package_version = package_version + '-1' + facts.dig(:os, 'distro', 'codename')
354363
it { is_expected.to contain_package('puppet-agent').with_ensure(deb_package_version) }
355-
elsif facts[:osfamily] == 'Solaris'
364+
elsif facts[:os]['family'] == 'Solaris'
356365
if facts[:operatingsystemmajrelease] == '11'
357366
it { is_expected.to contain_package('puppet-agent').with_ensure('6.5.4') }
358367
else
@@ -363,7 +372,7 @@ def global_facts(facts, os)
363372
)
364373
end
365374
end
366-
elsif facts[:osfamily] == 'windows'
375+
elsif facts[:os]['family'] == 'windows'
367376
# Windows does not contain any Package resources
368377
else
369378
it { is_expected.to contain_package('puppet-agent').with_ensure(package_version) }
@@ -377,7 +386,7 @@ def global_facts(facts, os)
377386

378387
# Windows platform does not use Service resources; their services
379388
# are managed by the MSI installer.
380-
unless facts[:osfamily] == 'windows'
389+
unless facts[:os]['family'] == 'windows'
381390
if params[:service_names].nil? && os !~ %r{sles|solaris|aix}
382391
it { is_expected.to contain_service('puppet') }
383392
else

0 commit comments

Comments
 (0)