Skip to content

Commit

Permalink
Only manage ISC DHCP when using the ISC provider
Browse files Browse the repository at this point in the history
The managed ISC DHCP server is only relevant when using the ISC
provider, wether that's isc or remote_isc.
  • Loading branch information
ekohl authored and mmoll committed Nov 27, 2019
1 parent 54067fe commit 6c37115
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 56 deletions.
4 changes: 3 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
135 changes: 80 additions & 55 deletions spec/classes/foreman_proxy__spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 6c37115

Please sign in to comment.