MySQL and PostreSQL class implementation

Change-Id: Ib7decde6d03047d91bc50e9441c741ba132642ae
This commit is contained in:
Alexey Deryugin 2015-08-28 14:40:33 +03:00
parent 0860bc269d
commit b0665e8a42
4 changed files with 252 additions and 0 deletions

58
manifests/db/mysql.pp Normal file
View File

@ -0,0 +1,58 @@
# == Class: murano::db::mysql
#
# The murano::db::mysql class creates a MySQL database for murano.
# It must be used on the MySQL server.
#
# === Parameters
#
# [*password*]
# (Required) Password to connect to the database.
#
# [*dbname*]
# (Optional) Name of the database.
# Defaults to 'murano'.
#
# [*user*]
# (Optional) User to connect to the database.
# Defaults to 'murano'.
#
# [*host*]
# (Optional) The default source host user is allowed to connect from.
# Defaults to '127.0.0.1'
#
# [*allowed_hosts*]
# (Optional) Other hosts the user is allowed to connect from.
# Defaults to 'undef'.
#
# [*charset*]
# (Optional) The database charset.
# Defaults to 'utf8'.
#
# [*collate*]
# (Optional) Charset collate of murano database.
# Defaults to 'utf8_general_ci'.
#
class murano::db::mysql(
$password,
$dbname = 'murano',
$user = 'murano',
$host = '127.0.0.1',
$allowed_hosts = undef,
$charset = 'utf8',
$collate = 'utf8_general_ci',
) {
validate_string($password)
::openstacklib::db::mysql{ 'murano':
user => $user,
password_hash => mysql_password($password),
dbname => $dbname,
host => $host,
charset => $charset,
collate => $collate,
allowed_hosts => $allowed_hosts,
}
::Openstacklib::Db::Mysql['murano'] ~> Exec<| title == 'murano-dbmanage' |>
}

View File

@ -0,0 +1,47 @@
# == Class: murano::db::postgresql
#
# The murano::db::postgresql creates a PostgreSQL database for murano.
# It must be used on the PostgreSQL server.
#
# === Parameters
#
# [*password*]
# (Required) Password to connect to the database.
#
# [*dbname*]
# (Optional) Name of the database.
# Defaults to 'murano'.
#
# [*user*]
# (Optional) User to connect to the database.
# Defaults to 'murano'.
#
# [*encoding*]
# (Optional) The charset to use for the database.
# Default to undef.
#
# [*privileges*]
# (Optional) Privileges given to the database user.
# Default to 'ALL'
#
class murano::db::postgresql(
$password,
$dbname = 'murano',
$user = 'murano',
$encoding = undef,
$privileges = 'ALL',
) {
validate_string($password)
::openstacklib::db::postgresql { 'murano':
password_hash => postgresql_password($user, $password),
dbname => $dbname,
user => $user,
encoding => $encoding,
privileges => $privileges,
}
::Openstacklib::Db::Postgresql['murano'] ~> Exec<| title == 'murano-dbmanage' |>
}

View File

@ -0,0 +1,89 @@
require 'spec_helper'
describe 'murano::db::mysql' do
let :pre_condition do
['include mysql::server']
end
let :params do
{ :dbname => 'murano',
:password => 's3cr3t',
:user => 'murano',
:charset => 'utf8',
:collate => 'utf8_general_ci',
:host => '127.0.0.1',
}
end
shared_examples_for 'murano mysql database' do
context 'when omiting the required parameter password' do
before { params.delete(:password) }
it { expect { is_expected.to raise_error(Puppet::Error) } }
end
it 'creates a mysql database' do
is_expected.to contain_openstacklib__db__mysql('murano').with(
:user => params[:user],
:dbname => params[:dbname],
:password_hash => '*58C036CDA51D8E8BBBBF2F9EA5ABF111ADA444F0',
:host => params[:host],
:charset => params[:charset]
)
end
context 'overriding allowed_hosts param to array' do
before :each do
params.merge!(
:allowed_hosts => ['127.0.0.1','%']
)
end
it {
is_expected.to contain_openstacklib__db__mysql('murano').with(
:user => params[:user],
:dbname => params[:dbname],
:password_hash => '*58C036CDA51D8E8BBBBF2F9EA5ABF111ADA444F0',
:host => params[:host],
:charset => params[:charset],
:allowed_hosts => ['127.0.0.1','%']
)}
end
context 'overriding allowed_hosts param to string' do
before :each do
params.merge!(
:allowed_hosts => '192.168.1.1'
)
end
it {
is_expected.to contain_openstacklib__db__mysql('murano').with(
:user => params[:user],
:dbname => params[:dbname],
:password_hash => '*58C036CDA51D8E8BBBBF2F9EA5ABF111ADA444F0',
:host => params[:host],
:charset => params[:charset],
:allowed_hosts => '192.168.1.1'
)}
end
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end
it_configures 'murano mysql database'
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end
it_configures 'murano mysql database'
end
end

View File

@ -0,0 +1,58 @@
require 'spec_helper'
describe 'murano::db::postgresql' do
let :req_params do
{ :password => 'pw' }
end
let :pre_condition do
'include postgresql::server'
end
context 'on a RedHat osfamily' do
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '7.0',
:concat_basedir => '/var/lib/puppet/concat'
}
end
context 'with only required parameters' do
let :params do
req_params
end
it { is_expected.to contain_postgresql__server__db('murano').with(
:user => 'murano',
:password => 'md5c73cd23dae0b015e51ff2b38714d0bab'
)}
end
end
context 'on a Debian osfamily' do
let :facts do
{
:operatingsystemrelease => '7.8',
:operatingsystem => 'Debian',
:osfamily => 'Debian',
:concat_basedir => '/var/lib/puppet/concat'
}
end
context 'with only required parameters' do
let :params do
req_params
end
it { is_expected.to contain_postgresql__server__db('murano').with(
:user => 'murano',
:password => 'md5c73cd23dae0b015e51ff2b38714d0bab'
)}
end
end
end