Merge "Configure the numvfs for SRIOV interfaces"
This commit is contained in:
commit
7ad7a07e50
@ -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
|
||||
|
11
lib/puppet/type/neutron_agent_sriov_numvfs.rb
Normal file
11
lib/puppet/type/neutron_agent_sriov_numvfs.rb
Normal 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
|
||||
|
@ -62,6 +62,13 @@
|
||||
# in the sriov config.
|
||||
# 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 (
|
||||
$package_ensure = 'present',
|
||||
$enabled = true,
|
||||
@ -71,6 +78,7 @@ class neutron::agents::ml2::sriov (
|
||||
$exclude_devices = $::os_service_default,
|
||||
$extensions = $::os_service_default,
|
||||
$purge_config = false,
|
||||
$number_of_vfs = $::os_service_default,
|
||||
) {
|
||||
|
||||
include ::neutron::deps
|
||||
@ -90,6 +98,10 @@ class neutron::agents::ml2::sriov (
|
||||
'securitygroup/firewall_driver': value => 'neutron.agent.firewall.NoopFirewallDriver';
|
||||
}
|
||||
|
||||
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':
|
||||
ensure => $package_ensure,
|
||||
name => $::neutron::params::sriov_nic_agent_package,
|
||||
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- Added a provider to configure VFs for SR-IOV interface
|
@ -47,7 +47,9 @@ describe 'neutron::agents::ml2::sriov' do
|
||||
is_expected.to contain_neutron_sriov_agent_config('securitygroup/firewall_driver').with_value('neutron.agent.firewall.NoopFirewallDriver')
|
||||
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
|
||||
is_expected.to contain_package('neutron-sriov-nic-agent').with(
|
||||
@ -70,6 +72,27 @@ describe 'neutron::agents::ml2::sriov' do
|
||||
is_expected.to contain_service('neutron-sriov-nic-agent-service').that_notifies('Anchor[neutron::service::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
|
||||
before :each do
|
||||
params.merge!(:manage_service => false)
|
||||
|
@ -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
|
47
spec/unit/type/neutron_agent_sriov_numvfs_spec.rb
Normal file
47
spec/unit/type/neutron_agent_sriov_numvfs_spec.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user