Add interface_propertiesi hash merge for

interfaces members of bond

CI disabled, because next patch in the chain should be passed.
Whole chain should be merged at one moment.

Change-Id: Ie7804dac600b2ea4747d0117f4951f811ef834a1
Partial-bug: #1643920
Fuel-CI: disabled
This commit is contained in:
Sergey Vasilenko 2017-01-20 17:17:07 +03:00
parent 45d2d6e9ba
commit 643e172d48
2 changed files with 218 additions and 0 deletions

View File

@ -323,6 +323,40 @@ Puppet::Parser::Functions::newfunction(:generate_network_config, :type => :rvalu
}
end
tmp << t
elsif t[:action] == 'add-bond'
t[:interfaces].each do |ifname|
if !(i=tmp.index{|x| x[:action]=='add-port' && x[:name]==ifname})
# we has no bond slave in the transformation
# should be added
debug("Auto-add 'add-port(#{ifname})' for '#{t[:name]}'")
if_sym = ifname.to_sym
b_provider=t[:provider]
mtu = t[:mtu]
if t[:interface_properties].is_a?(Hash)
# need merge
props = config_hash[:interfaces][if_sym]
t[:interface_properties].each do |k,v|
if k=='mtu' and !v.nil?
mtu==v.to_i
elsif v.is_a?(Hash) and props[k].is_a?(Hash)
props[k] = v.merge(props[k])
elsif props[k].nil?
props[k] = v
end
end
else
# just copy
props = config_hash[:interfaces][if_sym]
end
props[:provider] = b_provider if props[:provider].nil?
tmp << {
:action => 'add-port',
:name => ifname,
:mtu => mtu
}.merge(props)
end
end
tmp << t
elsif (i=tmp.index{|x| x[:action].match(/add-(port|bond)/) && x[:name]==t[:name]})
# we has transformation for this interface already auto-added by previous
# condition. We should merge this properties into which are autocreated

View File

@ -0,0 +1,184 @@
require 'spec_helper'
describe 'l23network::examples::run_network_scheme', :type => :class do
context 'pass vendor_specific through interface_properties' do
let(:title) { 'xxx' }
let(:facts) {
{
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:kernel => 'Linux',
:l23_os => 'ubuntu',
:l3_fqdn_hostname => 'stupid_hostname',
}
}
let(:params) do {
:settings_yaml => '''
network_scheme:
version: 1.1
provider: lnx
interfaces:
eth2: {}
eth3: {}
transformations:
- action: add-bond
name: bond23
interfaces:
- eth2
- eth3
interface_properties:
vendor_specific:
aaa: bbb
endpoints: {}
roles: {}
''',
} end
before(:each) do
puppet_debug_override()
end
it do
is_expected.to compile.with_all_deps
end
it do
is_expected.to contain_l2_bond('bond23').with({
'ensure' => 'present',
'slaves' => ['eth2', 'eth3'],
})
end
['eth2', 'eth3'].each do |iface|
it do
is_expected.to contain_l2_port(iface).with({
'ensure' => 'present',
'bond_master' => 'bond23',
'vendor_specific' => {
'aaa' => 'bbb',
}
})
end
end
end
context 'merge vendor_specific from port to interface_properties' do
let(:title) { 'xxx' }
let(:facts) {
{
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:kernel => 'Linux',
:l23_os => 'ubuntu',
:l3_fqdn_hostname => 'stupid_hostname',
}
}
let(:params) do {
:settings_yaml => '''
network_scheme:
version: 1.1
provider: lnx
interfaces:
eth2:
vendor_specific:
ifnumber: 2
eth3:
vendor_specific:
ifnumber: 3
eth4:
vendor_specific:
ifnumber: 4
eth5:
vendor_specific:
ifnumber: 5
transformations:
- action: add-bond
name: bond23
interfaces:
- eth2
- eth3
interface_properties:
mtu: 9000
vendor_specific:
aaa: bbb
- action: add-br
name: ovs-br1
provider: ovs
- action: add-bond
bridge: ovs-br1
name: bond45
mtu: 9000
interfaces:
- eth4
- eth5
interface_properties:
vendor_specific:
aaa: bbb
provider: ovs
endpoints: {}
roles: {}
''',
} end
before(:each) do
puppet_debug_override()
end
it do
is_expected.to compile.with_all_deps
end
it do
is_expected.to contain_l2_bond('bond23').with({
'ensure' => 'present',
'slaves' => ['eth2', 'eth3'],
})
end
['eth2', 'eth3'].each do |iface|
it do
is_expected.to contain_l2_port(iface).with({
'ensure' => 'present',
'bond_master' => 'bond23',
'mtu' => 9000,
'provider' => 'lnx',
'vendor_specific' => {
'aaa' => 'bbb',
'ifnumber' => iface[-1]
}
})
end
end
it do
is_expected.to contain_l2_bond('bond45').with({
'ensure' => 'present',
'mtu' => '9000',
'slaves' => ['eth4', 'eth5'],
'provider' => 'ovs'
})
end
['eth4', 'eth5'].each do |iface|
it do
is_expected.to contain_l2_port(iface).with({
'ensure' => 'present',
'mtu' => 9000,
'provider' => 'ovs',
'vendor_specific' => {
'aaa' => 'bbb',
'ifnumber' => iface[-1]
}
})
end
end
end
end
###