diff --git a/lib/puppet/catalog-diff/puppetdbfactory.rb b/lib/puppet/catalog-diff/puppetdbfactory.rb new file mode 100644 index 0000000..3a4537b --- /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 = 'https://puppetdb:8081' + end + puppetdb_url + end + end +end diff --git a/lib/puppet/face/catalog/diff.rb b/lib/puppet/face/catalog/diff.rb index 2603ca0..fd19b60 100644 --- a/lib/puppet/face/catalog/diff.rb +++ b/lib/puppet/face/catalog/diff.rb @@ -1,6 +1,6 @@ require 'puppet/face' require 'json' -require 'puppet/util/puppetdb' +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'catalog-diff', 'puppetdbfactory.rb')) begin require 'parallel' @@ -13,7 +13,7 @@ action :diff do summary 'Compare catalogs from different puppet versions.' arguments ' ' - puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert] @@ -136,20 +136,22 @@ 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 diff --git a/lib/puppet/face/catalog/pull.rb b/lib/puppet/face/catalog/pull.rb index 65aa0b8..594cd1e 100644 --- a/lib/puppet/face/catalog/pull.rb +++ b/lib/puppet/face/catalog/pull.rb @@ -1,12 +1,12 @@ require 'puppet/face' require 'digest' -require 'puppet/util/puppetdb' +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' + summary 'Pull catalogs from duel puppet masters' arguments '/tmp/old_catalogs /tmp/new_catalogs' - puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + 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 6f5b09a..a278a6b 100644 --- a/lib/puppet/face/catalog/seed.rb +++ b/lib/puppet/face/catalog/seed.rb @@ -1,11 +1,11 @@ require 'puppet/face' -require 'puppet/util/puppetdb' +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' - puppetdb_url = Puppet::Util::Puppetdb.config.server_urls[0] + puppetdb_url = Puppet::CatalogDiff::Puppetdbfactory.puppetdb_url hostcert = Puppet.settings[:hostcert] hostprivkey = Puppet.settings[:hostprivkey] localcacert = Puppet.settings[:localcacert]