Skip to content

Commit 31cfdea

Browse files
committed
Add descriptive error messages to fail_on_transport
This commit updates the `fail_on_transport` function with an optional `message` parameter that can be used to supply an error message. The `peadm::upgrade` and `peadm::subplans::modify_certificate` plans are also updated to use this parameter to provide an explanation of why use of the "pcp" transport is resulting in a failure along with suggestions for how to configure the plans for success.
1 parent f2c2b1f commit 31cfdea

File tree

7 files changed

+59
-10
lines changed

7 files changed

+59
-10
lines changed

REFERENCE.md

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

534534
Useful for excluding PCP when it's not appopriate
535535

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

538538
Fails if any nodes have the chosen transport.
539539

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
@@ -83,7 +83,19 @@
8383

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

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

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

@@ -141,9 +153,6 @@
141153
}
142154

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

spec/functions/fail_on_transport_spec.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
end
2424

2525
it 'raises an error when nodes use the specified transport' do
26-
expect { subject.execute(nodes, 'pcp') }.to raise_error(Puppet::PreformattedError, /target\.example uses pcp transport/)
26+
expect { subject.execute(nodes, 'pcp') }.to raise_error(Puppet::PreformattedError, %r{target\.example uses pcp transport: This is not supported\.})
27+
end
28+
29+
it 'raises an error with a custom explanation if one is provided' do
30+
expect { subject.execute(nodes, 'pcp', 'It would be bad.') }.to raise_error(Puppet::PreformattedError, %r{target\.example uses pcp transport: It would be bad\.})
2731
end
2832

2933
it 'raises no error when nodes do not use the specified transport' do

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.1')).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

0 commit comments

Comments
 (0)