puppet-gnocchi/spec/classes/gnocchi_db_spec.rb
Takashi Kajinami 74e7afdb9e replace validate_legacy with proper data types
the validate_legacy function is marked for deprecation in
v9.0.0 from puppetlabs-stdlib.

Change-Id: I14ad3f5a77573b1bf82b490249ca5a8a6b220565
2023-06-19 18:08:52 +09:00

127 lines
3.3 KiB
Ruby

require 'spec_helper'
describe 'gnocchi::db' do
shared_examples 'gnocchi::db' do
context 'with default parameters' do
it { should contain_gnocchi_config('indexer/url').with(
:value => 'sqlite:////var/lib/gnocchi/gnocchi.sqlite',
:secret => true,
)}
end
context 'with specific parameters' do
let :params do
{
:database_connection => 'mysql+pymysql://gnocchi:gnocchi@localhost/gnocchi'
}
end
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 sqlite' do
it { should contain_package('gnocchi-indexer-sqlalchemy').with(
:name => 'openstack-gnocchi-indexer-sqlalchemy',
:ensure => 'present',
:tag => ['openstack', 'gnocchi-package']
)}
end
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({
:supported_os => OSDefaults.get_supported_os
}).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
end
it_behaves_like 'gnocchi::db'
it_behaves_like "gnocchi::db on #{facts[:os]['family']}"
end
end
end