Skip to content

Commit 1157e77

Browse files
authored
Merge pull request #141 from timidri/check_bolt_version
Add bolt_version function and use it in plans
2 parents 7433df7 + 294f2d4 commit 1157e77

File tree

7 files changed

+47
-0
lines changed

7 files changed

+47
-0
lines changed

Diff for: functions/check_bolt_version.pp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Checks if the current Bolt version matches the SemVerRange defined in $supported_bolt_version
2+
# Fails the calling plan if false, does nothing if true.
3+
# Accepts a parameter for the $supported_bolt_version for unit testing purposes
4+
function peadm::check_bolt_version(
5+
$supported_bolt_version = '>= 2.42.0 < 3.0.0'
6+
) {
7+
$supported = (peadm::bolt_version() =~ SemVerRange($supported_bolt_version))
8+
9+
unless $supported {
10+
fail(@("REASON"/L))
11+
This version of puppetlabs-peadm requires Bolt version ${supported_bolt_version}.
12+
13+
You are using Bolt version ${peadm::bolt_version()}.
14+
15+
Please make sure you have a compatible Bolt version and try again.
16+
17+
| REASON
18+
}
19+
}

Diff for: lib/puppet/functions/peadm/bolt_version.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'bolt'
2+
3+
Puppet::Functions.create_function(:'peadm::bolt_version') do
4+
def bolt_version
5+
Bolt::VERSION
6+
end
7+
end
8+

Diff for: plans/convert.pp

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
'convert-node-groups',
2727
'finalize']] $begin_at_step = undef,
2828
) {
29+
peadm::check_bolt_version()
30+
2931
# TODO: read and validate convertable PE version
3032

3133
# Convert inputs into targets.

Diff for: plans/provision.pp

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
Optional[String] $stagingdir = undef,
5050
Enum[direct,bolthost] $download_mode = 'bolthost',
5151
) {
52+
peadm::check_bolt_version()
53+
5254
peadm::validate_version($version)
5355

5456
$install_result = run_plan('peadm::action::install',

Diff for: plans/status.pp

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
Boolean $summarize = true,
1515
Boolean $colors = $format ? { json => false, default => true }
1616
) {
17+
peadm::check_bolt_version()
18+
1719
$results = run_task('peadm::infrastatus', $targets, { format => 'json'})
1820
# returns the data in a hash
1921
$stack_status = $results.reduce({}) | $res, $item | {

Diff for: plans/upgrade.pp

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
'upgrade-replica-compilers',
4444
'finalize']] $begin_at_step = undef,
4545
) {
46+
peadm::check_bolt_version()
47+
4648
peadm::validate_version($version)
4749

4850
# Ensure input valid for a supported architecture

Diff for: spec/functions/bolt_version_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require 'bolt'
5+
6+
describe 'peadm::bolt_version' do
7+
8+
it 'should_return_bolt_version' do
9+
is_expected.to run.and_return(Bolt::VERSION)
10+
end
11+
12+
end

0 commit comments

Comments
 (0)