From 6121cba9cba662abed5a08003d2fcee69543f926 Mon Sep 17 00:00:00 2001 From: Andreas Ntaflos Date: Tue, 9 Jan 2018 20:20:12 +0100 Subject: [PATCH] Add support for additional DHCP listen interfaces This change adds a new parameter foreman_proxy::dhcp_additional_interfaces which defaults to undef. The parameter's value can be either a string or an array of interface names. When set the managed DHCP server will listen for DHCP requests on these interfaces, in addition to the interface specified in foreman_proxy::dhcp_interface. --- manifests/init.pp | 3 + manifests/params.pp | 1 + manifests/proxydhcp.pp | 2 +- .../classes/foreman_proxy__proxydhcp__spec.rb | 81 +++++++++++++++++++ 4 files changed, 86 insertions(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index b85c9b293..fd0fe240b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -174,6 +174,8 @@ # # $dhcp_interface:: DHCP listen interface # +# $dhcp_additional_interfaces:: Additional DHCP listen interfaces (in addition to dhcp_interface) +# # $dhcp_gateway:: DHCP pool gateway # # $dhcp_range:: Space-separated DHCP pool range @@ -366,6 +368,7 @@ Array[String] $dhcp_option_domain = $::foreman_proxy::params::dhcp_option_domain, Optional[Array[String]] $dhcp_search_domains = $::foreman_proxy::params::dhcp_search_domains, String $dhcp_interface = $::foreman_proxy::params::dhcp_interface, + Optional[Variant[Array[String], String]] $dhcp_additional_interfaces = $::foreman_proxy::params::dhcp_additional_interfaces, Optional[String] $dhcp_gateway = $::foreman_proxy::params::dhcp_gateway, Variant[Undef, Boolean, String] $dhcp_range = $::foreman_proxy::params::dhcp_range, Optional[String] $dhcp_pxeserver = $::foreman_proxy::params::dhcp_pxeserver, diff --git a/manifests/params.pp b/manifests/params.pp index 9252a4852..9632b551a 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -285,6 +285,7 @@ $dhcp_provider = 'isc' $dhcp_subnets = [] $dhcp_interface = 'eth0' + $dhcp_additional_interfaces = undef $dhcp_gateway = '192.168.100.1' $dhcp_range = undef $dhcp_option_domain = [$::domain] diff --git a/manifests/proxydhcp.pp b/manifests/proxydhcp.pp index 66e8069ed..fac22e4b1 100644 --- a/manifests/proxydhcp.pp +++ b/manifests/proxydhcp.pp @@ -33,7 +33,7 @@ class { '::dhcp': dnsdomain => $foreman_proxy::dhcp_option_domain, nameservers => $nameservers, - interfaces => [$foreman_proxy::dhcp_interface], + interfaces => [$foreman_proxy::dhcp_interface] + [$foreman_proxy::dhcp_additional_interfaces].flatten.delete_undef_values, pxeserver => $ip, pxefilename => 'pxelinux.0', omapi_name => $foreman_proxy::dhcp_key_name, diff --git a/spec/classes/foreman_proxy__proxydhcp__spec.rb b/spec/classes/foreman_proxy__proxydhcp__spec.rb index 8edeadce6..5b2170d74 100644 --- a/spec/classes/foreman_proxy__proxydhcp__spec.rb +++ b/spec/classes/foreman_proxy__proxydhcp__spec.rb @@ -101,6 +101,87 @@ it { should_not contain_class('dhcp::failover') } end + context "with additional dhcp listen interfaces" do + let :facts do + facts.merge({:ipaddress_eth0 => '127.0.1.1', + :netmask_eth0 => '255.0.0.0', + :network_eth0 => '127.0.0.0'}) + end + + let :pre_condition do + "class {'foreman_proxy': + dhcp_gateway => '127.0.0.254', + dhcp_additional_interfaces => [ 'vlan8', 'vlan9', 'vlan120' ], + }" + end + + it do should contain_class('dhcp').with( + 'dnsdomain' => ['example.com'], + 'nameservers' => ['127.0.1.1'], + 'interfaces' => ['eth0', 'vlan8', 'vlan9', 'vlan120' ], + 'pxeserver' => '127.0.1.1', + 'pxefilename' => 'pxelinux.0' + ) end + + it do should contain_dhcp__pool('example.com').with( + 'network' => '127.0.0.0', + 'mask' => '255.0.0.0', + 'range' => nil, + 'gateway' => '127.0.0.254', + 'failover' => nil + ) end + + it { should_not contain_class('dhcp::failover') } + end + + context "with one additional dhcp listen interface" do + let :facts do + facts.merge({:ipaddress_eth0 => '127.0.1.1', + :netmask_eth0 => '255.0.0.0', + :network_eth0 => '127.0.0.0'}) + end + + let :pre_condition do + "class {'foreman_proxy': + dhcp_gateway => '127.0.0.254', + dhcp_additional_interfaces => 'vlan83' + }" + end + + it do should contain_class('dhcp').with( + 'dnsdomain' => ['example.com'], + 'nameservers' => ['127.0.1.1'], + 'interfaces' => ['eth0', 'vlan83'], + 'pxeserver' => '127.0.1.1', + 'pxefilename' => 'pxelinux.0' + ) end + + it do should contain_dhcp__pool('example.com').with( + 'network' => '127.0.0.0', + 'mask' => '255.0.0.0', + 'range' => nil, + 'gateway' => '127.0.0.254', + 'failover' => nil + ) end + + it { should_not contain_class('dhcp::failover') } + end + + context "with additional dhcp listen interfaces specified as wrong data type" do + let :facts do + facts.merge({:ipaddress_eth0 => '127.0.1.1', + :netmask_eth0 => '255.0.0.0', + :network_eth0 => '127.0.0.0'}) + end + + let :pre_condition do + "class {'foreman_proxy': + dhcp_gateway => '127.0.0.254', + dhcp_additional_interfaces => { 'name' => 'vlan55' } + }" + end + it { should raise_error(Puppet::PreformattedError, /expects a value of type Undef, Array, or String, got Struct/) } + end context "with dhcp_search_domains" do let :facts do