From f1c5e34409e34a66284340b4f61ec77f01f5436f Mon Sep 17 00:00:00 2001 From: Saravanan KR Date: Mon, 11 Jul 2016 18:29:30 +0530 Subject: [PATCH] OVS DPDK package support with basic options Puppet changes requierd for supporting OVS DPDK packages. Basic DPDK_OPTIONS parameters are added (more to come). Implements: blueprint tripleo-ovs-dpdk Change-Id: I853517247f2892ad27cff179961d1498456d1cb5 --- manifests/dpdk.pp | 67 +++++++++++++++++++ manifests/ovs.pp | 1 + manifests/params.pp | 9 +++ spec/classes/vswitch_dpdk_spec.rb | 107 ++++++++++++++++++++++++++++++ 4 files changed, 184 insertions(+) create mode 100644 manifests/dpdk.pp create mode 100644 spec/classes/vswitch_dpdk_spec.rb diff --git a/manifests/dpdk.pp b/manifests/dpdk.pp new file mode 100644 index 00000000..e94323e7 --- /dev/null +++ b/manifests/dpdk.pp @@ -0,0 +1,67 @@ +# +# Configure OVS to use DPDK +# +# === 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 +# For example, to configure 3 cores the value should be "0-2" +# +# [*memory_channels*] +# (required) The number of memory channels to use as an integer +# +# [*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. +# +class vswitch::dpdk ( + $core_list, + $memory_channels, + $package_ensure = 'present', + $socket_mem = undef, +) { + + include ::vswitch::params + + package { $::vswitch::params::ovs_dpdk_package_name: + ensure => $package_ensure, + before => Service['openvswitch'], + tag => 'openvswitch', + } + + # Set DPDK_OPTIONS to openvswitch + if $socket_mem { + $socket_string = "--socket-mem ${socket_mem}" + } + + $options = "DPDK_OPTIONS = \"-l ${core_list} -n ${memory_channels} ${socket_string}\"" + + case $::osfamily { + 'Redhat': { + file_line { '/etc/sysconfig/openvswitch': + path => '/etc/sysconfig/openvswitch', + match => '^DPDK_OPTIONS.*', + line => $options, + require => Package[$::vswitch::params::ovs_dpdk_package_name], + before => Service['openvswitch'] + } + + service { 'openvswitch': + ensure => true, + enable => true, + name => $::vswitch::params::ovs_service_name, + } + } + default: { + fail( "${::osfamily} not yet supported for dpdk installation by puppet-vswitch") + } + } + +} diff --git a/manifests/ovs.pp b/manifests/ovs.pp index 261afa56..04a92b1a 100644 --- a/manifests/ovs.pp +++ b/manifests/ovs.pp @@ -128,6 +128,7 @@ class vswitch::ovs( package { $::vswitch::params::ovs_package_name: ensure => $package_ensure, before => Service['openvswitch'], + tag => 'openvswitch', } Service['openvswitch'] -> Vs_port<||> diff --git a/manifests/params.pp b/manifests/params.pp index 2b6181d7..c0b774a4 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -2,15 +2,24 @@ # class vswitch::params { include ::openstacklib::defaults + + if versioncmp($::puppetversion, '4.0.0') < 0 and versioncmp($::puppetversion, '3.6.1') >= 0 { + Package<| tag == 'openvswitch' |> { + allow_virtual => true, + } + } + case $::osfamily { 'Redhat': { $ovs_package_name = 'openvswitch' + $ovs_dpdk_package_name = 'openvswitch-dpdk' $ovs_dkms_package_name = undef $ovs_service_name = 'openvswitch' $provider = 'ovs_redhat' } 'Debian': { $ovs_package_name = 'openvswitch-switch' + $ovs_dpdk_package_name = 'openvswitch-switch-dpdk' $ovs_dkms_package_name = 'openvswitch-datapath-dkms' $ovs_service_name = 'openvswitch-switch' $provider = 'ovs' diff --git a/spec/classes/vswitch_dpdk_spec.rb b/spec/classes/vswitch_dpdk_spec.rb new file mode 100644 index 00000000..9c75cff0 --- /dev/null +++ b/spec/classes/vswitch_dpdk_spec.rb @@ -0,0 +1,107 @@ +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 + + let :redhat_platform_params do { + :ovs_dpdk_package_name => 'openvswitch-dpdk', + :ovs_service_name => 'openvswitch', + :provider => 'ovs_redhat', + } + end + + shared_examples_for 'vswitch dpdk' do + + it 'contains params' do + is_expected.to contain_class('vswitch::params') + end + + it 'configures service' do + is_expected.to contain_service('openvswitch').with( + :ensure => true, + :enable => true, + :name => platform_params[:ovs_service_name], + :hasstatus => platform_params[:service_hasstatus], + :status => platform_params[:service_status], + ) + end + + it 'install package' do + is_expected.to contain_package(platform_params[:ovs_dpdk_package_name]).with( + :name => platform_params[:ovs_dpdk_package_name], + :ensure => params[:package_ensure], + :before => 'Service[openvswitch]', + ) + end + + end + + shared_examples_for 'vswitch dpdk mandatory params' 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 "', + :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]', + ) + end + end + + context 'on redhat with only mandatory parameters' do + let :params do default_params end + + let :facts do + OSDefaults.get_facts({ + :osfamily => 'Redhat', + :ovs_version => '1.4.2', + }) + end + + let :platform_params do redhat_platform_params end + + it_configures 'vswitch dpdk' + it_configures 'vswitch dpdk mandatory params' + end + + context 'on redhat with additonal parameters' do + let :params do socket_mem_params end + + let :facts do + OSDefaults.get_facts({ + :osfamily => 'Redhat', + :ovs_version => '1.4.2', + }) + end + + let :platform_params do redhat_platform_params end + + it_configures 'vswitch dpdk' + it_configures 'vswitch dpdk socket_mem param' + end + +end \ No newline at end of file