Skip to content

Commit 727d670

Browse files
committed
Make $pe_installer_source more flexible
This makes the peadm::install plan more flexible. Previously the variable $pe_installer_source could point to an absolute URL directly to the desired .tar.gz. Now it can also point to a web directory. Then peadm will calculate the .tar.gz name and fetch it from the web directory. This applies for the peadm::upgrade and peadm::install plan.
1 parent 4d54a13 commit 727d670

File tree

7 files changed

+167
-41
lines changed

7 files changed

+167
-41
lines changed

REFERENCE.md

+49-11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* [`peadm::migration_opts_default`](#peadm--migration_opts_default)
3535
* [`peadm::node_manager_yaml_location`](#peadm--node_manager_yaml_location)
3636
* [`peadm::oid`](#peadm--oid)
37+
* [`peadm::pe_installer_source`](#peadm--pe_installer_source): calculates the PE installer URL and archive name
3738
* [`peadm::plan_step`](#peadm--plan_step)
3839
* [`peadm::recovery_opts_all`](#peadm--recovery_opts_all)
3940
* [`peadm::recovery_opts_default`](#peadm--recovery_opts_default)
@@ -805,6 +806,40 @@ Data type: `String`
805806

806807

807808

809+
### <a name="peadm--pe_installer_source"></a>`peadm::pe_installer_source`
810+
811+
Type: Puppet Language
812+
813+
calculates the PE installer URL and archive name
814+
815+
#### `peadm::pe_installer_source(Optional[String[1]] $pe_installer_source = undef, Optional[Peadm::Pe_version] $version = undef, Optional[String[1]] $platform = undef)`
816+
817+
The peadm::pe_installer_source function.
818+
819+
Returns: `Hash[String[1],String[1]]`
820+
821+
##### `pe_installer_source`
822+
823+
Data type: `Optional[String[1]]`
824+
825+
The URL to download the Puppet Enterprise installer media from. If not
826+
specified, PEAdm will attempt to download PE installation media from its
827+
standard public source. When specified, PEAdm will download directly from the
828+
URL given. Can be an URL, that ends with a /, to a web directory that
829+
contains the original archives or an absolute URL to the .tar.gz archive.
830+
831+
##### `version`
832+
833+
Data type: `Optional[Peadm::Pe_version]`
834+
835+
The desired version for PE. This is optional for custom provided absolute URLs.
836+
837+
##### `platform`
838+
839+
Data type: `Optional[String[1]]`
840+
841+
The platform we're on, for example el-9-x86_64 (osfamily short name - version - arch)
842+
808843
### <a name="peadm--plan_step"></a>`peadm::plan_step`
809844

810845
Type: Ruby 4.x API
@@ -1862,7 +1897,8 @@ Data type: `Optional[String]`
18621897
The URL to download the Puppet Enterprise installer media from. If not
18631898
specified, PEAdm will attempt to download PE installation media from its
18641899
standard public source. When specified, PEAdm will download directly from the
1865-
URL given.
1900+
URL given. Can be an URL, that ends with a /, to a web directory that
1901+
contains the original archives or an absolute URL to the .tar.gz archive.
18661902

18671903
Default value: `undef`
18681904

@@ -2277,12 +2313,12 @@ The following parameters are available in the `peadm::upgrade` plan:
22772313
* [`r10k_known_hosts`](#-peadm--upgrade--r10k_known_hosts)
22782314
* [`stagingdir`](#-peadm--upgrade--stagingdir)
22792315
* [`uploaddir`](#-peadm--upgrade--uploaddir)
2316+
* [`version`](#-peadm--upgrade--version)
22802317
* [`primary_host`](#-peadm--upgrade--primary_host)
22812318
* [`replica_host`](#-peadm--upgrade--replica_host)
22822319
* [`compiler_hosts`](#-peadm--upgrade--compiler_hosts)
22832320
* [`primary_postgresql_host`](#-peadm--upgrade--primary_postgresql_host)
22842321
* [`replica_postgresql_host`](#-peadm--upgrade--replica_postgresql_host)
2285-
* [`version`](#-peadm--upgrade--version)
22862322
* [`token_file`](#-peadm--upgrade--token_file)
22872323
* [`download_mode`](#-peadm--upgrade--download_mode)
22882324
* [`permit_unsafe_versions`](#-peadm--upgrade--permit_unsafe_versions)
@@ -2324,7 +2360,9 @@ Data type: `Optional[String]`
23242360
The URL to download the Puppet Enterprise installer media from. If not
23252361
specified, PEAdm will attempt to download PE installation media from its
23262362
standard public source. When specified, PEAdm will download directly from the
2327-
URL given.
2363+
URL given. Can be an URL, that ends with a /, to a web directory that
2364+
contains the original archives or an absolute URL to the .tar.gz archive.
2365+
If it's an URL ending with the archive name, you don't need to set $version.
23282366

23292367
Default value: `undef`
23302368

@@ -2366,6 +2404,14 @@ for offline usage.
23662404

23672405
Default value: `'/tmp'`
23682406

2407+
##### <a name="-peadm--upgrade--version"></a>`version`
2408+
2409+
Data type: `Optional[Peadm::Pe_version]`
2410+
2411+
The desired version for PE. This is optional for custom provided absolute URLs.
2412+
2413+
Default value: `undef`
2414+
23692415
##### <a name="-peadm--upgrade--primary_host"></a>`primary_host`
23702416

23712417
Data type: `Peadm::SingleTargetSpec`
@@ -2402,14 +2448,6 @@ Data type: `Optional[Peadm::SingleTargetSpec]`
24022448

24032449

24042450

2405-
Default value: `undef`
2406-
2407-
##### <a name="-peadm--upgrade--version"></a>`version`
2408-
2409-
Data type: `Optional[Peadm::Pe_version]`
2410-
2411-
2412-
24132451
Default value: `undef`
24142452

24152453
##### <a name="-peadm--upgrade--token_file"></a>`token_file`

functions/pe_installer_source.pp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# @summary calculates the PE installer URL and archive name
3+
#
4+
# @param pe_installer_source
5+
# The URL to download the Puppet Enterprise installer media from. If not
6+
# specified, PEAdm will attempt to download PE installation media from its
7+
# standard public source. When specified, PEAdm will download directly from the
8+
# URL given. Can be an URL, that ends with a /, to a web directory that
9+
# contains the original archives or an absolute URL to the .tar.gz archive.
10+
#
11+
# @param version
12+
# The desired version for PE. This is optional for custom provided absolute URLs.
13+
#
14+
# @param platform
15+
# The platform we're on, for example el-9-x86_64 (osfamily short name - version - arch)
16+
#
17+
# @author Tim Meusel <[email protected]>
18+
#
19+
function peadm::pe_installer_source (
20+
Optional[String[1]] $pe_installer_source = undef,
21+
Optional[Peadm::Pe_version] $version = undef,
22+
Optional[String[1]] $platform = undef,
23+
) >> Hash[String[1],String[1]] {
24+
if $pe_installer_source {
25+
# custom URL ends with /, so we assume it's a webdir with the original installer
26+
if $pe_installer_source[-1] == '/' {
27+
assert_type(Peadm::Pe_version, $version)
28+
assert_type(String[1], $platform)
29+
$_version = $version
30+
$pe_tarball_name = "puppet-enterprise-${version}-${platform}.tar.gz"
31+
$pe_tarball_source = "${pe_installer_source}${pe_tarball_name}"
32+
} else {
33+
$pe_tarball_name = $pe_installer_source.split('/')[-1]
34+
$pe_tarball_source = $pe_installer_source
35+
$_version = $pe_tarball_name.split('-')[2]
36+
}
37+
$data = { 'url' => $pe_tarball_source, 'filename' => $pe_tarball_name, 'version' => pick($_version,$version), }
38+
} else {
39+
assert_type(Peadm::Pe_version, $version)
40+
assert_type(String[1], $platform)
41+
$pe_tarball_name = "puppet-enterprise-${version}-${platform}.tar.gz"
42+
$pe_tarball_source = "https://s3.amazonaws.com/pe-builds/released/${version}/${pe_tarball_name}"
43+
$data = { 'url' => $pe_tarball_source, 'filename' => $pe_tarball_name, 'version' => $version }
44+
}
45+
$data
46+
}

plans/install.pp

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
# The URL to download the Puppet Enterprise installer media from. If not
1616
# specified, PEAdm will attempt to download PE installation media from its
1717
# standard public source. When specified, PEAdm will download directly from the
18-
# URL given.
18+
# URL given. Can be an URL, that ends with a /, to a web directory that
19+
# contains the original archives or an absolute URL to the .tar.gz archive.
1920
# @param ldap_config
2021
# If specified, configures PE RBAC DS with the supplied configuration hash.
2122
# The parameter should be set to a valid set of connection settings as

plans/subplans/install.pp

+7-12
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
# The URL to download the Puppet Enterprise installer media from. If not
3333
# specified, PEAdm will attempt to download PE installation media from its
3434
# standard public source. When specified, PEAdm will download directly from the
35-
# URL given.
35+
# URL given. Can be an URL, that ends with a /, to a web directory that
36+
# contains the original archives or an absolute URL to the .tar.gz archive.
3637
#
3738
plan peadm::subplans::install (
3839
# Standard
@@ -228,27 +229,21 @@
228229
)
229230
}
230231

231-
if $pe_installer_source {
232-
$pe_tarball_name = $pe_installer_source.split('/')[-1]
233-
$pe_tarball_source = $pe_installer_source
234-
} else {
235-
$pe_tarball_name = "puppet-enterprise-${version}-${platform}.tar.gz"
236-
$pe_tarball_source = "https://s3.amazonaws.com/pe-builds/released/${version}/${pe_tarball_name}"
237-
}
232+
$pe_installer = peadm::pe_installer_source($pe_installer_source, $version, $platform)
238233

239-
$upload_tarball_path = "${uploaddir}/${pe_tarball_name}"
234+
$upload_tarball_path = "${uploaddir}/${pe_installer['filename']}"
240235

241236
if $download_mode == 'bolthost' {
242237
# Download the PE tarball and send it to the nodes that need it
243238
run_plan('peadm::util::retrieve_and_upload', $pe_installer_targets,
244-
source => $pe_tarball_source,
245-
local_path => "${stagingdir}/${pe_tarball_name}",
239+
source => $pe_installer['url'],
240+
local_path => "${stagingdir}/${pe_installer['filename']}",
246241
upload_path => $upload_tarball_path,
247242
)
248243
} else {
249244
# Download PE tarballs directly to nodes that need it
250245
run_task('peadm::download', $pe_installer_targets,
251-
source => $pe_tarball_source,
246+
source => $pe_installer['url'],
252247
path => $upload_tarball_path,
253248
)
254249
}

plans/upgrade.pp

+12-16
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
# The URL to download the Puppet Enterprise installer media from. If not
1616
# specified, PEAdm will attempt to download PE installation media from its
1717
# standard public source. When specified, PEAdm will download directly from the
18-
# URL given.
18+
# URL given. Can be an URL, that ends with a /, to a web directory that
19+
# contains the original archives or an absolute URL to the .tar.gz archive.
20+
# If it's an URL ending with the archive name, you don't need to set $version.
1921
# @param final_agent_state
2022
# Configures the state the puppet agent should be in on infrastructure nodes
2123
# after PE is upgraded successfully.
@@ -30,6 +32,8 @@
3032
# @param uploaddir
3133
# Directory the installer tarball will be uploaded to or expected to be in
3234
# for offline usage.
35+
# @param version
36+
# The desired version for PE. This is optional for custom provided absolute URLs.
3337
#
3438
plan peadm::upgrade (
3539
# Standard
@@ -117,21 +121,13 @@
117121

118122
$platform = run_task('peadm::precheck', $primary_target).first['platform']
119123

120-
if $pe_installer_source {
121-
$pe_tarball_name = $pe_installer_source.split('/')[-1]
122-
$pe_tarball_source = $pe_installer_source
123-
$_version = $pe_tarball_name.split('-')[2]
124-
} else {
125-
$_version = $version
126-
$pe_tarball_name = "puppet-enterprise-${_version}-${platform}.tar.gz"
127-
$pe_tarball_source = "https://s3.amazonaws.com/pe-builds/released/${_version}/${pe_tarball_name}"
128-
}
124+
$pe_installer = peadm::pe_installer_source($pe_installer_source, $version, $platform)
129125

130-
$upload_tarball_path = "${uploaddir}/${pe_tarball_name}"
126+
$upload_tarball_path = "${uploaddir}/${pe_installer['filename']}"
131127

132128
peadm::assert_supported_bolt_version()
133129

134-
peadm::assert_supported_pe_version($_version, $permit_unsafe_versions)
130+
peadm::assert_supported_pe_version($pe_installer['version'], $permit_unsafe_versions)
135131

136132
# Gather certificate extension information from all systems
137133
$cert_extensions = run_task('peadm::cert_data', $all_targets).reduce({}) |$memo,$result| {
@@ -176,14 +172,14 @@
176172
if $download_mode == 'bolthost' {
177173
# Download the PE tarball on the nodes that need it
178174
run_plan('peadm::util::retrieve_and_upload', $pe_installer_targets,
179-
source => $pe_tarball_source,
180-
local_path => "${stagingdir}/${pe_tarball_name}",
175+
source => $pe_installer['url'],
176+
local_path => "${stagingdir}/${pe_installer['filename']}",
181177
upload_path => $upload_tarball_path,
182178
)
183179
} else {
184180
# Download PE tarballs directly to nodes that need it
185181
run_task('peadm::download', $pe_installer_targets,
186-
source => $pe_tarball_source,
182+
source => $pe_installer['url'],
187183
path => $upload_tarball_path,
188184
)
189185
}
@@ -418,7 +414,7 @@
418414
)
419415
}
420416

421-
peadm::check_version_and_known_hosts($current_pe_version, $_version, $r10k_known_hosts)
417+
peadm::check_version_and_known_hosts($current_pe_version, $pe_installer['version'], $r10k_known_hosts)
422418

423419
return("Upgrade of Puppet Enterprise ${arch['architecture']} completed.")
424420
}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'peadm::pe_installer_source' do
6+
it 'exists' do
7+
is_expected.not_to be_nil
8+
end
9+
10+
context 'when called with no parameters' do
11+
it { is_expected.to run.with_params.and_raise_error(Puppet::PreformattedError) }
12+
end
13+
context 'when called with absolute url and version' do
14+
result = {
15+
'url' => 'https://url/puppet-enterprise-2019.8.12-el-8-x86_64.tar.gz',
16+
'filename' => 'puppet-enterprise-2019.8.12-el-8-x86_64.tar.gz',
17+
'version' => '2019.8.12'
18+
}
19+
it { is_expected.to run.with_params('https://url/puppet-enterprise-2019.8.12-el-8-x86_64.tar.gz', '2019.8.12').and_return(result) }
20+
end
21+
context 'when called with absolute url' do
22+
result = {
23+
'url' => 'https://url/puppet-enterprise-2019.8.12-el-8-x86_64.tar.gz',
24+
'filename' => 'puppet-enterprise-2019.8.12-el-8-x86_64.tar.gz',
25+
'version' => '2019.8.12'
26+
}
27+
it { is_expected.to run.with_params('https://url/puppet-enterprise-2019.8.12-el-8-x86_64.tar.gz').and_return(result) }
28+
end
29+
context 'when called with url and version and platform' do
30+
result = {
31+
'url' => 'https://url/puppet-enterprise-2019.8.12-el-8-x86_64.tar.gz',
32+
'filename' => 'puppet-enterprise-2019.8.12-el-8-x86_64.tar.gz',
33+
'version' => '2019.8.12'
34+
}
35+
it { is_expected.to run.with_params('https://url/', '2019.8.12', 'el-8-x86_64').and_return(result) }
36+
end
37+
context 'when called without url and with version and platform' do
38+
result = {
39+
'url' => 'https://s3.amazonaws.com/pe-builds/released/2019.8.12/puppet-enterprise-2019.8.12-el-8-x86_64.tar.gz',
40+
'filename' => 'puppet-enterprise-2019.8.12-el-8-x86_64.tar.gz',
41+
'version' => '2019.8.12'
42+
}
43+
it do
44+
is_expected.to run.with_params(nil, '2019.8.12', 'el-8-x86_64').and_return(result)
45+
end
46+
end
47+
end

spec/plans/upgrade_spec.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def allow_standard_non_returning_calls
2828
.always_return({ 'content' => '2021.7.3' })
2929

3030
expect_task('peadm::cert_data').return_for_targets('primary' => trusted_primary)
31-
31+
allow_task('peadm::precheck').return_for_targets('primary' => { 'hostname' => 'primary', 'platform' => 'el-7.11-x86_64' })
3232
expect(run_plan('peadm::upgrade',
3333
'primary_host' => 'primary',
3434
'version' => '2021.7.8')).to be_ok
@@ -43,6 +43,7 @@ def allow_standard_non_returning_calls
4343

4444
expect_task('peadm::cert_data').return_for_targets('primary' => trusted_primary,
4545
'compiler' => trusted_compiler)
46+
allow_task('peadm::precheck').return_for_targets('primary' => { 'hostname' => 'primary', 'platform' => 'el-7.11-x86_64' })
4647

4748
expect(run_plan('peadm::upgrade',
4849
'primary_host' => 'primary',
@@ -92,6 +93,8 @@ def allow_standard_non_returning_calls
9293
.always_return({ 'content' => installed_version })
9394

9495
expect_task('peadm::cert_data').return_for_targets('primary' => trusted_primary)
96+
97+
allow_task('peadm::precheck').return_for_targets('primary' => { 'hostname' => 'primary', 'platform' => 'el-7.11-x86_64' })
9598
end
9699

97100
it 'updates pe.conf if r10k_known_hosts is set' do

0 commit comments

Comments
 (0)