Skip to content

Commit c0f3750

Browse files
(PE-42079) Add timeout for puppet run on db targets
1 parent 94cf2ac commit c0f3750

File tree

5 files changed

+75
-15
lines changed

5 files changed

+75
-15
lines changed

.github/workflows/test-upgrade-matrix.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ jobs:
4444
exclude:
4545
- version: 2021.7.9
4646
version_to_upgrade: 2021.7.9
47+
- version: 2021.7.9
48+
version_to_upgrade: 2025.6.0
4749
- version: 2023.8.6
4850
version_to_upgrade: 2021.7.9
4951
- version: 2023.8.6

Gemfile

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ group :development do
3838
gem "rubocop-factory_bot", '~> 2.27.1', require: false
3939
gem "rubocop-capybara", '~> 2.22.1', require: false
4040
gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]
41-
#gem "bolt", '>= 4.0.0', require: false
41+
gem "bolt", '>= 4.0.0', require: false
4242
gem "github_changelog_generator", '1.16.4', require: false
4343
gem "octokit", '4.21.0', require: false
4444
gem "orchestrator_client", '< 0.7.1', require: false
@@ -55,24 +55,14 @@ end
5555
puppet_version = ENV['PUPPET_GEM_VERSION']
5656
facter_version = ENV['FACTER_GEM_VERSION']
5757
hiera_version = ENV['HIERA_GEM_VERSION']
58-
bolt_version = ENV.fetch('BOLT_GEM_VERSION', nil)
5958

6059
gems = {}
6160

62-
# If PUPPET_FORGE_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet
63-
# Otherwise, do as before and use location_for to fetch gems from the default source
64-
if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty?
65-
gems['bolt'] = [bolt_version || '~> 5.0', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }]
66-
gems['puppet'] = [puppet_version || '~> 8.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }]
67-
gems['facter'] = [facter_version || '~> 4.0', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }]
68-
else
69-
gems['bolt'] = location_for(bolt_version)
70-
gems['puppet'] = location_for(puppet_version)
71-
gems['facter'] = location_for(facter_version) if facter_version
72-
end
61+
gems['puppet'] = location_for(puppet_version)
7362

74-
# If hiera version have been specified via the environment
63+
# If facter or hiera versions have been specified via the environment
7564
# variables
65+
gems['facter'] = location_for(facter_version) if facter_version
7666
gems['hiera'] = location_for(hiera_version) if hiera_version
7767

7868
gems.each do |gem_name, gem_params|

REFERENCE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
### Functions
1818

19+
* [`peadm::assert_puppet_not_installed`](#peadm--assert_puppet_not_installed): Assert that Puppet is not already installed on the provided nodes
1920
* [`peadm::assert_supported_architecture`](#peadm--assert_supported_architecture): Assert that the architecture given is a supported one
2021
* [`peadm::assert_supported_bolt_version`](#peadm--assert_supported_bolt_version): Assert that the Bolt executable running PEAdm is a supported version
2122
* [`peadm::assert_supported_pe_version`](#peadm--assert_supported_pe_version): Assert that the PE version given is supported by PEAdm
@@ -146,6 +147,24 @@ Supported use cases:
146147

147148
## Functions
148149

150+
### <a name="peadm--assert_puppet_not_installed"></a>`peadm::assert_puppet_not_installed`
151+
152+
Type: Puppet Language
153+
154+
Assert that Puppet is not already installed on the provided nodes
155+
156+
#### `peadm::assert_puppet_not_installed(TargetSpec $nodes)`
157+
158+
The peadm::assert_puppet_not_installed function.
159+
160+
Returns: `Boolean` Returns true if no Puppet installations are found, fails otherwise
161+
162+
##### `nodes`
163+
164+
Data type: `TargetSpec`
165+
166+
A list of nodes to check for existing Puppet installations
167+
149168
### <a name="peadm--assert_supported_architecture"></a>`peadm::assert_supported_architecture`
150169

151170
Type: Puppet Language
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# @summary Assert that Puppet is not already installed on the provided nodes
2+
# @param nodes
3+
# A list of nodes to check for existing Puppet installations
4+
# @return [Boolean] Returns true if no Puppet installations are found, fails otherwise
5+
function peadm::assert_puppet_not_installed(
6+
TargetSpec $nodes,
7+
) >> Boolean {
8+
# Normalize nodes to an array of targets
9+
$nodes_array = get_targets($nodes)
10+
11+
if empty($nodes_array) {
12+
return true
13+
}
14+
15+
out::message("Checking ${nodes_array.length} nodes for existing Puppet installations...")
16+
17+
# Run puppet --version command on all nodes to check for existing installations
18+
$results = run_command('puppet --version', $nodes_array, '_catch_errors' => true)
19+
20+
# Find nodes that have Puppet already installed (command succeeded)
21+
$nodes_with_puppet = $results.filter |$result| {
22+
$result.ok()
23+
}
24+
25+
if !empty($nodes_with_puppet) {
26+
$node_list = $nodes_with_puppet.map |$result| {
27+
" - ${result.target.name}: ${result.value['stdout'].strip()}"
28+
}.join("\n")
29+
30+
out::message(inline_epp(@(HEREDOC)))
31+
ERROR: Puppet is already installed on the following nodes:
32+
33+
<%= $node_list %>
34+
35+
PEADM requires clean nodes without existing Puppet installations.
36+
37+
To resolve this issue:
38+
1. Use fresh/clean target systems that don't have Puppet installed, OR
39+
2. Remove existing Puppet installations
40+
41+
| HEREDOC
42+
43+
fail("Puppet is already installed on ${nodes_with_puppet.length} node(s). Clean installations required.")
44+
}
45+
46+
out::message('✓ No existing Puppet installations found on target nodes')
47+
return true
48+
}

plans/subplans/install.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
$compiler_targets,
101101
$legacy_compiler_targets,
102102
])
103+
peadm::assert_puppet_not_installed($all_targets)
103104

104105
$primary_targets = peadm::flatten_compact([
105106
$primary_target,
@@ -429,7 +430,7 @@
429430
run_task('peadm::puppet_runonce', $target)
430431
}
431432

432-
wait([$bg_db_run])
433+
wait([$bg_db_run], 1200, _catch_errors => true)
433434

434435
# The puppetserver might be in the middle of a restart after the Puppet run,
435436
# so we check the status by calling the api and ensuring the puppetserver is

0 commit comments

Comments
 (0)