From 05eb5700e8552a54c0045867b47b8c4493885fca Mon Sep 17 00:00:00 2001 From: Josh Farwell Date: Fri, 29 May 2015 02:39:04 -0700 Subject: [PATCH] Started building initial structure for module. Created init.pp and params.pp, started building installation functionality. Added puppet-rpsec tests. Change-Id: Ife33ead1b2e1b04c8a04576b951677ee3b06634e Signed-off-by: Josh Farwell --- manifests/init.pp | 36 ++++++++++++++++++++++-- manifests/install.pp | 66 ++++++++++++++++++++++++++++++++++++++++++++ manifests/params.pp | 57 ++++++++++++++++++++++++++++++++++++++ spec/classes/init_spec.rb | 11 ++++++-- spec/classes/install_spec.rb | 56 +++++++++++++++++++++++++++++++++++++ spec/classes/params_spec.rb | 9 ++++++ spec/coverage_spec.rb | 5 ++++ tests/init.pp | 5 +++- 8 files changed, 239 insertions(+), 6 deletions(-) create mode 100644 manifests/install.pp create mode 100644 manifests/params.pp create mode 100644 spec/classes/install_spec.rb create mode 100644 spec/classes/params_spec.rb create mode 100644 spec/coverage_spec.rb diff --git a/manifests/init.pp b/manifests/init.pp index dd0ab0c..406e42d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -29,13 +29,43 @@ # # === Authors # -# Author Name +# Josh Farwell # # === 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 index 0000000..88b64d6 --- /dev/null +++ b/manifests/install.pp @@ -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 index 0000000..5a905bb --- /dev/null +++ b/manifests/params.pp @@ -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 +# +# === 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 : diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index d1a9f5f..f5bcf30 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -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 index 0000000..102af91 --- /dev/null +++ b/spec/classes/install_spec.rb @@ -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 index 0000000..7d5e34c --- /dev/null +++ b/spec/classes/params_spec.rb @@ -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 index 0000000..c16074f --- /dev/null +++ b/spec/coverage_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +at_exit { RSpec::Puppet::Coverage.report! } + +# vim: ts=2 sw=2 sts=2 et : diff --git a/tests/init.pp b/tests/init.pp index 3475ac0..73b707b 100644 --- a/tests/init.pp +++ b/tests/init.pp @@ -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 : -- 2.16.6