Add multiple floating ranges support

*Add new puppet function which formats allocation pools string for neutron
subnet resource.
*Remove ordering between neutron_network and neuton_subnet due to there
is autorequire in puppets types.
*Remove unneeded variable.

Change-Id: I040c3bc66fa0f57ed6f79d8471bd0bd239efc527
Closes-bug: #1490578
This commit is contained in:
Stanislav Makar 2015-10-16 11:55:02 +00:00
parent bc18428f04
commit cf54da03b1
6 changed files with 87 additions and 25 deletions

View File

@ -1,5 +1,4 @@
fixtures:
symlinks:
'l23network': '../../../../l23network'
'neutron': '../../../../neutron'
'osnailyfacter': "#{source_dir}"
symlinks:
'osnailyfacter': "#{source_dir}"
'l23network': "#{source_dir}/../l23network"

View File

@ -2,7 +2,7 @@ source 'https://rubygems.org'
group :development, :test do
gem 'rake', :require => false
gem 'fakefs', :require => false
gem 'fakefs', :require => false
gem 'pry', :require => false
gem 'rspec', '~>3.3', :require => false
gem 'rspec-puppet', '~>2.1.0', :require => false

View File

@ -0,0 +1,23 @@
Puppet::Parser::Functions::newfunction(:format_allocation_pools, :type => :rvalue, :doc => <<-EOS
This function gets floating ranges and format allocation_pools attribute value for neutron subnet resource.
EOS
) do |args|
raise ArgumentError, ("format_allocation_pools(): wrong number of arguments (#{args.length}; must be 1)") if args.length < 1
raise ArgumentError, ("format_allocation_pools(): wrong number of arguments (#{args.length}; must be 1)") if args.length > 1
floating_ranges = args[0]
raise ArgumentError, 'format_allocation_pools(): floating_ranges is not array!' if !(floating_ranges.is_a?(Array) or floating_ranges.is_a?(String))
debug "Formating allocation_pools for #{floating_ranges}"
allocation_pools = []
if floating_ranges.is_a?(Array) # Is a temporary solution while network_data['L3']['floating'] is not array
floating_ranges.each do | range |
allocation_pools << "start=#{range.split(':')[0]},end=#{range.split(':')[1]}"
end
else # TODO: remove else part after python part is merged
allocation_pools << "start=#{floating_ranges.split(':')[0]},end=#{floating_ranges.split(':')[1]}"
end
debug("Format is done, value is: #{allocation_pools}")
allocation_pools
end

View File

