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
This commit is contained in:
Mathieu Gagné 2017-09-05 13:51:00 -04:00
parent 6ff575f6c0
commit 5911b080b3
4 changed files with 123 additions and 37 deletions

View File

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

View File

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

View File

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

View File

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