Restructured installation into submodules 93/93/2
authorJosh Farwell <jfarwell@linuxfoundation.org>
Thu, 4 Jun 2015 04:03:06 +0000 (21:03 -0700)
committerJosh Farwell <jfarwell@linuxfoundation.org>
Thu, 4 Jun 2015 06:25:08 +0000 (23:25 -0700)
Because we are managing three separate applications which can be on
separate systems, splitting into submodules with shared paramaters and
other classes makes sense. Init.pp now throws an error if called
directly. Moved existing installation logic to mailman::core, which
handles the core service. Split yum repo resource into its own class
which is called by ::core and will be called by the other applications.

Also cleaned up unneeded mailman service user parameter; these are not
needed, the user is installed by the package and managed via the systemd
service. Created parameter for site_owner email address.

Fixed rspec tests; there is a known issue with using .merge!() on
options hashes. Changed semantics for confirming the absence of an
object on core__install_spec.rb (only looking for raise_error if we have
a specific message we want, otherwise using is_expected.to_not)

Change-Id: I60ef5e897d66574ee73be2768985b8915aa8d02f
Signed-off-by: Josh Farwell <jfarwell@linuxfoundation.org>
manifests/core.pp [new file with mode: 0644]
manifests/core/install.pp [new file with mode: 0644]
manifests/init.pp
manifests/params.pp
manifests/repo.pp [moved from manifests/install.pp with 68% similarity]
spec/classes/core__install_spec.rb [new file with mode: 0644]
spec/classes/core_spec.rb [new file with mode: 0644]
spec/classes/init_spec.rb
spec/classes/install_spec.rb [deleted file]
spec/classes/repo_spec.rb [new file with mode: 0644]

diff --git a/manifests/core.pp b/manifests/core.pp
new file mode 100644 (file)
index 0000000..2301e09
--- /dev/null
@@ -0,0 +1,69 @@
+# == Class: mailman3::core
+#
+# Full description of class mailman3 here.
+#
+# === Parameters
+#
+# Document parameters here.
+#
+# [*sample_parameter*]
+#   Explanation of what this parameter affects and what it defaults to.
+#   e.g. "Specify one or more upstream ntp servers as an array."
+#
+# === Variables
+#
+# Here you should define a list of variables that this module would require.
+#
+# [*sample_variable*]
+#   Explanation of how this variable affects the function of this class and if
+#   it has a default. e.g. "The parameter enc_ntp_servers must be set by the
+#   External Node Classifier as a comma separated list of hostnames." (Note,
+#   global variables should be avoided in favor of class parameters as
+#   of Puppet 2.6.)
+#
+# === Examples
+#
+#  class { 'mailman3':
+#    servers => [ 'pool.ntp.org', 'ntp.local.company.com' ],
+#  }
+#
+# === Authors
+#
+# Josh Farwell <jfarwell@linuxfoundation.org>
+#
+# === Copyright
+#
+# Copyright 2015 Josh Farwell, unless otherwise noted.
+#
+class mailman3::core (
+  $install_mailman = $mailman3::params::install_mailman,
+  $mailman_version = $mailman3::params::version,
+) inherits mailman3::params {
+
+  # Make sure parameters are properly formatted
+  validate_bool($install_mailman)
+  validate_string($mailman_version)
+
+  anchor { 'mailman3::core::begin': }
+  anchor { 'mailman3::core::end': }
+
+  class { '::mailman3::core::install':
+    install_mailman => $install_mailman,
+    mailman_version => $mailman_version,
+  }
+
+  #class { '::mailman3::core::config':
+    #default_secure_options  => $mailman3::params::default_secure_options,
+    #manage_database         => $manage_database,
+    #manage_firewall         => $manage_firewall,
+    #options                 => $options,
+    #override_secure_options => $override_secure_options,
+  #}
+
+  Anchor['mailman3::core::begin'] ->
+    Class['mailman3::core::install'] ->
+    #Class['mailman3::core::config'] ->
+  Anchor['mailman3::core::end']
+
+}
+# vim: ts=2 sw=2 sts=2 et :
diff --git a/manifests/core/install.pp b/manifests/core/install.pp
new file mode 100644 (file)
index 0000000..fadda27
--- /dev/null
@@ -0,0 +1,58 @@
+# == Class: mailman3
+#
+# Full description of class mailman3 here.
+#
+# === Parameters
+#
+# Document parameters here.
+#
+# [*sample_parameter*]
+#   Explanation of what this parameter affects and what it defaults to.
+#   e.g. "Specify one or more upstream ntp servers as an array."
+#
+# === Variables
+#
+# Here you should define a list of variables that this module would require.
+#
+# [*sample_variable*]
+#   Explanation of how this variable affects the function of this class and if
+#   it has a default. e.g. "The parameter enc_ntp_servers must be set by the
+#   External Node Classifier as a comma separated list of hostnames." (Note,
+#   global variables should be avoided in favor of class parameters as
+#   of Puppet 2.6.)
+#
+# === Examples
+#
+#  class { 'mailman3':
+#    servers => [ 'pool.ntp.org', 'ntp.local.company.com' ],
+#  }
+#
+# === Authors
+#
+# Josh Farwell
+#
+# === Copyright
+#
+# Copyright 2015 Josh Farwell, unless otherwise noted.
+#
+class mailman3::core::install (
+  $install_mailman,
+  $mailman_version,
+) {
+  validate_bool($install_mailman)
+  validate_string($mailman_version)
+
+  if ($install_mailman) {
+
+    include mailman3::repo
+
+    package { 'mailman3':
+      ensure  => $mailman_version,
+      require => Class['::mailman3::repo']
+    }
+
+  }
+
+}
+
+# vim: ts=2 sw=2 sts=2 et :
index 406e42d..42b4d16 100644 (file)
 #
 # Copyright 2015 Josh Farwell, unless otherwise noted.
 #
