Browse Source

Add ability to disable backend packages management

There are use cases where an user wants to not have backend packages
automatically installed. One use case would be the user having an alternative
set of packages already providing backend packages as built-in dependencies.
Installing system packages is redundant, useless and causing confusion.

This change adds the ability to disable backend packages management
while preserving previous behavior which consists of installing them
automatically.

Closes-bug: #1715204
Change-Id: Ief676d4c5aaa81f4547dd2e090dfcc8c62855148
changes/45/500945/3
Mathieu Gagné 5 years ago
parent
commit
5911b080b3
  1. 29
      manifests/cache.pp
  2. 59
      manifests/db.pp
  3. 24
      spec/defines/oslo_cache_spec.rb
  4. 48
      spec/defines/oslo_db_spec.rb

29
manifests/cache.pp

@ -113,6 +113,10 @@
# client connection. (integer value)
# Defaults to $::os_service_default
#
# [*manage_backend_package*]
# (Optional) Whether to install the backend package.
# Defaults to true.
#
define oslo::cache(
$config_prefix = $::os_service_default,
$expiration_time = $::os_service_default,
@ -127,6 +131,7 @@ define oslo::cache(
$memcache_pool_maxsize = $::os_service_default,
$memcache_pool_unused_timeout = $::os_service_default,
$memcache_pool_connection_get_timeout = $::os_service_default,
$manage_backend_package = true,
){
include ::oslo::params
@ -149,17 +154,19 @@ define oslo::cache(
$proxies_orig = $proxies
}
if ($backend =~ /pylibmc/ ) {
ensure_packages('python-pylibmc', {
ensure => present,
name => $::oslo::params::pylibmc_package_name,
tag => 'openstack',
})
} elsif ($backend =~ /\.memcache/ ) {
ensure_resources('package', { 'python-memcache' => {
name => $::oslo::params::python_memcache_package_name,
tag => ['openstack'],
}})
if $manage_backend_package {
if ($backend =~ /pylibmc/ ) {
ensure_packages('python-pylibmc', {
ensure => present,
name => $::oslo::params::pylibmc_package_name,
tag => 'openstack',
})
} elsif ($backend =~ /\.memcache/ ) {
ensure_resources('package', { 'python-memcache' => {
name => $::oslo::params::python_memcache_package_name,
tag => ['openstack'],
}})
}
}
$cache_options = {

59
manifests/db.pp

@ -15,6 +15,10 @@
# (Optional) The back end to use for the database.
# Defaults to $::os_service_default
#
# [*manage_backend_package*]
# (Optional) Whether to install the backend package.
# Defaults to true.
#
# [*backend_package_ensure*]
# (Optional) Desired ensure state of the backend database package,
# accepts latest or specific versions.
@ -105,6 +109,7 @@
define oslo::db(
$sqlite_synchronous = $::os_service_default,
$backend = $::os_service_default,
$manage_backend_package = true,
$backend_package_ensure = present,
$connection = $::os_service_default,
$slave_connection = $::os_service_default,
@ -135,36 +140,38 @@ define oslo::db(
validate_re($connection,
'^(sqlite|mysql(\+pymysql)?|postgresql|mongodb):\/\/(\S+:\S+@\S+\/\S+)?')
case $connection {
/^mysql(\+pymysql)?:\/\//: {
require '::mysql::bindings'
require '::mysql::bindings::python'
if $connection =~ /^mysql\+pymysql/ {
$backend_package = $::oslo::params::pymysql_package_name
} else {
if $manage_backend_package {
case $connection {
/^mysql(\+pymysql)?:\/\//: {
require '::mysql::bindings'
require '::mysql::bindings::python'
if $connection =~ /^mysql\+pymysql/ {
$backend_package = $::oslo::params::pymysql_package_name
} else {
$backend_package = false
}
}
/^postgresql:\/\//: {
$backend_package = false
require '::postgresql::lib::python'
}
/^mongodb:\/\//: {
$backend_package = $::oslo::params::pymongo_package_name
}
/^sqlite:\/\//: {
$backend_package = $::oslo::params::sqlite_package_name
}
default: {
fail('Unsupported backend configured')
}
}
/^postgresql:\/\//: {
$backend_package = false
require '::postgresql::lib::python'
}
/^mongodb:\/\//: {
$backend_package = $::oslo::params::pymongo_package_name
}
/^sqlite:\/\//: {
$backend_package = $::oslo::params::sqlite_package_name
}
default: {
fail('Unsupported backend configured')
}
}
if $backend_package and !defined(Package[$backend_package]) {
package { $backend_package:
ensure => $backend_package_ensure,
name => $backend_package,
tag => 'openstack',
if $backend_package and !defined(Package[$backend_package]) {
package { $backend_package:
ensure => $backend_package_ensure,
name => $backend_package,
tag => 'openstack',
}
}
}
}

24
spec/defines/oslo_cache_spec.rb

@ -75,6 +75,18 @@ describe 'oslo::cache' do
:tag => 'openstack',
)
end
context 'with backend package management disabled' do
before do
params.merge!({
:manage_backend_package => false,
})
end
it 'does not install backend package' do
is_expected.not_to contain_package('python-pylibmc')
end
end
end
context 'with memcache backend' do
@ -91,6 +103,18 @@ describe 'oslo::cache' do
:tag => ['openstack'],
)
end
context 'with backend package management disabled' do
before do
params.merge!({
:manage_backend_package => false,
})
end
it 'does not install backend package' do
is_expected.not_to contain_package('python-memcache')
end
end
end
context 'with string in list parameters' do

48
spec/defines/oslo_db_spec.rb

@ -89,6 +89,18 @@ describe 'oslo::db' do
:tag => 'openstack'
)
end
context 'with backend package management disabled' do
before do
params.merge!({
:manage_backend_package => false,
})
end
it 'does not install backend package' do
is_expected.not_to contain_package('python-pymongo')
end
end
end
context 'with specific mongodb connection string' do
@ -117,6 +129,18 @@ describe 'oslo::db' do
it 'install the proper backend package' do
is_expected.to contain_package('python-psycopg2').with(:ensure => 'present')
end
context 'with backend package management disabled' do
before do
params.merge!({
:manage_backend_package => false,
})
end
it 'does not install backend package' do
is_expected.not_to contain_package('python-psycopg2')
end
end
end
context 'with incorrect database_connection string' do
@ -149,6 +173,18 @@ describe 'oslo::db' do
:tag => 'openstack'
)
end
context 'with backend package management disabled' do
before do
params.merge!({
:manage_backend_package => false,
})
end
it 'does not install backend package' do
is_expected.not_to contain_package('python-pymysql')
end
end
end
context 'with sqlite backend' do
@ -163,6 +199,18 @@ describe 'oslo::db' do
:tag => 'openstack'
)
end
context 'with backend package management disabled' do
before do
params.merge!({
:manage_backend_package => false,
})
end
it 'does not install backend package' do
is_expected.not_to contain_package('python-pysqlite2')
end
end
end
end

Loading…
Cancel
Save