@ -1,9 +1,6 @@
notice('MODULAR: openstack-network/networks.pp')
$use_neutron = hiera('use_neutron', false)
if $use_neutron {
if hiera('use_neutron', false) {
$access_hash = hiera('access', { })
$keystone_admin_tenant = $access_hash['tenant']
$neutron_config = hiera_hash('neutron_config')
@ -11,8 +8,7 @@ if $use_neutron {
$private_net = try_get_value($neutron_config, 'default_private_net', 'net04')
$default_router = try_get_value($neutron_config, 'default_router', 'router04')
$segmentation_type = try_get_value($neutron_config, 'L2/segmentation_type')
$nets = $neutron_config['predefined_networks']
$nets = $neutron_config['predefined_networks']
if $segmentation_type == 'vlan' {
$network_type = 'vlan'
@ -25,16 +21,14 @@ if $use_neutron {
$segmentation_id_range = split(try_get_value($neutron_config, 'L2/tunnel_id_ranges', ''), ':')
}
$fallback_segment_id = $segmentation_id_range[0]
$fallback_segment_id = $segmentation_id_range[0]
$floating_net_segment_id = try_get_value($nets, "${$floating_net}/L2/segment_id", $fallback_segment_id)
$private_net_segment_id = try_get_value($nets, "${private_net}/L2/segment_id", $fallback_segment_id)
$floating_net_segment_id = try_get_value($nets, "${$floating_net}/L2/segment_id", $fallback_segment_id)
$private_net_segment_id = try_get_value($nets, "${private_net}/L2/segment_id", $fallback_segment_id)
$floating_net_floating_range = split(try_get_value($nets, "${$floating_net}/L3/floating", ''), ':')
$private_net_floating_range = split(try_get_value($nets, "${private_net}/L3/floating", ''), ':')
$floating_net_floating_range = try_get_value($nets, "${$floating_net}/L3/floating", '')
if !empty($floating_net_floating_range) {
$floating_net_allocation_pool = "start=${floating_net_floating_range[0]},end=${$floating_net_floating_range[1]}"
$floating_net_allocation_pool = format_allocation_pools($floating_net_floating_range)
}
$floating_net_physnet = try_get_value($nets, "${$floating_net}/L2/physnet", false)
@ -55,7 +49,7 @@ if $use_neutron {
router_external => $floating_net_router_external,
tenant_name => $tenant_name,
shared => $floating_net_shared
} ->
}
neutron_subnet { "${floating_net}__subnet" :
ensure => 'present',
@ -75,7 +69,7 @@ if $use_neutron {
router_external => $private_net_router_external,
tenant_name => $tenant_name,
shared => $private_net_shared
} ->
}
neutron_subnet { "${private_net}__subnet" :
ensure => 'present',
@ -101,7 +95,7 @@ if $use_neutron {
router_external => $baremetal_router_external,
tenant_name => $tenant_name,
shared => $baremetal_shared
} ->
}
neutron_subnet { 'baremetal__subnet' :
ensure => 'present',
@ -111,7 +105,7 @@ if $use_neutron {
gateway_ip => try_get_value($nets, 'baremetal/L3/gateway'),
enable_dhcp => true,
dns_nameservers => try_get_value($nets, 'baremetal/L3/nameservers'),
} ->
}
neutron_router_interface { "${default_router}:baremetal__subnet":
ensure => 'present',

View File

@ -0,0 +1,49 @@
require 'puppet'
require 'spec_helper'
describe 'function for formating allocation pools for neutron subnet resource' do
def setup_scope
@compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("floppy", :environment => 'production'))
if Puppet.version =~ /^3\./
@scope = Puppet::Parser::Scope.new(@compiler)
else
@scope = Puppet::Parser::Scope.new(:compiler => @compiler)
end
@topscope = @topscope
@scope.parent = @topscope
Puppet::Parser::Functions.function(:format_allocation_pools)
end
describe 'basic tests' do
before :each do
setup_scope
puppet_debug_override
end
it "should exist" do
Puppet::Parser::Functions.function(:format_allocation_pools).should == "function_format_allocation_pools"
end
it 'error if no arguments' do
lambda { @scope.function_format_allocation_pools([]) }.should raise_error(ArgumentError, 'format_allocation_pools(): wrong number of arguments (0; must be 1)')
end
it 'should require one argument' do
lambda { @scope.function_format_allocation_pools(['foo', 'wee']) }.should raise_error(ArgumentError, 'format_allocation_pools(): wrong number of arguments (2; must be 1)')
end
it 'should require flating ranges is Array' do
lambda { @scope.function_format_allocation_pools([{:fff => true}]) }.should raise_error(ArgumentError, 'format_allocation_pools(): floating_ranges is not array!')
end
it 'should be able to format allocation pool string' do
expect(@scope.function_format_allocation_pools([["10.109.1.151:10.109.1.254", "10.109.1.130:10.109.1.150"]])).to eq(["start=10.109.1.151,end=10.109.1.254", "start=10.109.1.130,end=10.109.1.150"])
end
it 'should be able to format allocation pool string for old structure' do
expect(@scope.function_format_allocation_pools(["10.109.1.133:10.109.1.169"])).to eq(["start=10.109.1.133,end=10.109.1.169"])
end
end
end

View File

@ -28,9 +28,6 @@ describe manifest do
'enable_dhcp' => 'true',
'dns_nameservers' => nets['baremetal']['L3']['nameservers'],
)
should contain_neutron_subnet('baremetal__subnet').that_comes_before(
'neutron_router_interface[router04:baremetal__subnet]'
)
end
end
end