Skip to content

Commit

Permalink
Merge pull request #341 from jay7x/fix_copr
Browse files Browse the repository at this point in the history
Improve yum::copr idempotency
  • Loading branch information
bastelfreak authored Dec 8, 2024
2 parents 75df7c0 + 595b5d7 commit 1a12f8e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
7 changes: 4 additions & 3 deletions manifests/copr.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@
}

if $facts['package_provider'] == 'dnf' {
$copr_name = regsubst($copr_repo, '@', 'group_')
case $ensure {
'enabled': {
exec { "dnf -y copr enable ${copr_repo}":
path => '/bin:/usr/bin:/sbin/:/usr/sbin',
unless => "dnf copr list | egrep -q '${copr_repo}\$'",
unless => "dnf copr list | egrep -q '${copr_name}\$'",
require => Package[$prereq_plugin],
}
}
'disabled': {
exec { "dnf -y copr disable ${copr_repo}":
path => '/bin:/usr/bin:/sbin/:/usr/sbin',
unless => "dnf copr list | egrep -q '${copr_repo} (disabled)\$'",
unless => "dnf copr list | egrep -q '${copr_name} \\(disabled\\)\$'",
require => Package[$prereq_plugin],
}
}
'removed': {
exec { "dnf -y copr remove ${copr_repo}":
path => '/bin:/usr/bin:/sbin/:/usr/sbin',
onlyif => "dnf copr list | egrep -q '${copr_repo}'",
onlyif => "dnf copr list | egrep -q '${copr_name}'",
require => Package[$prereq_plugin],
}
}
Expand Down
63 changes: 63 additions & 0 deletions spec/acceptance/copr_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'yum::copr' do
context 'when @caddy/caddy and copart/restic are enabled' do
# Using puppet_apply as a helper
it 'must work idempotently with no errors' do
pp = <<-PUPPET
yum::copr { ['@caddy/caddy', 'copart/restic']: }
PUPPET

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe command('dnf copr list') do
its(:stdout) { is_expected.to match(%r{^copr.fedorainfracloud.org/copart/restic$}) }
its(:stdout) { is_expected.to match(%r{^copr.fedorainfracloud.org/group_caddy/caddy$}) }
end
end

context 'when copart/restic is disabled' do
# Using puppet_apply as a helper
it 'must work idempotently with no errors' do
pp = <<-PUPPET
yum::copr { ['@caddy/caddy', 'copart/restic']:
ensure => 'disabled',
}
PUPPET

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe command('dnf copr list') do
its(:stdout) { is_expected.to match(%r{^copr.fedorainfracloud.org/copart/restic \(disabled\)$}) }
its(:stdout) { is_expected.to match(%r{^copr.fedorainfracloud.org/group_caddy/caddy \(disabled\)$}) }
end
end

context 'when copart/restic is removed' do
# Using puppet_apply as a helper
it 'must work idempotently with no errors' do
pp = <<-PUPPET
yum::copr { ['@caddy/caddy', 'copart/restic']:
ensure => 'removed',
}
PUPPET

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe command('dnf copr list') do
its(:stdout) { is_expected.not_to match(%r{^copr.fedorainfracloud.org/copart/restic$}) }
its(:stdout) { is_expected.not_to match(%r{^copr.fedorainfracloud.org/group_caddy/caddy$}) }
end
end
end
2 changes: 1 addition & 1 deletion spec/defines/copr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
it {
is_expected.to contain_exec("dnf -y copr disable #{title}").with(
'path' => '/bin:/usr/bin:/sbin/:/usr/sbin',
'unless' => "dnf copr list | egrep -q '#{title} (disabled)$'",
'unless' => "dnf copr list | egrep -q '#{title} \\(disabled\\)$'",
'require' => "Package[#{prereq_plugin}]"
)
}
Expand Down

0 comments on commit 1a12f8e

Please sign in to comment.