From ade66c382645b8ee10bab3950fde914d4898ba8d Mon Sep 17 00:00:00 2001 From: Sergey Vasilenko Date: Tue, 28 Feb 2017 14:34:25 +0300 Subject: [PATCH] Support bonds of subinterfaces while merge interface_properties Change-Id: I27ede232a37c4e8c2d669f5dd8936a60baf04b40 Related-bug: #1643920 Closes-bug: #1666229 (cherry picked from commit d5fd08f78118a36a2cde8df4f5d216ca7b042bcf) --- .../functions/generate_network_config.rb | 28 ++- .../bond_vendor_specific_merge__spec.rb | 180 ++++++++++++++++++ 2 files changed, 199 insertions(+), 9 deletions(-) diff --git a/deployment/puppet/l23network/lib/puppet/parser/functions/generate_network_config.rb b/deployment/puppet/l23network/lib/puppet/parser/functions/generate_network_config.rb index d58a20d793..55224b9264 100644 --- a/deployment/puppet/l23network/lib/puppet/parser/functions/generate_network_config.rb +++ b/deployment/puppet/l23network/lib/puppet/parser/functions/generate_network_config.rb @@ -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}) + 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]}'") - if_sym = ifname.to_sym - b_provider=t[:provider] - mtu = t[:mtu] + 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 << { diff --git a/deployment/puppet/l23network/spec/classes/bond_vendor_specific_merge__spec.rb b/deployment/puppet/l23network/spec/classes/bond_vendor_specific_merge__spec.rb index ad7fff36d8..50078f03c6 100644 --- a/deployment/puppet/l23network/spec/classes/bond_vendor_specific_merge__spec.rb +++ b/deployment/puppet/l23network/spec/classes/bond_vendor_specific_merge__spec.rb @@ -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 ###