Skip to content

Commit 25335c4

Browse files
authored
Merge pull request #317 from Sharpie/fix-upgrades-with-pcp
Fail with guidance if peadm::util::retrieve_and_upload is used on PE XL with the PCP transport
2 parents 13d6e3f + 5f00ad7 commit 25335c4

9 files changed

+119
-13
lines changed

REFERENCE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ Fails if any nodes have the chosen transport.
531531

532532
Useful for excluding PCP when it's not appopriate
533533

534-
#### `peadm::fail_on_transport(TargetSpec $nodes, String $transport)`
534+
#### `peadm::fail_on_transport(TargetSpec $nodes, String $transport, String $message)`
535535

536536
Fails if any nodes have the chosen transport.
537537

functions/fail_on_transport.pp

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
function peadm::fail_on_transport (
66
TargetSpec $nodes,
77
String $transport,
8+
String $message = 'This is not supported.',
89
) {
910
$targets = get_targets($nodes)
1011
$targets.each |$target| {
1112
if $target.protocol == $transport {
1213
fail_plan(
13-
"${target.name} uses ${transport} transport. This is not supported",
14+
"${target.name} uses ${transport} transport: ${message}",
1415
'unexpected-transport',
1516
{
1617
'target' => $target,

plans/subplans/modify_certificate.pp

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@
1111
$target = get_target($targets)
1212
$primary_target = get_target($primary_host)
1313

14-
# This plan doesn't work to reissue the master cert over the orchestrator due
15-
# to pe-puppetserver needing to restart
1614
if ($primary_target == $target) {
17-
$primary_target.peadm::fail_on_transport('pcp')
15+
$primary_target.peadm::fail_on_transport('pcp', @(HEREDOC/n))
16+
\nThe "pcp" transport is not available for use with the Primary
17+
as peadm::subplans::modify_certificate will cause a restart of the
18+
PE Orchestration service.
19+
20+
Use the "local" transport if running this plan directly from
21+
the Primary node, or the "ssh" transport if running this
22+
plan from an external Bolt host.
23+
24+
For information on configuring transports, see:
25+
26+
https://www.puppet.com/docs/bolt/latest/bolt_transports_reference.html
27+
|-HEREDOC
1828
}
1929

2030
# Figure out some information from the existing certificate

plans/upgrade.pp

+13-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,19 @@
8282

8383
out::message('# Gathering information')
8484

85-
$primary_target.peadm::fail_on_transport('pcp')
85+
$primary_target.peadm::fail_on_transport('pcp', @(HEREDOC/n))
86+
\nThe "pcp" transport is not available for use with the Primary
87+
as peadm::upgrade will cause a restart of the
88+
PE Orchestration service.
89+
90+
Use the "local" transport if running this plan directly from
91+
the Primary node, or the "ssh" transport if running this
92+
plan from an external Bolt host.
93+
94+
For information on configuring transports, see:
95+
96+
https://www.puppet.com/docs/bolt/latest/bolt_transports_reference.html
97+
|-HEREDOC
8698

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

@@ -142,9 +154,6 @@
142154
}
143155

144156
peadm::plan_step('preparation') || {
145-
# Support for running over the orchestrator transport relies on Bolt being
146-
# executed from the primary using the local transport. For now, fail the plan
147-
# if the orchestrator is being used for the primary.
148157
if $download_mode == 'bolthost' {
149158
# Download the PE tarball on the nodes that need it
150159
run_plan('peadm::util::retrieve_and_upload', $pe_installer_targets,

plans/util/retrieve_and_upload.pp

+22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@
55
String[1] $local_path,
66
String[1] $upload_path,
77
) {
8+
$nodes.peadm::fail_on_transport('pcp', @(HEREDOC/n))
9+
\nThe "pcp" transport is not available for uploading PE installers as
10+
the ".tar.gz" file is too large to send over the PE Orchestrator
11+
as an argument to the "bolt_shim::upload" task.
12+
13+
To upgrade PE XL database nodes via PCP, use "download_mode = direct".
14+
If Puppet download servers are not reachable over the internet,
15+
upload the ".tar.gz" to an internal fileserver and use the
16+
"pe_installer_source" parameter to retrieve it.
17+
18+
For information on configuring plan parameters, see:
19+
20+
https://forge.puppet.com/modules/puppetlabs/peadm/plans
21+
22+
Or, use the "ssh" transport for database nodes so that the
23+
installer can be transferred via SCP.
24+
25+
For information on configuring transports, see:
26+
27+
https://www.puppet.com/docs/bolt/latest/bolt_transports_reference.html
28+
|-HEREDOC
29+
830
$exists = without_default_logging() || {
931
run_command("test -e '${local_path}'", 'local://localhost',
1032
_catch_errors => true,

spec/functions/fail_on_transport_spec.rb

+31-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,39 @@
33
require 'spec_helper'
44

55
describe 'peadm::fail_on_transport' do
6+
include BoltSpec::BoltContext
7+
8+
around :each do |example|
9+
in_bolt_context do
10+
example.run
11+
end
12+
end
13+
14+
# NOTE: If https://github.com/puppetlabs/bolt/issues/3184
15+
# is fixed, this will start causing a duplicate declaration
16+
# error. If that happens, delete this pre_condition.
17+
let(:pre_condition) do
18+
'type TargetSpec = Boltlib::TargetSpec'
19+
end
20+
621
let(:nodes) do
7-
'some_value_goes_here'
22+
'pcp://target.example'
823
end
9-
let(:transport) do
10-
'some_value_goes_here'
24+
25+
# Function testing depends on rspec-puppet magic in the opening describe
26+
# statement. Re-defining the subject just to give it a different name
27+
# would require duplicating rspec-puppet code, and that's a far worse sin.
28+
# rubocop:disable Rspec/NamedSubject
29+
it 'raises an error when nodes use the specified transport' do
30+
expect { subject.execute(nodes, 'pcp') }.to raise_error(Puppet::PreformattedError, %r{target\.example uses pcp transport: This is not supported\.})
31+
end
32+
33+
it 'raises an error with a custom explanation if one is provided' do
34+
expect { subject.execute(nodes, 'pcp', 'It would be bad.') }.to raise_error(Puppet::PreformattedError, %r{target\.example uses pcp transport: It would be bad\.})
1135
end
1236

13-
xit { is_expected.to run.with_params(nodes, transport).and_return('some_value') }
37+
it 'raises no error when nodes do not use the specified transport' do
38+
expect { subject.execute(nodes, 'ssh') }.not_to raise_error
39+
end
40+
# rubocop:enable Rspec/NamedSubject
1441
end

spec/plans/subplans/modify_certificate_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,18 @@
3939
expect(run_plan('peadm::subplans::modify_certificate', params)).to be_ok
4040
end
4141
end
42+
43+
context 'modifying the primary certificate' do
44+
it 'fails if the primary is using the PCP transport' do
45+
result = run_plan('peadm::subplans::modify_certificate',
46+
{ 'targets' => 'pcp://primary.example',
47+
'primary_host' => 'pcp://primary.example',
48+
'primary_certname' => 'primary.example' })
49+
50+
expect(result).not_to be_ok
51+
expect(result.value.kind).to eq('unexpected-transport')
52+
expect(result.value.msg).to match(%r{The "pcp" transport is not available for use with the Primary})
53+
end
54+
end
4255
end
4356
end

spec/plans/upgrade_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,16 @@ def allow_standard_non_returning_calls
4343
'compiler_hosts' => 'compiler',
4444
'version' => '2021.7.2')).to be_ok
4545
end
46+
47+
it 'fails if the primary uses the pcp transport' do
48+
allow_standard_non_returning_calls
49+
50+
result = run_plan('peadm::upgrade',
51+
'primary_host' => 'pcp://primary.example',
52+
'version' => '2021.7.1')
53+
54+
expect(result).not_to be_ok
55+
expect(result.value.kind).to eq('unexpected-transport')
56+
expect(result.value.msg).to match(%r{The "pcp" transport is not available for use with the Primary})
57+
end
4658
end

spec/plans/util/retrieve_and_upload_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,16 @@
4141

4242
expect(run_plan('peadm::util::retrieve_and_upload', 'nodes' => 'primary', 'source' => '/tmp/source', 'upload_path' => '/tmp/upload', 'local_path' => '/tmp/download')).to be_ok
4343
end
44+
45+
it 'fails when nodes are configured to use the pcp transport' do
46+
result = run_plan('peadm::util::retrieve_and_upload',
47+
{ 'nodes' => ['pcp://node.example'],
48+
'source' => '/tmp/source',
49+
'upload_path' => '/tmp/upload',
50+
'local_path' => '/tmp/download' })
51+
52+
expect(result).not_to be_ok
53+
expect(result.value.kind).to eq('unexpected-transport')
54+
expect(result.value.msg).to match(%r{The "pcp" transport is not available for uploading PE installers})
55+
end
4456
end

0 commit comments

Comments
 (0)