Skip to content

Commit

Permalink
Implement version=absent to remove bolt
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Jun 24, 2024
1 parent a9c9032 commit f702ee4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
2 changes: 1 addition & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The following parameters are available in the `bolt` class:

Data type: `String[1]`

desired version for bolt
desired version for bolt or `absent`

Default value: `'3.29.0'`

Expand Down
10 changes: 7 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# @summary installs bolt via yumrepo or release package
#
# @param version desired version for bolt
# @param version desired version for bolt or `absent`
# @param base_url HTTPS URL to the yumrepo base
# @param release_package filename for the release package rpm
# @param gpgkey name of the GPG key filename in the repo
Expand Down Expand Up @@ -33,15 +33,19 @@
fail('class bolt only works on RedHat OS family')
}

$ensure = $version ? {
'absent' => 'absent',
default => 'present',
}
if $use_release_package {
package { 'puppet-tools-release':
ensure => present,
ensure => $ensure,
source => "${base_url}${release_package}",
before => Package['puppet-bolt'],
}
} else {
yumrepo { 'puppet-tools':
ensure => 'present',
ensure => $ensure,
baseurl => "${base_url}puppet-tools/el/${facts['os']['release']['major']}/\$basearch",
descr => "Puppet Tools Repository el ${facts['os']['release']['major']} - \$basearch",
enabled => '1',
Expand Down
56 changes: 52 additions & 4 deletions spec/acceptance/init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

RSpec::Matchers.define_negated_matcher :be_missing, :be_file
describe 'bolt' do
describe 'with manually managed repo' do
describe 'with use_release_package=false' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
Expand All @@ -20,8 +20,31 @@ class { 'bolt': use_release_package => false }
end
end

describe command('yum clean all --verbose; rm -rf /etc/yum.repos.d/puppet-tools-release.repo; yum erase --assumeyes puppet-bolt puppet-tools-release') do
its(:exit_status) { is_expected.to eq 0 }
describe 'with use_release_package=false & ensure=absent' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'bolt':
use_release_package => false,
version => 'absent',
}
PUPPET
end
end
# rubocop:disable RSpec/RepeatedExampleGroupBody
describe package('puppet-bolt') do
it { is_expected.not_to be_installed }
end

describe package('puppet-tools-release') do
it { is_expected.not_to be_installed }
end
# rubocop:enable RSpec/RepeatedExampleGroupBody

# puppet 7 and below remove repos from the file, puppet 8 deletes the file
describe file('/etc/yum.repos.d/puppet-tools.repo') do
it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_file.or(have_attributes(size: 0)) }
end
end

describe 'with defaults' do
Expand All @@ -42,4 +65,29 @@ class { 'bolt': use_release_package => false }
end
# rubocop:enable RSpec/RepeatedExampleGroupBody
end

describe 'with ensure=absent' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'bolt':
version => 'absent',
}
PUPPET
end
end
# rubocop:disable RSpec/RepeatedExampleGroupBody
describe package('puppet-bolt') do
it { is_expected.not_to be_installed }
end

describe package('puppet-tools-release') do
it { is_expected.not_to be_installed }
end
# rubocop:enable RSpec/RepeatedExampleGroupBody

describe file('/etc/yum.repos.d/puppet-tools.repo') do
it { is_expected.to be_missing.or(have_attributes(size: 0)) }
end
end
end

0 comments on commit f702ee4

Please sign in to comment.