Allow OVS bridge with two or more bridges

Change way to find minimal MTU for every paths

Change-Id: I1f77a6f034c00df4e119fba3cb6ebf3475036275
Closes-Bug: #1647557
This commit is contained in:
Vladimir Sharshov (warpc) 2016-12-15 19:54:47 +03:00 committed by Vladimir Sharshov
parent cd64397ca2
commit b9c7f17994
2 changed files with 195 additions and 47 deletions

View File

@ -1,43 +1,42 @@
DEFAULT_MTU ||= 1500
MAX_MIN_MTU ||= 65000
def get_mtu_for_bridge(br_name, network_scheme, inspected_bridges)
mtu = nil
# in this chain patch should be last, because ports and bonds has highest priority
{'add-port' => 'bridge' , 'add-bond' => 'bridge', 'add-patch' => 'bridges'}.each do |x , v|
transf = network_scheme['transformations'].select do |trans|
trans['action']==x and trans.has_key?(v) and (trans[v]==br_name or trans[v].include?(br_name))
end
if transf.empty?
next
elsif transf.size >2
raise("bridge #{br_name} can not be included into more then one element, elements: #{transf}")
else
transf = transf[0]
debug("Transformation #{transf} has bridge #{br_name}")
end
if transf['action'] == 'add-patch'
debug("Bridge #{br_name} is in a patch #{transf}!")
next_br_name = transf['bridges'].select{ |x| x!=br_name }[0]
if ! inspected_bridges.include?(br_name)
debug("Looking mtu for bridge #{next_br_name}")
inspected_bridges << br_name
mtu = get_mtu_for_bridge(next_br_name, network_scheme, inspected_bridges)
else
next
end
elsif !transf['mtu'].nil?
# this section into elsif, because patch MTU shouldn't affect result (MTU 65000 for example)
mtu = transf['mtu']
elsif transf['action']=='add-port' and !network_scheme['interfaces'].fetch(transf['name'],{}).fetch('mtu',nil).nil?
mtu = network_scheme['interfaces'][transf['name']]['mtu']
end
if !mtu.nil?
debug("And has mtu: #{mtu}")
break
end
class MinMTU
def value=(new_mtu)
return if new_mtu.nil? || new_mtu >= MAX_MIN_MTU
@min_mtu = new_mtu if @min_mtu.nil? || @min_mtu > new_mtu
end
mtu ||= DEFAULT_MTU
return mtu
def value
@min_mtu
end
end
def get_mtu_for_bridge(br_name, network_scheme, inspected_bridges, min_mtu)
{'add-port' => 'bridge' , 'add-bond' => 'bridge', 'add-patch' => 'bridges'}
.each do |action, has_bridge|
transfs = network_scheme['transformations'].select do |trans|
trans['action'] == action &&
trans.has_key?(has_bridge) &&
(trans[has_bridge] == br_name || trans[has_bridge].include?(br_name))
end
transfs.each do |transf|
min_mtu.value = transf['mtu'] if transf['mtu']
if transf['action'] == 'add-patch'
inspected_bridges << br_name
(transf['bridges'] - inspected_bridges).each do |next_br_name|
get_mtu_for_bridge(next_br_name, network_scheme, inspected_bridges, min_mtu)
end
elsif transf['action'] == 'add-port'
min_mtu.value = network_scheme['interfaces'].fetch(transf['name'], {})['mtu']
end
end
end
min_mtu.value || DEFAULT_MTU
end
Puppet::Parser::Functions::newfunction(:generate_physnet_mtus, :type => :rvalue, :doc => <<-EOS
@ -84,16 +83,9 @@ EOS
# Looking for MTUs
physnet_mtu_map = {}
physnet_bridge_map.each do |net, br|
mtu = nil
if br['mtu']
mtu = br['mtu']
else
mtu = get_mtu_for_bridge(br['name'], network_scheme, [])
end
physnet_mtu_map[net] = mtu
physnet_mtu_map[net] = br['mtu'] ? br['mtu'] : get_mtu_for_bridge(br['name'], network_scheme, [], MinMTU.new)
end
debug("Formatng the output")
result = []
return result if physnet_mtu_map.empty?
physnet_mtu_map.each do |net, mtu|

View File

@ -417,7 +417,6 @@ describe 'generate_physnet_mtus' do
is_expected.to run.with_params(neutron_config, network_scheme, { 'do_floating' => false, 'do_tenant' => true, 'do_provider' => false }).and_return(["physnet1:35000"])
end
it 'should be able to return only floating nets to mtu map' do
is_expected.to run.with_params(neutron_config, network_scheme, { 'do_floating' => true, 'do_tenant' => false, 'do_provider' => false }).and_return(["physnet2:1500"])
end
@ -427,7 +426,7 @@ describe 'generate_physnet_mtus' do
end
it 'should be able to return with floating nets to mtu map (bond)' do
is_expected.to run.with_params(neutron_config, network_scheme_mtu_on_bond, { 'do_floating' => true, 'do_tenant' => true, 'do_provider' => false }).and_return(["physnet1:35000", "physnet2:1340"])
is_expected.to run.with_params(neutron_config, network_scheme_mtu_on_bond, { 'do_floating' => true, 'do_tenant' => true, 'do_provider' => false }).and_return(["physnet1:35000", "physnet2:1300"])
end
it 'should be able to return without floating nets to mtu map (bond)' do
@ -462,5 +461,162 @@ describe 'generate_physnet_mtus' do
is_expected.to run.with_params(neutron_config, network_scheme_mtu_on_interfaces, { 'do_floating' => true, 'do_tenant' => true, 'do_provider' => false }).and_return(["physnet1:9000", "physnet2:4000"])
end
let :network_scheme_multipath_both_mtu do
YAML.load('''
version: "1.1"
provider: lnx
interfaces: {}
transformations:
- action: add-br
name: br-aux11
- action: add-br
name: br-aux12
- action: add-br
name: br-aux21
- action: add-br
name: br-aux22
- action: add-patch
bridges:
- br-aux11
- br-aux12
- action: add-patch
bridges:
- br-aux21
- br-aux22
- action: add-br
name: br-prv
provider: ovs
- action: add-patch
bridges:
- br-prv
- br-aux11
provider: ovs
- action: add-patch
bridges:
- br-prv
- br-aux21
provider: ovs
- action: add-port
name: eth1
bridge: br-aux12
mtu: 1400
- action: add-port
name: eth2
bridge: br-aux22
mtu: 1300
roles: {}
endpoints: {}
''')
end
it 'should be able to return tenant nets to mtu map for multipath from PRV to interfaces, both interfaces has defined MTU' do
is_expected.to run.with_params(neutron_config, network_scheme_multipath_both_mtu, { 'do_floating' => false, 'do_tenant' => true, 'do_provider' => false }).and_return(["physnet1:1300"])
end
let :network_scheme_multipath_one_mtu do
YAML.load('''
version: "1.1"
provider: lnx
interfaces: {}
transformations:
- action: add-br
name: br-aux11
- action: add-br
name: br-aux12
- action: add-br
name: br-aux21
- action: add-br
name: br-aux22
- action: add-patch
bridges:
- br-aux11
- br-aux12
- action: add-patch
bridges:
- br-aux21
- br-aux22
- action: add-br
name: br-prv
provider: ovs
- action: add-patch
bridges:
- br-prv
- br-aux11
provider: ovs
- action: add-patch
bridges:
- br-prv
- br-aux21
provider: ovs
- action: add-port
name: eth1
bridge: br-aux12
- action: add-port
name: eth2
bridge: br-aux22
mtu: 1300
roles: {}
endpoints: {}
''')
end
it 'should be able to return tenant nets to mtu map for multipath from PRV to interfaces, one interfaces has defined MTU' do
is_expected.to run.with_params(neutron_config, network_scheme_multipath_one_mtu, { 'do_floating' => false, 'do_tenant' => true, 'do_provider' => false }).and_return(["physnet1:1300"])
end
let :network_scheme_multipath_mtu_on_path do
YAML.load('''
version: "1.1"
provider: lnx
interfaces: {}
transformations:
- action: add-br
name: br-aux11
- action: add-br
name: br-aux12
- action: add-br
name: br-aux21
- action: add-br
name: br-aux22
- action: add-patch
bridges:
- br-aux11
- br-aux12
- action: add-patch
mtu: 1200
bridges:
- br-aux21
- br-aux22
- action: add-br
name: br-prv
provider: ovs
- action: add-patch
bridges:
- br-prv
- br-aux11
provider: ovs
- action: add-patch
bridges:
- br-prv
- br-aux21
provider: ovs
- action: add-port
name: eth1
bridge: br-aux12
mtu: 1400
- action: add-port
name: eth2
bridge: br-aux22
mtu: 1300
roles: {}
endpoints: {}
''')
end
it 'should be able to return tenant nets to mtu map for multipath from PRV to interfaces, patchcord defined MTU' do
is_expected.to run.with_params(neutron_config, network_scheme_multipath_mtu_on_path, { 'do_floating' => false, 'do_tenant' => true, 'do_provider' => false }).and_return(["physnet1:1200"])
end
end
end