From 7857c67e242712b7c7230d25c3f16438a48b414c Mon Sep 17 00:00:00 2001 From: Sebastien Badia Date: Tue, 30 Dec 2014 19:05:14 +0100 Subject: [PATCH] Migrate postgresql backend to use openstacklib::db::postgresql Let migrate to the new openstacklib::db::postgresql helper for postgresql backend. This commit also unpin postgresql fixture (openstacklib support now the latest version of postgre module). Change-Id: I29ae9506cb638aa3e3925705bac945511c96ca8f Implements: blueprint commmon-openstack-database-resource --- .fixtures.yml | 5 +- manifests/db/postgresql.pp | 46 +++++++++++++----- spec/classes/glance_db_postgresql_spec.rb | 58 ++++++++++++++++++----- 3 files changed, 82 insertions(+), 27 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index 70fa5d66..01b0f660 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,6 +1,7 @@ fixtures: repositories: "apt": "git://github.com/puppetlabs/puppetlabs-apt.git" + 'concat': 'git://github.com/puppetlabs/puppetlabs-concat.git' "keystone": "git://github.com/stackforge/puppet-keystone.git" "mysql": repo: "git://github.com/puppetlabs/puppetlabs-mysql.git" @@ -11,8 +12,6 @@ fixtures: repo: "git://github.com/puppetlabs/puppetlabs-rabbitmq" ref: 'origin/2.x' 'inifile': 'git://github.com/puppetlabs/puppetlabs-inifile' - "postgresql": - repo: "git://github.com/puppetlabs/puppet-postgresql.git" - ref: "2.5.0" + 'postgresql': 'git://github.com/puppetlabs/puppet-postgresql.git' symlinks: "glance": "#{source_dir}" diff --git a/manifests/db/postgresql.pp b/manifests/db/postgresql.pp index a1eb54c6..47730bb5 100644 --- a/manifests/db/postgresql.pp +++ b/manifests/db/postgresql.pp @@ -1,21 +1,45 @@ +# == Class: glance::db::postgresql # # Class that configures postgresql for glance -# # Requires the Puppetlabs postgresql module. +# +# === Parameters +# +# [*password*] +# (Required) Password to connect to the database. +# +# [*dbname*] +# (Optional) Name of the database. +# Defaults to 'glance'. +# +# [*user*] +# (Optional) User to connect to the database. +# Defaults to 'glance'. +# +# [*encoding*] +# (Optional) The charset to use for the database. +# Default to undef. +# +# [*privileges*] +# (Optional) Privileges given to the database user. +# Default to 'ALL' +# class glance::db::postgresql( $password, - $dbname = 'glance', - $user = 'glance' + $dbname = 'glance', + $user = 'glance', + $encoding = undef, + $privileges = 'ALL', ) { - require postgresql::python - - Postgresql::Db[$dbname] ~> Exec<| title == 'glance-manage db_sync' |> - Package['python-psycopg2'] -> Exec<| title == 'glance-manage db_sync' |> - - postgresql::db { $dbname: - user => $user, - password => $password, + ::openstacklib::db::postgresql { 'glance': + password_hash => postgresql_password($user, $password), + dbname => $dbname, + user => $user, + encoding => $encoding, + privileges => $privileges, } + ::Openstacklib::Db::Postgresql['glance'] ~> Exec<| title == 'glance-manage db_sync' |> + } diff --git a/spec/classes/glance_db_postgresql_spec.rb b/spec/classes/glance_db_postgresql_spec.rb index dcb2b012..95422eab 100644 --- a/spec/classes/glance_db_postgresql_spec.rb +++ b/spec/classes/glance_db_postgresql_spec.rb @@ -3,24 +3,56 @@ require 'spec_helper' describe 'glance::db::postgresql' do let :req_params do - {:password => 'pw'} + { :password => 'pw' } end - let :facts do - { - :postgres_default_version => '8.4', - :osfamily => 'RedHat', - } + let :pre_condition do + 'include postgresql::server' end - describe 'with only required params' do - let :params do - req_params + context 'on a RedHat osfamily' do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '7.0', + :concat_basedir => '/var/lib/puppet/concat' + } end - it { should contain_postgresql__db('glance').with( - :user => 'glance', - :password => 'pw' - ) } + + context 'with only required parameters' do + let :params do + req_params + end + + it { should contain_postgresql__server__db('glance').with( + :user => 'glance', + :password => 'md56c7c03b193c2c1e0667bc5bd891703db' + )} + 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 { should contain_postgresql__server__db('glance').with( + :user => 'glance', + :password => 'md56c7c03b193c2c1e0667bc5bd891703db' + )} + end + end end