From 02512cccbcd3d8b236bf332de97db727a469e862 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 15 Oct 2023 17:12:41 +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. Depends-on: https://review.opendev.org/c/openstack/puppet-vswitch/+/886112 Change-Id: I8d01236c04cf2b61f1c1bf39ecf54ca0a67a33a9 --- data/Debian-family.yaml | 9 +++++++ data/RedHat-family.yaml | 9 +++++++ hiera.yaml | 16 ++++++++++++ manifests/controller.pp | 35 +++++++++++++++++++------- manifests/northd.pp | 38 +++++++++++++++++++++-------- manifests/params.pp | 33 ------------------------- spec/classes/ovn_controller_spec.rb | 6 +---- spec/classes/ovn_northd_spec.rb | 6 +---- 8 files changed, 90 insertions(+), 62 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 0000000..cff64f1 --- /dev/null +++ b/data/Debian-family.yaml @@ -0,0 +1,9 @@ +--- +ovn::controller::package_name: 'ovn-host' +ovn::controller::service_name: 'ovn-host' +ovn::controller::config_file_path: '/etc/default/ovn-host' +ovn::controller::config_option_name: 'OVN_CTL_OPTS' +ovn::northd::package_name: 'ovn-central' +ovn::northd::service_name: 'ovn-central' +ovn::northd::config_file_path: '/etc/default/ovn-central' +ovn::northd::config_option_name: 'OVN_CTL_OPTS' diff --git a/data/RedHat-family.yaml b/data/RedHat-family.yaml new file mode 100644 index 0000000..9aa16c4 --- /dev/null +++ b/data/RedHat-family.yaml @@ -0,0 +1,9 @@ +--- +ovn::controller::package_name: 'openvswitch-ovn-host' +ovn::controller::service_name: 'ovn-controller' +ovn::controller::config_file_path: '/etc/sysconfig/ovn-controller' +ovn::controller::config_option_name: 'OVN_CONTROLLER_OPTS' +ovn::northd::package_name: 'openvswitch-ovn-central' +ovn::northd::service_name: 'ovn-northd' +ovn::northd::config_file_path: '/etc/sysconfig/ovn-northd' +ovn::northd::config_option_name: 'OVN_NORTHD_OPTS' diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 0000000..9196220 --- /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/controller.pp b/manifests/controller.pp index ead852b..c31bb85 100644 --- a/manifests/controller.pp +++ b/manifests/controller.pp @@ -5,6 +5,19 @@ # # === Parameters: # +# [*package_name*] +# (required) Name of ovn-controller package. +# +# [*service_name*] +# (required) Name of ovn-controller service. +# +# [*config_file_path*] +# (required) File path of the ovn-controller config file +# +# [*config_option_name*] +# (required) Name of the environment variable to customize options to launch +# the ovn-controller service. +# # [*ovn_remote*] # (Required) URL of the remote ovn southbound db. # Example: 'tcp:127.0.0.1:6642' @@ -127,6 +140,10 @@ # Defaults to [] # class ovn::controller( + String[1] $service_name, + String[1] $package_name, + Stdlib::Absolutepath $config_file_path, + String[1] $config_option_name, String $ovn_remote, String $ovn_encap_ip, String $package_ensure = 'present', @@ -154,8 +171,6 @@ class ovn::controller( Array[String[1]] $ovn_controller_extra_opts = [], ) { - include ovn::params - if $enable_dpdk and ! $datapath_type { fail('Datapath type must be set when DPDK is enabled') } @@ -170,15 +185,17 @@ class ovn::controller( service { 'controller': ensure => true, - name => $::ovn::params::ovn_controller_service_name, + name => $service_name, enable => true, - subscribe => Vs_config['external_ids:ovn-remote'] + subscribe => Vs_config['external_ids:ovn-remote'], + tag => 'ovn', } - package { $::ovn::params::ovn_controller_package_name: + package { 'ovn-controller': ensure => $package_ensure, notify => Service['controller'], - name => $::ovn::params::ovn_controller_package_name, + name => $package_name, + tag => 'ovn', } if $ovn_controller_ssl_key and $ovn_controller_ssl_cert and $ovn_controller_ssl_ca_cert { @@ -196,9 +213,9 @@ class ovn::controller( $ovn_controller_opts = join($ovn_controller_ssl_opts + $ovn_controller_extra_opts, ' ') augeas { 'config-ovn-controller': - context => $::ovn::params::ovn_controller_context, - changes => "set ${$::ovn::params::ovn_controller_option_name} '\"${ovn_controller_opts}\"'", - require => Package[$::ovn::params::ovn_controller_package_name], + context => "/files${config_file_path}", + changes => "set ${config_option_name} '\"${ovn_controller_opts}\"'", + require => Package['ovn-controller'], notify => Service['controller'], } diff --git a/manifests/northd.pp b/manifests/northd.pp index 4d81f94..a7c6a04 100644 --- a/manifests/northd.pp +++ b/manifests/northd.pp @@ -3,8 +3,21 @@ # # installs ovn package starts the ovn-northd service # +# [*package_name*] +# (required) Name of ovn-northd package. +# +# [*service_name*] +# (required) Name of ovn-northd service. +# +# [*config_file_path*] +# (required) File path of the ovn-controller config file +# +# [*config_option_name*] +# (required) Name of the environment variable to customize options to launch +# the ovn-controller service. +# # [*package_ensure*] -# (Optional) State of the openvswitch package +# (Optional) State of the ovn-northd package # Defaults to 'present'. # # [*dbs_listen_ip*] @@ -68,6 +81,10 @@ # Defaults to [] # class ovn::northd( + String[1] $package_name, + String[1] $service_name, + Stdlib::Absolutepath $config_file_path, + String[1] $config_option_name, String $package_ensure = 'present', String $dbs_listen_ip = '0.0.0.0', Optional[String] $dbs_cluster_local_addr = undef, @@ -85,7 +102,6 @@ class ovn::northd( Optional[Stdlib::Absolutepath] $ovn_sb_db_ssl_ca_cert = undef, Array[String] $ovn_northd_extra_opts = [], ) { - include ovn::params include vswitch::ovs $dbs_listen_ip_real = normalize_ip_for_uri($dbs_listen_ip) @@ -212,24 +228,26 @@ class ovn::northd( ' ') augeas { 'config-ovn-northd': - context => $::ovn::params::ovn_northd_context, - changes => "set ${$::ovn::params::ovn_northd_option_name} '\"${ovn_northd_opts}\"'", - require => Package[$::ovn::params::ovn_northd_package_name], + context => "/files${config_file_path}", + changes => "set ${config_option_name} '\"${ovn_northd_opts}\"'", + require => Package['ovn-northd'], before => Service['northd'], } service { 'northd': ensure => true, enable => true, - name => $::ovn::params::ovn_northd_service_name, - require => Service['openvswitch'] + name => $service_name, + require => Service['openvswitch'], + tag => 'ovn', } - package { $::ovn::params::ovn_northd_package_name: + package { 'ovn-northd': ensure => $package_ensure, - name => $::ovn::params::ovn_northd_package_name, + name => $package_name, notify => Service['northd'], - require => Package[$::vswitch::params::ovs_package_name] + require => Package['openvswitch'], + tag => 'ovn', } # NOTE(tkajinam): We have to escapte [ and ] otherwise egrep intereprets diff --git a/manifests/params.pp b/manifests/params.pp deleted file mode 100644 index 8338043..0000000 --- a/manifests/params.pp +++ /dev/null @@ -1,33 +0,0 @@ -# ovn params -# == Class: ovn::params -# -# This class defines the variable like -# -class ovn::params { - include openstacklib::defaults - case $facts['os']['family'] { - 'RedHat': { - $ovn_northd_package_name = 'openvswitch-ovn-central' - $ovn_controller_package_name = 'openvswitch-ovn-host' - $ovn_northd_service_name = 'ovn-northd' - $ovn_northd_context = '/files/etc/sysconfig/ovn-northd' - $ovn_northd_option_name = 'OVN_NORTHD_OPTS' - $ovn_controller_service_name = 'ovn-controller' - $ovn_controller_context = '/files/etc/sysconfig/ovn-controller' - $ovn_controller_option_name = 'OVN_CONTROLLER_OPTS' - } - 'Debian': { - $ovn_northd_package_name = 'ovn-central' - $ovn_controller_package_name = 'ovn-host' - $ovn_northd_service_name = 'ovn-central' - $ovn_northd_context = '/files/etc/default/ovn-central' - $ovn_northd_option_name = 'OVN_CTL_OPTS' - $ovn_controller_service_name = 'ovn-host' - $ovn_controller_context = '/files/etc/default/ovn-host' - $ovn_controller_option_name = 'OVN_CTL_OPTS' - } - default: { - fail " Osfamily ${facts['os']['family']} not supported yet" - } - } -} diff --git a/spec/classes/ovn_controller_spec.rb b/spec/classes/ovn_controller_spec.rb index 71c5652..c80d471 100644 --- a/spec/classes/ovn_controller_spec.rb +++ b/spec/classes/ovn_controller_spec.rb @@ -10,10 +10,6 @@ describe 'ovn::controller' do end shared_examples_for 'ovn controller' do - it 'includes params' do - is_expected.to contain_class('ovn::params') - end - it 'includes controller' do is_expected.to contain_class('ovn::controller') end @@ -27,7 +23,7 @@ describe 'ovn::controller' do end it 'installs controller package' do - is_expected.to contain_package(platform_params[:ovn_controller_package_name]).with( + is_expected.to contain_package('ovn-controller').with( :ensure => 'present', :name => platform_params[:ovn_controller_package_name], :notify => 'Service[controller]' diff --git a/spec/classes/ovn_northd_spec.rb b/spec/classes/ovn_northd_spec.rb index 8b07722..16ecc8d 100644 --- a/spec/classes/ovn_northd_spec.rb +++ b/spec/classes/ovn_northd_spec.rb @@ -224,10 +224,6 @@ describe 'ovn::northd' do end shared_examples_for 'ovn northd' do - it 'includes params' do - is_expected.to contain_class('ovn::params') - end - it 'starts northd' do is_expected.to contain_service('northd').with( :ensure => true, @@ -237,7 +233,7 @@ describe 'ovn::northd' do end it 'installs package' do - is_expected.to contain_package(platform_params[:ovn_northd_package_name]).with( + is_expected.to contain_package('ovn-northd').with( :ensure => 'present', :name => platform_params[:ovn_northd_package_name], :notify => 'Service[northd]'