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
This commit is contained in:
Takashi Kajinami 2023-10-15 00:34:46 +09:00
parent 91231c2eea
commit 10f574dc53
11 changed files with 72 additions and 55 deletions

5
data/Debian-family.yaml Normal file
View File

@ -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'

5
data/RedHat-family.yaml Normal file
View File

@ -0,0 +1,5 @@
---
vswitch::dpdk::package_name: 'openvswitch'
vswitch::dpdk::service_name: 'openvswitch'
vswitch::ovs::package_name: 'openvswitch'
vswitch::ovs::service_name: 'openvswitch'

16
hiera.yaml Normal file
View File

@ -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'

View File

@ -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 <c1>[-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,
}

View File

@ -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

View File

@ -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',
}

View File

@ -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']
}

View File

@ -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']
}

View File

@ -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' |>

View File

@ -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

View File

@ -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