Skip to content

Commit

Permalink
Refactor repository handling
Browse files Browse the repository at this point in the history
This removes the repo parameters from the main class, in favor of a
standalone class that can be included. It uses an anchor because that
can be collected in the main class to keep the correct dependency
chaining while using composition.
  • Loading branch information
ekohl committed Apr 16, 2020
1 parent 562822d commit 6a246c1
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 147 deletions.
24 changes: 4 additions & 20 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@
#
# $ssl:: Enable and set require_ssl in Foreman settings (note: requires passenger, SSL does not apply to kickstarts)
#
# $repo:: This can be a specific version or nightly
#
# $configure_epel_repo:: If disabled the EPEL repo will not be configured on Red Hat family systems.
#
# $configure_scl_repo:: If disabled the SCL repo will not be configured on Red Hat clone systems.
# (Currently only installs repos for CentOS and Scientific)
#
# $gpgcheck:: Turn on/off gpg check in repo files (effective only on RedHat family systems)
#
# $version:: Foreman package version, it's passed to ensure parameter of package resource
# can be set to specific version number, 'latest', 'present' etc.
#
Expand Down Expand Up @@ -227,10 +218,6 @@
Stdlib::Fqdn $servername = $foreman::params::servername,
Array[Stdlib::Fqdn] $serveraliases = $foreman::params::serveraliases,
Boolean $ssl = $foreman::params::ssl,
Optional[String] $repo = $foreman::params::repo,
Boolean $configure_epel_repo = $foreman::params::configure_epel_repo,
Boolean $configure_scl_repo = $foreman::params::configure_scl_repo,
Boolean $gpgcheck = $foreman::params::gpgcheck,
String $version = $foreman::params::version,
Enum['installed', 'present', 'latest'] $plugin_version = $foreman::params::plugin_version,
Boolean $db_manage = $foreman::params::db_manage,
Expand Down Expand Up @@ -336,13 +323,12 @@
$foreman_service_bind = '0.0.0.0'
}

include foreman::repo
include foreman::install
include foreman::config
include foreman::database
contain foreman::service

Class['foreman::repo'] ~> Class['foreman::install']
Anchor <| title == 'foreman::repo' |> ~> Class['foreman::install']
Class['foreman::install'] ~> Class['foreman::config', 'foreman::service']
Class['foreman::config'] ~> Class['foreman::database', 'foreman::service']
Class['foreman::database'] ~> Class['foreman::service']
Expand All @@ -365,14 +351,12 @@
~> Package <| tag == 'foreman-compute' |>
~> Class['foreman::service']

Class['foreman::repo']
Anchor <| title == 'foreman::repo' |>
~> Package <| tag == 'foreman::cli' |>
~> Class['foreman']

Class['foreman::repo']
~> Package <| tag == 'foreman::providers' |>
-> Class['foreman']

Package <| tag == 'foreman::providers' |> -> Class['foreman']

contain 'foreman::settings' # lint:ignore:relative_classname_inclusion (PUP-1597)
Class['foreman::database'] -> Class['foreman::settings']
}
6 changes: 3 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@
$passenger_min_instances = 1
$passenger_start_timeout = 90

<<<<<<< HEAD
# Additional software repos
$configure_epel_repo = ($facts['os']['family'] == 'RedHat' and $facts['os']['name'] != 'Fedora')

=======
>>>>>>> Refactor repository handling
# Advanced configuration
# this can be a version or nightly
$repo = undef
$app_root = '/usr/share/foreman'
$plugin_config_dir = '/etc/foreman/plugins'
$manage_user = true
$user = 'foreman'
$group = 'foreman'
$user_groups = ['puppet']
$rails_env = 'production'
$gpgcheck = true
$version = 'present'
$plugin_version = 'present'

