From 8c9f1533757486bbe3ded05370556a931316a898 Mon Sep 17 00:00:00 2001 From: tvpartytonight Date: Thu, 20 Nov 2025 15:48:37 -0800 Subject: [PATCH 1/2] (PA-7815) Updates for pdk template 3.5.1 --- .gitignore | 7 +++ .pdkignore | 7 +++ .puppet-lint.rc | 8 ++++ .rubocop.yml | 2 +- Gemfile | 118 ++++++++++++++++++++++++++++-------------------- Rakefile | 9 ++++ metadata.json | 6 +-- 7 files changed, 105 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index 3f15512..2803e56 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ /spec/fixtures/modules/* /tmp/ /vendor/ +/.vendor/ /convert_report.txt /update_report.txt .DS_Store @@ -26,3 +27,9 @@ .envrc /inventory.yaml /spec/fixtures/litmus_inventory.yaml +.resource_types +.modules +.task_cache.json +.plan_cache.json +.rerun.json +bolt-debug.log diff --git a/.pdkignore b/.pdkignore index 862847a..84684be 100644 --- a/.pdkignore +++ b/.pdkignore @@ -19,6 +19,7 @@ /spec/fixtures/modules/* /tmp/ /vendor/ +/.vendor/ /convert_report.txt /update_report.txt .DS_Store @@ -26,6 +27,12 @@ .envrc /inventory.yaml /spec/fixtures/litmus_inventory.yaml +.resource_types +.modules +.task_cache.json +.plan_cache.json +.rerun.json +bolt-debug.log /.fixtures.yml /Gemfile /.gitattributes diff --git a/.puppet-lint.rc b/.puppet-lint.rc index cc96ece..9e15c6e 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1 +1,9 @@ +--fail-on-warnings --relative +--no-80chars-check +--no-140chars-check +--no-class_inherits_from_params_class-check +--no-autoloader_layout-check +--no-documentation-check +--no-single_quote_string_with_variables-check +--ignore-paths=.vendor/**/*.pp,.bundle/**/*.pp,pkg/**/*.pp,spec/**/*.pp,tests/**/*.pp,types/**/*.pp,vendor/**/*.pp diff --git a/.rubocop.yml b/.rubocop.yml index e9dce91..0bfab04 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,7 +5,7 @@ require: AllCops: NewCops: enable DisplayCopNames: true - TargetRubyVersion: '2.6' + TargetRubyVersion: 3.1 Include: - "**/*.rb" Exclude: diff --git a/Gemfile b/Gemfile index 81905b8..de7965f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,53 +1,79 @@ -source ENV['GEM_SOURCE'] || 'https://rubygems.org' +# frozen_string_literal: true -def location_for(place_or_version, fake_version = nil) - git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} - file_url_regex = %r{\Afile:\/\/(?.*)} +# For puppetcore, set GEM_SOURCE_PUPPETCORE = 'https://rubygems-puppetcore.puppet.com' +gemsource_default = ENV['GEM_SOURCE'] || 'https://rubygems.org' +gemsource_puppetcore = if ENV['PUPPET_FORGE_TOKEN'] + 'https://rubygems-puppetcore.puppet.com' +else + ENV['GEM_SOURCE_PUPPETCORE'] || gemsource_default +end +source gemsource_default + +def location_for(place_or_constraint, fake_constraint = nil, opts = {}) + git_url_regex = /\A(?(?:https?|git)[:@][^#]*)(?:#(?.*))?/ + file_url_regex = %r{\Afile://(?.*)} + + if place_or_constraint && (git_url = place_or_constraint.match(git_url_regex)) + # Git source → ignore :source, keep fake_constraint + [fake_constraint, { git: git_url[:url], branch: git_url[:branch], require: false }].compact + + elsif place_or_constraint && (file_url = place_or_constraint.match(file_url_regex)) + # File source → ignore :source, keep fake_constraint or default >= 0 + [fake_constraint || '>= 0', { path: File.expand_path(file_url[:path]), require: false }] - if place_or_version && (git_url = place_or_version.match(git_url_regex)) - [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact - elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) - ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] else - [place_or_version, { require: false }] + # Plain version constraint → merge opts (including :source if provided) + [place_or_constraint, { require: false }.merge(opts)] + end +end + +# Print debug information if DEBUG_GEMS or VERBOSE is set +def print_gem_statement_for(gems) + puts 'DEBUG: Gem definitions that will be generated:' + gems.each do |gem_name, gem_params| + puts "DEBUG: gem #{([gem_name.inspect] + gem_params.map(&:inspect)).join(', ')}" end end group :development do - gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - 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)) - 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)) - 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)) - gem "deep_merge", '~> 1.0', require: false - gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false - gem "facterdb", '~> 1.18', require: false - gem "metadata-json-lint", '~> 4.0', require: false - gem "rspec-puppet-facts", '~> 3.0', require: false - gem "dependency_checker", '~> 1.0.0', require: false - gem "parallel_tests", '= 3.12.1', require: false - gem "pry", '~> 0.10', require: false - gem "simplecov-console", '~> 0.9', require: false - gem "puppet-debugger", '~> 1.0', require: false - gem "rubocop", '~> 1.50.0', require: false - gem "rubocop-performance", '= 1.16.0', require: false - gem "rubocop-rspec", '= 2.19.0', require: false - gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] + 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)) + 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)) + 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)) + gem "deep_merge", '~> 1.2.2', require: false + gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false + gem "facterdb", '~> 2.1', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "facterdb", '~> 3.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "metadata-json-lint", '~> 4.0', require: false + gem "json-schema", '< 5.1.1', require: false + gem "rspec-puppet-facts", '~> 4.0', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "rspec-puppet-facts", '~> 5.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "dependency_checker", '~> 1.0.0', require: false + gem "parallel_tests", '= 3.12.1', require: false + gem "pry", '~> 0.10', require: false + gem "simplecov-console", '~> 0.9', require: false + gem "puppet-debugger", '~> 1.6', require: false + gem "rubocop", '~> 1.50.0', require: false + gem "rubocop-performance", '= 1.16.0', require: false + gem "rubocop-rspec", '= 2.19.0', require: false + gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "bigdecimal", '< 3.2.2', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '~> 6.0') gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 1.0') gem "beaker-hostgenerator", *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'] || '~> 2') gem "beaker-rspec" 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)) - gem "async", '~> 1', require: false - gem "beaker-module_install_helper", require: false - gem "nokogiri", require: false + gem "async", '~> 1', require: false + gem "beaker-module_install_helper", require: false + gem "nokogiri", require: false end group :development, :release_prep do gem "puppet-strings", '~> 4.0', require: false - gem "puppetlabs_spec_helper", '~> 7.0', require: false + gem "puppetlabs_spec_helper", '~> 8.0', require: false + gem "puppet-blacksmith", '~> 7.0', require: false end group :system_tests do + gem "puppet_litmus", '~> 2.0', require: false, platforms: [:ruby, :x64_mingw] if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty? + gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] if ENV['PUPPET_FORGE_TOKEN'].to_s.empty? gem "CFPropertyList", '< 3.0.7', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "serverspec", '~> 2.41', require: false gem "voxpupuli-acceptance", require: false @@ -58,18 +84,12 @@ puppet_version = ENV.fetch('PUPPET_GEM_VERSION', nil) facter_version = ENV.fetch('FACTER_GEM_VERSION', nil) hiera_version = ENV.fetch('HIERA_GEM_VERSION', nil) -# If PUPPET_FORGE_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet -# Otherwise, do as before and use location_for to fetch gems from the default source -if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty? - gems['puppet'] = ['~> 8.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }] - gems['facter'] = ['~> 4.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }] -else - gems['puppet'] = location_for(puppet_version) - gems['facter'] = location_for(facter_version) if facter_version -end - -gems['hiera'] = location_for(hiera_version) if hiera_version +gems['puppet'] = location_for(puppet_version, nil, { source: gemsource_puppetcore }) +gems['facter'] = location_for(facter_version, nil, { source: gemsource_puppetcore }) +gems['hiera'] = location_for(hiera_version, nil, {}) if hiera_version +# Generate the gem definitions +print_gem_statement_for(gems) if ENV['DEBUG'] gems.each do |gem_name, gem_params| gem gem_name, *gem_params end @@ -77,12 +97,14 @@ end # Evaluate Gemfile.local and ~/.gemfile if they exist extra_gemfiles = [ "#{__FILE__}.local", - File.join(Dir.home, '.gemfile'), + File.join(Dir.home, '.gemfile') ] extra_gemfiles.each do |gemfile| - if File.file?(gemfile) && File.readable?(gemfile) - eval(File.read(gemfile), binding) - end + next unless File.file?(gemfile) && File.readable?(gemfile) + + # rubocop:disable Security/Eval + eval(File.read(gemfile), binding) + # rubocop:enable Security/Eval end # vim: syntax=ruby diff --git a/Rakefile b/Rakefile index 41f5ec8..2138a1f 100644 --- a/Rakefile +++ b/Rakefile @@ -8,3 +8,12 @@ require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' require 'voxpupuli/acceptance/rake' if Gem.loaded_specs.key? 'voxpupuli-acceptance' PuppetLint.configuration.send('disable_relative') +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send('disable_140chars') +PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send('disable_autoloader_layout') +PuppetLint.configuration.send('disable_documentation') +PuppetLint.configuration.send('disable_single_quote_string_with_variables') +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.ignore_paths = [".vendor/**/*.pp", ".bundle/**/*.pp", "pkg/**/*.pp", "spec/**/*.pp", "tests/**/*.pp", "types/**/*.pp", "vendor/**/*.pp"] + diff --git a/metadata.json b/metadata.json index dccb12e..af6bece 100644 --- a/metadata.json +++ b/metadata.json @@ -60,7 +60,7 @@ "version_requirement": ">= 6.0.0 < 9.0.0" } ], - "pdk-version": "3.2.0", - "template-url": "https://github.com/puppetlabs/pdk-templates#3.2.0", - "template-ref": "tags/3.2.0-0-gb257ef1" + "pdk-version": "3.5.1", + "template-url": "https://github.com/puppetlabs/pdk-templates#3.5.1", + "template-ref": "tags/3.5.1-0-g9d5b193" } From 2d4ddc74d9acd222188ce3bd5964601ba6b838a9 Mon Sep 17 00:00:00 2001 From: tvpartytonight Date: Thu, 20 Nov 2025 15:52:34 -0800 Subject: [PATCH 2/2] (PA-7815) Fix for rubocop in pdk template 3.5.1 --- lib/puppet/provider/mount/parsed.rb | 4 ++-- lib/puppet/type/mount.rb | 10 +++++----- spec/spec_helper_acceptance.rb | 2 +- spec/unit/type/mount_spec.rb | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/puppet/provider/mount/parsed.rb b/lib/puppet/provider/mount/parsed.rb index 1f57806..2e4eb37 100644 --- a/lib/puppet/provider/mount/parsed.rb +++ b/lib/puppet/provider/mount/parsed.rb @@ -294,9 +294,9 @@ def self.mountinstances end mount_output.each do |line| if (match = regex.match(line)) && (name = match.captures.first) - instances << { name: name, mounted: :yes } # Only :name is important here + instances << { name:, mounted: :yes } # Only :name is important here else - raise Puppet::Error, _('Could not understand line %{line} from mount output') % { line: line } + raise Puppet::Error, _('Could not understand line %{line} from mount output') % ({ line: }) end end instances diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb index 43523f3..0bf1ae5 100644 --- a/lib/puppet/type/mount.rb +++ b/lib/puppet/type/mount.rb @@ -132,7 +132,7 @@ def syncothers validate do |value| unless Facter.value(:kernel) == 'Linux' - raise Puppet::Error, _('device must not contain whitespace: %{value}') % { value: value } if %r{\s}.match?(value) + raise Puppet::Error, _('device must not contain whitespace: %{value}') % ({ value: }) if %r{\s}.match?(value) end end end @@ -159,7 +159,7 @@ def syncothers end validate do |value| - raise Puppet::Error, _('blockdevice must not contain whitespace: %{value}') % { value: value } if %r{\s}.match?(value) + raise Puppet::Error, _('blockdevice must not contain whitespace: %{value}') % ({ value: }) if %r{\s}.match?(value) end end @@ -168,7 +168,7 @@ def syncothers operating system. This is a required option." validate do |value| - raise Puppet::Error, _('fstype must not contain whitespace: %{value}') % { value: value } if %r{\s}.match?(value) + raise Puppet::Error, _('fstype must not contain whitespace: %{value}') % ({ value: }) if %r{\s}.match?(value) raise Puppet::Error, _('fstype must not be an empty string') if value.empty? end end @@ -183,7 +183,7 @@ def syncothers the list." validate do |value| - raise Puppet::Error, _('options must not contain whitespace: %{value}') % { value: value } if %r{\s}.match?(value) + raise Puppet::Error, _('options must not contain whitespace: %{value}') % ({ value: }) if %r{\s}.match?(value) raise Puppet::Error, _('options must not be an empty string') if value.empty? end end @@ -251,7 +251,7 @@ def munge(value) validate do |value| unless Facter.value(:kernel) == 'Linux' - raise Puppet::Error, _('name must not contain whitespace: %{value}') % { value: value } if %r{\s}.match?(value) + raise Puppet::Error, _('name must not contain whitespace: %{value}') % ({ value: }) if %r{\s}.match?(value) end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index ee00912..060ef14 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -17,7 +17,7 @@ def run_puppet_install_helper agent_sha = ENV['BEAKER_PUPPET_AGENT_SHA'] || ENV['PUPPET_AGENT_SHA'] if agent_sha.nil? || agent_sha.empty? - install_puppet_agent_on(hosts, options.merge(version: version)) + install_puppet_agent_on(hosts, options.merge(version:)) else # If we have a development sha, assume we're testing internally dev_builds_url = ENV['DEV_BUILDS_URL'] || 'http://builds.delivery.puppetlabs.net' diff --git a/spec/unit/type/mount_spec.rb b/spec/unit/type/mount_spec.rb index dde8c3b..a13061a 100644 --- a/spec/unit/type/mount_spec.rb +++ b/spec/unit/type/mount_spec.rb @@ -32,7 +32,7 @@ def mounted? end let :resource do - described_class.new(name: 'yay', audit: :ensure, provider: provider) + described_class.new(name: 'yay', audit: :ensure, provider:) end let :ensureprop do @@ -528,7 +528,7 @@ def test_ensure_change(options) end let :resource do - described_class.new(initial_values.merge(provider: provider)) + described_class.new(initial_values.merge(provider:)) end let :provider do @@ -577,8 +577,8 @@ def create_mount_resource(path) def create_file_resource(path) file_class = Puppet::Type.type(:file) file_class.new( - path: path, - provider: file_class.new(path: path).provider, + path:, + provider: file_class.new(path:).provider, ) end