Support bonds of subinterfaces while merge interface_properties
Change-Id: I27ede232a37c4e8c2d669f5dd8936a60baf04b40 Related-bug: #1643920 Closes-bug: #1666229
This commit is contained in:
parent
5035fd3557
commit
d5fd08f781
@ -325,16 +325,29 @@ Puppet::Parser::Functions::newfunction(:generate_network_config, :type => :rvalu
|
||||
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 (i=tmp.index{|x| x[:action]=='add-port' && x[:name]==ifname})
|
||||
# we should add something from bond's interface_properties to existing add-port in the transformations.
|
||||
debug("Merge interface_properties from bond '#{t[:name]}' to 'add-port(#{ifname})'")
|
||||
if t[:interface_properties].is_a?(Hash)
|
||||
t[:interface_properties].each do |k,v|
|
||||
if k=='mtu' and !v.nil?
|
||||
mtu==v.to_i
|
||||
elsif v.is_a?(Hash) and tmp[i][k].is_a?(Hash)
|
||||
tmp[i][k] = v.merge(tmp[i][k])
|
||||
elsif tmp[i][k].nil?
|
||||
tmp[i][k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
# we has no bond slave in the transformation
|
||||
# should be added
|
||||
debug("Auto-add 'add-port(#{ifname})' for '#{t[:name]}'")
|
||||
props = config_hash[:interfaces][if_sym] || {}
|
||||
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
|
||||
@ -344,9 +357,6 @@ Puppet::Parser::Functions::newfunction(:generate_network_config, :type => :rvalu
|
||||
props[k] = v
|
||||
end
|
||||
end
|
||||
else
|
||||
# just copy
|
||||
props = config_hash[:interfaces][if_sym]
|
||||
end
|
||||
props[:provider] = b_provider if props[:provider].nil?
|
||||
tmp << {
|
||||
|
@ -65,6 +65,133 @@ describe 'l23network::examples::run_network_scheme', :type => :class do
|
||||
|
||||
end
|
||||
|
||||
context 'pass vendor_specific through interface_properties for bonds implicit subinterfaces' 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: {}
|
||||
transformations:
|
||||
- action: add-bond
|
||||
name: bond23
|
||||
interfaces:
|
||||
- eth2.11
|
||||
- eth2.12
|
||||
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.11', 'eth2.12'],
|
||||
})
|
||||
end
|
||||
|
||||
['eth2.11', 'eth2.12'].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 'pass vendor_specific through interface_properties for bonds explicit subinterfaces' 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: {}
|
||||
transformations:
|
||||
- action: add-port
|
||||
name: eth2.11
|
||||
- action: add-port
|
||||
name: eth2.12
|
||||
- action: add-bond
|
||||
name: bond23
|
||||
interfaces:
|
||||
- eth2.11
|
||||
- eth2.12
|
||||
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.11', 'eth2.12'],
|
||||
})
|
||||
end
|
||||
|
||||
['eth2.11', 'eth2.12'].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) {
|
||||
@ -179,6 +306,59 @@ describe 'l23network::examples::run_network_scheme', :type => :class do
|
||||
|
||||
end
|
||||
|
||||
|
||||
context 'no interface_properties in the bond given' 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
|
||||
transformations:
|
||||
- action: add-bond
|
||||
name: bond23
|
||||
interfaces:
|
||||
- eth2
|
||||
- eth3
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
###
|
||||
|
Loading…
Reference in New Issue
Block a user