From 10f574dc532260d86a367577bd1d0a9166058572 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 15 Oct 2023 00:34:46 +0900 Subject: [PATCH] Replace params by hieradata The params class is the legacy approach to define OS/version specific values. This replaces the params class by the module hieradata following the recent standard. Change-Id: I046267279720e969b0ddde821fafff00e517e728 --- data/Debian-family.yaml | 5 +++++ data/RedHat-family.yaml | 5 +++++ hiera.yaml | 16 ++++++++++++++++ manifests/dpdk.pp | 28 ++++++++++++++++++---------- manifests/init.pp | 3 ++- manifests/ovs.pp | 18 +++++++++++++----- manifests/params.pp | 25 ------------------------- manifests/pki/cacert.pp | 3 +-- manifests/pki/cert.pp | 3 +-- spec/classes/vswitch_dpdk_spec.rb | 6 ++++-- spec/classes/vswitch_ovs_spec.rb | 15 +++++++-------- 11 files changed, 72 insertions(+), 55 deletions(-) create mode 100644 data/Debian-family.yaml create mode 100644 data/RedHat-family.yaml create mode 100644 hiera.yaml delete mode 100644 manifests/params.pp diff --git a/data/Debian-family.yaml b/data/Debian-family.yaml new file mode 100644 index 00000000..90b816c6 --- /dev/null +++ b/data/Debian-family.yaml @@ -0,0 +1,5 @@ +--- +vswitch::dpdk::package_name: 'openvswitch-switch-dpdk' +vswitch::dpdk::service_name: 'openvswitch-switch' +vswitch::ovs::package_name: 'openvswitch-switch' +vswitch::ovs::service_name: 'openvswitch-switch' diff --git a/data/RedHat-family.yaml b/data/RedHat-family.yaml new file mode 100644 index 00000000..7862bf80 --- /dev/null +++ b/data/RedHat-family.yaml @@ -0,0 +1,5 @@ +--- +vswitch::dpdk::package_name: 'openvswitch' +vswitch::dpdk::service_name: 'openvswitch' +vswitch::ovs::package_name: 'openvswitch' +vswitch::ovs::service_name: 'openvswitch' diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 00000000..91962207 --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,16 @@ +--- +version: 5 +defaults: + datadir: 'data' + data_hash: 'yaml_data' +hierarchy: + - name: 'Major operating system version' + path: '%{facts.os.name}-%{facts.os.release.major}.yaml' + - name: 'Operating system' + path: '%{facts.os.release.major}.yaml' + - name: 'Major OS Family version' + path: '%{facts.os.family}-%{facts.os.release.major}.yaml' + - name: 'OS Family' + path: '%{facts.os.family}-family.yaml' + - name: 'Common' + path: 'common.yaml' diff --git a/manifests/dpdk.pp b/manifests/dpdk.pp index 8a623b59..9c5e7054 100644 --- a/manifests/dpdk.pp +++ b/manifests/dpdk.pp @@ -3,6 +3,16 @@ # # === Parameters # +# [*package_name*] +# (required) Name of OVS DPDK package. +# +# [*service_name*] +# (required) Name of OVS service with DPDK functionality. +# +# [*package_ensure*] +# (Optional) State of the openvswitch package +# Defaults to 'present'. +# # [*memory_channels*] # (optional) The number of memory channels to use as an integer. # @@ -12,10 +22,6 @@ # where c1, c2, etc are core indexes between 0 and 128. # For example, to configure 3 cores the value should be "0-2" # -# [*package_ensure*] -# (Optional) State of the openvswitch package -# Defaults to 'present'. -# # [*pmd_core_list*] # (optional) The list of cores to be used by the DPDK PMD threads. # The pmd_core_list is a string with format as [-c2][,c3[-c4],...] where @@ -97,9 +103,11 @@ # Defaults to false. # class vswitch::dpdk ( + String[1] $package_name, + String[1] $service_name, + String $package_ensure = 'present', Optional[Variant[Integer[0], String]] $memory_channels = undef, Optional[String] $host_core_list = undef, - String $package_ensure = 'present', Optional[String] $pmd_core_list = undef, Optional[Variant[String, Integer, Array[String], Array[Integer]]] $socket_mem = undef, Optional[Variant[String, Integer, Array[String], Array[Integer]]] $socket_limit = undef, @@ -118,14 +126,13 @@ class vswitch::dpdk ( Boolean $skip_restart = false, ) { - include vswitch::params - $restart = !$skip_restart kmod::load { 'vfio-pci': } - package { $::vswitch::params::ovs_dpdk_package_name: + package { 'openvswitch': ensure => $package_ensure, + name => $package_name, before => Service['openvswitch'], tag => 'openvswitch', } @@ -277,14 +284,15 @@ class vswitch::dpdk ( service { 'openvswitch': ensure => true, enable => true, - name => $::vswitch::params::ovs_service_name, + name => $service_name, + tag => 'openvswitch', } # NOTE(tkajinam): This resource is defined to restart the openvswitch services # when any vs_config resource with restart => true is enabled. exec { 'restart openvswitch': path => ['/sbin', '/usr/sbin', '/bin', '/usr/bin'], - command => "systemctl -q restart ${::vswitch::params::ovs_service_name}.service", + command => "systemctl -q restart ${service_name}.service", refreshonly => true, } diff --git a/manifests/init.pp b/manifests/init.pp index 412622d5..41573624 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -6,6 +6,7 @@ # # [*provider*] # Select vswitch to install +# Defaults to 'ovs' # # === Examples # @@ -25,7 +26,7 @@ # Apache License 2.0 (see LICENSE file) # class vswitch ( - Enum['ovs', 'dpdk'] $provider = $vswitch::params::provider + Enum['ovs', 'dpdk'] $provider = 'ovs' ) { $cls = "::vswitch::${provider}" include $cls diff --git a/manifests/ovs.pp b/manifests/ovs.pp index c10c20bf..c32a3384 100644 --- a/manifests/ovs.pp +++ b/manifests/ovs.pp @@ -5,6 +5,12 @@ # # === Parameters: # +# [*package_name*] +# (required) Name of OVS package. +# +# [*service_name*] +# (required) Name of OVS service. +# # [*package_ensure*] # (Optional) State of the openvswitch package # Defaults to 'present'. @@ -37,6 +43,8 @@ # Defaults to false. # class vswitch::ovs( + String[1] $package_name, + String[1] $service_name, String $package_ensure = 'present', Boolean $enable_hw_offload = false, Boolean $disable_emc = false, @@ -45,8 +53,6 @@ class vswitch::ovs( Boolean $skip_restart = false, ) { - include vswitch::params - $restart = !$skip_restart if $enable_hw_offload { @@ -85,19 +91,21 @@ class vswitch::ovs( service { 'openvswitch': ensure => true, enable => true, - name => $::vswitch::params::ovs_service_name, + name => $service_name, + tag => 'openvswitch', } # NOTE(tkajinam): This resource is defined to restart the openvswitch service # when any vs_config resource with restart => true is enabled. exec { 'restart openvswitch': path => ['/sbin', '/usr/sbin', '/bin', '/usr/bin'], - command => "systemctl -q restart ${::vswitch::params::ovs_service_name}.service", + command => "systemctl -q restart ${service_name}.service", refreshonly => true, } - package { $::vswitch::params::ovs_package_name: + package { 'openvswitch': ensure => $package_ensure, + name => $package_name, before => Service['openvswitch'], tag => 'openvswitch', } diff --git a/manifests/params.pp b/manifests/params.pp deleted file mode 100644 index a8125208..00000000 --- a/manifests/params.pp +++ /dev/null @@ -1,25 +0,0 @@ -# vswitch params -# -class vswitch::params { - include openstacklib::defaults - - case $facts['os']['family'] { - 'Redhat': { - $ovs_package_name = 'openvswitch' - # OVS2.5 in Red Hat family is unified package which will support plain - # OVS and also DPDK (if enabled at runtime). - $ovs_dpdk_package_name = 'openvswitch' - $ovs_service_name = 'openvswitch' - $provider = 'ovs' - } - 'Debian': { - $ovs_package_name = 'openvswitch-switch' - $ovs_dpdk_package_name = 'openvswitch-switch-dpdk' - $ovs_service_name = 'openvswitch-switch' - $provider = 'ovs' - } - default: { - fail " Osfamily ${facts['os']['family']} not supported yet" - } - } # Case $facts['os']['family'] -} diff --git a/manifests/pki/cacert.pp b/manifests/pki/cacert.pp index 834b1d28..1de02e02 100644 --- a/manifests/pki/cacert.pp +++ b/manifests/pki/cacert.pp @@ -3,7 +3,6 @@ # Initialize CA authority # class vswitch::pki::cacert { - include vswitch::params exec { 'ovs-pki-init-ca-authority': command => 'ovs-pki init --force', @@ -11,6 +10,6 @@ class vswitch::pki::cacert { path => ['/usr/sbin', '/sbin', '/usr/bin', '/bin'], } - Package<| title == $::vswitch::params::ovs_package_name |> + Package<| title == 'openvswitch' |> -> Exec['ovs-pki-init-ca-authority'] } diff --git a/manifests/pki/cert.pp b/manifests/pki/cert.pp index 1e046e23..6ad0cbe8 100644 --- a/manifests/pki/cert.pp +++ b/manifests/pki/cert.pp @@ -11,7 +11,6 @@ define vswitch::pki::cert( Stdlib::Absolutepath $cert_dir = '/etc/openvswitch', ) { - include vswitch::params exec { "ovs-req-and-sign-cert-${name}": command => "ovs-pki req+sign ${name}", @@ -20,7 +19,7 @@ define vswitch::pki::cert( path => ['/usr/sbin', '/sbin', '/usr/bin', '/bin'], } - Package<| title == $::vswitch::params::ovs_package_name |> + Package<| title == 'openvswitch' |> -> Exec["ovs-req-and-sign-cert-${name}"] Exec<| title == 'ovs-pki-init-ca-authority' |> diff --git a/spec/classes/vswitch_dpdk_spec.rb b/spec/classes/vswitch_dpdk_spec.rb index bfd3f5de..ea7c1c01 100644 --- a/spec/classes/vswitch_dpdk_spec.rb +++ b/spec/classes/vswitch_dpdk_spec.rb @@ -57,14 +57,16 @@ describe 'vswitch::dpdk' do :ensure => true, :enable => true, :name => platform_params[:ovs_service_name], + :tag => 'openvswitch' ) end it 'install package' do - is_expected.to contain_package(platform_params[:ovs_dpdk_package_name]).with( + is_expected.to contain_package('openvswitch').with( :name => platform_params[:ovs_dpdk_package_name], :ensure => 'present', - :before => 'Service[openvswitch]' + :before => 'Service[openvswitch]', + :tag => 'openvswitch' ) end diff --git a/spec/classes/vswitch_ovs_spec.rb b/spec/classes/vswitch_ovs_spec.rb index 3f29d54a..e21561ca 100644 --- a/spec/classes/vswitch_ovs_spec.rb +++ b/spec/classes/vswitch_ovs_spec.rb @@ -9,10 +9,6 @@ describe 'vswitch::ovs' do is_expected.to contain_class('vswitch::ovs') end - it 'contains params' do - is_expected.to contain_class('vswitch::params') - end - it 'clears hw-offload option' do is_expected.to contain_vs_config('other_config:hw-offload').with( :ensure => 'absent', :restart => true, :wait => true, @@ -36,14 +32,16 @@ describe 'vswitch::ovs' do :ensure => true, :enable => true, :name => platform_params[:ovs_service_name], + :tag => 'openvswitch' ) end it 'install package' do - is_expected.to contain_package(platform_params[:ovs_package_name]).with( + is_expected.to contain_package('openvswitch').with( :name => platform_params[:ovs_package_name], :ensure => 'present', - :before => 'Service[openvswitch]' + :before => 'Service[openvswitch]', + :tag => 'openvswitch' ) end @@ -66,10 +64,11 @@ describe 'vswitch::ovs' do } end it 'installs correct package' do - is_expected.to contain_package(platform_params[:ovs_package_name]).with( + is_expected.to contain_package('openvswitch').with( :name => platform_params[:ovs_package_name], :ensure => 'latest', - :before => 'Service[openvswitch]' + :before => 'Service[openvswitch]', + :tag => 'openvswitch' ) end it 'configures hw-offload option' do