Merge "Remove the unused tripleo::host::sriov class"
This commit is contained in:
commit
758f2e49b0
|
@ -1,129 +0,0 @@
|
|||
Puppet::Type.type(:sriov_vf_config).provide(:numvfs) do
|
||||
desc <<-EOT
|
||||
The file /sys/class/net/<sriov_interface_name>/device/sriov_numvfs will be
|
||||
present when a physical PCIe device supports SR-IOV. A number written to
|
||||
this file will enable the specified number of VFs. This provider shall read
|
||||
the file and ensure that the value is zero, before writing the number of
|
||||
VFs that should be enabled. If the VFs needs to be disabled then we shall
|
||||
write a zero to this file.
|
||||
EOT
|
||||
|
||||
def create
|
||||
if File.file?(sriov_numvfs_path)
|
||||
if ovs_mode == "switchdev"
|
||||
_apply_hw_offload
|
||||
else
|
||||
_set_numvfs
|
||||
end
|
||||
else
|
||||
warning("#{sriov_numvfs_path} doesn't exist. Check if #{sriov_get_interface} is a valid network interface supporting SR-IOV")
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if File.file?(sriov_numvfs_path)
|
||||
File.write(sriov_numvfs_path,"0")
|
||||
end
|
||||
end
|
||||
|
||||
def exists?
|
||||
if File.file?(sriov_numvfs_path)
|
||||
cur_value = File.read(sriov_numvfs_path)
|
||||
if cur_value.to_i == sriov_numvfs_value
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def _set_numvfs
|
||||
# During an update, the content of file sriov_numvfs_path has to be set
|
||||
# to 0 (ZERO), before writing the actual value
|
||||
cur_value = File.read(sriov_numvfs_path)
|
||||
if cur_value != 0
|
||||
File.write(sriov_numvfs_path,"0")
|
||||
end
|
||||
File.write(sriov_numvfs_path,sriov_numvfs_value)
|
||||
end
|
||||
|
||||
def _apply_hw_offload
|
||||
# Changing the mode of virtual functions to support hw-offload
|
||||
|
||||
vendor_id = File.read(vendor_path).strip
|
||||
|
||||
# Setting the number of vfs
|
||||
_set_numvfs
|
||||
|
||||
# Applying the hardware offloading
|
||||
if vendor_id == "0x15b3"
|
||||
vfs_pcis = get_vfs_pcis
|
||||
# Unbinding virtual functions
|
||||
vfs_pcis.each do|vfs_pci|
|
||||
File.write("/sys/bus/pci/drivers/mlx5_core/unbind",vfs_pci)
|
||||
end
|
||||
end
|
||||
|
||||
# Saving the name of sriov interface to udev rules
|
||||
udev_file_path = "/etc/udev/rules.d/70-persistent-net.rules"
|
||||
sriov_interface_mac = File.read(sriov_interface_mac_path).strip
|
||||
udev_data_line = get_udev_data_line(sriov_interface_mac)
|
||||
File.write(udev_file_path, udev_data_line, mode: 'a')
|
||||
%x{/usr/sbin/udevadm control --reload-rules}
|
||||
%x{/usr/sbin/udevadm trigger}
|
||||
|
||||
# Changing the mode of sriov interface to switchdev mode
|
||||
%x{/usr/sbin/devlink dev eswitch set pci/#{get_interface_pci} mode switchdev}
|
||||
%x{/usr/sbin/ifup #{sriov_get_interface}}
|
||||
if get_interface_device == "0x1013" || get_interface_device == "0x1015"
|
||||
%x{/usr/sbin/devlink dev eswitch set pci/#{get_interface_pci} inline-mode transport}
|
||||
end
|
||||
%x{/usr/sbin/ethtool -K #{sriov_get_interface} hw-tc-offload on}
|
||||
end
|
||||
|
||||
def get_udev_data_line(mac)
|
||||
'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="' + "#{mac}" + '", NAME="' + "#{sriov_get_interface}" + "\"\n"
|
||||
end
|
||||
|
||||
def sriov_interface_mac_path
|
||||
"/sys/class/net/#{sriov_get_interface}/address"
|
||||
end
|
||||
|
||||
def sriov_numvfs_path
|
||||
"/sys/class/net/#{sriov_get_interface}/device/sriov_numvfs"
|
||||
end
|
||||
|
||||
def sriov_get_interface
|
||||
resource[:name].split(':', 3).first
|
||||
end
|
||||
|
||||
def sriov_numvfs_value
|
||||
resource[:name].split(':', 3)[1].to_i
|
||||
end
|
||||
|
||||
def vendor_path
|
||||
"/sys/class/net/#{sriov_get_interface}/device/vendor"
|
||||
end
|
||||
|
||||
def ovs_mode
|
||||
if resource[:name].split(':', 3).length == 2
|
||||
'legacy'
|
||||
else
|
||||
resource[:name].split(':', 3).last
|
||||
end
|
||||
end
|
||||
|
||||
def get_vfs_pcis
|
||||
%x{cat /sys/class/net/#{sriov_get_interface}/device/virtfn*/uevent | grep PCI_SLOT_NAME | cut -d'=' -f2}.split(/\n+/)
|
||||
end
|
||||
|
||||
def get_interface_pci
|
||||
%x{ethtool -i #{sriov_get_interface} | grep bus-info | awk {'print$2'}}.strip
|
||||
end
|
||||
|
||||
def get_interface_device
|
||||
%x{cat /sys/class/net/#{sriov_get_interface}/device/device}.strip
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
Puppet::Type.newtype(:sriov_vf_config) do
|
||||
|
||||
ensurable
|
||||
|
||||
newparam(:name) do
|
||||
desc "sriov_numvfs conf as <physical_network>:<number_of_vfs>:<mode> format"
|
||||
newvalues(/^[a-zA-Z0-9\-_]+:[0-9]+(:(switchdev|legacy))?$/)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,31 +0,0 @@
|
|||
# == Class: tripleo::host::sriov
|
||||
#
|
||||
# Configures host configuration for the SR-IOV interfaces
|
||||
#
|
||||
# === Parameters
|
||||
#
|
||||
# [*number_of_vfs*]
|
||||
# (optional) List of <physical_network>:<number_of_vfs>:<sriov_mode>
|
||||
# specifying the number VFs to be exposed per physical interface with sriov
|
||||
# mode, where <sriov_mode> is optional field which accepts legacy or
|
||||
# switchdev, and if it's not specified we default it to legacy.
|
||||
# For example, to configure two interface with number of VFs, specify
|
||||
# it as ['eth1:4','eth2:10:legacy'] for legacey mode or specify it as
|
||||
# ['eth1:4:switchdev'] for switchdev mode
|
||||
# Defaults to []
|
||||
#
|
||||
class tripleo::host::sriov (
|
||||
$number_of_vfs = [],
|
||||
) {
|
||||
|
||||
if !empty($number_of_vfs) {
|
||||
sriov_vf_config { $number_of_vfs: ensure => present }
|
||||
|
||||
# the numvfs configuration needs to be persisted for every boot
|
||||
tripleo::host::sriov::numvfs_persistence {'persistent_numvfs':
|
||||
vf_defs => $number_of_vfs,
|
||||
content_string => "#!/bin/bash\n",
|
||||
udev_rules => ''
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
#
|
||||
# tripleo::host::sriov::numvfs_persistence used by tripleo::host::sriov
|
||||
#
|
||||
# === Parameters:
|
||||
#
|
||||
# [*vf_defs*]
|
||||
# (required) Array of <physical_interface>:<numvfs>.
|
||||
# Example: ['eth1:10','eth2:8']
|
||||
#
|
||||
# [*content_string*]
|
||||
# (required) String which shall be written to the script file.
|
||||
#
|
||||
# [*udev_rules*]
|
||||
# (required) String of lines to write to udev rules to ensure
|
||||
# VFs are reconfigured if the PCI devices are removed and
|
||||
# readded without rebooting (e.g. when physical functions were
|
||||
# allocated to VMs)
|
||||
#
|
||||
define tripleo::host::sriov::numvfs_persistence(
|
||||
$vf_defs,
|
||||
$content_string,
|
||||
$udev_rules
|
||||
){
|
||||
# Since reduce isn't available, we use recursion to iterate each entries of
|
||||
# "physical_interface:vfs" and accumulate the content that needs to be
|
||||
# written to the script file.
|
||||
include stdlib
|
||||
|
||||
if empty($vf_defs) {
|
||||
file { '/etc/sysconfig/allocate_vfs':
|
||||
ensure => file,
|
||||
content => $content_string,
|
||||
group => 'root',
|
||||
mode => '0755',
|
||||
owner => 'root',
|
||||
}
|
||||
|
||||
file { '/sbin/ifup-local':
|
||||
group => 'root',
|
||||
mode => '0755',
|
||||
owner => 'root',
|
||||
content => '#!/bin/bash',
|
||||
replace => false
|
||||
}
|
||||
|
||||
file { '/etc/udev/rules.d/70-tripleo-reset-sriov.rules':
|
||||
ensure => file,
|
||||
group => 'root',
|
||||
mode => '0755',
|
||||
owner => 'root',
|
||||
content => $udev_rules,
|
||||
replace => true,
|
||||
}
|
||||
|
||||
|
||||
file_line { 'call_ifup-local':
|
||||
path => '/sbin/ifup-local',
|
||||
line => '/etc/sysconfig/allocate_vfs $1',
|
||||
require => File['/sbin/ifup-local'],
|
||||
}
|
||||
} else {
|
||||
$vfspec = split($vf_defs[0], ':')
|
||||
$interface = $vfspec[0]
|
||||
$count = $vfspec[1]
|
||||
if (length($vfspec) == 3) {
|
||||
$mode = $vfspec[2]
|
||||
} else {
|
||||
$mode = 'legacy'
|
||||
}
|
||||
if ($mode == 'switchdev') {
|
||||
$vfdef_str = epp('tripleo/switchdev/switchdev.epp', {
|
||||
'content_string' => "${content_string}",
|
||||
'interface' => "${interface}",
|
||||
'count' => "${count}"
|
||||
})
|
||||
} else {
|
||||
$vfdef_str = "${content_string}[ \"${interface}\" == \"\$1\" ] \
|
||||
&& echo ${count} > /sys/class/net/${interface}/device/sriov_numvfs\n"
|
||||
}
|
||||
$udev_str = "${udev_rules}KERNEL==\"${interface}\", \
|
||||
RUN+=\"/etc/sysconfig/allocate_vfs %k\"\n"
|
||||
tripleo::host::sriov::numvfs_persistence{"mapped ${interface}":
|
||||
vf_defs => delete_at($vf_defs, 0),
|
||||
content_string => $vfdef_str,
|
||||
udev_rules => $udev_str
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'tripleo::host::sriov' do
|
||||
|
||||
shared_examples_for 'tripleo::host::sriov' do
|
||||
let :params do
|
||||
{:number_of_vfs => []}
|
||||
end
|
||||
|
||||
it 'does not configure numvfs by default' do
|
||||
is_expected.not_to contain_sriov_vf_config([])
|
||||
end
|
||||
|
||||
context 'when number_of_vfs is configured' do
|
||||
let :params do
|
||||
{:number_of_vfs => ['eth0:4','eth1:5']}
|
||||
end
|
||||
|
||||
it 'configures numvfs' do
|
||||
is_expected.to contain_sriov_vf_config('eth0:4').with( :ensure => 'present' )
|
||||
is_expected.to contain_sriov_vf_config('eth1:5').with( :ensure => 'present' )
|
||||
is_expected.to contain_tripleo__host__sriov__numvfs_persistence('persistent_numvfs').with(
|
||||
:vf_defs => ['eth0:4','eth1:5'],
|
||||
:content_string => "#!/bin/bash\n"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
on_supported_os.each do |os, facts|
|
||||
context "on #{os}" do
|
||||
let(:facts) do
|
||||
facts.merge({})
|
||||
end
|
||||
|
||||
it_behaves_like 'tripleo::host::sriov'
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,134 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'tripleo::host::sriov::numvfs_persistence' do
|
||||
|
||||
describe 'confugure numvfs for persistence' do
|
||||
|
||||
let :title do
|
||||
'numvfs'
|
||||
end
|
||||
|
||||
let :params do
|
||||
{
|
||||
:name => 'persistence',
|
||||
:vf_defs => ['eth0:10','eth1:8'],
|
||||
:content_string => "Hashbang\n",
|
||||
:udev_rules => ""
|
||||
}
|
||||
end
|
||||
|
||||
it 'configures persistence' do
|
||||
is_expected.to contain_file('/etc/sysconfig/allocate_vfs').with(
|
||||
:ensure => 'file',
|
||||
:content => "Hashbang\n[ \"eth0\" == \"\$1\" ] && echo 10 > /sys/class/net/eth0/device/sriov_numvfs\n[ \"eth1\" == \"\$1\" ] && echo 8 > /sys/class/net/eth1/device/sriov_numvfs\n",
|
||||
:group => 'root',
|
||||
:mode => '0755',
|
||||
:owner => 'root',
|
||||
)
|
||||
is_expected.to contain_file('/sbin/ifup-local').with(
|
||||
:group => 'root',
|
||||
:mode => '0755',
|
||||
:owner => 'root',
|
||||
:content => '#!/bin/bash',
|
||||
:replace => false,
|
||||
)
|
||||
is_expected.to contain_file('/etc/udev/rules.d/70-tripleo-reset-sriov.rules').with(
|
||||
:ensure => 'file',
|
||||
:content => "KERNEL==\"eth0\", RUN+=\"/etc/sysconfig/allocate_vfs %k\"\nKERNEL==\"eth1\", RUN+=\"/etc/sysconfig/allocate_vfs %k\"\n",
|
||||
:group => 'root',
|
||||
:mode => '0755',
|
||||
:owner => 'root',
|
||||
:replace => true
|
||||
)
|
||||
is_expected.to contain_file_line('call_ifup-local').with(
|
||||
:path => '/sbin/ifup-local',
|
||||
:line => '/etc/sysconfig/allocate_vfs $1',
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'tripleo::host::sriov::numvfs_persistence' do
|
||||
|
||||
describe 'confugure numvfs for persistence' do
|
||||
|
||||
let :title do
|
||||
'numvfs'
|
||||
end
|
||||
|
||||
let :params do
|
||||
{
|
||||
:name => 'persistence',
|
||||
:vf_defs => ['eth0:10:switchdev','eth1:8:legacy'],
|
||||
:content_string => "Hashbang\n",
|
||||
:udev_rules => ""
|
||||
}
|
||||
end
|
||||
|
||||
it 'configures persistence' do
|
||||
is_expected.to contain_file('/etc/sysconfig/allocate_vfs').with(
|
||||
:ensure => 'file',
|
||||
:content => "Hashbang\nset -ex
|
||||
set -o pipefail
|
||||
|
||||
if [ \"eth0\" == \"$1\" ]
|
||||
then
|
||||
exec 1> >(logger -s -t $(basename $0)) 2>&1
|
||||
vendor_id=\"$(cat /sys/class/net/eth0/device/vendor)\"
|
||||
if [ \"$(cat /sys/class/net/eth0/device/sriov_numvfs)\" == \"0\" ]
|
||||
then
|
||||
echo 10 > /sys/class/net/eth0/device/sriov_numvfs
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
if [ $vendor_id == \"0x15b3\" ]
|
||||
then
|
||||
vfs_pci_list=$(grep PCI_SLOT_NAME /sys/class/net/eth0/device/virtfn*/uevent | cut -d'=' -f2)
|
||||
for pci in $vfs_pci_list
|
||||
do
|
||||
echo \"$pci\" > /sys/bus/pci/drivers/mlx5_core/unbind
|
||||
done
|
||||
fi
|
||||
interface_pci=$(grep PCI_SLOT_NAME /sys/class/net/eth0/device/uevent | cut -d'=' -f2)
|
||||
/usr/sbin/devlink dev eswitch set pci/\"$interface_pci\" mode switchdev
|
||||
/usr/sbin/ifup eth0
|
||||
if [[ \"$(/usr/sbin/devlink dev eswitch show pci/\"$interface_pci\")\" =~ \"mode switchdev\" ]]
|
||||
then
|
||||
echo \"PCI device $interface_pci set to mode switchdev.\"
|
||||
else
|
||||
echo \"Failed to set PCI device $interface_pci to mode switchdev.\"
|
||||
exit 1
|
||||
fi
|
||||
interface_device=$(cat /sys/class/net/eth0/device/device)
|
||||
if [ \"$interface_device\" == \"0x1013\" ] || [ \"$interface_device\" == \"0x1015\" ]
|
||||
then
|
||||
/usr/sbin/devlink dev eswitch set pci/\"$interface_pci\" inline-mode transport
|
||||
fi
|
||||
/usr/sbin/ethtool -K eth0 hw-tc-offload on
|
||||
fi\n[ \"eth1\" == \"\$1\" ] && echo 8 > /sys/class/net/eth1/device/sriov_numvfs\n",
|
||||
:group => 'root',
|
||||
:mode => '0755',
|
||||
:owner => 'root',
|
||||
)
|
||||
is_expected.to contain_file('/sbin/ifup-local').with(
|
||||
:group => 'root',
|
||||
:mode => '0755',
|
||||
:owner => 'root',
|
||||
:content => '#!/bin/bash',
|
||||
:replace => false,
|
||||
)
|
||||
is_expected.to contain_file('/etc/udev/rules.d/70-tripleo-reset-sriov.rules').with(
|
||||
:ensure => 'file',
|
||||
:content => "KERNEL==\"eth0\", RUN+=\"/etc/sysconfig/allocate_vfs %k\"\nKERNEL==\"eth1\", RUN+=\"/etc/sysconfig/allocate_vfs %k\"\n",
|
||||
:group => 'root',
|
||||
:mode => '0755',
|
||||
:owner => 'root',
|
||||
:replace => true
|
||||
)
|
||||
is_expected.to contain_file_line('call_ifup-local').with(
|
||||
:path => '/sbin/ifup-local',
|
||||
:line => '/etc/sysconfig/allocate_vfs $1',
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,117 +0,0 @@
|
|||
require 'puppet'
|
||||
require 'spec_helper'
|
||||
require 'puppet/provider/sriov_vf_config/numvfs'
|
||||
|
||||
provider_class = Puppet::Type.type(:sriov_vf_config).
|
||||
provider(:numvfs)
|
||||
|
||||
describe provider_class do
|
||||
|
||||
let(:test_cfg_path) { "/tmp/test-ifup-local.txt" }
|
||||
let :numvfs_conf do
|
||||
{
|
||||
:name => 'eth0:10',
|
||||
:ensure => 'present',
|
||||
}
|
||||
end
|
||||
|
||||
describe 'when setting the attributes' do
|
||||
let :resource do
|
||||
Puppet::Type::Sriov_vf_config.new(numvfs_conf)
|
||||
end
|
||||
|
||||
let :provider do
|
||||
provider_class.new(resource)
|
||||
end
|
||||
|
||||
it 'should return the correct interface name' do
|
||||
expect(provider.sriov_get_interface).to eql('eth0')
|
||||
end
|
||||
|
||||
it 'should return the correct numvfs value' do
|
||||
expect(provider.sriov_numvfs_value).to eql(10)
|
||||
end
|
||||
|
||||
it 'should return path of the file to enable vfs' do
|
||||
expect(provider.sriov_numvfs_path).to eql('/sys/class/net/eth0/device/sriov_numvfs')
|
||||
end
|
||||
it 'should return ovs mode: legacy' do
|
||||
expect(provider.ovs_mode).to eql('legacy')
|
||||
end
|
||||
end
|
||||
|
||||
let :numvfs_conf_switchdev do
|
||||
{
|
||||
:name => 'eth1:12:switchdev',
|
||||
:ensure => 'present',
|
||||
}
|
||||
end
|
||||
|
||||
describe 'when setting the attributes' do
|
||||
let :resource_switchdev do
|
||||
Puppet::Type::Sriov_vf_config.new(numvfs_conf_switchdev)
|
||||
end
|
||||
|
||||
let :provider_switchdev do
|
||||
provider_class.new(resource_switchdev)
|
||||
end
|
||||
|
||||
it 'should return the correct interface name' do
|
||||
expect(provider_switchdev.sriov_get_interface).to eql('eth1')
|
||||
end
|
||||
|
||||
it 'should return the correct numvfs value' do
|
||||
expect(provider_switchdev.sriov_numvfs_value).to eql(12)
|
||||
end
|
||||
|
||||
it 'should return path of the file to enable vfs' do
|
||||
expect(provider_switchdev.sriov_numvfs_path).to eql('/sys/class/net/eth1/device/sriov_numvfs')
|
||||
end
|
||||
|
||||
it 'should return path of the vendor file' do
|
||||
expect(provider_switchdev.vendor_path).to eql('/sys/class/net/eth1/device/vendor')
|
||||
end
|
||||
|
||||
it 'should return ovs mode: switchdev' do
|
||||
expect(provider_switchdev.ovs_mode).to eql('switchdev')
|
||||
end
|
||||
end
|
||||
|
||||
let :numvfs_conf_legacy do
|
||||
{
|
||||
:name => 'eth2:14:legacy',
|
||||
:ensure => 'present',
|
||||
}
|
||||
end
|
||||
|
||||
describe 'when setting the attributes' do
|
||||
let :resource_legacy do
|
||||
Puppet::Type::Sriov_vf_config.new(numvfs_conf_legacy)
|
||||
end
|
||||
|
||||
let :provider_legacy do
|
||||
provider_class.new(resource_legacy)
|
||||
end
|
||||
|
||||
it 'should return the correct interface name' do
|
||||
expect(provider_legacy.sriov_get_interface).to eql('eth2')
|
||||
end
|
||||
|
||||
it 'should return the correct numvfs value' do
|
||||
expect(provider_legacy.sriov_numvfs_value).to eql(14)
|
||||
end
|
||||
|
||||
it 'should return path of the file to enable vfs' do
|
||||
expect(provider_legacy.sriov_numvfs_path).to eql('/sys/class/net/eth2/device/sriov_numvfs')
|
||||
end
|
||||
|
||||
it 'should return path of the vendor file' do
|
||||
expect(provider_legacy.vendor_path).to eql('/sys/class/net/eth2/device/vendor')
|
||||
end
|
||||
|
||||
it 'should return ovs mode: legacy' do
|
||||
expect(provider_legacy.ovs_mode).to eql('legacy')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,78 +0,0 @@
|
|||
require 'puppet'
|
||||
require 'puppet/type/sriov_vf_config'
|
||||
|
||||
describe 'Puppet::Type.type(:sriov_vf_config)' do
|
||||
it 'should allow name to be passed' do
|
||||
expect{Puppet::Type.type(:sriov_vf_config).new(
|
||||
:name => 'eth0:10',
|
||||
:ensure => 'present'
|
||||
)}.not_to raise_error
|
||||
end
|
||||
it 'should allow name to be passed' do
|
||||
expect{Puppet::Type.type(:sriov_vf_config).new(
|
||||
:name => 'eTH0:10',
|
||||
:ensure => 'present'
|
||||
)}.not_to raise_error
|
||||
end
|
||||
it 'should allow name to be passed with -' do
|
||||
expect{Puppet::Type.type(:sriov_vf_config).new(
|
||||
:name => 'eth-0:10',
|
||||
:ensure => 'present'
|
||||
)}.not_to raise_error
|
||||
end
|
||||
it 'should allow name to be passed with _' do
|
||||
expect{Puppet::Type.type(:sriov_vf_config).new(
|
||||
:name => 'eth_0:10',
|
||||
:ensure => 'present'
|
||||
)}.not_to raise_error
|
||||
end
|
||||
it 'should throw error for invalid format' do
|
||||
expect{Puppet::Type.type(:sriov_vf_config).new(
|
||||
:name => 'eth0',
|
||||
:ensure => 'present'
|
||||
)}.to raise_error(Puppet::ResourceError)
|
||||
end
|
||||
it 'should throw error for invalid format without interface name' do
|
||||
expect{Puppet::Type.type(:sriov_vf_config).new(
|
||||
:name => ':9',
|
||||
:ensure => 'present'
|
||||
)}.to raise_error(Puppet::ResourceError)
|
||||
end
|
||||
it 'should throw error for invalid format for numvfs' do
|
||||
expect{Puppet::Type.type(:sriov_vf_config).new(
|
||||
:name => 'eth8:none',
|
||||
:ensure => 'present'
|
||||
)}.to raise_error(Puppet::ResourceError)
|
||||
end
|
||||
it 'should throw error for invalid format without numvfs' do
|
||||
expect{Puppet::Type.type(:sriov_vf_config).new(
|
||||
:name => 'eth0:',
|
||||
:ensure => 'present'
|
||||
)}.to raise_error(Puppet::ResourceError)
|
||||
end
|
||||
it 'should allow name to be passed' do
|
||||
expect{Puppet::Type.type(:sriov_vf_config).new(
|
||||
:name => 'eth0:10:legacy',
|
||||
:ensure => 'present'
|
||||
)}.not_to raise_error
|
||||
end
|
||||
it 'should allow name to be passed' do
|
||||
expect{Puppet::Type.type(:sriov_vf_config).new(
|
||||
:name => 'eth0:10:switchdev',
|
||||
:ensure => 'present'
|
||||
)}.not_to raise_error
|
||||
end
|
||||
it 'should throw error for invalid format for ovs mode' do
|
||||
expect{Puppet::Type.type(:sriov_vf_config).new(
|
||||
:name => 'eth0:10:None',
|
||||
:ensure => 'present'
|
||||
)}.to raise_error(Puppet::ResourceError)
|
||||
end
|
||||
it 'should throw error for invalid format without ovs mode' do
|
||||
expect{Puppet::Type.type(:sriov_vf_config).new(
|
||||
:name => 'eth0:10:',
|
||||
:ensure => 'present'
|
||||
)}.to raise_error(Puppet::ResourceError)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,39 +0,0 @@
|
|||
<%- | String $content_string = '', String $interface = '', String $count = '' | -%>
|
||||
<%=$content_string%>set -ex
|
||||
set -o pipefail
|
||||
|
||||
if [ "<%=$interface%>" == "$1" ]
|
||||
then
|
||||
exec 1> >(logger -s -t $(basename $0)) 2>&1
|
||||
vendor_id="$(cat /sys/class/net/<%=$interface%>/device/vendor)"
|
||||
if [ "$(cat /sys/class/net/<%=$interface%>/device/sriov_numvfs)" == "0" ]
|
||||
then
|
||||
echo <%=$count%> > /sys/class/net/<%=$interface%>/device/sriov_numvfs
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
if [ $vendor_id == "0x15b3" ]
|
||||
then
|
||||
vfs_pci_list=$(grep PCI_SLOT_NAME /sys/class/net/<%=$interface%>/device/virtfn*/uevent | cut -d'=' -f2)
|
||||
for pci in $vfs_pci_list
|
||||
do
|
||||
echo "$pci" > /sys/bus/pci/drivers/mlx5_core/unbind
|
||||
done
|
||||
fi
|
||||
interface_pci=$(grep PCI_SLOT_NAME /sys/class/net/<%=$interface%>/device/uevent | cut -d'=' -f2)
|
||||
/usr/sbin/devlink dev eswitch set pci/"$interface_pci" mode switchdev
|
||||
/usr/sbin/ifup <%=$interface%>
|
||||
if [[ "$(/usr/sbin/devlink dev eswitch show pci/"$interface_pci")" =~ "mode switchdev" ]]
|
||||
then
|
||||
echo "PCI device $interface_pci set to mode switchdev."
|
||||
else
|
||||
echo "Failed to set PCI device $interface_pci to mode switchdev."
|
||||
exit 1
|
||||
fi
|
||||
interface_device=$(cat /sys/class/net/<%=$interface%>/device/device)
|
||||
if [ "$interface_device" == "0x1013" ] || [ "$interface_device" == "0x1015" ]
|
||||
then
|
||||
/usr/sbin/devlink dev eswitch set pci/"$interface_pci" inline-mode transport
|
||||
fi
|
||||
/usr/sbin/ethtool -K <%=$interface%> hw-tc-offload on
|
||||
fi
|
Loading…
Reference in New Issue