Skip to content

Commit

Permalink
Squashing local mods for upstreaming
Browse files Browse the repository at this point in the history
This is a combination of the changes below. Attribution for the original
work is done via the co-author lines at the end of this commit.

- Allow passing options to createrepo in mrepo.conf
- Add createrepo_options variable to package class
- Add regex validation for ppc64le architecture
  Modified manifests/repo.pp and added a regex statement for validating
  ppc64le architecture when used in the $arch param.
- Additional changes based on work upstream
  - Added a spec test to cover createrepo_options
  - Fixed duplicate resource declaration in iso.pp
  - Fixed passing params through to ncc and rhn repo types
  - Typed all parameters and replaced empty strings with undef
  - Removed .empty? checks from erb due to Puppet type checking doing this
  - Replaced legacy and top-scope facts

Co-authored-by: Rob Braden <bradejr@puppetlabs.com>
Co-authored-by: Eric Zounes <zounes99@gmail.com>
Co-authored-by: Heston Snodgrass <hsnodgrass3@gmail.com>
Co-authored-by: Erik Hansen <suckatrash@users.noreply.github.com>
  • Loading branch information
4 people authored and genebean committed Nov 18, 2019
1 parent 31b702d commit 94c0876
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 109 deletions.
65 changes: 33 additions & 32 deletions manifests/init.pp
Expand Up @@ -16,7 +16,7 @@
#
# [*www_ip*]
# Which IP address to use when www_ip_based is set.
# Default: $::ipaddress
# Default: $facts['networking']['ip']
#
# [*www_ip_based*]
# Whether to use IP-based virtual hosts or not.
Expand Down Expand Up @@ -116,36 +116,37 @@
# Copyright 2011 Puppet Labs, unless otherwise noted
#
class mrepo (
$src_root = $mrepo::params::src_root,
$www_root = $mrepo::params::www_root,
$www_servername = $mrepo::params::www_servername,
$www_ip = $mrepo::params::www_ip,
$www_ip_based = $mrepo::params::www_ip_based,
$user = $mrepo::params::user,
$group = $mrepo::params::group,
Enum['git', 'package'] $source = $mrepo::params::source,
$ensure_src = $mrepo::params::ensure_src,
Optional[Boolean] $selinux = $mrepo::params::selinux,
Boolean $rhn = $mrepo::params::rhn,
$rhn_config = $mrepo::params::rhn_config,
Optional[String] $rhn_username = $mrepo::params::rhn_username,
Optional[String] $rhn_password = $mrepo::params::rhn_password,
Optional[Boolean] $rhnget_cleanup = $mrepo::params::rhnget_cleanup,
Optional[Boolean] $rhnget_download_all = $mrepo::params::rhnget_download_all,
$genid_command = $mrepo::params::genid_command,
Optional[String] $mailto = $mrepo::params::mailto,
Optional[String] $mailfrom = $mrepo::params::mailfrom,
$smtpserver = $mrepo::params::smtpserver,
Enum['git', 'https'] $git_proto = $mrepo::params::git_proto,
Hash $descriptions = $mrepo::params::descriptions,
$http_proxy = $mrepo::params::http_proxy,
$https_proxy = $mrepo::params::https_proxy,
Integer $priority = $mrepo::params::priority,
Integer $port = $mrepo::params::port,
$selinux_context = $mrepo::params::selinux_context,
$service_enable = $mrepo::params::service_enable,
$service_manage = $mrepo::params::service_manage,
) inherits ::mrepo::params {
Stdlib::Absolutepath $src_root = $mrepo::params::src_root,
Stdlib::Absolutepath $www_root = $mrepo::params::www_root,
String[1] $www_servername = $mrepo::params::www_servername,
Stdlib::IP::Address $www_ip = $mrepo::params::www_ip,
Boolean $www_ip_based = $mrepo::params::www_ip_based,
String[1] $user = $mrepo::params::user,
String[1] $group = $mrepo::params::group,
Enum['git', 'package'] $source = $mrepo::params::source,
Enum['latest', 'present', 'absent'] $ensure_src = $mrepo::params::ensure_src,
Optional[Boolean] $selinux = $mrepo::params::selinux,
Boolean $rhn = $mrepo::params::rhn,
Boolean $rhn_config = $mrepo::params::rhn_config,
Optional[String[1]] $rhn_username = $mrepo::params::rhn_username,
Optional[String[1]] $rhn_password = $mrepo::params::rhn_password,
Optional[Boolean] $rhnget_cleanup = $mrepo::params::rhnget_cleanup,
Optional[Boolean] $rhnget_download_all = $mrepo::params::rhnget_download_all,
Stdlib::Absolutepath $genid_command = $mrepo::params::genid_command,
Optional[String[1]] $mailto = $mrepo::params::mailto,
Optional[String[1]] $mailfrom = $mrepo::params::mailfrom,
Optional[Stdlib::Host] $smtpserver = $mrepo::params::smtpserver,
Enum['git', 'https'] $git_proto = $mrepo::params::git_proto,
Hash $descriptions = $mrepo::params::descriptions,
Optional[Stdlib::HTTPUrl] $http_proxy = $mrepo::params::http_proxy,
Optional[Stdlib::HTTPUrl] $https_proxy = $mrepo::params::https_proxy,
Integer $priority = $mrepo::params::priority,
Integer $port = $mrepo::params::port,
Optional[String[1]] $createrepo_options = $mrepo::params::createrepo_options,
String[1] $selinux_context = $mrepo::params::selinux_context,
Boolean $service_enable = $mrepo::params::service_enable,
Boolean $service_manage = $mrepo::params::service_manage,
) inherits mrepo::params {

if $rhn {
assert_type(String[1], $rhn_username)
Expand All @@ -156,7 +157,7 @@
# If undefined and selinux is present and not disabled, use selinux.
case $mrepo::selinux {
undef: {
case $::selinux {
case $selinux {
'enforcing', 'permissive': {
$use_selinux = true
}
Expand Down
20 changes: 10 additions & 10 deletions manifests/iso.pp
Expand Up @@ -8,20 +8,20 @@
# from title param, which then forms the whole URL to the ISO file.
# @param repo Title of the mrepo::repo resources the ISO file belongs to
define mrepo::iso($source_url, $repo) {

include mrepo

$target_file = "${mrepo::src_root}/iso/${name}"

file { "${mrepo::src_root}/iso":
ensure => directory,
owner => $mrepo::user,
group => $mrepo::group,
mode => '0644',
}
ensure_resource('file', "${mrepo::src_root}/iso", {
'ensure' => 'directory',
'owner' => $mrepo::user,
'group' => $mrepo::group,
'mode' => '0644',
})

-> archive { $target_file:
source => "${source_url}/${name}",
before => Mrepo::Repo[$repo],
archive { $target_file:
source => "${source_url}/${name}",
before => Mrepo::Repo[$repo],
require => File["${mrepo::src_root}/iso"],
}
}
1 change: 1 addition & 0 deletions manifests/package.pp
Expand Up @@ -62,6 +62,7 @@
$mailto = $mrepo::mailto
$http_proxy = $mrepo::http_proxy
$https_proxy = $mrepo::https_proxy
$createrepo_options = $mrepo::createrepo_options

file { '/etc/mrepo.conf':
ensure => present,
Expand Down
16 changes: 7 additions & 9 deletions manifests/params.pp
Expand Up @@ -9,13 +9,11 @@
#
# Copyright 2011 Puppet Labs unless otherwise noted
#
class mrepo::params
{

class mrepo::params {
$src_root = '/var/mrepo'
$www_root = '/var/www/mrepo'
$www_servername = 'mrepo'
$www_ip = $::ipaddress
$www_ip = $facts['networking']['ip']
$www_ip_based = false
$user = 'apache'
$group = 'apache'
Expand All @@ -24,8 +22,8 @@
$selinux = undef
$rhn = false
$rhn_config = false
$rhn_username = ''
$rhn_password = ''
$rhn_username = undef
$rhn_password = undef
$rhnget_cleanup = undef
$rhnget_download_all = undef
$genid_command = '/usr/bin/gensystemid'
Expand All @@ -34,12 +32,12 @@
$smtpserver = undef
$git_proto = 'git'
$descriptions = {}
$http_proxy = ''
$https_proxy = ''
$http_proxy = undef
$https_proxy = undef
$priority = 10
$port = 80
$createrepo_options = undef
$selinux_context = 'system_u:object_r:httpd_sys_content_t'
$service_enable = true
$service_manage = false

}
86 changes: 58 additions & 28 deletions manifests/repo.pp
Expand Up @@ -116,23 +116,25 @@
#
define mrepo::repo (
Enum['present', 'absent'] $ensure,
$release,
String[1] $release,
Mrepo::Arch $arch,
$urls = {},
$metadata = 'repomd',
Mrepo::Update $update = 'nightly',
$hour = '0',
$minute = '0',
$iso = '',
$repotitle = $name,
$gen_timeout = '1200',
$sync_timeout = '1200',
Enum['std', 'ncc', 'rhn'] $type = 'std',
$typerelease = undef,
Optional[String[1]] $mrepo_env = undef,
$mrepo_command = '/usr/bin/mrepo',
$mrepo_options = '-qgu',
$mrepo_logging = undef,
Hash[String, String] $urls = {},
String[1] $metadata = 'repomd',
Mrepo::Update $update = 'nightly',
Variant[String[1], Integer] $hour = '0',
Variant[String[1], Integer] $minute = '0',
Optional[String[1]] $iso = undef,
String[1] $repotitle = $name,
Variant[String[1], Integer] $gen_timeout = '1200',
Variant[String[1], Integer] $sync_timeout = '1200',
Enum['std', 'ncc', 'rhn'] $type = 'std',
Optional[String[1]] $typerelease = undef,
Optional[String[1]] $mrepo_env = undef,
Stdlib::Absolutepath $mrepo_command = '/usr/bin/mrepo',
String $mrepo_options = '-qgu',
Optional[String[1]] $mrepo_logging = undef,
Optional[String[1]] $ncc_username = undef,
Optional[String[1]] $ncc_password = undef,
) {
include mrepo

Expand Down Expand Up @@ -243,18 +245,46 @@
}
}

if $type != 'std' {
#notify { "Type = ${type}": }
create_resources( "mrepo::repo::${type}",
{ "${name}" => {
ensure => $ensure,
release => $release,
arch => $arch,
repotitle => $repotitle,
typerelease => $typerelease,
case $type {
'ncc': {
create_resources( 'mrepo::repo::ncc',
{ "${name}" => {
ensure => $ensure,
release => $release,
arch => $arch,
ncc_username => $ncc_username,
ncc_password => $ncc_password,
urls => $urls,
metadata => $metadata,
update => $update,
hour => $hour,
iso => $iso,
repotitle => $repotitle,
typerelease => $typerelease,
}
}
}
)
)
}
'rhn': {
create_resources( 'mrepo::repo::rhn',
{ "${name}" => {
ensure => $ensure,
release => $release,
arch => $arch,
urls => $urls,
metadata => $metadata,
update => $update,
hour => $hour,
iso => $iso,
repotitle => $repotitle,
typerelease => $typerelease,
}
}
)
}
default: {
# don't do anything for 'std'
}
}

}
Expand All @@ -274,7 +304,7 @@
before => File[$src_root_subdir],
require => Exec["Unmount any mirrored ISOs for ${name}"],
}
file { "${mrepo::src_root}/${name}":
file { $src_root_subdir:
ensure => absent,
backup => false,
recurse => false,
Expand Down
24 changes: 12 additions & 12 deletions manifests/repo/ncc.pp
Expand Up @@ -23,18 +23,18 @@
# Copyright 2012 Puppet Labs, unless otherwise noted
#
define mrepo::repo::ncc (
$ensure,
$release,
$arch,
$ncc_username,
$ncc_password,
$urls = {},
$metadata = 'repomd',
$update = 'nightly',
$hour = '0',
$iso = '',
$repotitle = $name,
$typerelease = $release,
Enum['present', 'absent'] $ensure,
String[1] $release,
Mrepo::Arch $arch,
String[1] $ncc_username,
String[1] $ncc_password,
Hash[String, String] $urls = {},
String[1] $metadata = 'repomd',
Mrepo::Update $update = 'nightly',
Variant[String[1], Integer] $hour = '0',
Optional[String[1]] $iso = undef,
String[1] $repotitle = $name,
Optional[String[1]] $typerelease = $release,
) {
include mrepo

Expand Down
20 changes: 10 additions & 10 deletions manifests/repo/rhn.pp
Expand Up @@ -24,16 +24,16 @@
# Copyright 2012 Puppet Labs, unless otherwise noted
#
define mrepo::repo::rhn (
$ensure,
$release,
$arch,
$urls = {},
$metadata = 'repomd',
$update = 'nightly',
$hour = '0',
$iso = '',
$typerelease = $release,
$repotitle = $name,
Enum['present', 'absent'] $ensure,
String[1] $release,
Mrepo::Arch $arch,
Hash[String, String] $urls = {},
String[1] $metadata = 'repomd',
Mrepo::Update $update = 'nightly',
Variant[String[1], Integer] $hour = '0',
Optional[String[1]] $iso = undef,
String[1] $repotitle = $name,
Optional[String[1]] $typerelease = $release,
) {
include mrepo::params

Expand Down
4 changes: 2 additions & 2 deletions manifests/rhn.pp
Expand Up @@ -31,7 +31,7 @@
}

# CentOS does not have redhat network specific configuration files by default
if $::operatingsystem == 'CentOS' or $rhn_config == true {
if $facts['os']['name'] == 'CentOS' or $rhn_config == true {

file { '/etc/sysconfig/rhn':
ensure => 'file',
Expand All @@ -41,7 +41,7 @@
}

# Generate UUID using the fqdn_uuid function from stdlib
$rhnuuid_setting = fqdn_uuid($::fqdn)
$rhnuuid_setting = fqdn_uuid($facts['networking']['fqdn'])

file { '/etc/sysconfig/rhn/up2date-uuid':
ensure => 'file',
Expand Down
10 changes: 10 additions & 0 deletions spec/classes/package_spec.rb
Expand Up @@ -71,6 +71,16 @@
end
end
end
describe 'with createrepo_options' do
let(:pre_condition) do
'class { "mrepo": createrepo_options => "--some-opt --another-opt -q -p" }'
end

it do
content = catalogue.resource('file', '/etc/mrepo.conf').send(:parameters)[:content]
expect(content).to match %r{^createrepo-options = --some-opt --another-opt -q -p$}
end
end
end
end
end
11 changes: 7 additions & 4 deletions templates/mrepo.conf.erb
Expand Up @@ -5,16 +5,19 @@ srcdir = <%= @src_root %>
wwwdir = <%= @www_root %>
confdir = /etc/mrepo.conf.d

<% if not @http_proxy.empty? -%>
<% if @createrepo_options -%>
createrepo-options = <%= @createrepo_options %>
<% end -%>
<% if @http_proxy -%>
http_proxy = <%= @http_proxy %>
<% end -%>
<% if not @https_proxy.empty? -%>
<% if @https_proxy -%>
https_proxy = <%= @https_proxy %>
<% end -%>
<% if not @rhn_username.empty? and not @rhn_password.empty? -%>
<% if @rhn_username and @rhn_password -%>
rhnlogin = <%= @rhn_username %>:<%= @rhn_password %>
<% elsif not @rhn_username.empty? -%>
<% elsif @rhn_username -%>
rhnlogin = <%= @rhn_username %>
<% end -%>
<% unless @rhnget_cleanup.nil? -%>
Expand Down

0 comments on commit 94c0876

Please sign in to comment.