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

Refactor extras repo handling #672

Merged
merged 1 commit into from
Oct 8, 2018
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
21 changes: 8 additions & 13 deletions manifests/repos/extra.pp
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
# Configure thirdparty repos
class foreman::repos::extra(
$configure_epel_repo = $::foreman::configure_epel_repo,
$configure_scl_repo = $::foreman::configure_scl_repo,
Boolean $configure_epel_repo = $::foreman::configure_epel_repo,
Boolean $configure_scl_repo = $::foreman::configure_scl_repo,
String $scl_repo_ensure = 'installed',
) {
$osreleasemajor = regsubst($::operatingsystemrelease, '^(\d+)\..*$', '\1')

if $configure_epel_repo {
$epel_gpgkey = $osreleasemajor ? {
'7' => 'https://fedoraproject.org/static/352C64E5.txt',
default => 'https://fedoraproject.org/static/0608B895.txt',
}
yumrepo { 'epel':
descr => "Extra Packages for Enterprise Linux ${osreleasemajor} - \$basearch",
mirrorlist => "https://mirrors.fedoraproject.org/metalink?repo=epel-${osreleasemajor}&arch=\$basearch",
baseurl => "http://download.fedoraproject.org/pub/epel/${osreleasemajor}/\$basearch",
descr => "Extra Packages for Enterprise Linux ${::operatingsystemmajrelease} - \$basearch",
mirrorlist => "https://mirrors.fedoraproject.org/metalink?repo=epel-${::operatingsystemmajrelease}&arch=\$basearch",
baseurl => "http://download.fedoraproject.org/pub/epel/${::operatingsystemmajrelease}/\$basearch",
enabled => 1,
gpgcheck => 1,
gpgkey => $epel_gpgkey,
gpgkey => 'https://fedoraproject.org/static/352C64E5.txt',
}
}

if $configure_scl_repo {
package {'foreman-release-scl':
ensure => installed,
ensure => $scl_repo_ensure,
}
}
}
60 changes: 28 additions & 32 deletions spec/classes/foreman_repos_extra_spec.rb
Original file line number Diff line number Diff line change
@@ -1,53 +1,49 @@
require 'spec_helper'

describe 'foreman::repos::extra' do

on_os_under_test.each do |os, facts|
context "on #{os}" do
context "on #{os}", if: facts[:osfamily] == 'RedHat' do
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was a nice optimization but I'd be happy to change this.

let :facts do facts end

describe 'when repos are fully enabled' do
case facts[:osfamily]
when 'RedHat'
if facts[:operatingsystem] != 'Fedora'
let(:params) do
{
:configure_scl_repo => true,
:configure_epel_repo => true,
}
end
let(:params) do
{
configure_scl_repo: true,
configure_epel_repo: true,
}
end

let(:gpgkey) do
case facts[:operatingsystemmajrelease]
when '6'
'0608B895'
when '7'
'352C64E5'
end
end
it do
is_expected.to contain_yumrepo('epel')
.with_mirrorlist("https://mirrors.fedoraproject.org/metalink?repo=epel-#{facts[:operatingsystemmajrelease]}&arch=$basearch")
.with_gpgcheck(1)
.with_gpgkey('https://fedoraproject.org/static/352C64E5.txt')
end
it { is_expected.to contain_package('foreman-release-scl').with_ensure('installed') }
end

it { should contain_yumrepo('epel').with({
:mirrorlist => "https://mirrors.fedoraproject.org/metalink?repo=epel-#{facts[:operatingsystemmajrelease]}&arch=$basearch",
:gpgcheck => 1,
:gpgkey => "https://fedoraproject.org/static/#{gpgkey}.txt",
}) }
it { should contain_package('foreman-release-scl') }
end
describe 'when scl repo set to latest' do
let(:params) do
{
configure_scl_repo: true,
configure_epel_repo: true,
scl_repo_ensure: 'latest',
}
end

it { is_expected.to contain_package('foreman-release-scl').with_ensure('latest') }
end

describe 'when fully disabled' do
let(:params) do
{
:configure_scl_repo => false,
:configure_epel_repo => false,
configure_scl_repo: false,
configure_epel_repo: false,
}
end

it { should_not contain_yumrepo('epel') }
it { should_not contain_package('foreman-release-scl') }
it { should_not contain_class('apt') }
it { should have_apt__ppa_resource_count(0) }
it { is_expected.to_not contain_yumrepo('epel') }
it { is_expected.to_not contain_package('foreman-release-scl') }
end
end
end
Expand Down