diff --git a/deployment/puppet/osnailyfacter/lib/puppet/parser/functions/generate_physnet_mtus.rb b/deployment/puppet/osnailyfacter/lib/puppet/parser/functions/generate_physnet_mtus.rb new file mode 100644 index 0000000000..269ca876cd --- /dev/null +++ b/deployment/puppet/osnailyfacter/lib/puppet/parser/functions/generate_physnet_mtus.rb @@ -0,0 +1,77 @@ +Puppet::Parser::Functions::newfunction(:generate_physnet_mtus, :type => :rvalue, :doc => <<-EOS +This function gets neutron_config, network_scheme, flags and formats physnet to vlan ranges according to flags. +EOS +) do |args| + + raise ArgumentError, ("generate_physnet_mtus(): wrong number of arguments (#{args.length}; must be 3)") if args.length != 3 + args.each do | arg | + raise ArgumentError, "generate_physnet_mtus(): #{arg} is not hash!" if !arg.is_a?(Hash) + end + + neutron_config, network_scheme, flags = *args + + #flags = { do_floating => true, do_tenant => true, do_provider => false } + + debug "Collecting phys_nets and bridges" + physnet_bridge_map = {} + neutron_config['L2']['phys_nets'].each do |k,v| + next unless v['bridge'] + bridge = v['bridge'] + trans = network_scheme['transformations'].select{ |x| x['name'] == bridge } + physnet_bridge_map[k] = trans[0] unless trans.empty? + end + + debug("Physnet to bridge map: #{physnet_bridge_map}") + + unless flags['do_floating'] + debug("Perform floating networks") + physnet_bridge_map.each do | net, br | + physnet_bridge_map.delete(net) if !neutron_config['predefined_networks'].select{ |pnet, value| value['L2']['physnet'] == net and value['L2']['router_ext'] }.empty? + end + end + + # Looking for MTUs + bridge_including_flow = { :'add-patch' => 'bridges', :'add-port' => 'bridge' , :'add-bond' => 'bridge', :'add-port' => 'bridge' } + physnet_mtu_map = {} + physnet_bridge_map.each do |net, br| + mtu = nil + if br['mtu'] + mtu = br['mtu'] + else + br = br['name'] + bridge_including_flow.each do |x , v| + bridge_incleded = network_scheme['transformations'].select { |a| a['action'] == x.to_s and (a[v] == br or a[v].include?(br)) } + if bridge_incleded.empty? + next + elsif bridge_incleded.size >2 + raise("bridge #{br} can not be included into more then one element, elements: #{bridge_incleded}") + else + bridge_incleded = bridge_incleded[0] + debug("Transformation #{bridge_incleded} has bridge #{br}") + end + if bridge_incleded['action'] == 'add-patch' + debug("Bridge #{br} is in a patch #{bridge_incleded}!") + br = bridge_incleded['bridges'].select{ |x| x!=br }[0] + debug("Looking mtu for bridge #{br}") + next + elsif bridge_incleded['mtu'] + mtu = bridge_incleded['mtu'] + debug("And has mtu: #{mtu}") + break + end + end + mtu = 1500 unless mtu + physnet_mtu_map[net] = mtu + end + end + + debug("Formatng the output") + result = [] + return result if physnet_mtu_map.empty? + physnet_mtu_map.each do |net, mtu| + record = mtu ? ":#{mtu}" : '' + result << "#{net}"+ record + end + debug("Format is done, value is: #{result}") + result +end diff --git a/deployment/puppet/osnailyfacter/modular/openstack-network/plugins/ml2.pp b/deployment/puppet/osnailyfacter/modular/openstack-network/plugins/ml2.pp index 8e876c55e6..ba30fde2ed 100644 --- a/deployment/puppet/osnailyfacter/modular/openstack-network/plugins/ml2.pp +++ b/deployment/puppet/osnailyfacter/modular/openstack-network/plugins/ml2.pp @@ -55,12 +55,13 @@ if $use_neutron { if $segmentation_type == 'vlan' { $net_role_property = 'neutron/private' $iface = get_network_role_property($net_role_property, 'phys_dev') - $physical_net_mtu = pick(get_transformation_property('mtu', $iface[0]), '1500') - $overlay_net_mtu = $physical_net_mtu + $overlay_net_mtu = pick(get_transformation_property('mtu', $iface[0]), '1500') $enable_tunneling = false - $physnet2_bridge = try_get_value($neutron_config, 'L2/phys_nets/physnet2/bridge') - $physnet2 = "physnet2:${physnet2_bridge}" - $physical_network_mtus = ["physnet2:${physical_net_mtu}"] + $physical_network_mtus = generate_physnet_mtus($neutron_config, $network_scheme, { + 'do_floating' => $do_floating, + 'do_tenant' => true, + 'do_provider' => false + }) $tunnel_id_ranges = [] $network_type = 'vlan' $tunnel_types = [] diff --git a/deployment/puppet/osnailyfacter/spec/fixtures/manifests/site.pp b/deployment/puppet/osnailyfacter/spec/fixtures/manifests/site.pp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/deployment/puppet/osnailyfacter/spec/functions/generate_physnet_mtus__spec.rb b/deployment/puppet/osnailyfacter/spec/functions/generate_physnet_mtus__spec.rb new file mode 100644 index 0000000000..f04b0a7588 --- /dev/null +++ b/deployment/puppet/osnailyfacter/spec/functions/generate_physnet_mtus__spec.rb @@ -0,0 +1,249 @@ +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(:generate_physnet_mtus) + end + + describe 'basic tests' do + + before :each do + setup_scope + puppet_debug_override + end + + let :network_scheme do +{"transformations"=> + [{"action"=>"add-br", "name"=>"br-fw-admin"}, + {"action"=>"add-br", "name"=>"br-mgmt"}, + {"action"=>"add-br", "name"=>"br-storage"}, + {"action"=>"add-br", "name"=>"br-ex"}, + {"action"=>"add-br", "name"=>"br-floating", "provider"=>"ovs"}, + {"action"=>"add-patch", + "bridges"=>["br-floating", "br-ex"], + "provider"=>"ovs", + "mtu"=>65000}, + {"action"=>"add-br", "name"=>"br-prv", "provider"=>"ovs"}, + {"action"=>"add-br", "name"=>"br-aux"}, + {"action"=>"add-patch", + "bridges"=>["br-prv", "br-aux"], + "provider"=>"ovs", + "mtu"=>65000}, + {"action"=>"add-port", "bridge"=>"br-fw-admin", "name"=>"eth0"}, + {"action"=>"add-port", "bridge"=>"br-ex", "name"=>"eth1"}, + {"bridge"=>"br-aux", + "mtu" => 35000, + "name"=>"bond0", + "interfaces"=>["eth2", "eth3"], + "bond_properties"=>{"mode"=>"active-backup"}, + "interface_properties"=>{"vendor_specific"=>{"disable_offloading"=>true}}, + "action"=>"add-bond"}, + {"action"=>"add-port", "bridge"=>"br-mgmt", "name"=>"bond0.101"}, + {"action"=>"add-port", "bridge"=>"br-storage", "name"=>"bond0.102"}], + "roles"=> {}, + "interfaces"=> {}, + "version"=>"1.1", + "provider"=>"lnx", + "endpoints"=> {} + } + end + + let :network_scheme_just_port do +{"transformations"=> + [{"action"=>"add-br", "name"=>"br-fw-admin"}, + {"action"=>"add-br", "name"=>"br-mgmt"}, + {"action"=>"add-br", "name"=>"br-storage"}, + {"action"=>"add-br", "name"=>"br-floating", "provider"=>"ovs"}, + {"action"=>"add-br", "name"=>"br-prv", "provider"=>"ovs"}, + {"action"=>"add-br", "name"=>"br-aux"}, + {"action"=>"add-patch", + "bridges"=>["br-prv", "br-aux"], + "provider"=>"ovs", + "mtu"=>65000}, + {"action"=>"add-port", "bridge"=>"br-fw-admin", "name"=>"eth0"}, + {"action"=>"add-port", "bridge"=>"br-floating", "name"=>"eth1", "mtu"=>2000, "provider"=>"ovs"}, + {"bridge"=>"br-aux", + "mtu" => 35000, + "name"=>"bond0", + "interfaces"=>["eth2", "eth3"], + "bond_properties"=>{"mode"=>"active-backup"}, + "interface_properties"=>{"vendor_specific"=>{"disable_offloading"=>true}}, + "action"=>"add-bond"}, + {"action"=>"add-port", "bridge"=>"br-mgmt", "name"=>"bond0.101"}, + {"action"=>"add-port", "bridge"=>"br-storage", "name"=>"bond0.102"}], + "roles"=> {}, + "interfaces"=> {}, + "version"=>"1.1", + "provider"=>"lnx", + "endpoints"=> {} + } + end + + + let :network_scheme_mtu_on_bond do +{"transformations"=> + [{"action"=>"add-br", "name"=>"br-fw-admin"}, + {"action"=>"add-br", "name"=>"br-mgmt"}, + {"action"=>"add-br", "name"=>"br-storage"}, + {"action"=>"add-br", "name"=>"br-ex"}, + {"action"=>"add-br", "name"=>"br-floating", "provider"=>"ovs"}, + {"action"=>"add-patch", + "bridges"=>["br-floating", "br-ex"], + "provider"=>"ovs", + "mtu"=>1300 }, + {"action"=>"add-br", "name"=>"br-prv", "provider"=>"ovs"}, + {"action"=>"add-br", "name"=>"br-aux"}, + {"action"=>"add-patch", + "bridges"=>["br-prv", "br-aux"], + "provider"=>"ovs", + }, + {"action"=>"add-port", "bridge"=>"br-fw-admin", "name"=>"eth0"}, + {"action"=>"add-port", "bridge"=>"br-ex", "name"=>"eth1", "mtu"=>1340 }, + {"bridge"=>"br-aux", + "mtu" => 35000, + "name"=>"bond0", + "interfaces"=>["eth2", "eth3"], + "bond_properties"=>{"mode"=>"active-backup"}, + "interface_properties"=>{"vendor_specific"=>{"disable_offloading"=>true}}, + "action"=>"add-bond"}, + {"action"=>"add-port", "bridge"=>"br-mgmt", "name"=>"bond0.101"}, + {"action"=>"add-port", "bridge"=>"br-storage", "name"=>"bond0.102"}], + "roles"=> {}, + "interfaces"=> {}, + "version"=>"1.1", + "provider"=>"lnx", + "endpoints"=> {} + } + end + + let :network_scheme_mtu_on_port do +{"transformations"=> + [{"action"=>"add-br", "name"=>"br-fw-admin"}, + {"action"=>"add-br", "name"=>"br-mgmt"}, + {"action"=>"add-br", "name"=>"br-storage"}, + {"action"=>"add-br", "name"=>"br-ex"}, + {"action"=>"add-br", "name"=>"br-floating", "provider"=>"ovs"}, + {"action"=>"add-patch", + "bridges"=>["br-floating", "br-ex"], + "provider"=>"ovs"}, + {"action"=>"add-br", "name"=>"br-prv", "provider"=>"ovs"}, + {"action"=>"add-br", "name"=>"br-aux"}, + {"action"=>"add-patch", + "bridges"=>["br-prv", "br-aux"], + "provider"=>"ovs", + }, + {"action"=>"add-port", "bridge"=>"br-fw-admin", "name"=>"eth0"}, + {"action"=>"add-port", "bridge"=>"br-ex", "name"=>"eth1", "mtu"=>1800 }, + {"bridge"=>"br-aux", + "mtu" => 35000, + "name"=>"bond0", + "interfaces"=>["eth2", "eth3"], + "bond_properties"=>{"mode"=>"active-backup"}, + "interface_properties"=>{"vendor_specific"=>{"disable_offloading"=>true}}, + "action"=>"add-bond"}, + {"action"=>"add-port", "bridge"=>"br-mgmt", "name"=>"bond0.101"}, + {"action"=>"add-port", "bridge"=>"br-storage", "name"=>"bond0.102"}], + "roles"=> {}, + "interfaces"=> {}, + "version"=>"1.1", + "provider"=>"lnx", + "endpoints"=> {} + } + end + + let :neutron_config do + {"default_floating_net"=>"admin_floating_net", + "database"=>{"passwd"=>"2eaczPxjQNxkR6qik3sZlsaW"}, + "default_private_net"=>"admin_internal_net", + "keystone"=>{"admin_password"=>"EanTYjYlXqzATHAriBPkllal"}, + "L3"=>{"use_namespaces"=>true}, + "L2"=>{"phys_nets"=>{"physnet1"=>{"bridge"=>"br-floating", "vlan_range"=>"1000:1030"}, + "physnet2"=>{"bridge"=>"br-prv", "vlan_range"=>nil}}, + "base_mac"=>"fa:16:3e:00:00:00", + "segmentation_type"=>"vlan"}, + "predefined_networks"=>{ + "admin_floating_net"=>{ + "shared"=>false, + "L2"=>{"network_type"=>"local", + "router_ext"=>true, + "physnet"=>'physnet2', + "segment_id"=>nil}, + "L3"=>{"nameservers"=>[], + "subnet"=>"10.109.1.0/24", + "floating"=>["10.109.1.130:10.109.1.254"], + "gateway"=>"10.109.1.1", + "enable_dhcp"=>false}, + "tenant"=>"admin"}, + "admin_internal_net"=>{ + "shared"=>false, + "L2"=>{"network_type"=>"vlan", + "router_ext"=>false, + "physnet"=>"physnet2", + "segment_id"=>nil}, + "L3"=>{"nameservers"=>["8.8.4.4", "8.8.8.8"], + "subnet"=>"192.168.111.0/24", + "floating"=>nil, + "gateway"=>"192.168.111.1", + "enable_dhcp"=>true}, + "tenant"=>"admin"}}, + "metadata"=>{"metadata_proxy_shared_secret"=>"uLLpFlxwX848GYnTUse2PjMp"} + } + end + + it "should exist" do + Puppet::Parser::Functions.function(:generate_physnet_mtus).should == "function_generate_physnet_mtus" + end + + it 'error if no arguments' do + lambda { @scope.function_generate_physnet_mtus([]) }.should raise_error(ArgumentError, 'generate_physnet_mtus(): wrong number of arguments (0; must be 3)') + end + + it 'should require one argument' do + lambda { @scope.function_generate_physnet_mtus(['foo', 'wee', 'ee', 'rr']) }.should raise_error(ArgumentError, 'generate_physnet_mtus(): wrong number of arguments (4; must be 3)') + end + + + it 'should be able to return floating nets to mtu map' do + expect(@scope.function_generate_physnet_mtus([neutron_config, network_scheme, { 'do_floating' => true, 'do_tenant' => true, 'do_provider' => false }])).to eq(["physnet1:1500", "physnet2:35000"]) + end + + it 'should be able to return without floating nets to mtu map' do + expect(@scope.function_generate_physnet_mtus([neutron_config, network_scheme, { 'do_floating' => false, 'do_tenant' => true, 'do_provider' => false }])).to eq(["physnet1:1500"]) + end + + it 'should be able to return with floating nets to mtu map (bond)' do + expect(@scope.function_generate_physnet_mtus([neutron_config, network_scheme_mtu_on_bond, { 'do_floating' => true, 'do_tenant' => true, 'do_provider' => false }])).to eq(["physnet1:1340", "physnet2:35000"]) + end + + it 'should be able to return without floating nets to mtu map (bond)' do + expect(@scope.function_generate_physnet_mtus([neutron_config, network_scheme_mtu_on_bond, { 'do_floating' => false, 'do_tenant' => true, 'do_provider' => false }])).to eq(["physnet1:1340"]) + end + + it 'should be able to return with floating nets to mtu map (port)' do + expect(@scope.function_generate_physnet_mtus([neutron_config, network_scheme_mtu_on_port, { 'do_floating' => true, 'do_tenant' => true, 'do_provider' => false }])).to eq(["physnet1:1800", "physnet2:35000"]) + end + + it 'should be able to return without floating nets to mtu map (port)' do + expect(@scope.function_generate_physnet_mtus([neutron_config, network_scheme_mtu_on_port, { 'do_floating' => false, 'do_tenant' => true, 'do_provider' => false }])).to eq(["physnet1:1800"]) + end + + it 'should be able to return with floating nets to mtu map (just OVS port)' do + expect(@scope.function_generate_physnet_mtus([neutron_config, network_scheme_just_port, { 'do_floating' => true, 'do_tenant' => true, 'do_provider' => false }])).to eq(["physnet1:2000", "physnet2:35000"]) + end + + it 'should be able to return without floating nets to mtu map (just OVS port)' do + expect(@scope.function_generate_physnet_mtus([neutron_config, network_scheme_just_port, { 'do_floating' => false, 'do_tenant' => true, 'do_provider' => false }])).to eq(["physnet1:2000"]) + end + + end +end diff --git a/tests/noop/spec/hosts/openstack-network/plugins/ml2_spec.rb b/tests/noop/spec/hosts/openstack-network/plugins/ml2_spec.rb index 6f0ac6074d..863f0f6a27 100644 --- a/tests/noop/spec/hosts/openstack-network/plugins/ml2_spec.rb +++ b/tests/noop/spec/hosts/openstack-network/plugins/ml2_spec.rb @@ -31,6 +31,10 @@ describe manifest do configuration_override.fetch('neutron_agent_ovs', {}) end + let(:phys_net_mtus) do + Noop.puppet_function('generate_physnet_mtus', Noop.hiera_hash('neutron_config'), network_scheme, { 'do_floating' => true, 'do_tenant' => true, 'do_provider' => false }) + end + context 'with Neutron-ml2-plugin' do role = Noop.hiera('role') @@ -52,7 +56,6 @@ describe manifest do network_vlan_ranges = ["physnet2:#{network_vlan_ranges_physnet2}"] end tunnel_id_ranges = [] - physical_network_mtus = ["physnet2:1500"] overlay_net_mtu = '1500' tunnel_types = [] if pnets['physnet-ironic'] @@ -68,7 +71,6 @@ describe manifest do network_type = 'vxlan' network_vlan_ranges = ["physnet1"] tunnel_id_ranges = [neutron_config.fetch('L2',{}).fetch('tunnel_id_ranges')] - physical_network_mtus = [] overlay_net_mtu = '1450' tunnel_types = [network_type] end @@ -105,7 +107,13 @@ describe manifest do it { should contain_class('neutron::plugins::ml2').with( 'vxlan_group' => '224.0.0.1', )} - it { should contain_class('neutron::plugins::ml2').with( + it { + if segmentation_type == 'vlan' + physical_network_mtus = phys_net_mtus + else + physical_network_mtus = [] + end + should contain_class('neutron::plugins::ml2').with( 'physical_network_mtus' => physical_network_mtus, )} it { should contain_class('neutron::plugins::ml2').with(