From c0f36aaeb16a803c1230db3f44f226d8fc22bc45 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Thu, 19 Oct 2023 20:50:35 +0200 Subject: [PATCH] fix #281 Background daemons of modules are not optional, so should not be treated like that in Puppet module --- REFERENCE.md | 27 ++++++ manifests/module/director.pp | 8 ++ manifests/module/reporting.pp | 8 ++ manifests/module/vspheredb.pp | 8 ++ spec/classes/director_service_spec.rb | 2 +- spec/classes/director_spec.rb | 13 ++- spec/classes/reporting_service_spec.rb | 41 +++++++++ spec/classes/reporting_spec.rb | 120 +++++++++++++++++++++++++ spec/classes/vspheredb_service_spec.rb | 2 +- spec/classes/vspheredb_spec.rb | 33 ++++++- 10 files changed, 256 insertions(+), 6 deletions(-) create mode 100644 spec/classes/reporting_service_spec.rb create mode 100644 spec/classes/reporting_spec.rb diff --git a/REFERENCE.md b/REFERENCE.md index 4a9cf802..109feb39 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1038,6 +1038,7 @@ The following parameters are available in the `icingaweb2::module::director` cla * [`api_port`](#-icingaweb2--module--director--api_port) * [`api_username`](#-icingaweb2--module--director--api_username) * [`api_password`](#-icingaweb2--module--director--api_password) +* [`manage_service`](#-icingaweb2--module--director--manage_service) ##### `ensure` @@ -1279,6 +1280,14 @@ Icinga 2 API password. This setting is only valid if `kickstart` is `true`. Default value: `undef` +##### `manage_service` + +Data type: `Boolean` + +Also manage the service (daemon), running and enabled. Otherwise do your config via hiera. + +Default value: `true` + ### `icingaweb2::module::director::service` Installs and configures the director service. @@ -2991,6 +3000,7 @@ The following parameters are available in the `icingaweb2::module::reporting` cl * [`tls_cipher`](#-icingaweb2--module--reporting--tls_cipher) * [`import_schema`](#-icingaweb2--module--reporting--import_schema) * [`mail`](#-icingaweb2--module--reporting--mail) +* [`manage_service`](#-icingaweb2--module--reporting--manage_service) ##### `ensure` @@ -3186,6 +3196,14 @@ Mails are sent with this sender address. Default value: `undef` +##### `manage_service` + +Data type: `Boolean` + +Also manage the service (daemon), running and enabled. Otherwise do your config via hiera. + +Default value: `true` + ### `icingaweb2::module::reporting::service` Installs and configures the reporting scheduler. @@ -3318,6 +3336,7 @@ The following parameters are available in the `icingaweb2::module::vspheredb` cl * [`tls_noverify`](#-icingaweb2--module--vspheredb--tls_noverify) * [`tls_cipher`](#-icingaweb2--module--vspheredb--tls_cipher) * [`import_schema`](#-icingaweb2--module--vspheredb--import_schema) +* [`manage_service`](#-icingaweb2--module--vspheredb--manage_service) ##### `ensure` @@ -3513,6 +3532,14 @@ whereas with mysql its different options. Default value: `false` +##### `manage_service` + +Data type: `Boolean` + +Also manage the service (daemon), running and enabled. Otherwise do your config via hiera. + +Default value: `true` + ### `icingaweb2::module::vspheredb::service` Installs and configures the vspheredb service. diff --git a/manifests/module/director.pp b/manifests/module/director.pp index e11724d8..e1740c23 100644 --- a/manifests/module/director.pp +++ b/manifests/module/director.pp @@ -95,6 +95,9 @@ # @param api_password # Icinga 2 API password. This setting is only valid if `kickstart` is `true`. # +# @param manage_service +# Also manage the service (daemon), running and enabled. Otherwise do your config via hiera. +# # @note Please checkout the [Director module documentation](https://www.icinga.com/docs/director/latest/) for requirements. # # @example @@ -126,6 +129,7 @@ String $db_username = 'director', Optional[Icingaweb2::Secret] $db_password = undef, String $db_charset = 'utf8', + Boolean $manage_service = true, Optional[Boolean] $use_tls = undef, Optional[Stdlib::Absolutepath] $tls_key_file = undef, Optional[Stdlib::Absolutepath] $tls_cert_file = undef, @@ -252,4 +256,8 @@ package_name => $package_name, settings => $db_settings + $kickstart_settings, } + + if $manage_service { + include icingaweb2::module::director::service + } } diff --git a/manifests/module/reporting.pp b/manifests/module/reporting.pp index 132cf424..3a9953d0 100644 --- a/manifests/module/reporting.pp +++ b/manifests/module/reporting.pp @@ -79,6 +79,9 @@ # @param mail # Mails are sent with this sender address. # +# @param manage_service +# Also manage the service (daemon), running and enabled. Otherwise do your config via hiera. +# # @example # class { 'icingaweb2::module::reporting': # ensure => present, @@ -104,6 +107,7 @@ Optional[Icingaweb2::Secret] $db_password = undef, Optional[String] $db_charset = undef, Variant[Boolean, Enum['mariadb', 'mysql']] $import_schema = false, + Boolean $manage_service = true, Optional[Boolean] $use_tls = undef, Optional[Stdlib::Absolutepath] $tls_key_file = undef, Optional[Stdlib::Absolutepath] $tls_cert_file = undef, @@ -237,4 +241,8 @@ } } } # schema import + + if $manage_service { + include icingaweb2::module::reporting::service + } } diff --git a/manifests/module/vspheredb.pp b/manifests/module/vspheredb.pp index 12cedc64..96cd0974 100644 --- a/manifests/module/vspheredb.pp +++ b/manifests/module/vspheredb.pp @@ -76,6 +76,9 @@ # both means true. With mariadb its cli options are used for the import, # whereas with mysql its different options. # +# @param manage_service +# Also manage the service (daemon), running and enabled. Otherwise do your config via hiera. +# # @example # class { 'icingaweb2::module::vspheredb': # ensure => 'present', @@ -101,6 +104,7 @@ Optional[Icingaweb2::Secret] $db_password = undef, String $db_charset = 'utf8mb4', Variant[Boolean, Enum['mariadb', 'mysql']] $import_schema = false, + Boolean $manage_service = true, Optional[Boolean] $use_tls = undef, Optional[Stdlib::Absolutepath] $tls_key_file = undef, Optional[Stdlib::Absolutepath] $tls_cert_file = undef, @@ -216,4 +220,8 @@ } } } # schema import + + if $manage_service { + include icingaweb2::module::vspheredb::service + } } diff --git a/spec/classes/director_service_spec.rb b/spec/classes/director_service_spec.rb index d898dc67..8b22f8a1 100644 --- a/spec/classes/director_service_spec.rb +++ b/spec/classes/director_service_spec.rb @@ -4,7 +4,7 @@ let(:pre_condition) do [ "class { 'icingaweb2': db_type => 'mysql' }", - "class { 'icingaweb2::module::director': db_type => 'mysql' }", + "class { 'icingaweb2::module::director': db_type => 'mysql', manage_service => false }", ] end diff --git a/spec/classes/director_spec.rb b/spec/classes/director_spec.rb index 203a6ed5..89ecbe45 100644 --- a/spec/classes/director_spec.rb +++ b/spec/classes/director_spec.rb @@ -63,11 +63,17 @@ }) } + it { + is_expected.to contain_class('icingaweb2::module::director::service') + .with_ensure('running') + .with_enable(true) + } + it { is_expected.to contain_exec('director-migration') } it { is_expected.to contain_exec('director-kickstart') } end - context "#{os} with import_schema 'false'" do + context "#{os} with import_schema 'false', manage_service 'false'" do let(:params) do { git_revision: 'foobar', db_type: 'mysql', @@ -75,6 +81,7 @@ db_name: 'director', db_username: 'director', db_password: 'director', + manage_service: false, import_schema: false } end @@ -102,6 +109,10 @@ }) } + it { + is_expected.not_to contain_class('icingaweb2::module::director::service') + } + it { is_expected.not_to contain_exec('director-migration') } it { is_expected.not_to contain_exec('director-kickstart') } end diff --git a/spec/classes/reporting_service_spec.rb b/spec/classes/reporting_service_spec.rb new file mode 100644 index 00000000..aafdc81b --- /dev/null +++ b/spec/classes/reporting_service_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe('icingaweb2::module::reporting::service', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': db_type => 'mysql' }", + "class { 'icingaweb2::module::reporting': db_type => 'mysql', manage_service => false }", + ] + end + + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end + + context "#{os} with defaults" do + it do + is_expected.to contain_user('icingareporting') + .with( + 'ensure' => 'present', + 'gid' => 'icingaweb2', + 'shell' => '/bin/false', + ).that_comes_before('Systemd::Unit_file[icinga-reporting.service]') + end + it do + is_expected.to contain_systemd__unit_file('icinga-reporting.service').with( + content: %r{[Unit]}, + ).that_notifies('Service[icinga-reporting]') + end + it do + is_expected.to contain_service('icinga-reporting') + .with( + 'ensure' => 'running', + 'enable' => true, + ) + end + end + end + end +end diff --git a/spec/classes/reporting_spec.rb b/spec/classes/reporting_spec.rb new file mode 100644 index 00000000..dc6601de --- /dev/null +++ b/spec/classes/reporting_spec.rb @@ -0,0 +1,120 @@ +require 'spec_helper' + +describe('icingaweb2::module::reporting', type: :class) do + let(:pre_condition) do + [ + "class { 'icingaweb2': db_type => 'mysql' }", + ] + end + + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end + + context "#{os} with db_type 'mysql'" do + let(:params) do + { git_revision: 'foobar', + db_type: 'mysql' } + end + + it { + is_expected.to contain_icingaweb2__resource__database('reporting') + .with_type('mysql') + .with_host('localhost') + .with_database('reporting') + .with_username('reporting') + .with_charset('utf8mb4') + } + + it { + is_expected.to contain_icingaweb2__module('reporting') + .with_install_method('git') + .with_git_revision('foobar') + .with_module_dir('/usr/share/icingaweb2/modules/reporting') + .with_settings('icingaweb2-module-reporting-backend' => { + 'section_name' => 'backend', + 'target' => '/etc/icingaweb2/modules/reporting/config.ini', + 'settings' => { + 'resource' => 'reporting', + }, + }, + 'icingaweb2-module-reporting-mail' => { + 'section_name' => 'mail', + 'target' => '/etc/icingaweb2/modules/reporting/config.ini', + 'settings' => {}, + }) + } + + it { is_expected.not_to contain_exec('import icingaweb2::module::reporting schema') } + + it { + is_expected.to contain_class('icingaweb2::module::reporting::service') + .with_ensure('running') + .with_enable(true) + } + end + + context "#{os} with db_type 'mysql', import_schema 'true'" do + let(:params) do + { db_type: 'mysql', + import_schema: true } + end + + it { is_expected.to contain_exec('import icingaweb2::module::reporting schema') } + end + + context "#{os} with db_type 'pgsql', mail 'foobar@examle.com', manage_service 'false', install_method 'package'" do + let(:params) do + { install_method: 'package', + db_type: 'pgsql', + manage_service: false, + mail: 'foobar@example.com' } + end + + it { + is_expected.to contain_icingaweb2__resource__database('reporting') + .with_type('pgsql') + .with_host('localhost') + .with_database('reporting') + .with_username('reporting') + .with_charset('UTF8') + } + + it { + is_expected.to contain_icingaweb2__module('reporting') + .with_install_method('package') + .with_package_name('icingaweb2-module-reporting') + .with_module_dir('/usr/share/icingaweb2/modules/reporting') + .with_settings('icingaweb2-module-reporting-backend' => { + 'section_name' => 'backend', + 'target' => '/etc/icingaweb2/modules/reporting/config.ini', + 'settings' => { + 'resource' => 'reporting', + }, + }, + 'icingaweb2-module-reporting-mail' => { + 'section_name' => 'mail', + 'target' => '/etc/icingaweb2/modules/reporting/config.ini', + 'settings' => { + 'from' => 'foobar@example.com', + }, + }) + } + + it { is_expected.not_to contain_exec('import icingaweb2::module::reporting schema') } + it { is_expected.not_to contain_class('icingaweb2::module::reporting::service') } + end + + context "#{os} with db_type 'pgsql', import_schema 'true'" do + let(:params) do + { db_type: 'pgsql', + import_schema: true } + end + + it { is_expected.to contain_exec('import icingaweb2::module::reporting schema') } + end + end + end +end diff --git a/spec/classes/vspheredb_service_spec.rb b/spec/classes/vspheredb_service_spec.rb index df585aa7..3f7af32f 100644 --- a/spec/classes/vspheredb_service_spec.rb +++ b/spec/classes/vspheredb_service_spec.rb @@ -4,7 +4,7 @@ let(:pre_condition) do [ "class { 'icingaweb2': db_type => 'mysql' }", - "class { 'icingaweb2::module::vspheredb': db_type => 'mysql' }", + "class { 'icingaweb2::module::vspheredb': db_type => 'mysql', manage_service => false }", ] end diff --git a/spec/classes/vspheredb_spec.rb b/spec/classes/vspheredb_spec.rb index 59449cea..0916618b 100644 --- a/spec/classes/vspheredb_spec.rb +++ b/spec/classes/vspheredb_spec.rb @@ -13,9 +13,9 @@ facts end - context "#{os} with git_revision 'v1.1.0'" do + context "#{os} with git_revision 'v1.7.1'" do let(:params) do - { git_revision: 'v1.1.0', + { git_revision: 'v1.7.1', db_type: 'mysql', db_host: 'localhost', db_name: 'vspheredb', @@ -37,7 +37,7 @@ it { is_expected.to contain_icingaweb2__module('vspheredb') .with_install_method('git') - .with_git_revision('v1.1.0') + .with_git_revision('v1.7.1') .with_package_name('icingaweb2-module-vspheredb') .with_settings('icingaweb2-module-vspheredb' => { 'section_name' => 'db', @@ -47,6 +47,33 @@ }, }) } + + it { + is_expected.to contain_class('icingaweb2::module::vspheredb::service') + .with_ensure('running') + .with_enable(true) + } + end + + context "#{os} with install_method 'package', manage_service 'false'" do + let(:params) do + { install_method: 'package', + manage_service: false, + db_type: 'mysql', + db_host: 'localhost', + db_name: 'vspheredb', + db_username: 'vspheredb', + db_password: 'vspheredb' } + end + + it { + is_expected.to contain_package('icingaweb2-module-vspheredb') + .with_ensure('installed') + } + + it { + is_expected.not_to contain_class('icingaweb2::module::vspheredb::service') + } end end end