Skip to content

Commit

Permalink
Introduce foreman_proxy::module
Browse files Browse the repository at this point in the history
This define introduced an abstraction for Foreman Proxy modules slightly
more explicit than just the settings_file.
  • Loading branch information
ekohl authored and mmoll committed Apr 2, 2020
1 parent 3fec1b9 commit db65c34
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 58 deletions.
83 changes: 25 additions & 58 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -51,48 +51,27 @@
module => false,
}

foreman_proxy::settings_file { 'bmc':
enabled => $::foreman_proxy::bmc,
feature => 'BMC',
listen_on => $::foreman_proxy::bmc_listen_on,
}
foreman_proxy::settings_file { 'dhcp':
enabled => $::foreman_proxy::dhcp,
feature => 'DHCP',
listen_on => $::foreman_proxy::dhcp_listen_on,
}
foreman_proxy::settings_file { 'dhcp_isc':
module => false,
}
foreman_proxy::settings_file { 'dns':
enabled => $::foreman_proxy::dns,
feature => 'DNS',
listen_on => $::foreman_proxy::dns_listen_on,
}
foreman_proxy::settings_file { ['dns_nsupdate', 'dns_nsupdate_gss']:
contain foreman_proxy::module::bmc

contain foreman_proxy::module::dhcp
foreman_proxy::settings_file { ['dhcp_isc', 'dhcp_libvirt']:
module => false,
}
foreman_proxy::settings_file { ['dns_libvirt', 'dhcp_libvirt']:

contain foreman_proxy::module::dns
foreman_proxy::settings_file { ['dns_nsupdate', 'dns_nsupdate_gss', 'dns_libvirt']:
module => false,
}
foreman_proxy::settings_file { 'httpboot':
enabled => pick($::foreman_proxy::httpboot, $::foreman_proxy::tftp),
feature => 'HTTPBoot',
listen_on => $::foreman_proxy::httpboot_listen_on,
}
foreman_proxy::settings_file { 'puppet':
enabled => $::foreman_proxy::puppet,
feature => 'Puppet',
listen_on => $::foreman_proxy::puppet_listen_on,
}

contain foreman_proxy::module::httpboot

contain foreman_proxy::module::puppet
foreman_proxy::settings_file { [
'puppet_proxy_customrun',
'puppet_proxy_mcollective',
'puppet_proxy_puppet_api',
'puppet_proxy_salt',
'puppet_proxy_ssh',
'puppetca_hostname_whitelisting',
'puppetca_token_whitelisting',
]:
module => false,
}
Expand All @@ -103,34 +82,11 @@
ensure => 'absent',
module => false,
}
foreman_proxy::settings_file { 'puppetca':
enabled => $::foreman_proxy::puppetca,
feature => 'Puppet CA',
listen_on => $::foreman_proxy::puppetca_listen_on,
}
foreman_proxy::settings_file { 'realm':
enabled => $::foreman_proxy::realm,
feature => 'Realm',
listen_on => $::foreman_proxy::realm_listen_on,
}
foreman_proxy::settings_file { 'realm_freeipa':

contain foreman_proxy::module::puppetca
foreman_proxy::settings_file { ['puppetca_hostname_whitelisting', 'puppetca_token_whitelisting']:
module => false,
}
foreman_proxy::settings_file { 'tftp':
enabled => $::foreman_proxy::tftp,
feature => 'TFTP',
listen_on => $::foreman_proxy::tftp_listen_on,
}
foreman_proxy::settings_file { 'templates':
enabled => $::foreman_proxy::templates,
feature => 'Templates',
listen_on => $::foreman_proxy::templates_listen_on,
}
foreman_proxy::settings_file { 'logs':
enabled => $::foreman_proxy::logs,
feature => 'Logs',
listen_on => $::foreman_proxy::logs_listen_on,
}

if $foreman_proxy::puppetca_split_configs {
foreman_proxy::settings_file { [
Expand All @@ -141,6 +97,17 @@
}
}

contain foreman_proxy::module::realm
foreman_proxy::settings_file { 'realm_freeipa':
module => false,
}

contain foreman_proxy::module::tftp

contain foreman_proxy::module::templates

contain foreman_proxy::module::logs

if $foreman_proxy::puppetca or $foreman_proxy::puppet {
$uses_sudo = $foreman_proxy::puppetca and versioncmp($facts['puppetversion'], '6.0') < 0

Expand Down
30 changes: 30 additions & 0 deletions manifests/module.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# @summary Low level abstraction of Foreman Proxy modules
#
# Foreman Proxy internally has the concept of modules. Some modules have
# providers or even multiple ones. That's not part of this definition.
#
# @param enabled
# Whether the module is enabled or disabled.
#
# @param listen_on
# When enabled, it's configured to listen on HTTPS (default), HTTP or both.
# Unless the module explicitly needs HTTP (usually because clients needs it),
# HTTPS should be chosen.
#
# @param feature
# Each module is exposed as a feature to Foreman on registration.
# foreman_proxy::register will validate the feature name is loaded and
# advertised.
#
define foreman_proxy::module (
Boolean $enabled = false,
Foreman_proxy::ListenOn $listen_on = 'https',
String $feature = upcase($title),
) {
foreman_proxy::settings_file { $name:
module => true,
enabled => $enabled,
feature => $feature,
listen_on => $listen_on,
}
}
16 changes: 16 additions & 0 deletions manifests/module/bmc.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @summary The built in BMC module
#
# @param enabled
# Whether the module is enabled or disabled.
#
# @param listen_on
# Where to listen on.
class foreman_proxy::module::bmc (
Boolean $enabled = $foreman_proxy::bmc,
Foreman_proxy::ListenOn $listen_on = $foreman_proxy::bmc_listen_on,
) {
foreman_proxy::module { 'bmc':
enabled => $enabled,
listen_on => $listen_on,
}
}
16 changes: 16 additions & 0 deletions manifests/module/dhcp.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @summary The built in DHCP module
#
# @param enabled
# Whether the module is enabled or disabled.
#
# @param listen_on
# Where to listen on.
class foreman_proxy::module::dhcp (
Boolean $enabled = $foreman_proxy::dhcp,
Foreman_proxy::ListenOn $listen_on = $foreman_proxy::dhcp_listen_on,
) {
foreman_proxy::module { 'dhcp':
enabled => $enabled,
listen_on => $listen_on,
}
}
16 changes: 16 additions & 0 deletions manifests/module/dns.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @summary The built in DNS module
#
# @param enabled
# Whether the module is enabled or disabled.
#
# @param listen_on
# Where to listen on.
class foreman_proxy::module::dns (
Boolean $enabled = $foreman_proxy::dns,
Foreman_proxy::ListenOn $listen_on = $foreman_proxy::dns_listen_on,
) {
foreman_proxy::module { 'dns':
enabled => $enabled,
listen_on => $listen_on,
}
}
25 changes: 25 additions & 0 deletions manifests/module/httpboot.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# @summary The built in HTTPBoot module
#
# @param enabled
# Whether the module is enabled or disabled.
#
# @param listen_on
# Where to listen on.
class foreman_proxy::module::httpboot (
Optional[Boolean] $enabled = $foreman_proxy::httpboot,
Foreman_proxy::ListenOn $listen_on = $foreman_proxy::httpboot_listen_on,
) {
$real_enabled = pick($enabled, $foreman_proxy::tftp)
if $real_enabled {
include foreman_proxy::module::tftp
unless $foreman_proxy::module::tftp::enabled {
fail('The HTTPBoot module depends on the TFTP module to be enabled')
}
}

foreman_proxy::module { 'httpboot':
enabled => $real_enabled,
feature => 'HTTPBoot',
listen_on => $listen_on,
}
}
17 changes: 17 additions & 0 deletions manifests/module/logs.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# @summary The built in Logs module
#
# @param enabled
# Whether the module is enabled or disabled.
#
# @param listen_on
# Where to listen on.
class foreman_proxy::module::logs (
Boolean $enabled = $foreman_proxy::logs,
Foreman_proxy::ListenOn $listen_on = $foreman_proxy::logs_listen_on,
) {
foreman_proxy::module { 'logs':
enabled => $enabled,
feature => 'Logs',
listen_on => $listen_on,
}
}
17 changes: 17 additions & 0 deletions manifests/module/puppet.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# @summary The built in Puppet module
#
# @param enabled
# Whether the module is enabled or disabled.
#
# @param listen_on
# Where to listen on.
class foreman_proxy::module::puppet (
Boolean $enabled = $foreman_proxy::puppet,
Foreman_proxy::ListenOn $listen_on = $foreman_proxy::puppet_listen_on,
) {
foreman_proxy::module { 'puppet':
enabled => $enabled,
feature => 'Puppet',
listen_on => $listen_on,
}
}
17 changes: 17 additions & 0 deletions manifests/module/puppetca.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# @summary The built in Puppet CA module
#
# @param enabled
# Whether the module is enabled or disabled.
#
# @param listen_on
# Where to listen on.
class foreman_proxy::module::puppetca (
Boolean $enabled = $foreman_proxy::puppetca,
Foreman_proxy::ListenOn $listen_on = $foreman_proxy::puppetca_listen_on,
) {
foreman_proxy::module { 'puppetca':
enabled => $enabled,
feature => 'Puppet CA',
listen_on => $listen_on,
}
}
17 changes: 17 additions & 0 deletions manifests/module/realm.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# @summary The built in Realm module
#
# @param enabled
# Whether the module is enabled or disabled.
#
# @param listen_on
# Where to listen on.
class foreman_proxy::module::realm (
Boolean $enabled = $foreman_proxy::realm,
Foreman_proxy::ListenOn $listen_on = $foreman_proxy::realm_listen_on,
) {
foreman_proxy::module { 'realm':
enabled => $enabled,
feature => 'Realm',
listen_on => $listen_on,
}
}
17 changes: 17 additions & 0 deletions manifests/module/templates.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# @summary The built in Templates module
#
# @param enabled
# Whether the module is enabled or disabled.
#
# @param listen_on
# Where to listen on.
class foreman_proxy::module::templates (
Boolean $enabled = $foreman_proxy::templates,
Foreman_proxy::ListenOn $listen_on = $foreman_proxy::templates_listen_on,
) {
foreman_proxy::module { 'templates':
enabled => $enabled,
feature => 'Templates',
listen_on => $listen_on,
}
}
16 changes: 16 additions & 0 deletions manifests/module/tftp.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @summary The built in TFTP module
#
# @param enabled
# Whether the module is enabled or disabled.
#
# @param listen_on
# Where to listen on.
class foreman_proxy::module::tftp (
Boolean $enabled = $foreman_proxy::tftp,
Foreman_proxy::ListenOn $listen_on = $foreman_proxy::tftp_listen_on,
) {
foreman_proxy::module { 'tftp':
enabled => $enabled,
listen_on => $listen_on,
}
}
61 changes: 61 additions & 0 deletions spec/defines/foreman_proxy_module_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
require 'spec_helper'

describe 'foreman_proxy::module' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }
let(:title) { 'test' }
let(:pre_condition) { 'include foreman_proxy::params' }

context 'with defaults' do
it { is_expected.to compile.with_all_deps }
it do
is_expected.to contain_foreman_proxy__settings_file('test')
.with_enabled(false)
.with_feature('TEST')
.with_listen_on('https')
end

it { is_expected.not_to contain_foreman_proxy__feature('TEST') }
end

context 'with enabled => true' do
let(:params) { { enabled: true } }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_foreman_proxy__settings_file('test').with_enabled(true) }
it { is_expected.to contain_foreman_proxy__feature('TEST') }
end

context 'with feature' do
let(:params) { { feature: 'Test' } }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_foreman_proxy__settings_file('test').with_feature('Test') }
it { is_expected.not_to contain_foreman_proxy__feature('Test') }

context 'with enabled => true' do
let(:params) { super().merge(enabled: true) }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_foreman_proxy__settings_file('test').with_enabled(true).with_feature('Test') }
it { is_expected.to contain_foreman_proxy__feature('Test') }
end
end

context 'with listen_on => both' do
let(:params) { { listen_on: 'both' } }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_foreman_proxy__settings_file('test').with_listen_on('both') }
end

context 'with listen_on => http' do
let(:params) { { listen_on: 'http' } }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_foreman_proxy__settings_file('test').with_listen_on('http') }
end
end
end
end

0 comments on commit db65c34

Please sign in to comment.