Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new param manage_service for all module background daemons to start automatically #379

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

##### <a name="-icingaweb2--module--director--ensure"></a>`ensure`

Expand Down Expand Up @@ -1279,6 +1280,14 @@ Icinga 2 API password. This setting is only valid if `kickstart` is `true`.

Default value: `undef`

##### <a name="-icingaweb2--module--director--manage_service"></a>`manage_service`

Data type: `Boolean`

Also manage the service (daemon), running and enabled. Otherwise do your config via hiera.

Default value: `true`

### <a name="icingaweb2--module--director--service"></a>`icingaweb2::module::director::service`

Installs and configures the director service.
Expand Down Expand Up @@ -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)

##### <a name="-icingaweb2--module--reporting--ensure"></a>`ensure`

Expand Down Expand Up @@ -3186,6 +3196,14 @@ Mails are sent with this sender address.

Default value: `undef`

##### <a name="-icingaweb2--module--reporting--manage_service"></a>`manage_service`

Data type: `Boolean`

Also manage the service (daemon), running and enabled. Otherwise do your config via hiera.

Default value: `true`

### <a name="icingaweb2--module--reporting--service"></a>`icingaweb2::module::reporting::service`

Installs and configures the reporting scheduler.
Expand Down Expand Up @@ -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)

##### <a name="-icingaweb2--module--vspheredb--ensure"></a>`ensure`

Expand Down Expand Up @@ -3513,6 +3532,14 @@ whereas with mysql its different options.

Default value: `false`

##### <a name="-icingaweb2--module--vspheredb--manage_service"></a>`manage_service`

Data type: `Boolean`

Also manage the service (daemon), running and enabled. Otherwise do your config via hiera.

Default value: `true`

### <a name="icingaweb2--module--vspheredb--service"></a>`icingaweb2::module::vspheredb::service`

Installs and configures the vspheredb service.
Expand Down
8 changes: 8 additions & 0 deletions manifests/module/director.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -252,4 +256,8 @@
package_name => $package_name,
settings => $db_settings + $kickstart_settings,
}

if $manage_service {
include icingaweb2::module::director::service
}
}
8 changes: 8 additions & 0 deletions manifests/module/reporting.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -237,4 +241,8 @@
}
}
} # schema import

if $manage_service {
include icingaweb2::module::reporting::service
}
}
8 changes: 8 additions & 0 deletions manifests/module/vspheredb.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand Down Expand Up @@ -216,4 +220,8 @@
}
}
} # schema import

if $manage_service {
include icingaweb2::module::vspheredb::service
}
}
2 changes: 1 addition & 1 deletion spec/classes/director_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 12 additions & 1 deletion spec/classes/director_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,25 @@
})
}

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',
db_host: 'localhost',
db_name: 'director',
db_username: 'director',
db_password: 'director',
manage_service: false,
import_schema: false }
end

Expand Down Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions spec/classes/reporting_service_spec.rb
Original file line number Diff line number Diff line change
@@ -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
120 changes: 120 additions & 0 deletions spec/classes/reporting_spec.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/classes/vspheredb_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading