Skip to content

Commit ae080f1

Browse files
committed
Add function to check if nodes are reachable via bolt
At the moment the plans assume that all nodes are available. I had a few customer setups where one of the compilers wasn't reachable during a convert/upgrade. To not put the PE infra into an undefined state, it makes sense to check the availability before running the plans.
1 parent a99cb66 commit ae080f1

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

REFERENCE.md

+25
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* [`peadm::assert_supported_pe_version`](#peadm--assert_supported_pe_version): Assert that the PE version given is supported by PEAdm
2121
* [`peadm::bolt_version`](#peadm--bolt_version)
2222
* [`peadm::certname`](#peadm--certname): Return the certname of the given target-like input
23+
* [`peadm::check_availability`](#peadm--check_availability): check if a group of targets are reachable for bolt
2324
* [`peadm::check_version_and_known_hosts`](#peadm--check_version_and_known_hosts): Checks PE verison and warns about setting r10k_known_hosts
2425
* [`peadm::convert_hash`](#peadm--convert_hash): converts two arrays into hash
2526
* [`peadm::convert_status`](#peadm--convert_status): Transforms a value in a human readable status with or without colors
@@ -266,6 +267,30 @@ Variant[Target,
266267

267268

268269

270+
### <a name="peadm--check_availability"></a>`peadm::check_availability`
271+
272+
Type: Puppet Language
273+
274+
check if a group of targets are reachable for bolt
275+
276+
#### `peadm::check_availability(TargetSpec $targets, Boolean $output_details = true)`
277+
278+
The peadm::check_availability function.
279+
280+
Returns: `Integer` counter for unavailable nodes
281+
282+
##### `targets`
283+
284+
Data type: `TargetSpec`
285+
286+
list of targets that are going to be checked
287+
288+
##### `output_details`
289+
290+
Data type: `Boolean`
291+
292+
flag to enable/disable error output for failed nodes
293+
269294
### <a name="peadm--check_version_and_known_hosts"></a>`peadm::check_version_and_known_hosts`
270295

271296
Type: Puppet Language

functions/check_availability.pp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# @summary check if a group of targets are reachable for bolt
3+
#
4+
# @param targets list of targets that are going to be checked
5+
# @param output_details flag to enable/disable error output for failed nodes
6+
#
7+
# @return counter for unavailable nodes
8+
#
9+
# @author Tim Meusel <[email protected]>
10+
#
11+
function peadm::check_availability(TargetSpec $targets, Boolean $output_details = true) >> Integer {
12+
$check_result = wait_until_available($targets, wait_time => 2, _catch_errors => true)
13+
if $check_result.ok {
14+
} elsif $output_details {
15+
$check_result.error_set.each |$result| {
16+
out::message("## node ${result.target} has connection error '${result.error.kind}' with message '${result.error.msg}'")
17+
}
18+
}
19+
20+
return $check_result.error_set.count
21+
}

plans/convert.pp

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
)
5757

5858
out::message('# Gathering information')
59+
$failed_node_counter = peadm::check_availability($pe_installer_targets)
60+
if $failed_node_counter > 0 {
61+
fail("# Stopping peadm::convert because ${$failed_node_counter} nodes aren't available")
62+
} else {
63+
out::message('# All nodes are reachable, continuing with peadm::convert')
64+
}
5965

6066
# Get trusted fact information for all compilers. Use peadm::certname() as
6167
# the hash key because the apply block below will break trying to parse the

plans/install.pp

+7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@
7676
) {
7777
peadm::assert_supported_bolt_version()
7878

79+
out::message('# Gathering information')
7980
peadm::assert_supported_pe_version($version, $permit_unsafe_versions)
81+
$failed_node_counter = peadm::check_availability($pe_installer_targets)
82+
if $failed_node_counter > 0 {
83+
fail("# Stopping peadm::upgrade because ${$failed_node_counter} nodes aren't available")
84+
} else {
85+
out::message('# All nodes are reachable, continuing with peadm::install')
86+
}
8087

8188
$install_result = run_plan('peadm::subplans::install',
8289
# Standard

plans/upgrade.pp

+6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@
9898
])
9999

100100
out::message('# Gathering information')
101+
$failed_node_counter = peadm::check_availability($pe_installer_targets)
102+
if $failed_node_counter > 0 {
103+
fail("# Stopping peadm::upgrade because ${$failed_node_counter} nodes aren't available")
104+
} else {
105+
out::message('# All nodes are reachable, continuing with peadm::upgrade')
106+
}
101107

102108
# lint:ignore:strict_indent
103109
$primary_target.peadm::fail_on_transport('pcp', @(HEREDOC/n))

0 commit comments

Comments
 (0)