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:
@@ -19,39 +19,13 @@ class gnocchi::db (
|
|||||||
|
|
||||||
include gnocchi::deps
|
include gnocchi::deps
|
||||||
|
|
||||||
if $database_connection {
|
oslo::db { 'gnocchi_config':
|
||||||
case $database_connection {
|
connection => $database_connection,
|
||||||
/^mysql(\+pymysql)?:\/\//: {
|
backend_package_ensure => $package_ensure,
|
||||||
require mysql::bindings
|
manage_config => false,
|
||||||
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')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if $backend_package and !defined(Package[$backend_package]) {
|
gnocchi_config {
|
||||||
package {'gnocchi-backend-package':
|
'indexer/url': value => $database_connection, secret => true;
|
||||||
ensure => present,
|
|
||||||
name => $backend_package,
|
|
||||||
tag => 'openstack',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gnocchi_config {
|
|
||||||
'indexer/url': value => $database_connection, secret => true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,10 @@ class gnocchi::deps {
|
|||||||
# installed before service startup
|
# installed before service startup
|
||||||
Oslo::Coordination<||> -> Anchor['gnocchi::service::begin']
|
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.
|
# policy config should occur in the config block also.
|
||||||
Anchor['gnocchi::config::begin']
|
Anchor['gnocchi::config::begin']
|
||||||
-> Openstacklib::Policy<| tag == 'gnocchi' |>
|
-> Openstacklib::Policy<| tag == 'gnocchi' |>
|
||||||
|
@@ -21,14 +21,10 @@ class gnocchi::params {
|
|||||||
|
|
||||||
case $facts['os']['family'] {
|
case $facts['os']['family'] {
|
||||||
'RedHat': {
|
'RedHat': {
|
||||||
$sqlite_package_name = undef
|
$gnocchi_wsgi_script_path = '/var/www/cgi-bin/gnocchi'
|
||||||
$gnocchi_wsgi_script_path = '/var/www/cgi-bin/gnocchi'
|
|
||||||
$pymysql_package_name = undef
|
|
||||||
}
|
}
|
||||||
'Debian': {
|
'Debian': {
|
||||||
$sqlite_package_name = 'python-pysqlite2'
|
$gnocchi_wsgi_script_path = '/usr/lib/cgi-bin/gnocchi'
|
||||||
$gnocchi_wsgi_script_path = '/usr/lib/cgi-bin/gnocchi'
|
|
||||||
$pymysql_package_name = 'python3-pymysql'
|
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
fail("Unsupported osfamily: ${facts['os']['family']}")
|
fail("Unsupported osfamily: ${facts['os']['family']}")
|
||||||
|
@@ -3,6 +3,12 @@ require 'spec_helper'
|
|||||||
describe 'gnocchi::db' do
|
describe 'gnocchi::db' do
|
||||||
shared_examples 'gnocchi::db' do
|
shared_examples 'gnocchi::db' do
|
||||||
context 'with default parameters' 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(
|
it { should contain_gnocchi_config('indexer/url').with(
|
||||||
:value => 'sqlite:////var/lib/gnocchi/gnocchi.sqlite',
|
:value => 'sqlite:////var/lib/gnocchi/gnocchi.sqlite',
|
||||||
:secret => true,
|
:secret => true,
|
||||||
@@ -16,78 +22,17 @@ describe 'gnocchi::db' do
|
|||||||
}
|
}
|
||||||
end
|
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(
|
it { should contain_gnocchi_config('indexer/url').with(
|
||||||
:value => 'mysql+pymysql://gnocchi:gnocchi@localhost/gnocchi',
|
:value => 'mysql+pymysql://gnocchi:gnocchi@localhost/gnocchi',
|
||||||
:secret => true,
|
:secret => true,
|
||||||
)}
|
)}
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
on_supported_os({
|
on_supported_os({
|
||||||
@@ -95,24 +40,10 @@ describe 'gnocchi::db' do
|
|||||||
}).each do |os,facts|
|
}).each do |os,facts|
|
||||||
context "on #{os}" do
|
context "on #{os}" do
|
||||||
let (:facts) do
|
let (:facts) do
|
||||||
facts.merge!(OSDefaults.get_facts({
|
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'gnocchi::db'
|
it_behaves_like 'gnocchi::db'
|
||||||
it_behaves_like "gnocchi::db on #{facts[:os]['family']}"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user