Configure the numvfs for SRIOV interfaces

This patch shall create VFs via the PCI SYS interface.
Default value : $::os_service_default
Sample Format : ['eth0:4','eth2:128']
For values as in sample format, the sriov_numvfs config files
for eth0 and eth2 will have the values 4 and 128 respectively

Change-Id: I2c1fce461d4602cd9f7de44b34e94920d1a581a6
Implements: blueprint tripleo-sriov
Signed-off-by: karthik s <ksundara@redhat.com>
This commit is contained in:
karthik s 2016-07-20 21:47:39 +05:30
parent 7cf5e0781b
commit c425a5b9fb
7 changed files with 191 additions and 1 deletions

View File

@ -0,0 +1,58 @@
Puppet::Type.type(:neutron_agent_sriov_numvfs).provide(:sriov_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)
_set_numvfs
else
fail("#{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 sriov_numvfs_path
"/sys/class/net/#{sriov_get_interface}/device/sriov_numvfs"
end
def sriov_get_interface
resource[:name].split(':', 2).first
end
def sriov_numvfs_value
resource[:name].split(':', 2).last.to_i
end
end

View File

@ -0,0 +1,11 @@
Puppet::Type.newtype(:neutron_agent_sriov_numvfs) do
ensurable
newparam(:name) do
desc "sriov_numvfs conf as <physical_network>:<number_of_vfs> format"
newvalues(/^[a-z0-9-_]+:[0-9]+$/)
end
end

View File

@ -62,6 +62,13 @@
# in the sriov config. # in the sriov config.
# Defaults to false. # Defaults to false.
# #
# [*number_of_vfs*]
# (optional) List of <physical_network>:<number_of_vfs> specifying the number
# VFs to be exposed per physical interface.
# For example, to configure two inteface with number of VFs, specify
# it as "eth1:4,eth2:10"
# Defaults to $::os_service_default.
#
class neutron::agents::ml2::sriov ( class neutron::agents::ml2::sriov (
$package_ensure = 'present', $package_ensure = 'present',
$enabled = true, $enabled = true,
@ -71,6 +78,7 @@ class neutron::agents::ml2::sriov (
$exclude_devices = $::os_service_default, $exclude_devices = $::os_service_default,
$extensions = $::os_service_default, $extensions = $::os_service_default,
$purge_config = false, $purge_config = false,
$number_of_vfs = $::os_service_default,
) { ) {
include ::neutron::deps include ::neutron::deps
@ -87,6 +95,10 @@ class neutron::agents::ml2::sriov (
'agent/extensions': value => join(any2array($extensions), ','); 'agent/extensions': value => join(any2array($extensions), ',');
} }
if !is_service_default($number_of_vfs) and !empty($number_of_vfs) {
neutron_agent_sriov_numvfs { $number_of_vfs: ensure => present }
}
package { 'neutron-sriov-nic-agent': package { 'neutron-sriov-nic-agent':
ensure => $package_ensure, ensure => $package_ensure,
name => $::neutron::params::sriov_nic_agent_package, name => $::neutron::params::sriov_nic_agent_package,

View File

@ -0,0 +1,3 @@
---
features:
- Added a provider to configure VFs for SR-IOV interface

View File

@ -46,7 +46,9 @@ describe 'neutron::agents::ml2::sriov' do
is_expected.to contain_neutron_sriov_agent_config('agent/extensions').with_value(['<SERVICE DEFAULT>']) is_expected.to contain_neutron_sriov_agent_config('agent/extensions').with_value(['<SERVICE DEFAULT>'])
end end
it 'does not configure numvfs by default' do
is_expected.not_to contain_neutron_agents_ml2_sriov_numvfs('<SERVICE DEFAULT>')
end
it 'installs neutron sriov-nic agent package' do it 'installs neutron sriov-nic agent package' do
is_expected.to contain_package('neutron-sriov-nic-agent').with( is_expected.to contain_package('neutron-sriov-nic-agent').with(
@ -69,6 +71,27 @@ describe 'neutron::agents::ml2::sriov' do
is_expected.to contain_service('neutron-sriov-nic-agent-service').that_notifies('Anchor[neutron::service::end]') is_expected.to contain_service('neutron-sriov-nic-agent-service').that_notifies('Anchor[neutron::service::end]')
end end
context 'when number_of_vfs is empty' do
before :each do
params.merge!(:number_of_vfs => "")
end
it 'does not configure numvfs ' do
is_expected.not_to contain_neutron_agents_ml2_sriov_numvfs('<SERVICE DEFAULT>')
end
end
context 'when number_of_vfs is configured' do
before :each do
params.merge!(:number_of_vfs => ['eth0:4','eth1:5'])
end
it 'configures numvfs' do
is_expected.to contain_neutron_agent_sriov_numvfs('eth0:4').with( :ensure => 'present' )
is_expected.to contain_neutron_agent_sriov_numvfs('eth1:5').with( :ensure => 'present')
end
end
context 'with manage_service as false' do context 'with manage_service as false' do
before :each do before :each do
params.merge!(:manage_service => false) params.merge!(:manage_service => false)

View File

@ -0,0 +1,36 @@
require 'puppet'
require 'spec_helper'
require 'puppet/provider/neutron_agent_sriov_numvfs/sriov_numvfs'
provider_class = Puppet::Type.type(:neutron_agent_sriov_numvfs).
provider(:sriov_numvfs)
describe provider_class do
let :numvfs_conf do
{
:name => 'eth0:10',
:ensure => 'present',
}
end
describe 'when setting the attributes' do
let :resource do
Puppet::Type::Neutron_agent_sriov_numvfs.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
end
end

View File

@ -0,0 +1,47 @@
require 'puppet'
require 'puppet/type/neutron_agent_sriov_numvfs'
describe 'Puppet::Type.type(:neutron_agent_sriov_numvfs)' do
it 'should allow name to be passed' do
expect{Puppet::Type.type(:neutron_agent_sriov_numvfs).new(
:name => 'eth0:10',
:ensure => 'present'
)}.not_to raise_error
end
it 'should allow name to be passed with -' do
expect{Puppet::Type.type(:neutron_agent_sriov_numvfs).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(:neutron_agent_sriov_numvfs).new(
:name => 'eth_0:10',
:ensure => 'present'
)}.not_to raise_error
end
it 'should throw error for invalid format' do
expect{Puppet::Type.type(:neutron_agent_sriov_numvfs).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(:neutron_agent_sriov_numvfs).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(:neutron_agent_sriov_numvfs).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(:neutron_agent_sriov_numvfs).new(
:name => 'eth0:',
:ensure => 'present'
)}.to raise_error(Puppet::ResourceError)
end
end