Added python-psycopg2 dependency 65/165/2
authorJosh Farwell <jfarwell@linuxfoundation.org>
Wed, 17 Jun 2015 21:19:28 +0000 (14:19 -0700)
committerJosh Farwell <jfarwell@linuxfoundation.org>
Wed, 17 Jun 2015 21:27:21 +0000 (14:27 -0700)
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 <jfarwell@linuxfoundation.org>
manifests/core.pp
manifests/core/install.pp
spec/classes/core__install_spec.rb

index 5b717cf..771aff0 100644 (file)
@@ -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':
index 638f6dc..71354fe 100644 (file)
 # 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']
+        }
+      }
+    }
+
+
   }
 
 }
index c4fa73e..d6322bb 100644 (file)
@@ -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