Merge "Update dnsmasq for additional networks" into stable/mitaka

This commit is contained in:
Jenkins 2016-08-11 16:11:29 +00:00 committed by Gerrit Code Review
commit 30899cdca4
4 changed files with 26 additions and 1 deletions

View File

@ -13,6 +13,18 @@ Creates fuel::dnsmasq::dhcp_range puppet resources from list of admin networks.
admin_nets.each do |net|
next unless net['ip_ranges'].is_a? Array
net['ip_ranges'].each do |ip_range|
# loop through local facts to pull which interface has an IP in the
# dhcp range so we can properly listen on the interface for dhcp
# messages
cidr = IPAddr.new(net['cidr'])
listen_address = []
interfaces = lookupvar('interfaces')
if ! interfaces.nil?
interfaces.split(',').each do |interface|
local_address = lookupvar("ipaddress_#{interface}")
listen_address.push(local_address) if cidr.include?(local_address)
end
end
netmask = IPAddr.new('255.255.255.255').mask(net['cidr'].split('/')[1]).to_s
print_range = ip_range.join('_')
resource_name = sprintf("range_%08x", Zlib::crc32("#{print_range}_#{net['cidr']}").to_i)
@ -20,6 +32,7 @@ Creates fuel::dnsmasq::dhcp_range puppet resources from list of admin networks.
dhcp_range_resource = {
resource_name => {
'file_header' => "# Generated automatically by puppet\n#{range_comment}",
'listen_address' => listen_address.join(','),
'dhcp_start_address' => ip_range[0],
'dhcp_end_address' => ip_range[1],
'dhcp_netmask' => netmask,

View File

@ -14,6 +14,7 @@ define fuel::dnsmasq::dhcp_range(
$dhcp_end_address = '10.0.0.254',
$dhcp_netmask = '255.255.255.0',
$dhcp_gateway = $::ipaddress,
$listen_address = $::ipaddress,
$file_header = undef,
$lease_time = '120m',
$next_server = $::ipaddress,

View File

@ -25,6 +25,14 @@ describe 'create_dnsmasq_dhcp_ranges' do
]
end
let(:facts) do
{
:interfaces => 'docker0,enp0s3,enp0s4,enp0s5,lo',
:ipaddress_docker0 => '172.17.0.1',
:ipaddress_enp0s3 => '10.145.0.2',
:ipaddress_enp0s4 => '10.144.0.2',
}
end
let(:catalog) do
lambda { catalogue }
end
@ -32,7 +40,7 @@ describe 'create_dnsmasq_dhcp_ranges' do
it 'refuses String' do
is_expected.to run.with_params('foo').and_raise_error(Puppet::ParseError, /Should pass list of hashes as a parameter/)
end
it 'accepts empty data' do
is_expected.to run.with_params([{}])
end
@ -41,6 +49,7 @@ describe 'create_dnsmasq_dhcp_ranges' do
is_expected.to run.with_params(admin_networks)
parameters = {
:file_header=>"# Generated automatically by puppet\n# Environment: \n# Nodegroup: \n# IP range: [\"10.145.0.3\", \"10.145.0.250\"]",
:listen_address=>'10.145.0.2',
:dhcp_start_address=>"10.145.0.3",
:dhcp_end_address=>"10.145.0.250",
:dhcp_netmask=>"255.255.255.0",
@ -49,6 +58,7 @@ describe 'create_dnsmasq_dhcp_ranges' do
expect(catalog).to contain_fuel__dnsmasq__dhcp_range('range_6be3c888').with parameters
parameters = {
:file_header=>"# Generated automatically by puppet\n# Environment: default2\n# Nodegroup: default2\n# IP range: [\"10.144.0.10\", \"10.144.0.254\"]",
:listen_address=>'10.144.0.2',
:dhcp_start_address=>"10.144.0.10",
:dhcp_end_address=>"10.144.0.254",
:dhcp_netmask=>"255.255.255.0",

View File

@ -1,4 +1,5 @@
<% if @file_header %><%= @file_header %><% end %>
<% if @listen_address %>listen-address=<%= @listen_address %><% end %>
dhcp-range=<%= @range_name %>,<%= @dhcp_start_address %>,<%= @dhcp_end_address %>,<%= @dhcp_netmask %>,<%= @lease_time %>
dhcp-option=net:<%= @range_name %>,option:router,<%= @dhcp_gateway %>
dhcp-boot=net:<%= @range_name %>,pxelinux.0,boothost,<%= @next_server %>