From: Josh Farwell Date: Wed, 17 Jun 2015 21:19:28 +0000 (-0700) Subject: Added python-psycopg2 dependency X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=2b7bb593e23cdc3774ad603b93b02f3f6a281ae3;p=puppet%2Fmodules%2Fmailman3.git Added python-psycopg2 dependency mailman3::core::install now parses the config data for database information and installs a needed Postgresql dependency if we are using Postgres. Change-Id: I9d1b5f4c0c1e856df31ffcc30378e95e97e73867 Signed-off-by: Josh Farwell --- diff --git a/manifests/core.pp b/manifests/core.pp index 5b717cf..771aff0 100644 --- a/manifests/core.pp +++ b/manifests/core.pp @@ -70,8 +70,9 @@ class mailman3::core ( anchor { 'mailman3::core::end': } class { '::mailman3::core::install': - install_core => $install_core, + core_options => $core_options, core_version => $core_version, + install_core => $install_core, } class { '::mailman3::core::config': diff --git a/manifests/core/install.pp b/manifests/core/install.pp index 638f6dc..71354fe 100644 --- a/manifests/core/install.pp +++ b/manifests/core/install.pp @@ -36,10 +36,12 @@ # Copyright 2015 Josh Farwell, unless otherwise noted. # class mailman3::core::install ( - $install_core, + $core_options, $core_version, + $install_core, ) { validate_bool($install_core) + validate_hash($core_options) validate_string($core_version) if ($install_core) { @@ -61,6 +63,24 @@ class mailman3::core::install ( require => Class['::mailman3::repo'] } + if has_key($core_options, 'database') { + + validate_hash($core_options['database']) + unless has_key($core_options['database'], 'class') { + fail "Database options do not contain value for 'class'" + } + + validate_string($core_options['database']['class']) + + if ($core_options['database']['class'] == 'mailman.database.postgresql.PostgreSQLDatabase') { + package { 'python34-psycopg2': + ensure => present, + require => Class['::mailman3::repo'] + } + } + } + + } } diff --git a/spec/classes/core__install_spec.rb b/spec/classes/core__install_spec.rb index c4fa73e..d6322bb 100644 --- a/spec/classes/core__install_spec.rb +++ b/spec/classes/core__install_spec.rb @@ -7,6 +7,7 @@ describe 'mailman3::core::install', :type => :class do { 'install_core' => true, 'core_version' => 'installed', + 'core_options' => {}, } } @@ -33,6 +34,7 @@ describe 'mailman3::core::install', :type => :class do { 'install_core' => false, 'core_version' => 'installed', + 'core_options' => {}, } } @@ -44,4 +46,37 @@ describe 'mailman3::core::install', :type => :class do end + context 'with a PostGresSQL database class in config' do + + let(:params) { + { + 'install_core' => true, + 'core_version' => 'installed', + 'core_options' => { + 'database' => { + 'class' => 'mailman.database.postgresql.PostgreSQLDatabase', + }, + }, + } + } + + it { is_expected.to contain_package('python-psycopg2') } + end + + context 'with a non-Postgresql database in config' do + + let(:params) { + { + 'install_core' => true, + 'core_version' => 'installed', + 'core_options' => { + 'database' => { + 'class' => 'mailman.database.sqlite.FakeConfig', + }, + }, + } + } + + it { is_expected.to_not contain_package('python-psycopg2') } + end end