From 2b769eea5914c5918c82f1f5e939461fcba85bab Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Wed, 9 Apr 2025 11:43:59 +0200 Subject: [PATCH 1/5] network definition: move virtualport in the xml template --- templates/network/generic.xml.epp | 2 +- templates/network/simple.xml.erb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/network/generic.xml.epp b/templates/network/generic.xml.epp index 6583148..792b0dd 100644 --- a/templates/network/generic.xml.epp +++ b/templates/network/generic.xml.epp @@ -35,8 +35,8 @@ <%- %><%= epp('libvirt/network/sub-element.xml.epp', { 'name' => 'bandwith', 'attrs' => $bandwith, 'tree' => $tree['bandwith'] }) -%> <%- %><%= epp('libvirt/network/sub-element.xml.epp', { 'name' => 'vlan', 'attrs' => $vlan, 'tree' => $tree['vlan'] }) -%> <%- %><%= epp('libvirt/network/sub-element.xml.epp', { 'name' => 'port', 'attrs' => $port, 'tree' => $tree['port'] }) -%> - <%- %><%= epp('libvirt/network/sub-element.xml.epp', { 'name' => 'virtualport', 'attrs' => $virtualport, 'tree' => $tree['virtualport'] }) -%> <%- %><%= epp('libvirt/network/sub-element.xml.epp', { 'name' => 'portgroup', 'attrs' => $portgroups, 'tree' => $tree['portgroup'] }) -%> + <%- %><%= epp('libvirt/network/sub-element.xml.epp', { 'name' => 'virtualport', 'attrs' => $virtualport, 'tree' => $tree['virtualport'] }) -%> <%- %><%= epp('libvirt/network/sub-element.xml.epp', { 'name' => 'ip', 'attrs' => $ips, 'tree' => $tree['ip'] }) -%> <%- %><%= epp('libvirt/network/sub-element.xml.epp', { 'name' => 'route', 'attrs' => $routes, 'tree' => $tree['route'] }) -%> <%- %><%= epp('libvirt/network/sub-element.xml.epp', { 'name' => 'dns', 'attrs' => $dns, 'tree' => $tree['dns'] }) -%> diff --git a/templates/network/simple.xml.erb b/templates/network/simple.xml.erb index 5d6b340..384f307 100644 --- a/templates/network/simple.xml.erb +++ b/templates/network/simple.xml.erb @@ -27,9 +27,6 @@ <%- if @dns_enable -%> <%- end -%> - <%- if @virtualport_type -%> - - <%- end -%> <%- @portgroups.each do |pg| -%> '> <%- if pg['trunk'] -%> @@ -45,4 +42,7 @@ <%- end -%> <%- end -%> + <%- if @virtualport_type -%> + + <%- end -%> From 9c79634bdaa7cd566c28e8819146212a50c4b810 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Wed, 9 Apr 2025 11:46:04 +0200 Subject: [PATCH 2/5] libvirt_network type: remove unused diff functions with the implementation of proper diffs (see #75), these to functions are not necessary anymore. --- lib/puppet/type/libvirt_network.rb | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/lib/puppet/type/libvirt_network.rb b/lib/puppet/type/libvirt_network.rb index 57a0c99..14f264e 100644 --- a/lib/puppet/type/libvirt_network.rb +++ b/lib/puppet/type/libvirt_network.rb @@ -61,21 +61,5 @@ def change_to_s(current, desire) '{md5}' + Digest::MD5.hexdigest(current.to_s) + ' to: ' + '{md5}' + Digest::MD5.hexdigest(desire.to_s) end end - - def should_to_s(value) - if @resource[:show_diff] - ":\n" + value + "\n" - else - '{md5}' + Digest::MD5.hexdigest(value.to_s) - end - end - - def is_to_s(value) # rubocop:disable Naming/PredicateName - if @resource[:show_diff] - ":\n" + value + "\n" - else - '{md5}' + Digest::MD5.hexdigest(value.to_s) - end - end end end From 70c6846e259f11d00f2c4db9ad8ed9c519a23717 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Wed, 9 Apr 2025 11:51:40 +0200 Subject: [PATCH 3/5] Revert partly "human readable diff in case of changes; correct sort for portgroups inside XML" This partly reverts commit 4c559086bde670435a1fd83ba9acfecf2d93f54a (#75). The part 'human readable diff' is kept, the part 'correct sort...' is reverted. Fixing the sort in the provider only is the wrong approach. This module uses the function defined in lib/puppet_x/libvirt/sort_elements.rb to have equal XML's to compare. The sort_elements function is used in the provider to ensure sorting of the 'is' part. The 'should' part is sorted using the function libirt::normalxml on the template XML output. See Bug #85 --- lib/puppet/provider/libvirt_network/virsh.rb | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/puppet/provider/libvirt_network/virsh.rb b/lib/puppet/provider/libvirt_network/virsh.rb index e4c0e81..957865a 100644 --- a/lib/puppet/provider/libvirt_network/virsh.rb +++ b/lib/puppet/provider/libvirt_network/virsh.rb @@ -99,16 +99,7 @@ def content formatter = REXML::Formatters::Pretty.new(2) formatter.compact = true output = ''.dup - - xml = recursive_sort(xml.root) - sorted_portgroups = xml.root.get_elements('//portgroup').sort_by { |obj| obj.attributes['name'] } - - REXML::XPath.match(xml, '//portgroup').each(&:remove) - sorted_portgroups.each do |pg| - xml.root.add_element pg - end - - formatter.write(xml.root, output) + formatter.write(recursive_sort(xml.root), output) output end From f87f4c06ac66f49291a50d5349c9112cd6f9fef9 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Wed, 9 Apr 2025 12:23:25 +0200 Subject: [PATCH 4/5] update pdk --- .puppet-lint.rc | 8 ++++++++ .sync.yml | 9 --------- Gemfile | 34 +++++++++++++++++++--------------- Rakefile | 8 ++++++++ metadata.json | 6 +++--- 5 files changed, 38 insertions(+), 27 deletions(-) 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/.sync.yml b/.sync.yml index f2884e6..3e5a628 100644 --- a/.sync.yml +++ b/.sync.yml @@ -6,12 +6,3 @@ spec/spec_helper.rb: hiera_config: 'spec/fixtures/hiera.yaml' coverage_report: true mock_with: ':rspec' - -Gemfile: - required: - ':development': - - gem: 'puppet-blacksmith' - - gem: 'github_changelog_generator' -# - gem: 'rexml' -# version: '~> 3.2' -# condition: "Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3')" diff --git a/Gemfile b/Gemfile index dddd5a4..1b5b9ed 100644 --- a/Gemfile +++ b/Gemfile @@ -22,9 +22,12 @@ group :development do 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 + 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 "rspec-puppet-facts", '~> 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 @@ -34,13 +37,11 @@ group :development do 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 "rexml", '>= 3.0.0', '< 3.2.7', require: false - gem "puppet-blacksmith", require: false - gem "github_changelog_generator", 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", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] @@ -48,18 +49,21 @@ group :system_tests do gem "serverspec", '~> 2.41', require: false end -puppet_version = ENV['PUPPET_GEM_VERSION'] -facter_version = ENV['FACTER_GEM_VERSION'] -hiera_version = ENV['HIERA_GEM_VERSION'] - gems = {} +puppet_version = ENV.fetch('PUPPET_GEM_VERSION', nil) +facter_version = ENV.fetch('FACTER_GEM_VERSION', nil) +hiera_version = ENV.fetch('HIERA_GEM_VERSION', nil) -gems['puppet'] = location_for(puppet_version) - -# If facter or hiera versions have been specified via the environment -# variables +# 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['facter'] = location_for(facter_version) if facter_version gems['hiera'] = location_for(hiera_version) if hiera_version gems.each do |gem_name, gem_params| diff --git a/Rakefile b/Rakefile index caa4e30..31b5930 100644 --- a/Rakefile +++ b/Rakefile @@ -7,4 +7,12 @@ require 'puppet-syntax/tasks/puppet-syntax' require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' 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 848df42..a24d8f2 100644 --- a/metadata.json +++ b/metadata.json @@ -70,7 +70,7 @@ "drbd", "virtualization" ], - "pdk-version": "3.3.0", - "template-url": "pdk-default#3.3.0", - "template-ref": "tags/3.3.0-0-g5d17ec1" + "pdk-version": "3.4.0", + "template-url": "https://github.com/puppetlabs/pdk-templates#main", + "template-ref": "heads/main-0-g1a55f8d" } From 1a4eab668f631b34af996bbd6485bec4b42abf94 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Wed, 9 Apr 2025 13:35:29 +0200 Subject: [PATCH 5/5] fix space in alignment --- manifests/nwfilter.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/nwfilter.pp b/manifests/nwfilter.pp index 9f6d8f9..08cbb13 100644 --- a/manifests/nwfilter.pp +++ b/manifests/nwfilter.pp @@ -76,7 +76,7 @@ if $ensure == 'absent' { libvirt_nwfilter { $title: - ensure => 'absent', + ensure => 'absent', } } else { if $template == 'simple' {