Started building initial structure for module. 60/60/2
authorJosh Farwell <jfarwell@linuxfoundation.org>
Fri, 29 May 2015 09:39:04 +0000 (02:39 -0700)
committerJosh Farwell <jfarwell@linuxfoundation.org>
Fri, 29 May 2015 23:31:14 +0000 (16:31 -0700)
Created init.pp and params.pp, started building installation
functionality.

Added puppet-rpsec tests.

Change-Id: Ife33ead1b2e1b04c8a04576b951677ee3b06634e
Signed-off-by: Josh Farwell <jfarwell@linuxfoundation.org>
manifests/init.pp
manifests/install.pp [new file with mode: 0644]
manifests/params.pp [new file with mode: 0644]
spec/classes/init_spec.rb
spec/classes/install_spec.rb [new file with mode: 0644]
spec/classes/params_spec.rb [new file with mode: 0644]
spec/coverage_spec.rb [new file with mode: 0644]
tests/init.pp

index dd0ab0c..406e42d 100644 (file)
 #
 # === Authors
 #
-# Author Name <author@domain.com>
+# Josh Farwell <jfarwell@linuxfoundation.org>
 #
 # === Copyright
 #
-# Copyright 2015 Your name here, unless otherwise noted.
+# Copyright 2015 Josh Farwell, unless otherwise noted.
 #
-class mailman3 {
+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']
 
 }
+# vim: ts=2 sw=2 sts=2 et :
diff --git a/manifests/install.pp b/manifests/install.pp
new file mode 100644 (file)
index 0000000..88b64d6
--- /dev/null
@@ -0,0 +1,66 @@
+# == 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::install (
+  $install_mailman,
+  $mailman_version,
+  $options
+) {
+  validate_bool($install_mailman)
+  validate_string($mailman_version)
+  validate_hash($options)
+
+  # Install mailman3 yum repo - EL7 only at this time
+  yumrepo { 'fedorapeople-mailman3':
+    ensure        => present,
+    name          => 'fedorapeople-mailman3',
+    baseurl       => 'https://repos.fedorapeople.org/repos/abompard/hyperkitty/el-7/x86_64/',
+    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,
+    }
+  }
+
+}
+
+# vim: ts=2 sw=2 sts=2 et :
diff --git a/manifests/params.pp b/manifests/params.pp
new file mode 100644 (file)
index 0000000..5a905bb
--- /dev/null
@@ -0,0 +1,57 @@
+# == 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 <jfarwell@linuxfoundation.org>
+#
+# === Copyright
+#
+# Copyright 2015 Josh Farwell, unless otherwise noted.
+#
+class mailman3::params {
+
+  # TODO: Strategy for organizing this manifest
+  # TODO: Secure_default_options hash
+  # Mangement Booleans
+  $install_mailman        = false
+
+  # Mailman Core values
+  $mailman_version        = 'installed' # could also be 3.0.0
+  $mailman_user           = 'mailman'
+
+  # default options hash
+  $default_options = {
+    'mailman'   => {
+      'user'    => $mailman3::params::mailman_user,
+    },
+  }
+
+}
+# vim: ts=2 sw=2 sts=2 et :
index d1a9f5f..f5bcf30 100644 (file)
@@ -1,7 +1,14 @@
 require 'spec_helper'
-describe 'mailman3' do
+
+describe 'mailman3', :type => :class do
 
   context 'with defaults for all parameters' do
-    it { should contain_class('mailman3') }
+    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') }
   end
 end
+
+# vim: ts=2 sw=2 sts=2 et :
diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb
new file mode 100644 (file)
index 0000000..102af91
--- /dev/null
@@ -0,0 +1,56 @@
+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')
+    end
+
+  end
+
+end
diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb
new file mode 100644 (file)
index 0000000..7d5e34c
--- /dev/null
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe 'mailman3::params' do
+  context 'with defaults' do
+    it { is_expected.to contain_class('mailman3::params')}
+  end
+end
+
+# vim: ts=2 sw=2 sts=2 et :
diff --git a/spec/coverage_spec.rb b/spec/coverage_spec.rb
new file mode 100644 (file)
index 0000000..c16074f
--- /dev/null
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+at_exit { RSpec::Puppet::Coverage.report! }
+
+# vim: ts=2 sw=2 sts=2 et :
index 3475ac0..73b707b 100644 (file)
@@ -9,4 +9,7 @@
 # Learn more about module testing here:
 # http://docs.puppetlabs.com/guides/tests_smoke.html
 #
-include mailman3
+
+#include mailman3
+class { 'mailman3': install_mailman => true }
+# vim: ts=2 sw=2 sts=2 et :