From 6c37115c5139b5b0ed5deef7a0497c73903afcce Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Wed, 27 Nov 2019 19:20:23 +0100 Subject: [PATCH] Only manage ISC DHCP when using the ISC provider The managed ISC DHCP server is only relevant when using the ISC provider, wether that's isc or remote_isc. --- manifests/config.pp | 4 +- spec/classes/foreman_proxy__spec.rb | 135 ++++++++++++++++------------ 2 files changed, 83 insertions(+), 56 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 5946a354..de704747 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -17,7 +17,9 @@ if $foreman_proxy::tftp and $foreman_proxy::tftp_managed { include ::foreman_proxy::tftp } # Somehow, calling these DHCP and DNS seems to conflict. So, they get a prefix... - if $foreman_proxy::dhcp and $foreman_proxy::dhcp_managed { include ::foreman_proxy::proxydhcp } + if $foreman_proxy::dhcp and $foreman_proxy::dhcp_provider in ['isc', 'remote_isc'] and $foreman_proxy::dhcp_managed { + include ::foreman_proxy::proxydhcp + } if $foreman_proxy::dns and $foreman_proxy::dns_provider in ['nsupdate', 'nsupdate_gss'] and $foreman_proxy::dns_managed { include ::foreman_proxy::proxydns diff --git a/spec/classes/foreman_proxy__spec.rb b/spec/classes/foreman_proxy__spec.rb index 93512764..fde37576 100644 --- a/spec/classes/foreman_proxy__spec.rb +++ b/spec/classes/foreman_proxy__spec.rb @@ -756,31 +756,6 @@ end end - context 'when dhcp_provider => libvirt' do - let(:params) do - super().merge( - dhcp_provider: 'libvirt', - libvirt_network: 'mynet', - libvirt_connection: 'http://myvirt', - ) - end - - it 'should set the provider correctly' do - verify_exact_contents(catalogue, "#{etc_dir}/foreman-proxy/settings.d/dhcp.yml", [ - '---', - ':enabled: false', - ':use_provider: dhcp_libvirt', - ':server: 127.0.0.1', - ]) - - verify_exact_contents(catalogue, "#{etc_dir}/foreman-proxy/settings.d/dhcp_libvirt.yml", [ - '---', - ':network: mynet', - ':url: http://myvirt', - ]) - end - end - context 'with puppetrun_provider set to mcollective and user overridden' do let(:params) do super().merge( @@ -960,41 +935,91 @@ end context 'with dhcp enabled' do - case facts[:osfamily] - when 'FreeBSD', 'DragonFly' - dhcp_leases = '/var/db/dhcpd/dhcpd.leases' - dhcp_config = "#{etc_dir}/dhcpd.conf" - when 'Debian' - dhcp_leases = '/var/lib/dhcp/dhcpd.leases' - dhcp_config = "#{etc_dir}/dhcp/dhcpd.conf" - when 'Archlinux' - dhcp_leases = '/var/lib/dhcp/dhcpd.leases' - dhcp_config = "#{etc_dir}/dhcpd.conf" - else - dhcp_leases = '/var/lib/dhcpd/dhcpd.leases' - dhcp_config = "#{etc_dir}/dhcp/dhcpd.conf" - end + let(:params) { super().merge(dhcp: true) } - let(:facts) { super().merge(ipaddress_dhcpif: '192.0.2.1', network_dhcpif: '192.0.2.0', netmask_dhcpif: '255.255.255.0') } + context 'dhcp_provider => isc' do + let(:params) { super().merge(dhcp_interface: 'dhcpif') } + let(:facts) { super().merge(ipaddress_dhcpif: '192.0.2.1', network_dhcpif: '192.0.2.0', netmask_dhcpif: '255.255.255.0') } - let(:params) { super().merge(dhcp: true, dhcp_interface: 'dhcpif') } + case facts[:osfamily] + when 'FreeBSD', 'DragonFly' + dhcp_leases = '/var/db/dhcpd/dhcpd.leases' + dhcp_config = "#{etc_dir}/dhcpd.conf" + when 'Debian' + dhcp_leases = '/var/lib/dhcp/dhcpd.leases' + dhcp_config = "#{etc_dir}/dhcp/dhcpd.conf" + when 'Archlinux' + dhcp_leases = '/var/lib/dhcp/dhcpd.leases' + dhcp_config = "#{etc_dir}/dhcpd.conf" + else + dhcp_leases = '/var/lib/dhcpd/dhcpd.leases' + dhcp_config = "#{etc_dir}/dhcp/dhcpd.conf" + end - it 'should generate correct dhcp.yml' do - verify_exact_contents(catalogue, "#{etc_dir}/foreman-proxy/settings.d/dhcp.yml", [ - '---', - ':enabled: https', - ':use_provider: dhcp_isc', - ':server: 127.0.0.1', - ]) + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('foreman_proxy::proxydhcp') } + + it 'should generate correct dhcp.yml' do + verify_exact_contents(catalogue, "#{etc_dir}/foreman-proxy/settings.d/dhcp.yml", [ + '---', + ':enabled: https', + ':use_provider: dhcp_isc', + ':server: 127.0.0.1', + ]) + end + + it 'should generate correct dhcp_isc.yml' do + verify_exact_contents(catalogue, "#{etc_dir}/foreman-proxy/settings.d/dhcp_isc.yml", [ + '---', + ":config: #{dhcp_config}", + ":leases: #{dhcp_leases}", + ':omapi_port: 7911', + ]) + end + + context 'dhcp_managed => false' do + let(:params) { super().merge(dhcp_managed: false) } + + it { is_expected.to compile.with_all_deps } + it { is_expected.not_to contain_class('foreman_proxy::proxydhcp') } + + it 'should generate correct dhcp_isc.yml' do + verify_exact_contents(catalogue, "#{etc_dir}/foreman-proxy/settings.d/dhcp_isc.yml", [ + '---', + ":config: #{dhcp_config}", + ":leases: #{dhcp_leases}", + ':omapi_port: 7911', + ]) + end + end end - it 'should generate correct dhcp_isc.yml' do - verify_exact_contents(catalogue, "#{etc_dir}/foreman-proxy/settings.d/dhcp_isc.yml", [ - '---', - ":config: #{dhcp_config}", - ":leases: #{dhcp_leases}", - ':omapi_port: 7911', - ]) + context 'when dhcp_provider => libvirt' do + let(:params) do + super().merge( + dhcp_provider: 'libvirt', + libvirt_network: 'mynet', + libvirt_connection: 'http://myvirt', + ) + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.not_to contain_class('foreman_proxy::proxydhcp') } + + it 'should set the provider correctly' do + verify_exact_contents(catalogue, "#{etc_dir}/foreman-proxy/settings.d/dhcp.yml", [ + '---', + ':enabled: https', + ':use_provider: dhcp_libvirt', + ':server: 127.0.0.1', + ]) + + verify_exact_contents(catalogue, "#{etc_dir}/foreman-proxy/settings.d/dhcp_libvirt.yml", [ + '---', + ':network: mynet', + ':url: http://myvirt', + ]) + end end end