Some l23network ethtool fixes

* Fix ethtool parse issues for centos/rhel
* Test coverage of l23network ethtool

Partial-bug: #1527616

Change-Id: Iddaa996d4e08db9dbc5422a2eb46ab256044bbd0
This commit is contained in:
Stanislav Makar 2015-12-22 15:41:04 +00:00
parent 7ddb373ac9
commit a655b9985c
6 changed files with 259 additions and 1 deletions

View File

@ -246,7 +246,7 @@ class Puppet::Provider::L23_stored_config_centos < Puppet::Provider::L23_stored_
k,v = feature.split(' ')
tk = Hash[L23network.ethtool_name_commands_mapping[section_name].select { |key, value| value==k }]
next if tk == ''
feature_params[tk.keys.to_s] = ((v=='on' ? true : false))
feature_params[tk.keys.join()] = ((v=='on' ? true : false))
end
rv[section_name] = feature_params
end

View File

@ -0,0 +1,191 @@
require 'spec_helper'
describe 'l23network::examples::run_network_scheme', :type => :class do
let(:network_scheme) do
<<eof
---
network_scheme:
version: 1.1
provider: lnx
interfaces:
eth0:
ethtool:
offload:
generic-receive-offload: true
generic-segmentation-offload: true
rx-all: true
rx-checksumming: true
rx-fcs: true
rx-vlan-offload: true
scatter-gather: true
tcp-segmentation-offload: true
tx-checksumming: true
tx-nocache-copy: true
eth1:
vendor_specific:
disable_offloading: true
eth2: {}
eth3: {}
transformations:
- action: add-br
name: br-eth0
- action: add-port
bridge: br-eth0
name: eth0
- action: add-br
name: br-eth1
- action: add-port
bridge: br-eth1
name: eth1
- action: add-bond
name: bond23
interfaces:
- eth2
- eth3
mtu: 4000
bond_properties:
mode: balance-rr
interface_properties:
mtu: 9000
vendor_specific:
disable_offloading: true
emdpoints: {}
roles: {}
eof
end
context 'ethtool for interfaces' do
let(:title) { 'empty network scheme' }
let(:facts) {
{
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:kernel => 'Linux',
:l23_os => 'ubuntu',
:l3_fqdn_hostname => 'stupid_hostname',
}
}
let(:params) do {
:settings_yaml => network_scheme,
} end
before(:each) do
puppet_debug_override()
end
it do
should compile.with_all_deps
end
it do
should contain_l2_bridge('br-eth0').with({
})
end
it do
should contain_l23_stored_config('eth0').with({
'ensure' => 'present',
'bridge' => 'br-eth0',
'ethtool' => {
'offload' => {
'generic-receive-offload' => true,
'generic-segmentation-offload' => true,
'rx-all' => true,
'rx-checksumming' => true,
'rx-fcs' => true,
'rx-vlan-offload' => true,
'scatter-gather' => true,
'tcp-segmentation-offload' => true,
'tx-checksumming' => true,
'tx-nocache-copy' => true
}}
})
end
it do
should contain_l2_port('eth0').with({
'bridge' => 'br-eth0',
'ethtool' => {
'offload' => {
'generic-receive-offload' => true,
'generic-segmentation-offload' => true,
'rx-all' => true,
'rx-checksumming' => true,
'rx-fcs' => true,
'rx-vlan-offload' => true,
'scatter-gather' => true,
'tcp-segmentation-offload' => true,
'tx-checksumming' => true,
'tx-nocache-copy' => true
}}
})
end
it do
should contain_l2_bridge('br-eth1').with({
})
end
it do
should contain_l23_stored_config('eth1').with({
'ensure' => 'present',
'bridge' => 'br-eth1',
'ethtool' => {
'offload' => {
'generic-receive-offload' => false,
'generic-segmentation-offload' => false
}}
})
end
it do
should contain_l2_port('eth1').with({
'bridge' => 'br-eth1',
'ethtool' => {
'offload' => {
'generic-receive-offload' => false,
'generic-segmentation-offload' => false
}
}})
end
it do
should contain_l2_bond('bond23').with({
'ensure' => 'present',
'slaves' => ['eth2', 'eth3'],
'mtu' => 4000,
})
end
['eth2', 'eth3'].each do |iface|
it do
should contain_l2_port(iface).with({
'ensure' => 'present',
'mtu' => 9000,
'bond_master' => 'bond23',
'ethtool' => {
'offload' => {
'generic-receive-offload' => false,
'generic-segmentation-offload' => false
}
}
})
should contain_l23_stored_config(iface).with({
'ensure' => 'present',
'mtu' => 9000,
'bond_master' => 'bond23',
'ethtool' => {
'offload' => {
'generic-receive-offload' => false,
'generic-segmentation-offload' => false
}
}
})
end
end
end
end

