Refactor db class using oslo::db
This replaces the existing logic in the gnocchi::db class by the common logic in oslo::db, to use the single logic to manage backend packages. Depends-on: https://review.opendev.org/889374 Change-Id: Icd916df0b3463128df5b2ed3b49c2cdbee871504
This commit is contained in:
parent
120450bec8
commit
de085305c4
@ -19,39 +19,13 @@ class gnocchi::db (
|
||||
|
||||
include gnocchi::deps
|
||||
|
||||
if $database_connection {
|
||||
case $database_connection {
|
||||
/^mysql(\+pymysql)?:\/\//: {
|
||||
require mysql::bindings
|
||||
require mysql::bindings::python
|
||||
if $database_connection =~ /^mysql\+pymysql/ {
|
||||
$backend_package = $::gnocchi::params::pymysql_package_name
|
||||
} else {
|
||||
$backend_package = false
|
||||
}
|
||||
}
|
||||
/^postgresql:\/\//: {
|
||||
$backend_package = false
|
||||
require postgresql::lib::python
|
||||
}
|
||||
/^sqlite:\/\//: {
|
||||
$backend_package = $::gnocchi::params::sqlite_package_name
|
||||
}
|
||||
default: {
|
||||
fail('Unsupported backend configured')
|
||||
}
|
||||
}
|
||||
oslo::db { 'gnocchi_config':
|
||||
connection => $database_connection,
|
||||
backend_package_ensure => $package_ensure,
|
||||
manage_config => false,
|
||||
}
|
||||
|
||||
if $backend_package and !defined(Package[$backend_package]) {
|
||||
package {'gnocchi-backend-package':
|
||||
ensure => present,
|
||||
name => $backend_package,
|
||||
tag => 'openstack',
|
||||
}
|
||||
}
|
||||
|
||||
gnocchi_config {
|
||||
'indexer/url': value => $database_connection, secret => true;
|
||||
}
|
||||
gnocchi_config {
|
||||
'indexer/url': value => $database_connection, secret => true;
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,10 @@ class gnocchi::deps {
|
||||
# installed before service startup
|
||||
Oslo::Coordination<||> -> Anchor['gnocchi::service::begin']
|
||||
|
||||
# all db settings should be applied and all packages should be installed
|
||||
# before dbsync starts
|
||||
Oslo::Db<||> -> Anchor['gnocchi::dbsync::begin']
|
||||
|
||||
# policy config should occur in the config block also.
|
||||
Anchor['gnocchi::config::begin']
|
||||
-> Openstacklib::Policy<| tag == 'gnocchi' |>
|
||||
|
@ -21,14 +21,10 @@ class gnocchi::params {
|
||||
|
||||
case $facts['os']['family'] {
|
||||
'RedHat': {
|
||||
$sqlite_package_name = undef
|
||||
$gnocchi_wsgi_script_path = '/var/www/cgi-bin/gnocchi'
|
||||
$pymysql_package_name = undef
|
||||
$gnocchi_wsgi_script_path = '/var/www/cgi-bin/gnocchi'
|
||||
}
|
||||
'Debian': {
|
||||
$sqlite_package_name = 'python-pysqlite2'
|
||||
$gnocchi_wsgi_script_path = '/usr/lib/cgi-bin/gnocchi'
|
||||
$pymysql_package_name = 'python3-pymysql'
|
||||
$gnocchi_wsgi_script_path = '/usr/lib/cgi-bin/gnocchi'
|
||||
}
|
||||
default: {
|
||||
fail("Unsupported osfamily: ${facts['os']['family']}")
|
||||
|
@ -3,6 +3,12 @@ require 'spec_helper'
|
||||
describe 'gnocchi::db' do
|
||||
shared_examples 'gnocchi::db' do
|
||||
context 'with default parameters' do
|
||||
it { should contain_class('gnocchi::deps') }
|
||||
|
||||
it { should contain_oslo__db('gnocchi_config').with(
|
||||
:connection => 'sqlite:////var/lib/gnocchi/gnocchi.sqlite',
|
||||
:manage_config => false,
|
||||
)}
|
||||
it { should contain_gnocchi_config('indexer/url').with(
|
||||
:value => 'sqlite:////var/lib/gnocchi/gnocchi.sqlite',
|
||||
:secret => true,
|
||||
@ -16,78 +22,17 @@ describe 'gnocchi::db' do
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_class('gnocchi::deps') }
|
||||
|
||||
it { should contain_oslo__db('gnocchi_config').with(
|
||||
:connection => 'mysql+pymysql://gnocchi:gnocchi@localhost/gnocchi',
|
||||
:manage_config => false,
|
||||
)}
|
||||
it { should contain_gnocchi_config('indexer/url').with(
|
||||
:value => 'mysql+pymysql://gnocchi:gnocchi@localhost/gnocchi',
|
||||
:secret => true,
|
||||
)}
|
||||
end
|
||||
|
||||
context 'with postgresql backend' do
|
||||
let :params do
|
||||
{ :database_connection => 'postgresql://gnocchi:gnocchi@localhost/gnocchi', }
|
||||
end
|
||||
|
||||
it { should contain_class('postgresql::lib::python') }
|
||||
end
|
||||
|
||||
context 'with MySQL-python library as backend package' do
|
||||
let :params do
|
||||
{
|
||||
:database_connection => 'mysql://gnocchi:gnocchi@localhost/gnocchi',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_class('mysql::bindings') }
|
||||
it { should contain_class('mysql::bindings::python') }
|
||||
end
|
||||
|
||||
context 'with incorrect database_connection string' do
|
||||
let :params do
|
||||
{
|
||||
:database_connection => 'redis://gnocchi:gnocchi@localhost/gnocchi',
|
||||
}
|
||||
end
|
||||
|
||||
it { should raise_error(Puppet::Error) }
|
||||
end
|
||||
|
||||
context 'with incorrect pymysql database_connection string' do
|
||||
let :params do
|
||||
{
|
||||
:database_connection => 'foo+pymysql://gnocchi:gnocchi@localhost/gnocchi',
|
||||
}
|
||||
end
|
||||
|
||||
it { should raise_error(Puppet::Error) }
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'gnocchi::db on Debian' do
|
||||
context 'using pymysql driver' do
|
||||
let :params do
|
||||
{
|
||||
:database_connection => 'mysql+pymysql://gnocchi:gnocchi@localhost/gnocchi',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_package('gnocchi-backend-package').with(
|
||||
:ensure => 'present',
|
||||
:name => platform_params[:pymysql_package_name],
|
||||
:tag => 'openstack'
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'gnocchi::db on RedHat' do
|
||||
context 'using pymysql driver' do
|
||||
let :params do
|
||||
{
|
||||
:database_connection => 'mysql+pymysql://gnocchi:gnocchi@localhost/gnocchi',
|
||||
}
|
||||
end
|
||||
|
||||
it { should_not contain_package('gnocchi-backend-package') }
|
||||
end
|
||||
end
|
||||
|
||||
on_supported_os({
|
||||
@ -95,24 +40,10 @@ describe 'gnocchi::db' do
|
||||
}).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
let (:facts) do
|
||||
facts.merge!(OSDefaults.get_facts({
|
||||
# puppet-postgresql requires the service_provider fact provided by
|
||||
# puppetlabs-postgresql.
|
||||
:service_provider => 'systemd'
|
||||
}))
|
||||
end
|
||||
|
||||
let(:platform_params) do
|
||||
case facts[:os]['family']
|
||||
when 'Debian'
|
||||
{
|
||||
:pymysql_package_name => 'python3-pymysql',
|
||||
}
|
||||
end
|
||||
facts.merge!(OSDefaults.get_facts())
|
||||
end
|
||||
|
||||
it_behaves_like 'gnocchi::db'
|
||||
it_behaves_like "gnocchi::db on #{facts[:os]['family']}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user