From d98c5513664de59fe55ceba4231ca3f4b70edbab Mon Sep 17 00:00:00 2001 From: Jarret Lavallee Date: Thu, 9 Sep 2021 08:44:34 -0600 Subject: [PATCH 1/2] (SUP-2643) Add option to override version assertion Prior to this commit, there was no way to force an override to the PE version assertion. This commit adds a new parameter that will override the PE version check and output a warning when enabled. This is useful in testing new PE versions that are not yet supported by the module. --- functions/assert_supported_pe_version.pp | 10 +++++++++- plans/install.pp | 8 +++++--- plans/subplans/install.pp | 7 ++++--- plans/upgrade.pp | 9 +++++---- spec/functions/assert_supported_pe_version_spec.rb | 14 ++++++++++++++ 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/functions/assert_supported_pe_version.pp b/functions/assert_supported_pe_version.pp index 1e2ff05d..31d1b137 100644 --- a/functions/assert_supported_pe_version.pp +++ b/functions/assert_supported_pe_version.pp @@ -2,10 +2,18 @@ # @param [String] the version number to check function peadm::assert_supported_pe_version ( String $version, + Boolean $permit_unsafe_versions = false, ) >> Struct[{'supported' => Boolean}] { $oldest = '2019.7' $newest = '2021.3' - $supported = ($version =~ SemVerRange(">= ${oldest} <= ${newest}")) + $supported = (($version =~ SemVerRange(">= ${oldest} <= ${newest}")) or $permit_unsafe_versions) + + if $permit_unsafe_versions { + warning(@("WARN"/L)) + WARNING: Permitting unsafe PE versions. This is not supported or tested. + Proceeding with this action could result in a broken PE Infrastructure. + | WARN + } unless $supported { fail(@("REASON"/L)) diff --git a/plans/install.pp b/plans/install.pp index 196dd0b7..50ffa96d 100644 --- a/plans/install.pp +++ b/plans/install.pp @@ -46,12 +46,13 @@ Optional[String] $license_key_content = undef, # Other - Optional[String] $stagingdir = undef, - Enum[direct,bolthost] $download_mode = 'bolthost', + Optional[String] $stagingdir = undef, + Enum[direct,bolthost] $download_mode = 'bolthost', + Boolean $permit_unsafe_versions = false, ) { peadm::assert_supported_bolt_version() - peadm::assert_supported_pe_version($version) + peadm::assert_supported_pe_version($version, $permit_unsafe_versions) $install_result = run_plan('peadm::subplans::install', # Standard @@ -83,6 +84,7 @@ # Other stagingdir => $stagingdir, download_mode => $download_mode, + permit_unsafe_versions => $permit_unsafe_versions, ) $configure_result = run_plan('peadm::subplans::configure', diff --git a/plans/subplans/install.pp b/plans/subplans/install.pp index 8cfd975e..7ed08e3c 100644 --- a/plans/subplans/install.pp +++ b/plans/subplans/install.pp @@ -49,10 +49,11 @@ Optional[String] $license_key_content = undef, # Other - String $stagingdir = '/tmp', - Enum[direct,bolthost] $download_mode = 'bolthost', + String $stagingdir = '/tmp', + Enum[direct,bolthost] $download_mode = 'bolthost', + Boolean $permit_unsafe_versions = false, ) { - peadm::assert_supported_pe_version($version) + peadm::assert_supported_pe_version($version, $permit_unsafe_versions) # Convert inputs into targets. $primary_target = peadm::get_targets($primary_host, 1) diff --git a/plans/upgrade.pp b/plans/upgrade.pp index c8733947..f7b5fa7d 100644 --- a/plans/upgrade.pp +++ b/plans/upgrade.pp @@ -31,9 +31,10 @@ Optional[String] $internal_compiler_b_pool_address = undef, # Other - Optional[String] $token_file = undef, - String $stagingdir = '/tmp', - Enum[direct,bolthost] $download_mode = 'bolthost', + Optional[String] $token_file = undef, + String $stagingdir = '/tmp', + Enum[direct,bolthost] $download_mode = 'bolthost', + Boolean $permit_unsafe_versions = false, Optional[Enum[ 'upgrade-primary', @@ -45,7 +46,7 @@ ) { peadm::assert_supported_bolt_version() - peadm::assert_supported_pe_version($version) + peadm::assert_supported_pe_version($version, $permit_unsafe_versions) # Ensure input valid for a supported architecture $arch = peadm::assert_supported_architecture( diff --git a/spec/functions/assert_supported_pe_version_spec.rb b/spec/functions/assert_supported_pe_version_spec.rb index d2c25c63..9dd087c7 100644 --- a/spec/functions/assert_supported_pe_version_spec.rb +++ b/spec/functions/assert_supported_pe_version_spec.rb @@ -26,4 +26,18 @@ is_expected.to run.with_params('2019.8.7').and_return({ 'supported' => true }) end end + + context 'unsafe versions' do + it 'accepts PE versions that are too old' do + is_expected.to run.with_params('2018.1.0', true).and_return({ 'supported' => true }) + end + + it 'accepts PE versions that are too new' do + is_expected.to run.with_params('2035.0.0', true).and_return({ 'supported' => true }) + end + + it 'accepts PE versions that are in the supported range' do + is_expected.to run.with_params('2019.8.7', true).and_return({ 'supported' => true }) + end + end end From 275ecb47a54c86d176f292c1ce20219cb0858d21 Mon Sep 17 00:00:00 2001 From: Reid Vandewiele Date: Tue, 28 Sep 2021 21:43:35 -0700 Subject: [PATCH 2/2] Return accurate 'supported' data even when unsafe The new $permit_unsafe_versions parameter allows the assert_supported_pe_version() function to not raise on failure, but it should always return accurate data about whether or not the given version is or isn't supported. --- functions/assert_supported_pe_version.pp | 9 +++++++-- spec/functions/assert_supported_pe_version_spec.rb | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/functions/assert_supported_pe_version.pp b/functions/assert_supported_pe_version.pp index 31d1b137..1cf2b8ac 100644 --- a/functions/assert_supported_pe_version.pp +++ b/functions/assert_supported_pe_version.pp @@ -6,7 +6,7 @@ function peadm::assert_supported_pe_version ( ) >> Struct[{'supported' => Boolean}] { $oldest = '2019.7' $newest = '2021.3' - $supported = (($version =~ SemVerRange(">= ${oldest} <= ${newest}")) or $permit_unsafe_versions) + $supported = ($version =~ SemVerRange(">= ${oldest} <= ${newest}")) if $permit_unsafe_versions { warning(@("WARN"/L)) @@ -15,7 +15,12 @@ function peadm::assert_supported_pe_version ( | WARN } - unless $supported { + if (!$supported and $permit_unsafe_versions) { + warning(@("WARN"/L)) + WARNING: PE version ${version} is NOT SUPPORTED! + | WARN + } + elsif (!$supported) { fail(@("REASON"/L)) This version of the puppetlabs-peadm module does not support PE ${version}. diff --git a/spec/functions/assert_supported_pe_version_spec.rb b/spec/functions/assert_supported_pe_version_spec.rb index 9dd087c7..4394ddae 100644 --- a/spec/functions/assert_supported_pe_version_spec.rb +++ b/spec/functions/assert_supported_pe_version_spec.rb @@ -29,11 +29,11 @@ context 'unsafe versions' do it 'accepts PE versions that are too old' do - is_expected.to run.with_params('2018.1.0', true).and_return({ 'supported' => true }) + is_expected.to run.with_params('2018.1.0', true).and_return({ 'supported' => false }) end it 'accepts PE versions that are too new' do - is_expected.to run.with_params('2035.0.0', true).and_return({ 'supported' => true }) + is_expected.to run.with_params('2035.0.0', true).and_return({ 'supported' => false }) end it 'accepts PE versions that are in the supported range' do