Expand Down
1 change: 1 addition & 0 deletions manifests/providers.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
) inherits foreman::providers::params {
if $oauth {
ensure_packages([$oauth_package])
Anchor <| title == 'foreman::repo' |> ~> Package[$oauth_package]
}
}
43 changes: 32 additions & 11 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
# @summary Configure the foreman repo
# @api private
# Configure the foreman repo
#
# @param repo
# The repository version to manage. This can be a specific version or nightly
#
# @param configure_scl_repo
# If disabled the SCL repo will not be configured on Red Hat clone systems.
# (Currently only installs repos for CentOS and Scientific)
#
# @param gpgcheck
# Turn on/off gpg check in repo files (effective only on RedHat family systems)
#
# @param scl_repo_ensure
# The ensure to set on the SCL repo package
#
class foreman::repo(
$repo = $foreman::repo,
$gpgcheck = $foreman::gpgcheck,
$configure_epel_repo = $foreman::configure_epel_repo,
$configure_scl_repo = $foreman::configure_scl_repo,
Optional[Variant[Enum['nightly'], Pattern['^\d+\.\d+$']]] $repo = undef,
Boolean $gpgcheck = true,
Boolean $configure_scl_repo = $facts['os']['family'] == 'RedHat' and $facts['os']['major'] == '7',
String $scl_repo_ensure = 'installed',
) {
if $repo {
foreman::repos { 'foreman':
repo => $repo,
gpgcheck => $gpgcheck,
before => Class['foreman::repos::extra'],
before => Anchor['foreman::repo'],
}

if $configure_scl_repo {
Foreman::Repos['foreman'] -> Package['foreman-release-scl']
}
}

class { 'foreman::repos::extra':
configure_epel_repo => $configure_epel_repo,
configure_scl_repo => $configure_scl_repo,
if $configure_scl_repo {
package {'foreman-release-scl':
ensure => $scl_repo_ensure,
before => Anchor['foreman::repo'],
}
}
contain foreman::repos::extra

# An anchor is used because it can be collected
anchor { 'foreman::repo': } # lint:ignore:anchor_resource
}
24 changes: 0 additions & 24 deletions manifests/repos/extra.pp

This file was deleted.

10 changes: 3 additions & 7 deletions spec/classes/foreman_repo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
context "on #{os}" do
let(:facts) { facts }

it { is_expected.to compile.with_all_deps }

describe 'with explicit parameters' do
let :params do
{
repo: '1.19',
gpgcheck: true,
configure_epel_repo: false,
configure_scl_repo: false
}
end
Expand All @@ -23,11 +23,7 @@
.with_gpgcheck(true)
end

it 'should include extra repos' do
is_expected.to contain_class('foreman::repos::extra')
.with_configure_epel_repo(false)
.with_configure_scl_repo(false)
end
it { is_expected.not_to contain_package('foreman-release-scl') }
end
end
end
Expand Down
50 changes: 0 additions & 50 deletions spec/classes/foreman_repos_extra_spec.rb

This file was deleted.

27 changes: 0 additions & 27 deletions spec/classes/foreman_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,6 @@
context 'with default parameters' do
it { is_expected.to compile.with_all_deps }

# repo
it { should contain_class('foreman::repo').that_notifies('Class[foreman::install]') }
it { should_not contain_foreman__repos('foreman') }
case facts[:osfamily]
when 'RedHat'
configure_repo = facts[:operatingsystem] != 'Fedora'
it {
should contain_class('foreman::repos::extra')
.with_configure_scl_repo(configure_repo)
.with_configure_epel_repo(configure_repo)
}

if facts[:operatingsystem] != 'Fedora'
it { should_not contain_package('tfm-rubygem-passenger-native') }
end
when 'Debian'
it {
should contain_class('foreman::repos::extra')
.with_configure_scl_repo(false)
.with_configure_epel_repo(false)
}
end

# install
it { should contain_class('foreman::install') }
it { should contain_package('foreman-postgresql').with_ensure('present') }
Expand Down Expand Up @@ -208,10 +185,6 @@
servername: 'localhost',
serveraliases: ['foreman'],
ssl: true,
repo: 'nightly',
configure_epel_repo: true,
configure_scl_repo: false,
gpgcheck: true,
version: '1.12',
plugin_version: 'installed',
db_manage: true,
Expand Down
7 changes: 2 additions & 5 deletions spec/setup_acceptance_node.pp
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
$configure_scl_repo = $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '7'

class { 'foreman::repo':
repo => 'nightly',
gpgcheck => false,
configure_epel_repo => false,
configure_scl_repo => $configure_scl_repo,
repo => 'nightly',
}

# Needed for idempotency when SELinux is enabled
if $configure_scl_repo {
if $foreman::repo::configure_scl_repo {
package { 'rh-redis5-redis':
ensure => installed,
require => Class['foreman::repo'],
Expand Down

0 comments on commit 6a246c1

Please sign in to comment.