diff --git a/lib/facter/pci_address.rb b/lib/facter/pci_address.rb new file mode 100644 index 00000000..aeb3eb19 --- /dev/null +++ b/lib/facter/pci_address.rb @@ -0,0 +1,28 @@ +require 'facter' +drivers_details=Facter::Util::Resolution.exec("cat /proc/bus/pci/devices") +drivers_lines=drivers_details.split("\n") +drivers=Hash.new +drivers_lines.each do |line| + line = line.gsub(/^\s+|\s+$/m, '').split(" ") + if line.length == 18 + pci_embed = line[0] + driver = line[-1] + bus = pci_embed[0] + pci_embed[1] + dev = ((pci_embed[2].to_i(16) << 1) + (pci_embed[3].to_i(16) >> 3)).to_s(16).upcase + fun = (pci_embed[3].to_i(16) & 7).to_s(16).upcase + pci = "0000:" + bus + ":" + dev + "." + fun + if not drivers.has_key?(driver) + drivers[driver] = Array.new + end + drivers[driver] << pci + end +end + +drivers.each do |driver,pci_addr| + Facter.add("pci_address_driver_#{driver}") do + confine :kernel => :linux + setcode do + pci_addr.join(',') + end + end +end diff --git a/manifests/dpdk.pp b/manifests/dpdk.pp index e94323e7..713403a0 100644 --- a/manifests/dpdk.pp +++ b/manifests/dpdk.pp @@ -3,10 +3,6 @@ # # === Parameters # -# [*package_ensure*] -# (Optional) State of the openvswitch package -# Defaults to 'present'. -# # [*core_list*] # (required) The list of cores to be used by the DPDK Poll Mode Driver # The core_list is a string with format as [-c2][,c3[-c4],...] where c1, c2, etc are core indexes between 0 and 128 @@ -15,17 +11,26 @@ # [*memory_channels*] # (required) The number of memory channels to use as an integer # +# [*package_ensure*] +# (Optional) State of the openvswitch package +# Defaults to 'present'. +# # [*socket_mem*] # (Optional) Set the memory to be allocated on each socket # The socket_mem is a string with comma separated memory list in MB in the order of socket numbers. # For example, to allocate memory of 1GB for socket 1 and no allocation for socket 0, the value should be "0,1024" # Defaults to undef. # +# [*driver_type*] +# (Optional) The DPDK Driver type +# Defaults to 'vfio-pci' +# class vswitch::dpdk ( $core_list, $memory_channels, $package_ensure = 'present', $socket_mem = undef, + $driver_type = 'vfio-pci', ) { include ::vswitch::params @@ -41,7 +46,14 @@ class vswitch::dpdk ( $socket_string = "--socket-mem ${socket_mem}" } - $options = "DPDK_OPTIONS = \"-l ${core_list} -n ${memory_channels} ${socket_string}\"" + if $driver_type { + $pci_list = inline_template('<%= Facter.value("pci_address_driver_#@driver_type") %>') + unless empty($pci_list) { + $white_list = inline_template('-w <%= @pci_list.gsub(",", " -w ") %>') + } + } + + $options = "DPDK_OPTIONS = \"-l ${core_list} -n ${memory_channels} ${socket_string} ${white_list}\"" case $::osfamily { 'Redhat': { diff --git a/releasenotes/notes/ovs-dpdk-97916bffadb9d594.yaml b/releasenotes/notes/ovs-dpdk-97916bffadb9d594.yaml new file mode 100644 index 00000000..54ae2903 --- /dev/null +++ b/releasenotes/notes/ovs-dpdk-97916bffadb9d594.yaml @@ -0,0 +1,3 @@ +--- +features: + - DPDK puppet class is added to configure DPDK with ovs. diff --git a/spec/classes/vswitch_dpdk_spec.rb b/spec/classes/vswitch_dpdk_spec.rb index 9c75cff0..248fbf2e 100644 --- a/spec/classes/vswitch_dpdk_spec.rb +++ b/spec/classes/vswitch_dpdk_spec.rb @@ -3,17 +3,9 @@ require 'spec_helper' describe 'vswitch::dpdk' do let :default_params do { - :package_ensure => 'present', - :core_list => '1,2', - :memory_channels => '2' - } - end - - let :socket_mem_params do { :package_ensure => 'present', :core_list => '1,2', :memory_channels => '2', - :socket_mem => '1024' } end @@ -47,7 +39,6 @@ describe 'vswitch::dpdk' do :before => 'Service[openvswitch]', ) end - end shared_examples_for 'vswitch dpdk mandatory params' do @@ -55,20 +46,39 @@ describe 'vswitch::dpdk' do is_expected.to contain_file_line('/etc/sysconfig/openvswitch').with( :path => '/etc/sysconfig/openvswitch', :match => '^DPDK_OPTIONS.*', - :line => 'DPDK_OPTIONS = "-l 1,2 -n 2 "', + :line => 'DPDK_OPTIONS = "-l 1,2 -n 2 "', :before => 'Service[openvswitch]', ) end end - shared_examples_for 'vswitch dpdk socket_mem param' do - it 'configures dpdk options for ovs' do - is_expected.to contain_file_line('/etc/sysconfig/openvswitch').with( - :path => '/etc/sysconfig/openvswitch', - :match => '^DPDK_OPTIONS.*', - :line => 'DPDK_OPTIONS = "-l 1,2 -n 2 --socket-mem 1024"', - :before => 'Service[openvswitch]', - ) + shared_examples_for 'vswitch dpdk additional params' do + context 'when passing socket mem' do + before :each do + params.merge!(:socket_mem => '1024') + end + it 'configures dpdk options with socket memory' do + is_expected.to contain_file_line('/etc/sysconfig/openvswitch').with( + :path => '/etc/sysconfig/openvswitch', + :match => '^DPDK_OPTIONS.*', + :line => 'DPDK_OPTIONS = "-l 1,2 -n 2 --socket-mem 1024 "', + :before => 'Service[openvswitch]', + ) + end + end + + context 'when providing valid driver type facts' do + before :each do + params.merge!(:driver_type => 'test') + end + it 'configures dpdk options with pci address for driver test' do + is_expected.to contain_file_line('/etc/sysconfig/openvswitch').with( + :path => '/etc/sysconfig/openvswitch', + :match => '^DPDK_OPTIONS.*', + :line => 'DPDK_OPTIONS = "-l 1,2 -n 2 -w 0000:00:05.0 -w 0000:00:05.1"', + :before => 'Service[openvswitch]', + ) + end end end @@ -89,19 +99,20 @@ describe 'vswitch::dpdk' do end context 'on redhat with additonal parameters' do - let :params do socket_mem_params end + let :params do default_params end let :facts do OSDefaults.get_facts({ :osfamily => 'Redhat', :ovs_version => '1.4.2', + :pci_address_driver_test => '0000:00:05.0,0000:00:05.1' }) end let :platform_params do redhat_platform_params end it_configures 'vswitch dpdk' - it_configures 'vswitch dpdk socket_mem param' + it_configures 'vswitch dpdk additional params' end end \ No newline at end of file