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

Improve yum::copr idempotency #341

Merged
merged 1 commit into from
Dec 8, 2024
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
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
Loading