Merge "Ensure python-redis is install"

This commit is contained in:
Zuul 2024-04-11 15:30:23 +00:00 committed by Gerrit Code Review
commit f023fca49e
6 changed files with 112 additions and 26 deletions

View File

@ -1,25 +1,36 @@
# == class: zaqar::management::redis # == class: zaqar::management::redis
# #
# [*uri*] # [*uri*]
# Redis connection URI. Required. # (Required) Redis Connection URI.
# #
# [*max_reconnect_attempts*] # [*max_reconnect_attempts*]
# Maximum number of times to retry an operation that failed due to a redis # (Optional) Maximum number of times to retry an operation that failed due to
# node failover. # a primary node failover.
# Defaults to $facts['os_service_default'] # Defaults to $facts['os_service_default'].
# #
# [*reconnect_sleep*] # [*reconnect_sleep*]
# Base sleep interval between attempts to reconnect after a redis node # (Optional) Base sleep interval between attempts to reconnect after
# failover. # a primary node failover.
# Defaults to $facts['os_service_default'] # 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( class zaqar::management::redis(
$uri, $uri,
$max_reconnect_attempts = $facts['os_service_default'], $max_reconnect_attempts = $facts['os_service_default'],
$reconnect_sleep = $facts['os_service_default'], $reconnect_sleep = $facts['os_service_default'],
$package_ensure = 'present',
Boolean $manage_package = true,
) { ) {
include zaqar::deps include zaqar::deps
include zaqar::params
zaqar_config { zaqar_config {
'drivers:management_store:redis/uri': value => $uri, secret => true; '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; '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']
}
} }

View File

@ -1,26 +1,36 @@
# == class: zaqar::messaging::redis # == class: zaqar::messaging::redis
# #
# [*uri*] # [*uri*]
# Redis Connection URI. Required. # (Required) Redis Connection URI.
# #
# [*max_reconnect_attempts*] # [*max_reconnect_attempts*]
# Maximum number of times to retry an operation that failed due to a # (Optional) Maximum number of times to retry an operation that failed due to
# primary node failover. (integer value) # a primary node failover.
# Defaults to $facts['os_service_default']. # Defaults to $facts['os_service_default'].
# #
# [*reconnect_sleep*] # [*reconnect_sleep*]
# Base sleep interval between attempts to reconnect after a primary # (Optional) Base sleep interval between attempts to reconnect after
# node failover. The actual sleep time increases exponentially (power # a primary node failover.
# of 2) each time the operation is retried. (floating point value)
# Defaults to $facts['os_service_default']. # 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( class zaqar::messaging::redis(
$uri, $uri,
$max_reconnect_attempts = $facts['os_service_default'], $max_reconnect_attempts = $facts['os_service_default'],
$reconnect_sleep = $facts['os_service_default'], $reconnect_sleep = $facts['os_service_default'],
$package_ensure = 'present',
Boolean $manage_package = true,
) { ) {
include zaqar::deps include zaqar::deps
include zaqar::params
zaqar_config { zaqar_config {
'drivers:message_store:redis/uri': value => $uri, secret => true; '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; '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']
}
} }

View File

@ -13,16 +13,18 @@ class zaqar::params {
case $facts['os']['family'] { case $facts['os']['family'] {
'RedHat': { 'RedHat': {
$package_name = 'openstack-zaqar' $package_name = 'openstack-zaqar'
$service_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_source = "/usr/lib/python${pyver3}/site-packages/zaqar/transport/wsgi/app.py"
$zaqar_wsgi_script_path = '/var/www/cgi-bin/zaqar' $zaqar_wsgi_script_path = '/var/www/cgi-bin/zaqar'
$python_redis_package_name = 'python3-redis'
} }
'Debian': { 'Debian': {
$package_name = 'zaqar-server' $package_name = 'zaqar-server'
$service_name = 'zaqar-server' $service_name = 'zaqar-server'
$zaqar_wsgi_script_source = '/usr/lib/python3/dist-packages/zaqar/transport/wsgi/app.py' $zaqar_wsgi_script_source = '/usr/lib/python3/dist-packages/zaqar/transport/wsgi/app.py'
$zaqar_wsgi_script_path = '/usr/lib/cgi-bin/zaqar' $zaqar_wsgi_script_path = '/usr/lib/cgi-bin/zaqar'
$python_redis_package_name = 'python3-redis'
} }
default: { default: {
fail("Unsupported osfamily: ${facts['os']['family']}") fail("Unsupported osfamily: ${facts['os']['family']}")

View File

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

View File

@ -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/uri').with_value('redis://127.0.0.1:6379')
is_expected.to contain_zaqar_config('drivers:management_store:redis/max_reconnect_attempts').with_value('<SERVICE DEFAULT>') is_expected.to contain_zaqar_config('drivers:management_store:redis/max_reconnect_attempts').with_value('<SERVICE DEFAULT>')
is_expected.to contain_zaqar_config('drivers:management_store:redis/reconnect_sleep').with_value('<SERVICE DEFAULT>') is_expected.to contain_zaqar_config('drivers:management_store:redis/reconnect_sleep').with_value('<SERVICE DEFAULT>')
is_expected.to contain_package('python-redis').with(
:ensure => 'installed',
:name => platform_params[:python_redis_package_name],
:tag => ['openstack'],
)
end end
end end
@ -58,6 +63,19 @@ describe 'zaqar::management::redis' do
facts.merge!(OSDefaults.get_facts()) facts.merge!(OSDefaults.get_facts())
end 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' it_configures 'zaqar::management::redis'
end end
end end

View File

@ -27,11 +27,13 @@ describe 'zaqar::messaging::redis' do
end end
it 'should config redis messaging driver' do it 'should config redis messaging driver' do
is_expected.to contain_zaqar_config('drivers/message_store').with( is_expected.to contain_zaqar_config('drivers/message_store').with_value('redis')
: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('<SERVICE DEFAULT>')
is_expected.to contain_zaqar_config('drivers:message_store:redis/uri').with( is_expected.to contain_package('python-redis').with(
:value => 'redis://127.0.0.1:6379' :ensure => 'installed',
:name => platform_params[:python_redis_package_name],
:tag => ['openstack'],
) )
end end
@ -60,6 +62,19 @@ describe 'zaqar::messaging::redis' do
facts.merge!(OSDefaults.get_facts()) facts.merge!(OSDefaults.get_facts())
end 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' it_configures 'zaqar::messaging::redis'
end end
end end