From 0cc6468f2be5b24cee5c8e08416a9070ac608154 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 8 Apr 2024 15:53:11 +0900 Subject: [PATCH] Ensure python-redis is install The python-redis package is an optional dependency and needs to be installed explicitly in Ubuntu or Debian. (The zaqar package in RDO has additonal dependency to require python-redis now). Change-Id: I5c768a4ed60909f2e764ed6a39c372814b50c58b --- manifests/management/redis.pp | 36 +++++++++++++++---- manifests/messaging/redis.pp | 33 +++++++++++++---- manifests/params.pp | 18 +++++----- .../notes/redis-package-4b3062bc2a6253ee.yaml | 8 +++++ spec/classes/zaqar_management_redis_spec.rb | 18 ++++++++++ spec/classes/zaqar_messaging_redis_spec.rb | 25 ++++++++++--- 6 files changed, 112 insertions(+), 26 deletions(-) create mode 100644 releasenotes/notes/redis-package-4b3062bc2a6253ee.yaml diff --git a/manifests/management/redis.pp b/manifests/management/redis.pp index 99562e1..f7b9475 100644 --- a/manifests/management/redis.pp +++ b/manifests/management/redis.pp @@ -1,25 +1,36 @@ # == class: zaqar::management::redis # # [*uri*] -# Redis connection URI. Required. +# (Required) Redis Connection URI. # # [*max_reconnect_attempts*] -# Maximum number of times to retry an operation that failed due to a redis -# node failover. -# Defaults to $facts['os_service_default'] +# (Optional) Maximum number of times to retry an operation that failed due to +# a primary node failover. +# Defaults to $facts['os_service_default']. # # [*reconnect_sleep*] -# Base sleep interval between attempts to reconnect after a redis node -# failover. -# Defaults to $facts['os_service_default'] +# (Optional) Base sleep interval between attempts to reconnect after +# a primary node failover. +# Defaults to $facts['os_service_default']. +# +# [*package_ensure*] +# (Optional) Ensure state for package. +# Defaults to 'present' +# +# [*manage_package*] +# (Optional) Manage pyhton-redis package. +# Defaults to true # class zaqar::management::redis( $uri, $max_reconnect_attempts = $facts['os_service_default'], $reconnect_sleep = $facts['os_service_default'], + $package_ensure = 'present', + Boolean $manage_package = true, ) { include zaqar::deps + include zaqar::params zaqar_config { 'drivers:management_store:redis/uri': value => $uri, secret => true; @@ -27,4 +38,15 @@ class zaqar::management::redis( 'drivers:management_store:redis/reconnect_sleep': value => $reconnect_sleep; } + if $manage_package { + ensure_packages('python-redis', { + name => $::zaqar::params::python_redis_package_name, + ensure => $package_ensure, + tag => ['openstack'], + }) + + Anchor['zaqar::install::begin'] + -> Package<| name == $::oslo::params::python_redis_package_name |> + -> Anchor['zaqar::install::end'] + } } diff --git a/manifests/messaging/redis.pp b/manifests/messaging/redis.pp index 1bd1f61..ffe4507 100644 --- a/manifests/messaging/redis.pp +++ b/manifests/messaging/redis.pp @@ -1,26 +1,36 @@ # == class: zaqar::messaging::redis # # [*uri*] -# Redis Connection URI. Required. +# (Required) Redis Connection URI. # # [*max_reconnect_attempts*] -# Maximum number of times to retry an operation that failed due to a -# primary node failover. (integer value) +# (Optional) Maximum number of times to retry an operation that failed due to +# a primary node failover. # Defaults to $facts['os_service_default']. # # [*reconnect_sleep*] -# Base sleep interval between attempts to reconnect after a primary -# node failover. The actual sleep time increases exponentially (power -# of 2) each time the operation is retried. (floating point value) +# (Optional) Base sleep interval between attempts to reconnect after +# a primary node failover. # Defaults to $facts['os_service_default']. # +# [*package_ensure*] +# (Optional) Ensure state for package. +# Defaults to 'present' +# +# [*manage_package*] +# (Optional) Manage pyhton-redis package. +# Defaults to true +# class zaqar::messaging::redis( $uri, $max_reconnect_attempts = $facts['os_service_default'], $reconnect_sleep = $facts['os_service_default'], + $package_ensure = 'present', + Boolean $manage_package = true, ) { include zaqar::deps + include zaqar::params zaqar_config { 'drivers:message_store:redis/uri': value => $uri, secret => true; @@ -28,4 +38,15 @@ class zaqar::messaging::redis( 'drivers:message_store:redis/reconnect_sleep': value => $reconnect_sleep; } + if $manage_package { + ensure_packages('python-redis', { + name => $::zaqar::params::python_redis_package_name, + ensure => $package_ensure, + tag => ['openstack'], + }) + + Anchor['zaqar::install::begin'] + -> Package<| name == $::oslo::params::python_redis_package_name |> + -> Anchor['zaqar::install::end'] + } } diff --git a/manifests/params.pp b/manifests/params.pp index 492d029..cc7a12b 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -13,16 +13,18 @@ class zaqar::params { case $facts['os']['family'] { 'RedHat': { - $package_name = 'openstack-zaqar' - $service_name = 'openstack-zaqar' - $zaqar_wsgi_script_source = "/usr/lib/python${pyver3}/site-packages/zaqar/transport/wsgi/app.py" - $zaqar_wsgi_script_path = '/var/www/cgi-bin/zaqar' + $package_name = 'openstack-zaqar' + $service_name = 'openstack-zaqar' + $zaqar_wsgi_script_source = "/usr/lib/python${pyver3}/site-packages/zaqar/transport/wsgi/app.py" + $zaqar_wsgi_script_path = '/var/www/cgi-bin/zaqar' + $python_redis_package_name = 'python3-redis' } 'Debian': { - $package_name = 'zaqar-server' - $service_name = 'zaqar-server' - $zaqar_wsgi_script_source = '/usr/lib/python3/dist-packages/zaqar/transport/wsgi/app.py' - $zaqar_wsgi_script_path = '/usr/lib/cgi-bin/zaqar' + $package_name = 'zaqar-server' + $service_name = 'zaqar-server' + $zaqar_wsgi_script_source = '/usr/lib/python3/dist-packages/zaqar/transport/wsgi/app.py' + $zaqar_wsgi_script_path = '/usr/lib/cgi-bin/zaqar' + $python_redis_package_name = 'python3-redis' } default: { fail("Unsupported osfamily: ${facts['os']['family']}") diff --git a/releasenotes/notes/redis-package-4b3062bc2a6253ee.yaml b/releasenotes/notes/redis-package-4b3062bc2a6253ee.yaml new file mode 100644 index 0000000..10e0dd1 --- /dev/null +++ b/releasenotes/notes/redis-package-4b3062bc2a6253ee.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + The ``zaqar::messaging::redis`` class and the ``zaqar::management::redis`` + class now ensures that the python3-redis package is installed. + The new ``package_ensure`` parameter can be used to customize state of + the package. To disable the package management, use the ``manage_package`` + parameter. diff --git a/spec/classes/zaqar_management_redis_spec.rb b/spec/classes/zaqar_management_redis_spec.rb index c21fcf6..bcd17e9 100644 --- a/spec/classes/zaqar_management_redis_spec.rb +++ b/spec/classes/zaqar_management_redis_spec.rb @@ -31,6 +31,11 @@ describe 'zaqar::management::redis' do is_expected.to contain_zaqar_config('drivers:management_store:redis/uri').with_value('redis://127.0.0.1:6379') is_expected.to contain_zaqar_config('drivers:management_store:redis/max_reconnect_attempts').with_value('') is_expected.to contain_zaqar_config('drivers:management_store:redis/reconnect_sleep').with_value('') + is_expected.to contain_package('python-redis').with( + :ensure => 'installed', + :name => platform_params[:python_redis_package_name], + :tag => ['openstack'], + ) end end @@ -58,6 +63,19 @@ describe 'zaqar::management::redis' do facts.merge!(OSDefaults.get_facts()) end + let(:platform_params) do + case facts[:os]['family'] + when 'Debian' + { + :python_redis_package_name => 'python3-redis', + } + when 'RedHat' + { + :python_redis_package_name => 'python3-redis', + } + end + end + it_configures 'zaqar::management::redis' end end diff --git a/spec/classes/zaqar_messaging_redis_spec.rb b/spec/classes/zaqar_messaging_redis_spec.rb index d083525..6bf5e0a 100644 --- a/spec/classes/zaqar_messaging_redis_spec.rb +++ b/spec/classes/zaqar_messaging_redis_spec.rb @@ -27,11 +27,13 @@ describe 'zaqar::messaging::redis' do end it 'should config redis messaging driver' do - is_expected.to contain_zaqar_config('drivers/message_store').with( - :value => 'redis' - ) - is_expected.to contain_zaqar_config('drivers:message_store:redis/uri').with( - :value => 'redis://127.0.0.1:6379' + is_expected.to contain_zaqar_config('drivers/message_store').with_value('redis') + is_expected.to contain_zaqar_config('drivers:message_store:redis/uri').with_value('redis://127.0.0.1:6379') + is_expected.to contain_zaqar_config('drivers:message_store:redis/reconnect_sleep').with_value('') + is_expected.to contain_package('python-redis').with( + :ensure => 'installed', + :name => platform_params[:python_redis_package_name], + :tag => ['openstack'], ) end @@ -60,6 +62,19 @@ describe 'zaqar::messaging::redis' do facts.merge!(OSDefaults.get_facts()) end + let(:platform_params) do + case facts[:os]['family'] + when 'Debian' + { + :python_redis_package_name => 'python3-redis', + } + when 'RedHat' + { + :python_redis_package_name => 'python3-redis', + } + end + end + it_configures 'zaqar::messaging::redis' end end