Skip to content

Add development and testing option to permit installing unsupported PE versions #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion functions/assert_supported_pe_version.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@
# @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}"))

unless $supported {
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
}

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}.

Expand Down
8 changes: 5 additions & 3 deletions plans/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,6 +84,7 @@
# Other
stagingdir => $stagingdir,
download_mode => $download_mode,
permit_unsafe_versions => $permit_unsafe_versions,
)

$configure_result = run_plan('peadm::subplans::configure',
Expand Down
7 changes: 4 additions & 3 deletions plans/subplans/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions plans/upgrade.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions spec/functions/assert_supported_pe_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' => false })
end

it 'accepts PE versions that are too new' do
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
is_expected.to run.with_params('2019.8.7', true).and_return({ 'supported' => true })
end
end
end