forked from CERIT-SC/puppet-yum
-
-
Notifications
You must be signed in to change notification settings - Fork 101
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 yum::copr resource to handle COPR repositories. #215
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
04fa3ec
Add yum::copr resource to handle COPR repositories.
olifre b88c142
README: Note how to prevent COPR yumrepos from being purged.
olifre e26bac2
yum::copr: use puppet-strings
olifre 903ebac
Regenerate REFERENCE.md.
olifre 3f1d236
yum::copr: add manage_prereq_plugin parameter
olifre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# | ||
# @summary This definition manages Copr (Cool Other Package Repo) repositories. | ||
# | ||
# @param copr_repo | ||
# Name of repository, defaults to title. | ||
# @param manage_prereq_plugin | ||
# Wheter required plugin for dnf/yum should be installed by this resource. | ||
# @param ensure | ||
# Specifies if repo should be enabled, disabled or removed. | ||
# | ||
# @example add and enable COPR restic repository | ||
# yum::copr { 'copart/restic': | ||
# ensure => 'enabled', | ||
# } | ||
# | ||
define yum::copr ( | ||
String $copr_repo = $title, | ||
Boolean $manage_prereq_plugin = true, | ||
Enum['enabled', 'disabled', 'removed'] $ensure = 'enabled', | ||
) { | ||
$prereq_plugin = $facts['package_provider'] ? { | ||
'dnf' => 'dnf-plugins-core', | ||
default => 'yum-plugin-copr', | ||
} | ||
if $manage_prereq_plugin { | ||
stdlib::ensure_packages([$prereq_plugin]) | ||
} | ||
|
||
if $facts['package_provider'] == 'dnf' { | ||
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}\$'", | ||
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)\$'", | ||
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}'", | ||
require => Package[$prereq_plugin], | ||
} | ||
} | ||
default: { | ||
fail("The value for ensure for `yum::copr` must be enabled, disabled or removed, but it is ${ensure}.") | ||
} | ||
} | ||
} else { | ||
$copr_repo_name_part = regsubst($copr_repo, '/', '-', 'G') | ||
case $ensure { | ||
'enabled': { | ||
exec { "yum -y copr enable ${copr_repo}": | ||
path => '/bin:/usr/bin:/sbin/:/usr/sbin', | ||
onlyif => "test ! -e /etc/yum.repos.d/_copr_${copr_repo_name_part}.repo", | ||
require => Package[$prereq_plugin], | ||
} | ||
} | ||
'disabled', 'removed': { | ||
exec { "yum -y copr disable ${copr_repo}": | ||
path => '/bin:/usr/bin:/sbin/:/usr/sbin', | ||
onlyif => "test -e /etc/yum.repos.d/_copr_${copr_repo_name_part}.repo", | ||
require => Package[$prereq_plugin], | ||
} | ||
} | ||
default: { | ||
fail("The value for ensure for `yum::copr` must be enabled, disabled or removed, but it is ${ensure}.") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'yum::copr' do | ||
context 'with package_provider set to yum' do | ||
let(:facts) { { package_provider: 'yum' } } | ||
let(:prereq_plugin) { 'yum-plugin-copr' } | ||
let(:title) { 'copart/restic' } | ||
let(:copr_repo_name_part) { title.gsub('/', '-') } | ||
|
||
context 'package provider plugin installed' do | ||
it { is_expected.to compile.with_all_deps } | ||
|
||
it { | ||
is_expected.to contain_package(prereq_plugin.to_s) | ||
} | ||
end | ||
|
||
context 'with ensure = enabled' do | ||
let(:params) { { ensure: 'enabled' } } | ||
|
||
it { is_expected.to compile.with_all_deps } | ||
|
||
it { | ||
is_expected.to contain_exec("yum -y copr enable #{title}").with( | ||
'path' => '/bin:/usr/bin:/sbin/:/usr/sbin', | ||
'onlyif' => "test ! -e /etc/yum.repos.d/_copr_#{copr_repo_name_part}.repo", | ||
'require' => "Package[#{prereq_plugin}]" | ||
) | ||
} | ||
end | ||
|
||
context 'with ensure = disabled' do | ||
let(:params) { { ensure: 'disabled' } } | ||
|
||
it { is_expected.to compile.with_all_deps } | ||
|
||
it { | ||
is_expected.to contain_exec("yum -y copr disable #{title}").with( | ||
'path' => '/bin:/usr/bin:/sbin/:/usr/sbin', | ||
'onlyif' => "test -e /etc/yum.repos.d/_copr_#{copr_repo_name_part}.repo", | ||
'require' => "Package[#{prereq_plugin}]" | ||
) | ||
} | ||
end | ||
|
||
context 'with ensure = removed' do | ||
let(:params) { { ensure: 'removed' } } | ||
|
||
it { is_expected.to compile.with_all_deps } | ||
|
||
it { | ||
is_expected.to contain_exec("yum -y copr disable #{title}").with( | ||
'path' => '/bin:/usr/bin:/sbin/:/usr/sbin', | ||
'onlyif' => "test -e /etc/yum.repos.d/_copr_#{copr_repo_name_part}.repo", | ||
'require' => "Package[#{prereq_plugin}]" | ||
) | ||
} | ||
end | ||
end | ||
|
||
context 'with package_provider set to dnf' do | ||
let(:facts) { { package_provider: 'dnf' } } | ||
let(:prereq_plugin) { 'dnf-plugins-core' } | ||
let(:title) { 'copart/restic' } | ||
|
||
context 'package provider plugin installed' do | ||
it { is_expected.to compile.with_all_deps } | ||
|
||
it { | ||
is_expected.to contain_package(prereq_plugin.to_s) | ||
} | ||
end | ||
|
||
context 'with ensure = enabled' do | ||
let(:params) { { ensure: 'enabled' } } | ||
|
||
it { is_expected.to compile.with_all_deps } | ||
|
||
it { | ||
is_expected.to contain_exec("dnf -y copr enable #{title}").with( | ||
'path' => '/bin:/usr/bin:/sbin/:/usr/sbin', | ||
'unless' => "dnf copr list | egrep -q '#{title}\$'", | ||
'require' => "Package[#{prereq_plugin}]" | ||
) | ||
} | ||
end | ||
|
||
context 'with ensure = disabled' do | ||
let(:params) { { ensure: 'disabled' } } | ||
|
||
it { is_expected.to compile.with_all_deps } | ||
|
||
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)\$'", | ||
'require' => "Package[#{prereq_plugin}]" | ||
) | ||
} | ||
end | ||
|
||
context 'with ensure = removed' do | ||
let(:params) { { ensure: 'removed' } } | ||
|
||
it { is_expected.to compile.with_all_deps } | ||
|
||
it { | ||
is_expected.to contain_exec("dnf -y copr remove #{title}").with( | ||
'path' => '/bin:/usr/bin:/sbin/:/usr/sbin', | ||
'onlyif' => "dnf copr list | egrep -q '#{title}'", | ||
'require' => "Package[#{prereq_plugin}]" | ||
) | ||
} | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always prefer to make the future, dnf in this case, the default case since it's more obvious what code needs removing once yum is gone from the universe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea, thanks for the suggestion! I've also addressed this in the last push.