From 3004531e9a4b306b2a71f09370ca002e1d6a992d Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Fri, 2 May 2025 10:59:07 +0200 Subject: [PATCH 1/8] Optional --- lib/puppet/face/catalog/diff.rb | 10 ++++++++-- lib/puppet/face/catalog/pull.rb | 10 ++++++++-- lib/puppet/face/catalog/seed.rb | 10 ++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/puppet/face/catalog/diff.rb b/lib/puppet/face/catalog/diff.rb index 2603ca0..f8a015c 100644 --- a/lib/puppet/face/catalog/diff.rb +++ b/lib/puppet/face/catalog/diff.rb @@ -1,6 +1,5 @@ require 'puppet/face' require 'json' -require 'puppet/util/puppetdb' begin require 'parallel' @@ -13,7 +12,14 @@ action :diff do summary 'Compare catalogs from different puppet versions.' arguments ' ' - puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + begin + require 'puppet/util/puppetdb' + puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + rescue LoadError + # PuppetDB is not available, so we can't use it + # This is fine, we can still run the catalog diff without it + puppetdb_url = 'PuppetDB plugin is not available! Install puppetdb-termini to enable PuppetDB functionality.' + end hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert] diff --git a/lib/puppet/face/catalog/pull.rb b/lib/puppet/face/catalog/pull.rb index 65aa0b8..3d54e35 100644 --- a/lib/puppet/face/catalog/pull.rb +++ b/lib/puppet/face/catalog/pull.rb @@ -1,12 +1,18 @@ require 'puppet/face' require 'digest' -require 'puppet/util/puppetdb' Puppet::Face.define(:catalog, '0.0.1') do action :pull do description 'Pull catalogs from duel puppet masters' arguments '/tmp/old_catalogs /tmp/new_catalogs' - puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + begin + require 'puppet/util/puppetdb' + puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + rescue LoadError + # PuppetDB is not available, so we can't use it + # This is fine, we can still run the catalog diff without it + puppetdb_url = 'PuppetDB plugin is not available! Install puppetdb-termini to enable PuppetDB functionality.' + end hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert] diff --git a/lib/puppet/face/catalog/seed.rb b/lib/puppet/face/catalog/seed.rb index 6f5b09a..4f293f1 100644 --- a/lib/puppet/face/catalog/seed.rb +++ b/lib/puppet/face/catalog/seed.rb @@ -1,11 +1,17 @@ require 'puppet/face' -require 'puppet/util/puppetdb' Puppet::Face.define(:catalog, '0.0.1') do action :seed do summary 'Generate a series of catalogs' arguments ' fact=CaseSensitiveValue' - puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + begin + require 'puppet/util/puppetdb' + puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + rescue LoadError + # PuppetDB is not available, so we can't use it + # This is fine, we can still run the catalog diff without it + puppetdb_url = 'PuppetDB plugin is not available! Install puppetdb-termini to enable PuppetDB functionality.' + end hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert] From d422ad773619d797599f51db27a316621eceff1c Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Fri, 2 May 2025 12:11:34 +0200 Subject: [PATCH 2/8] Using a factory for puppetdb_url --- lib/puppet/catalog-diff/puppetdbfactory.rb | 18 ++++++++++++++++++ lib/puppet/face/catalog/diff.rb | 10 ++-------- lib/puppet/face/catalog/pull.rb | 10 ++-------- lib/puppet/face/catalog/seed.rb | 10 ++-------- 4 files changed, 24 insertions(+), 24 deletions(-) create mode 100644 lib/puppet/catalog-diff/puppetdbfactory.rb diff --git a/lib/puppet/catalog-diff/puppetdbfactory.rb b/lib/puppet/catalog-diff/puppetdbfactory.rb new file mode 100644 index 0000000..accedbc --- /dev/null +++ b/lib/puppet/catalog-diff/puppetdbfactory.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# Puppet::CatalogDiff +module Puppet::CatalogDiff + class Puppetdbfactory + def self.puppetdb_url() + begin + require 'puppet/util/puppetdb' + puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + rescue LoadError + # PuppetDB is not available, so we can't use it + # This is fine, we can still run the catalog diff without it + puppetdb_url = 'PuppetDB plugin is not available! Install puppetdb-termini to enable PuppetDB functionality.' + end + puppetdb_url + end + end +end diff --git a/lib/puppet/face/catalog/diff.rb b/lib/puppet/face/catalog/diff.rb index f8a015c..3f62461 100644 --- a/lib/puppet/face/catalog/diff.rb +++ b/lib/puppet/face/catalog/diff.rb @@ -1,5 +1,6 @@ require 'puppet/face' require 'json' +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'catalog-diff', 'puppetdbfactory.rb')) begin require 'parallel' @@ -12,14 +13,7 @@ action :diff do summary 'Compare catalogs from different puppet versions.' arguments ' ' - begin - require 'puppet/util/puppetdb' - puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] - rescue LoadError - # PuppetDB is not available, so we can't use it - # This is fine, we can still run the catalog diff without it - puppetdb_url = 'PuppetDB plugin is not available! Install puppetdb-termini to enable PuppetDB functionality.' - end + puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url() hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert] diff --git a/lib/puppet/face/catalog/pull.rb b/lib/puppet/face/catalog/pull.rb index 3d54e35..c9a6e22 100644 --- a/lib/puppet/face/catalog/pull.rb +++ b/lib/puppet/face/catalog/pull.rb @@ -1,18 +1,12 @@ require 'puppet/face' require 'digest' +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'catalog-diff', 'puppetdbfactory.rb')) Puppet::Face.define(:catalog, '0.0.1') do action :pull do description 'Pull catalogs from duel puppet masters' arguments '/tmp/old_catalogs /tmp/new_catalogs' - begin - require 'puppet/util/puppetdb' - puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] - rescue LoadError - # PuppetDB is not available, so we can't use it - # This is fine, we can still run the catalog diff without it - puppetdb_url = 'PuppetDB plugin is not available! Install puppetdb-termini to enable PuppetDB functionality.' - end + puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url() hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert] diff --git a/lib/puppet/face/catalog/seed.rb b/lib/puppet/face/catalog/seed.rb index 4f293f1..c27412e 100644 --- a/lib/puppet/face/catalog/seed.rb +++ b/lib/puppet/face/catalog/seed.rb @@ -1,17 +1,11 @@ require 'puppet/face' +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'catalog-diff', 'puppetdbfactory.rb')) Puppet::Face.define(:catalog, '0.0.1') do action :seed do summary 'Generate a series of catalogs' arguments ' fact=CaseSensitiveValue' - begin - require 'puppet/util/puppetdb' - puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] - rescue LoadError - # PuppetDB is not available, so we can't use it - # This is fine, we can still run the catalog diff without it - puppetdb_url = 'PuppetDB plugin is not available! Install puppetdb-termini to enable PuppetDB functionality.' - end + puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url() hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert] From 280b76037352a8da8de891604572f172f9745b18 Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Fri, 2 May 2025 12:56:29 +0200 Subject: [PATCH 3/8] Avoid help error pull undocumented action --- lib/puppet/face/catalog/pull.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/face/catalog/pull.rb b/lib/puppet/face/catalog/pull.rb index c9a6e22..b5652df 100644 --- a/lib/puppet/face/catalog/pull.rb +++ b/lib/puppet/face/catalog/pull.rb @@ -4,7 +4,7 @@ Puppet::Face.define(:catalog, '0.0.1') do action :pull do - description 'Pull catalogs from duel puppet masters' + summary 'Pull catalogs from duel puppet masters' arguments '/tmp/old_catalogs /tmp/new_catalogs' puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url() hostcert = Puppet.settings[:hostcert] From df0e4e97504738bf21ed68aea83064445b4e7b60 Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Fri, 2 May 2025 13:05:33 +0200 Subject: [PATCH 4/8] Add class param to puppetdbfactory to check if the lib was loaded. --- lib/puppet/catalog-diff/puppetdbfactory.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/puppet/catalog-diff/puppetdbfactory.rb b/lib/puppet/catalog-diff/puppetdbfactory.rb index accedbc..04c2b6c 100644 --- a/lib/puppet/catalog-diff/puppetdbfactory.rb +++ b/lib/puppet/catalog-diff/puppetdbfactory.rb @@ -3,16 +3,22 @@ # Puppet::CatalogDiff module Puppet::CatalogDiff class Puppetdbfactory + @@puppetdb_loaded = false def self.puppetdb_url() begin require 'puppet/util/puppetdb' + @@puppetdb_loaded = true puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] rescue LoadError # PuppetDB is not available, so we can't use it # This is fine, we can still run the catalog diff without it - puppetdb_url = 'PuppetDB plugin is not available! Install puppetdb-termini to enable PuppetDB functionality.' + puppetdb_url = 'https://puppetdb:8081' end puppetdb_url end + + def self.puppetdb_loaded?() + @@puppetdb_loaded + end end end From 8449ad493c4d2939cb7dbe0948b559489530b849 Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Fri, 2 May 2025 13:11:35 +0200 Subject: [PATCH 5/8] Fix indenting in notes --- lib/puppet/face/catalog/diff.rb | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/puppet/face/catalog/diff.rb b/lib/puppet/face/catalog/diff.rb index 3f62461..16dfb1c 100644 --- a/lib/puppet/face/catalog/diff.rb +++ b/lib/puppet/face/catalog/diff.rb @@ -136,20 +136,21 @@ Validation Process: - - Grab a catalog from your existing machine running the old version - - Configure your new Puppet master, copy the facts from your old master - to the new one - - Compile the catalog for this host on the new master: + - Grab a catalog from your existing machine running the old version + - Configure your new Puppet master, copy the facts from your old master + to the new one + - Compile the catalog for this host on the new master: - puppet master --compile fqdn > fqdn.pson + puppet master --compile fqdn > fqdn.pson - - Puppet puts a header in some catalogs compiled in this way, remove it if present - - At this point you should have 2 different catalogs. To compare them run: + - Puppet puts a header in some catalogs compiled in this way, remove it if present + - At this point you should have 2 different catalogs. To compare them run: - puppet catalog diff - - Alternatively you can process a directory containing matching files - - i.e. path/to/old/node_name.yaml and path/to/new/node_name.yaml - puppet catalog diff + puppet catalog diff + - Alternatively you can process a directory containing matching files + - i.e. path/to/old/node_name.yaml and path/to/new/node_name.yaml + + puppet catalog diff This code only validates the catalogs, it cannot tell you if the behavior of the providers that interpret the catalog has changed so testing is still From 31e2ad49b029fb131d63fe9f0461f416020ac298 Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Fri, 2 May 2025 13:15:36 +0200 Subject: [PATCH 6/8] RuboCop does NOT like class vatriables. --- lib/puppet/catalog-diff/puppetdbfactory.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/puppet/catalog-diff/puppetdbfactory.rb b/lib/puppet/catalog-diff/puppetdbfactory.rb index 04c2b6c..3a4537b 100644 --- a/lib/puppet/catalog-diff/puppetdbfactory.rb +++ b/lib/puppet/catalog-diff/puppetdbfactory.rb @@ -3,11 +3,9 @@ # Puppet::CatalogDiff module Puppet::CatalogDiff class Puppetdbfactory - @@puppetdb_loaded = false - def self.puppetdb_url() + def self.puppetdb_url begin require 'puppet/util/puppetdb' - @@puppetdb_loaded = true puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] rescue LoadError # PuppetDB is not available, so we can't use it @@ -16,9 +14,5 @@ def self.puppetdb_url() end puppetdb_url end - - def self.puppetdb_loaded?() - @@puppetdb_loaded - end end end From 85c67cb26429728cb5e3eef4e9ca0a8bbf3feb73 Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Fri, 2 May 2025 13:17:21 +0200 Subject: [PATCH 7/8] Do not use parentheses for method calls with no arguments. --- lib/puppet/face/catalog/diff.rb | 2 +- lib/puppet/face/catalog/pull.rb | 2 +- lib/puppet/face/catalog/seed.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet/face/catalog/diff.rb b/lib/puppet/face/catalog/diff.rb index 16dfb1c..d221b6f 100644 --- a/lib/puppet/face/catalog/diff.rb +++ b/lib/puppet/face/catalog/diff.rb @@ -13,7 +13,7 @@ action :diff do summary 'Compare catalogs from different puppet versions.' arguments ' ' - puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url() + puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert] diff --git a/lib/puppet/face/catalog/pull.rb b/lib/puppet/face/catalog/pull.rb index b5652df..594cd1e 100644 --- a/lib/puppet/face/catalog/pull.rb +++ b/lib/puppet/face/catalog/pull.rb @@ -6,7 +6,7 @@ action :pull do summary 'Pull catalogs from duel puppet masters' arguments '/tmp/old_catalogs /tmp/new_catalogs' - puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url() + puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert] diff --git a/lib/puppet/face/catalog/seed.rb b/lib/puppet/face/catalog/seed.rb index c27412e..a278a6b 100644 --- a/lib/puppet/face/catalog/seed.rb +++ b/lib/puppet/face/catalog/seed.rb @@ -5,7 +5,7 @@ action :seed do summary 'Generate a series of catalogs' arguments ' fact=CaseSensitiveValue' - puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url() + puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert] From c466e38f7bc1c9729bc7b37ff6b4205ab3b77873 Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Fri, 2 May 2025 13:19:38 +0200 Subject: [PATCH 8/8] Fix another doc inconsitency --- lib/puppet/face/catalog/diff.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/puppet/face/catalog/diff.rb b/lib/puppet/face/catalog/diff.rb index d221b6f..fd19b60 100644 --- a/lib/puppet/face/catalog/diff.rb +++ b/lib/puppet/face/catalog/diff.rb @@ -147,10 +147,11 @@ - At this point you should have 2 different catalogs. To compare them run: puppet catalog diff + - Alternatively you can process a directory containing matching files - i.e. path/to/old/node_name.yaml and path/to/new/node_name.yaml - puppet catalog diff + puppet catalog diff This code only validates the catalogs, it cannot tell you if the behavior of the providers that interpret the catalog has changed so testing is still