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 bolt_version function and use it in plans #141

Merged
merged 1 commit into from
Jan 19, 2021
Merged
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
19 changes: 19 additions & 0 deletions functions/check_bolt_version.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Checks if the current Bolt version matches the SemVerRange defined in $supported_bolt_version
# Fails the calling plan if false, does nothing if true.
# Accepts a parameter for the $supported_bolt_version for unit testing purposes
function peadm::check_bolt_version(
$supported_bolt_version = '>= 2.42.0 < 3.0.0'
) {
$supported = (peadm::bolt_version() =~ SemVerRange($supported_bolt_version))

unless $supported {
fail(@("REASON"/L))
This version of puppetlabs-peadm requires Bolt version ${supported_bolt_version}.

You are using Bolt version ${peadm::bolt_version()}.

Please make sure you have a compatible Bolt version and try again.

| REASON
}
}
8 changes: 8 additions & 0 deletions lib/puppet/functions/peadm/bolt_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'bolt'

Puppet::Functions.create_function(:'peadm::bolt_version') do
def bolt_version
Bolt::VERSION
end
end

2 changes: 2 additions & 0 deletions plans/convert.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
'convert-node-groups',
'finalize']] $begin_at_step = undef,
) {
peadm::check_bolt_version()

# TODO: read and validate convertable PE version

# Convert inputs into targets.
Expand Down
2 changes: 2 additions & 0 deletions plans/provision.pp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
Optional[String] $stagingdir = undef,
Enum[direct,bolthost] $download_mode = 'bolthost',
) {
peadm::check_bolt_version()

peadm::validate_version($version)

$install_result = run_plan('peadm::action::install',
Expand Down
2 changes: 2 additions & 0 deletions plans/status.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
Boolean $summarize = true,
Boolean $colors = $format ? { json => false, default => true }
) {
peadm::check_bolt_version()

$results = run_task('peadm::infrastatus', $targets, { format => 'json'})
# returns the data in a hash
$stack_status = $results.reduce({}) | $res, $item | {
Expand Down
2 changes: 2 additions & 0 deletions plans/upgrade.pp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
'upgrade-replica-compilers',
'finalize']] $begin_at_step = undef,
) {
peadm::check_bolt_version()

peadm::validate_version($version)

# Ensure input valid for a supported architecture
Expand Down
12 changes: 12 additions & 0 deletions spec/functions/bolt_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require 'spec_helper'
require 'bolt'

describe 'peadm::bolt_version' do

it 'should_return_bolt_version' do
is_expected.to run.and_return(Bolt::VERSION)
end

end