Skip to content
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

Add function to check if nodes are reachable via bolt #433

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* [`peadm::assert_supported_pe_version`](#peadm--assert_supported_pe_version): Assert that the PE version given is supported by PEAdm
* [`peadm::bolt_version`](#peadm--bolt_version)
* [`peadm::certname`](#peadm--certname): Return the certname of the given target-like input
* [`peadm::check_availability`](#peadm--check_availability): check if a group of targets are reachable for bolt
* [`peadm::check_version_and_known_hosts`](#peadm--check_version_and_known_hosts): Checks PE verison and warns about setting r10k_known_hosts
* [`peadm::convert_hash`](#peadm--convert_hash): converts two arrays into hash
* [`peadm::convert_status`](#peadm--convert_status): Transforms a value in a human readable status with or without colors
Expand Down Expand Up @@ -266,6 +267,30 @@ Variant[Target,



### <a name="peadm--check_availability"></a>`peadm::check_availability`

Type: Puppet Language

check if a group of targets are reachable for bolt

#### `peadm::check_availability(TargetSpec $targets, Boolean $output_details = true)`

The peadm::check_availability function.

Returns: `Integer` counter for unavailable nodes

##### `targets`

Data type: `TargetSpec`

list of targets that are going to be checked

##### `output_details`

Data type: `Boolean`

flag to enable/disable error output for failed nodes

### <a name="peadm--check_version_and_known_hosts"></a>`peadm::check_version_and_known_hosts`

Type: Puppet Language
Expand Down
22 changes: 22 additions & 0 deletions functions/check_availability.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# @summary check if a group of targets are reachable for bolt
#
# @param targets list of targets that are going to be checked
# @param output_details flag to enable/disable error output for failed nodes
#
# @return counter for unavailable nodes
#
# @author Tim Meusel <[email protected]>
#
function peadm::check_availability(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not peadm specific and I think other plans could benefit from it as well. But I'm not sure which module would be a good place for such a generic function. I think bolt has no generic module where we could add it? Maybe stdlib or extlib are good candidates?

TargetSpec $targets,
Boolean $output_details = true
) >> Integer {
$check_result = wait_until_available($targets, wait_time => 2, _catch_errors => true)
unless $check_result.ok {
$end_message = "${check_result.error_set.count} targets are not reachable, stopping plan"
Copy link
Contributor

@Jo-Lillie Jo-Lillie Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bastelfreak I was chatting to our Docs and he has suggested this change for the messaging;
Bolt cannot reach the following targets: [email protected], [email protected]
<installation conversion upgrade> cannot be continued
Exiting

Is it possible to update it like this?

fail_plan($end_message, 'peadm/unreachable-nodes', error_set => $check_result.error_set)
}

return $check_result.error_set.count
}
1 change: 1 addition & 0 deletions plans/convert.pp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
)

out::message('# Gathering information')
peadm::check_availability($all_targets)

# Get trusted fact information for all compilers. Use peadm::certname() as
# the hash key because the apply block below will break trying to parse the
Expand Down
9 changes: 9 additions & 0 deletions plans/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@
) {
peadm::assert_supported_bolt_version()

out::message('# Gathering information')
$all_targets = peadm::flatten_compact([
$primary_host,
$replica_host,
$replica_postgresql_host,
$compiler_hosts,
$primary_postgresql_host,
])
peadm::check_availability($all_targets)
peadm::assert_supported_pe_version($version, $permit_unsafe_versions)

$install_result = run_plan('peadm::subplans::install',
Expand Down
1 change: 1 addition & 0 deletions plans/upgrade.pp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
])

out::message('# Gathering information')
peadm::check_availability($all_targets)

# lint:ignore:strict_indent
$primary_target.peadm::fail_on_transport('pcp', @(HEREDOC/n))
Expand Down
1 change: 1 addition & 0 deletions spec/plans/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

describe 'basic functionality' do
it 'runs successfully with the minimum required parameters' do
allow_out_message
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is missing:

expect_plan('peadm::check_availability')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bastelfreak this too

expect_plan('peadm::subplans::install')
expect_plan('peadm::subplans::configure')
expect(run_plan('peadm::install', 'primary_host' => 'primary', 'console_password' => 'puppetlabs', 'version' => '2021.7.7')).to be_ok
Expand Down
Loading