Skip to content

Commit

Permalink
Add support for additional DHCP listen interfaces
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
antaflos committed Jan 9, 2018
1 parent 8d4b06c commit 6121cba
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion manifests/proxydhcp.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
81 changes: 81 additions & 0 deletions spec/classes/foreman_proxy__proxydhcp__spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6121cba

Please sign in to comment.