forked from CERIT-SC/puppet-yum
-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add yum::copr resource to handle COPR repositories.
COPR (Cool Other Package Repo) is a Fedora project for third-party package repositories.
- Loading branch information
Showing
4 changed files
with
264 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# @summary This definition manages COPR (Cool Other Package Repo) repositories. | ||
# | ||
# @param repo [String] | ||
# Name of repository. | ||
# | ||
# @param ensure | ||
# Specifies if repo should be enabled, disabled or removed. | ||
# | ||
# @example Add a COPR repository: | ||
# --- | ||
# yum::copr { 'copart/restic': | ||
# ensure => 'enabled', | ||
# } | ||
# | ||
define yum::copr ( | ||
String $repo = $title, | ||
Enum['enabled', 'disabled', 'removed'] $ensure = 'enabled', | ||
) { | ||
$prereq_plugin = $facts['package_provider'] ? { | ||
'yum' => 'yum-plugin-copr', | ||
default => 'dnf-plugins-core', | ||
} | ||
ensure_packages([$prereq_plugin]) | ||
|
||
if $facts['package_provider'] == 'yum' { | ||
$repo_name_part = regsubst($repo, '/', '-', 'G') | ||
case $ensure { | ||
'enabled': { | ||
exec { "yum -y copr enable ${repo}": | ||
path => '/bin:/usr/bin:/sbin/:/usr/sbin', | ||
onlyif => "test ! -e /etc/yum.repos.d/_copr_${repo_name_part}.repo", | ||
require => Package[$prereq_plugin], | ||
} | ||
} | ||
'disabled', 'removed': { | ||
exec { "yum -y copr disable ${repo}": | ||
path => '/bin:/usr/bin:/sbin/:/usr/sbin', | ||
onlyif => "test -e /etc/yum.repos.d/_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}.") | ||
} | ||
} | ||
} else { | ||
case $ensure { | ||
'enabled': { | ||
exec { "dnf -y copr enable ${repo}": | ||
path => '/bin:/usr/bin:/sbin/:/usr/sbin', | ||
unless => "dnf copr list | egrep -q '${repo}\$'", | ||
require => Package[$prereq_plugin], | ||
} | ||
} | ||
'disabled': { | ||
# Need to enable first, then disable, to ensure it is added in disabled state. | ||
exec { "dnf -y copr enable ${repo}; dnf -y copr disable ${repo}": | ||
path => '/bin:/usr/bin:/sbin/:/usr/sbin', | ||
unless => "dnf copr list | egrep -q '${repo} (disabled)\$'", | ||
require => Package[$prereq_plugin], | ||
} | ||
} | ||
'removed': { | ||
exec { "dnf -y copr remove ${repo}": | ||
path => '/bin:/usr/bin:/sbin/:/usr/sbin', | ||
unless => "dnf copr list | egrep -q '${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,67 @@ | ||
require 'spec_helper_acceptance' | ||
|
||
describe 'yum::copr define' do | ||
repo_filename = %w[6 7].include?(fact('os.release.major')) ? '_copr_copart-restic.repo' : '_copr:copr.fedorainfracloud.org:copart:restic.repo' | ||
context 'enable a repository' do | ||
# Using puppet_apply as a helper | ||
it 'must work idempotently with no errors' do | ||
pp = <<-EOS | ||
yum::copr{ 'copart/restic': | ||
ensure => enabled, | ||
} | ||
EOS | ||
# Run it twice and test for idempotency | ||
apply_manifest(pp, catch_failures: true) | ||
apply_manifest(pp, catch_changes: true) | ||
end | ||
describe file("/etc/yum.repos.d/#{repo_filename}") do | ||
it { is_expected.to be_file } | ||
it { is_expected.to contain '[copr:copr.fedorainfracloud.org:copart:restic]' } | ||
it { is_expected.to contain 'enabled=1' } | ||
end | ||
end | ||
context 'disable a repository' do | ||
# Using puppet_apply as a helper | ||
it 'must work idempotently with no errors' do | ||
pp = <<-EOS | ||
yum::copr{ 'copart/restic': | ||
ensure => disabled, | ||
} | ||
EOS | ||
# Run it twice and test for idempotency | ||
apply_manifest(pp, catch_failures: true) | ||
apply_manifest(pp, catch_changes: true) | ||
end | ||
describe file("/etc/yum.repos.d/#{repo_filename}") do | ||
if %w[6 7].include?(fact('os.release.major')) | ||
it { is_expected.not_to be_file } | ||
else | ||
it { is_expected.to be_file } | ||
it { is_expected.to contain '[copr:copr.fedorainfracloud.org:copart:restic]' } | ||
it { is_expected.to contain 'enabled=0' } | ||
end | ||
end | ||
end | ||
context 'remove a repository after adding it' do | ||
# Using puppet_apply as a helper | ||
it 'must work idempotently with no errors' do | ||
ppadd = <<-EOS | ||
yum::copr{ 'copart/restic': | ||
ensure => enabled, | ||
} | ||
EOS | ||
apply_manifest(ppadd, catch_failures: true) | ||
pp = <<-EOS | ||
yum::copr{ 'copart/restic': | ||
ensure => removed, | ||
} | ||
EOS | ||
# Run it twice and test for idempotency | ||
apply_manifest(pp, catch_failures: true) | ||
apply_manifest(pp, catch_changes: true) | ||
end | ||
describe file("/etc/yum.repos.d/#{repo_filename}") do | ||
it { is_expected.not_to be_file } | ||
end | ||
end | ||
end |
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,108 @@ | ||
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(:repo_name_part) { title.tr('/', '-') } | ||
|
||
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_#{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_#{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_#{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', | ||
'unless' => "dnf copr list | egrep -q '#{title}'", | ||
'require' => "Package[#{prereq_plugin}]" | ||
) | ||
} | ||
end | ||
end | ||
end |