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 d3596b1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 19 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
59 changes: 44 additions & 15 deletions spec/acceptance/init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
# 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
class { 'bolt': use_release_package => false }
PUPPET
end
end
describe package('puppet-bolt') do
it { is_expected.to be_installed }
end

describe package('puppet-tools-release') do
it { is_expected.not_to be_installed }
describe 'packages' do
it { expect(package('puppet-bolt')).to be_installed }
it { expect(package('puppet-tools-release')).to be_installed }

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - AlmaLinux 8 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - AlmaLinux 8 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - AlmaLinux 9 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - AlmaLinux 9 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Rocky 8 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Rocky 8 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Rocky 9 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Rocky 9 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - CentOS 9 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - CentOS 9 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - OracleLinux 8 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - OracleLinux 8 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - OracleLinux 9 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed

Check failure on line 17 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - OracleLinux 9 - PE-Role primary

bolt with use_release_package=false packages is expected to be installed Failure/Error: it { expect(package('puppet-tools-release')).to be_installed } expected Package "puppet-tools-release" to be installed
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

describe 'packages' do
it { expect(package('puppet-bolt')).not_to be_installed }
it { expect(package('puppet-tools-release')).not_to be_installed }
end

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

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - AlmaLinux 8 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - AlmaLinux 8 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - AlmaLinux 9 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - AlmaLinux 9 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Rocky 8 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Rocky 8 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Rocky 9 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Rocky 9 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - CentOS 9 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - CentOS 9 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - OracleLinux 8 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - OracleLinux 8 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - OracleLinux 9 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,

Check failure on line 39 in spec/acceptance/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - OracleLinux 9 - PE-Role primary

bolt with use_release_package=false & ensure=absent is expected to be missing or have attributes {:size => 0} Failure/Error: it { expect(file('/etc/yum.repos.d/puppet-tools.repo')).to be_missing.or(have_attributes(size: 0)) } expected `File "/etc/yum.repos.d/puppet-tools.repo".file?` to be falsey, got true ...or: expected File "/etc/yum.repos.d/puppet-tools.repo" to have attributes {:size => 0} but had attributes {:size => 199} Diff for (have attributes {:size => 0}): @@ -1 +1 @@ -:size => 0, +:size => 199,
end

describe 'with defaults' do
Expand All @@ -32,14 +47,28 @@ class { 'bolt': use_release_package => false }
PUPPET
end
end
# rubocop:disable RSpec/RepeatedExampleGroupBody
describe package('puppet-bolt') do
it { is_expected.to be_installed }

describe 'packages' do
it { expect(package('puppet-bolt')).to be_installed }
it { expect(package('puppet-tools-release')).to be_installed }
end
end

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

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

0 comments on commit d3596b1

Please sign in to comment.