View File

@ -0,0 +1,4 @@
BOOTPROTO=none
DEVICE=lnx-port3
ONBOOT=yes
ETHTOOL_OPTS="-K lnx-port3 gro off gso off ;"

View File

@ -0,0 +1,4 @@
auto p2p3
iface p2p3 inet manual
post-up ethtool -K p2p3 gro off | true # generic-receive-offload
post-up ethtool -K p2p3 gso off | true # generic-segmentation-offload

View File

@ -30,6 +30,17 @@ describe Puppet::Type.type(:l23_stored_config).provider(:lnx_centos7) do
:method => 'manual',
:provider => 'lnx_centos7',
},
:lnx_port_ethtool => {
:name => 'lnx-port3',
:ensure => 'present',
:onboot => true,
:method => 'manual',
:ethtool => {
'offload' => {
'generic-receive-offload' => false,
'generic-segmentation-offload' => false }},
:provider => 'lnx_centos7',
},
}
end
@ -98,6 +109,15 @@ describe Puppet::Type.type(:l23_stored_config).provider(:lnx_centos7) do
it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(4) } # no more lines in the interface file
end
context 'format file for lnx-port3 ethtool' do
subject { providers[:lnx_port_ethtool] }
let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
it { expect(cfg_file).to match(%r{DEVICE=lnx-port3}) }
it { expect(cfg_file).to match(%r{BOOTPROTO=none}) }
it { expect(cfg_file).to match(%r{ONBOOT=yes}) }
it { expect(cfg_file).to match(%r{ETHTOOL_OPTS="-K\s+lnx-port3\s+gro\s+off\s+gso\s+off\s+;"}) }
it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(4) } # no more lines in the interface file
end
context "parse port lnx-port data from fixture" do
let(:res) { subject.class.parse_file('lnx-port', fixture_data('ifcfg-lnx-port'))[0] }
@ -118,6 +138,16 @@ describe Puppet::Type.type(:l23_stored_config).provider(:lnx_centos7) do
it { expect(res[:provider]).to eq :lnx_centos7 }
end
context "parse port lnx-port3 data from fixture" do
let(:res) { subject.class.parse_file('lnx-port3', fixture_data('ifcfg-lnx-port3'))[0] }
it { expect(res[:name]).to eq 'lnx-port3' }
it { expect(res[:method].to_s).to eq 'manual' }
it { expect(res[:onboot]).to eq true }
it { expect(res[:ethtool]).to eq 'offload' => { 'generic-receive-offload'=>false, 'generic-segmentation-offload'=>false } }
it { expect(res[:provider]).to eq :lnx_centos7 }
end
end
end

View File

@ -6,6 +6,15 @@ resources_map = {
:if_type => 'ethernet',
:provider => 'lnx_ubuntu',
},
:'p2p3' => {
:name => 'p2p3',
:ethtool => {
'offload' => {
'generic-receive-offload' => false,
'generic-segmentation-offload' => false }},
:provider => 'lnx_ubuntu',
},
}
describe Puppet::Type.type(:l23_stored_config).provider(:lnx_ubuntu) do
@ -63,6 +72,16 @@ describe Puppet::Type.type(:l23_stored_config).provider(:lnx_ubuntu) do
it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(2) }
end
context 'Phys port p2p3 with ethtool' do
subject { providers[:'p2p3'] }
let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
it { expect(cfg_file).to match(/auto\s+p2p3/) }
it { expect(cfg_file).to match(/iface\s+p2p3\s+inet\s+manual/) }
it { expect(cfg_file).to match(%r{post-up\s+ethtool\s+-K\s+p2p3\s+gro\s+off\s+|\s+true\s+#\s+generic-receive-offload}) }
it { expect(cfg_file).to match(%r{post-up\s+ethtool\s+-K\s+p2p3\s+gso\s+off\s+|\s+true\s+#\s+generic-segmentation-offload}) }
it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(4) }
end
end
context "parsing config files" do
@ -75,6 +94,16 @@ describe Puppet::Type.type(:l23_stored_config).provider(:lnx_ubuntu) do
it { expect(res[:if_provider].to_s).to eq 'lnx' }
end
context 'Phys port p2p3 with ethtool' do
let(:res) { subject.class.parse_file('p2p3', fixture_data('ifcfg-p2p3'))[0] }
it { expect(res[:method]).to eq :manual }
it { expect(res[:onboot]).to eq true }
it { expect(res[:name]).to eq 'p2p3' }
it { expect(res[:ethtool]).to eq 'offload' => { 'generic-receive-offload'=>false, 'generic-segmentation-offload'=>false } }
it { expect(res[:if_provider].to_s).to eq 'lnx' }
end
end
end