-class mailman3 (
-  $install_mailman          = $mailman3::params::install_mailman,
-  $mailman_version          = $mailman3::params::version,
-  $override_options         = {},
-  $override_secure_options  = {},
-) inherits mailman3::params {
-
-  # Make sure parameters are properly formatted
-  validate_bool($install_mailman)
-  validate_string($mailman_version)
-  validate_hash($override_options)
-  validate_hash($override_secure_options)
-
-  # Merge our default options hash with overrides, right wins over left
-  $options = merge($mailman3::params::default_options, $override_options)
-
-  $secure_options = merge($mailman3::params::default_secure_options,
-    $override_secure_options)
-
-  anchor { 'mailman3::begin': }
-  anchor { 'mailman3::end': }
-
-  class { '::mailman3::install':
-    install_mailman   => $install_mailman,
-    mailman_version   => $mailman_version,
-    options           => $options,
-  }
-
-  Anchor['mailman3::begin'] ->
-    Class['mailman3::install'] ->
-  Anchor['mailman3::end']
-
+class mailman3 {
+  fail "This module's base class cannot be called directly."
 }
-# vim: ts=2 sw=2 sts=2 et :
index 5a905bb..aa80c05 100644 (file)
@@ -40,16 +40,16 @@ class mailman3::params {
   # TODO: Strategy for organizing this manifest
   # TODO: Secure_default_options hash
   # Mangement Booleans
-  $install_mailman        = false
+  $install_mailman = true
 
   # Mailman Core values
-  $mailman_version        = 'installed' # could also be 3.0.0
-  $mailman_user           = 'mailman'
+  $mailman_version = 'installed' # could also be 3.0.0
+  $site_owner      = undef
 
   # default options hash
   $default_options = {
-    'mailman'   => {
-      'user'    => $mailman3::params::mailman_user,
+    'core'  => {
+      'site_owner'  => $mailman3::params::site_owner_email,
     },
   }
 
similarity index 68%
rename from manifests/install.pp
rename to manifests/repo.pp
index 034042a..2b3877f 100644 (file)
@@ -1,4 +1,4 @@
-# == Class: mailman3
+# == Class: mailman3::repo
 #
 # Full description of class mailman3 here.
 #
 #
 # === Authors
 #
-# Josh Farwell
+# Josh Farwell <jfarwell@linuxfoundation.org>
 #
 # === Copyright
 #
 # Copyright 2015 Josh Farwell, unless otherwise noted.
 #
-class mailman3::install (
-  $install_mailman,
-  $mailman_version,
-  $options
-) {
-  validate_bool($install_mailman)
-  validate_string($mailman_version)
-  validate_hash($options)
+class mailman3::repo {
 
-  # Install mailman3 yum repo - EL7 only at this time
   yumrepo { 'fedorapeople-mailman3':
     ensure   => present,
     name     => 'fedorapeople-mailman3',
@@ -53,17 +45,4 @@ class mailman3::install (
     gpgcheck => 'no',
     enabled  => true,
   }
-
-  # Install mailman core if we want to
-  # TODO: Split out into subclasses for each application component
-  if ($install_mailman) {
-    package { 'mailman3':
-      ensure  => $mailman_version,
-      require => Yumrepo['fedorapeople-mailman3'],
-    }
-
-  }
-
 }
-
-# vim: ts=2 sw=2 sts=2 et :
diff --git a/spec/classes/core__install_spec.rb b/spec/classes/core__install_spec.rb
new file mode 100644 (file)
index 0000000..d53e186
--- /dev/null
@@ -0,0 +1,43 @@
+require 'spec_helper'
+
+describe 'mailman3::core::install', :type => :class do
+
+  # default parameters from params.pp
+  let(:params) {
+    {
+      'install_mailman'  => true,
+      'mailman_version'  => 'installed',
+      }
+    }
+
+  # since we don't have default parameters in the class,
+  # we should fail to compile if they're gone
+  context 'with defaults for all parameters' do
+    let (:params) {{}}
+    it { is_expected.to_not compile }
+  end
+
+  # With good parameters, we should include repo install packages by default
+  context 'with known good parameters' do
+    it { is_expected.to contain_package('mailman3') }
+    it { is_expected.to contain_class('mailman3::repo') }
+    it { is_expected.to contain_yumrepo('fedorapeople-mailman3') }
+  end
+
+  context 'with install flags disabled' do
+
+    # should not install if the flags are set
+    let(:params) {
+      {
+        'install_mailman'  => false,
+        'mailman_version'  => 'installed',
+        }
+      }
+
+    it { is_expected.to_not contain_package('mailman3') }
+    it { is_expected.to_not contain_class('mailman3::repo') }
+    it { is_expected.to_not contain_yumrepo('fedorapeople-mailman3') }
+
+  end
+
+end
diff --git a/spec/classes/core_spec.rb b/spec/classes/core_spec.rb
new file mode 100644 (file)
index 0000000..e320675
--- /dev/null
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe 'mailman3::core', :type => :class do
+
+  context 'with defaults for all parameters' do
+    it { is_expected.to contain_class('mailman3::core') }
+    it { is_expected.to contain_class('mailman3::params') }
+    it { is_expected.to contain_anchor('mailman3::core::begin') }
+    it { is_expected.to contain_class('mailman3::core::install') }
+    it { is_expected.to contain_anchor('mailman3::core::end') }
+  end
+end
+
+# vim: ts=2 sw=2 sts=2 et :
index f5bcf30..bfe0993 100644 (file)
@@ -3,11 +3,12 @@ require 'spec_helper'
 describe 'mailman3', :type => :class do
 
   context 'with defaults for all parameters' do
-    it { is_expected.to contain_class('mailman3') }
-    it { is_expected.to contain_class('mailman3::params') }
-    it { is_expected.to contain_anchor('mailman3::begin') }
-    it { is_expected.to contain_class('mailman3::install') }
-    it { is_expected.to contain_anchor('mailman3::end') }
+    it do
+      expect {
+        should compile
+      }.to raise_error(RSpec::Expectations::ExpectationNotMetError,
+        /This module's base class cannot be called directly./)
+    end
   end
 end
 
diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb
deleted file mode 100644 (file)
index bd5dc5c..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-require 'spec_helper'
-
-describe 'mailman3::install', :type => :class do
-
-  # default parameters from params.pp
-  let(:params) {
-    {
-      'install_mailman'  => false,
-      'mailman_version'  => 'installed',
-      'options'          => {
-        'mailman'        => {
-          'user'         => 'mailman',
-        },
-      },
-    }
-  }
-
-  # since we don't have default parameters in the class,
-  # we should fail to compile if they're gone
-  context 'with defaults for all parameters' do
-    let (:params) {{}}
-
-    it do
-      expect {
-        should compile
-      }.to raise_error(RSpec::Expectations::ExpectationNotMetError,
-        /Must pass /)
-    end
-  end
-
-  # With good parameters
-  context 'with known good parameters' do
-
-    it { is_expected.to contain_yumrepo('fedorapeople-mailman3') }
-
-    # it will need to look for user, but not right now
-    #it { is_expected.to contain_user('mailman') }
-
-    # shouldn't install any packages without explicit flags
-    it do
-      expect {
-        should contain_package('mailman3')
-      }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
-    end
-
-    # should install if the flags are set
-
-    it 'should have mailman if install_mailman is true' do
-      params.merge!({'install_mailman' => true})
-
-      should contain_package('mailman3').that_requires('Yumrepo[fedorapeople-mailman3]')
-    end
-
-  end
-
-end
diff --git a/spec/classes/repo_spec.rb b/spec/classes/repo_spec.rb
new file mode 100644 (file)
index 0000000..90b867e
--- /dev/null
@@ -0,0 +1,7 @@
+require 'spec_helper'
+
+describe 'mailman3::repo', :type => :class do
+
+   it { is_expected.to contain_yumrepo('fedorapeople-mailman3') }
+
+end