$core_override_hyperkittycfg = {},
$core_override_options = {},
$core_override_allowed_hosts = {},
+ $core_refresh_service = $mailman3::params::core_refresh_service,
+ $core_service_enabled = $mailman3::params::core_service_enabled,
$core_version = $mailman3::params::core_version,
$db_tag = $mailman3::params::core_db_tag,
$install_core = $mailman3::params::install_core,
validate_bool($install_core)
validate_bool($core_manage_database)
validate_bool($core_manage_firewall)
+ validate_bool($core_refresh_service)
validate_hash($core_override_hyperkittycfg)
validate_hash($core_override_options)
validate_hash($core_override_allowed_hosts)
validate_string($db_tag)
validate_string($core_version)
+ unless is_bool($core_service_enabled) {
+ validate_re($core_service_enabled, '^manual$',
+ "${core_service_enabled} is not supported for service_enabled. \
+Allowed values are true, false, 'manual'.")
+ }
+
# Merge together options with defaults from ::params, right most wins
$core_hyperkittycfg = merge($mailman3::params::core_default_hyperkittycfg,
$core_override_hyperkittycfg)
db_tag => $db_tag,
}
+ class { '::mailman3::core::service':
+ service_enabled => $core_service_enabled,
+ }
+
Anchor['mailman3::core::begin'] ->
Class['mailman3::core::install'] ->
Class['mailman3::core::config'] ->
+ Class['mailman3::core::service'] ->
Anchor['mailman3::core::end']
+ # The config class should notify the service class when its resources change
+ # We are doing it here because these classes don't have interdependencies and using
+ # notify or subscribe within them would cause compile / tests to fail
+ if ($core_refresh_service) {
+ Class['mailman3::core::config'] ~> Class['mailman3::core::service']
+ }
+
}
# vim: ts=2 sw=2 sts=2 et :
--- /dev/null
+# == 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::core::service (
+ $service_enabled,
+) {
+
+ unless is_bool($service_enabled) {
+ validate_re($service_enabled, '^manual$',
+ "${service_enabled} is not supported for service_enabled. \
+Allowed values are true, false, 'manual'.")
+ }
+
+ if (is_bool($service_enabled)) {
+ $ensure = $service_enabled
+ }
+ else {
+ $ensure = undef
+ }
+
+ $enable = $service_enabled
+
+ service { 'mailman3':
+ ensure => $ensure,
+ enable => $enable,
+ hasrestart => true,
+ hasstatus => true,
+ }
+}
# Mangement Booleans
$core_manage_database = true
$core_manage_firewall = true
+ $core_refresh_service = true
+ $core_service_enabled = true
$install_core = true
# Shared values
--- /dev/null
+require 'spec_helper'
+
+describe 'mailman3::core::service', :type => :class do
+ # set some default good params so we can override with bad ones in
+ # test
+ let(:params) {
+ {
+ 'service_enabled' => true,
+ }
+ }
+
+ # we do not have default values so the class should fail to compile
+ 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 assumed good params
+ context 'with good parameters' do
+ it { is_expected.to contain_service('mailman3').with(
+ :ensure => true,
+ :enable => true,
+ ) }
+ end
+
+ context 'service_enabled is incorrect' do
+ let(:params) {{ 'service_enabled' => 'invalid_val' }}
+
+ it 'should report an error when service_enabled is invalid' do
+ expect { should compile }.to \
+ raise_error(RSpec::Expectations::ExpectationNotMetError,
+ /invalid_val is not supported for service_enabled\. \
+Allowed values are true, false, 'manual'\./)
+ end
+ end
+
+ context 'service_enabled set to false' do
+ let(:params) {{ 'service_enabled' => false }}
+
+ it { is_expected.to contain_service('mailman3').with(
+ :ensure => false
+ ) }
+ end
+
+ context 'service_enabled set to manual' do
+ let(:params) {{ 'service_enabled' => 'manual' }}
+
+ it { is_expected.to contain_service('mailman3').with(
+ :enable => 'manual',
+ ) }
+ end
+end
+
+# vim: sw=2 ts=2 sts=2 et :
it { is_expected.to contain_anchor('mailman3::core::begin') }
it { is_expected.to contain_class('mailman3::core::install') }
it { is_expected.to contain_class('mailman3::core::config') }
+ it { is_expected.to contain_class('mailman3::core::service') }
it { is_expected.to contain_anchor('mailman3::core::end') }
end
end