Skip to content

Commit

Permalink
reporting, vspheredb modules: move config setting to config sub class
Browse files Browse the repository at this point in the history
  • Loading branch information
lbetz committed Nov 6, 2023
1 parent 8af8ff2 commit 72a4567
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 49 deletions.
20 changes: 19 additions & 1 deletion manifests/module/reporting.pp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@
) {
icingaweb2::assert_module()

$cert_dir = "${icingaweb2::globals::state_dir}/reporting/certs"
$module_conf_dir = "${icingaweb2::globals::conf_dir}/modules/reporting"
$cert_dir = "${icingaweb2::globals::state_dir}/reporting/certs"

$db = {
type => $db_type,
Expand All @@ -156,6 +157,23 @@
$tls_cacert,
)

$settings = {
'icingaweb2-module-reporting-backend' => {
'section_name' => 'backend',
'target' => "${module_conf_dir}/config.ini",
'settings' => {
'resource' => 'reporting',
},
},
'icingaweb2-module-reporting-mail' => {
'section_name' => 'mail',
'target' => "${module_conf_dir}/config.ini",
'settings' => delete_undef_values({
'from' => $mail,
}),
},
}

class { 'icingaweb2::module::reporting::install': }
-> class { 'icingaweb2::module::reporting::config': }
~> class { 'icingaweb2::module::reporting::service': }
Expand Down
3 changes: 3 additions & 0 deletions manifests/module/reporting/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$icingacli_bin = $icingaweb2::globals::icingacli_bin
$service_user = $icingaweb2::module::reporting::service_user
$install_method = $icingaweb2::module::reporting::install_method
$settings = $icingaweb2::module::reporting::settings

Exec {
user => 'root',
Expand Down Expand Up @@ -56,6 +57,8 @@
tls_cipher => $tls['cipher'],
}

create_resources('icingaweb2::inisection', $settings)

if $import_schema {
$real_db_type = if $import_schema =~ Boolean {
if $db['type'] == 'pgsql' { 'pgsql' } else { 'mariadb' }
Expand Down
18 changes: 0 additions & 18 deletions manifests/module/reporting/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
class icingaweb2::module::reporting::install {
assert_private()

$module_conf_dir = "${icingaweb2::globals::conf_dir}/modules/reporting"
$conf_user = $icingaweb2::conf_user
$conf_group = $icingaweb2::conf_group
$ensure = $icingaweb2::module::reporting::ensure
Expand All @@ -19,7 +18,6 @@
$tls = $icingaweb2::module::reporting::tls
$cert_dir = $icingaweb2::module::reporting::cert_dir
$service_user = $icingaweb2::module::reporting::service_user
$mail = $icingaweb2::module::reporting::mail

icingaweb2::module { 'reporting':
ensure => $ensure,
Expand All @@ -28,22 +26,6 @@
install_method => $install_method,
module_dir => $module_dir,
package_name => $package_name,
settings => {
'icingaweb2-module-reporting-backend' => {
'section_name' => 'backend',
'target' => "${module_conf_dir}/config.ini",
'settings' => {
'resource' => 'reporting',
},
},
'icingaweb2-module-reporting-mail' => {
'section_name' => 'mail',
'target' => "${module_conf_dir}/config.ini",
'settings' => delete_undef_values({
'from' => $mail,
}),
},
},
}

if $use_tls {
Expand Down
13 changes: 12 additions & 1 deletion manifests/module/vspheredb.pp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@
) {
icingaweb2::assert_module()

$cert_dir = "${icingaweb2::globals::state_dir}/vspheredb/certs"
$module_conf_dir = "${icingaweb2::globals::conf_dir}/modules/vspheredb"
$cert_dir = "${icingaweb2::globals::state_dir}/vspheredb/certs"

$db = {
type => $db_type,
Expand All @@ -152,6 +153,16 @@
$tls_cacert,
)

$settings = {
'icingaweb2-module-vspheredb' => {
'section_name' => 'db',
'target' => "${module_conf_dir}/config.ini",
'settings' => {
'resource' => 'icingaweb2-module-vspheredb',
},
},
}

class { 'icingaweb2::module::vspheredb::install': }
-> class { 'icingaweb2::module::vspheredb::config': }
~> class { 'icingaweb2::module::vspheredb::service': }
Expand Down
3 changes: 3 additions & 0 deletions manifests/module/vspheredb/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$icingacli_bin = $icingaweb2::globals::icingacli_bin
$service_user = $icingaweb2::module::vspheredb::service_user
$install_method = $icingaweb2::module::vspheredb::install_method
$settings = $icingaweb2::module::vspheredb::settings

Exec {
user => 'root',
Expand Down Expand Up @@ -59,6 +60,8 @@
tls_cipher => $tls['cipher'],
}

create_resources('icingaweb2::inisection', $settings)

if $import_schema {
$real_db_type = if $import_schema =~ Boolean {
if $db['type'] == 'pgsql' { 'pgsql' } else { 'mariadb' }
Expand Down
10 changes: 0 additions & 10 deletions manifests/module/vspheredb/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
class icingaweb2::module::vspheredb::install {
assert_private()

$module_conf_dir = "${icingaweb2::globals::conf_dir}/modules/vspheredb"
$conf_user = $icingaweb2::conf_user
$conf_group = $icingaweb2::conf_group
$ensure = $icingaweb2::module::vspheredb::ensure
Expand All @@ -27,15 +26,6 @@
install_method => $install_method,
module_dir => $module_dir,
package_name => $package_name,
settings => {
'icingaweb2-module-vspheredb' => {
'section_name' => 'db',
'target' => "${module_conf_dir}/config.ini",
'settings' => {
'resource' => 'icingaweb2-module-vspheredb',
},
},
},
}

if $use_tls {
Expand Down
26 changes: 14 additions & 12 deletions spec/classes/modules/reporting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,20 @@
.with_install_method('git')
.with_git_revision('v1.0.0')
.with_package_name('icingaweb2-module-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' => 'foo@icinga.com' },
})
}

it {
is_expected.to contain_icingaweb2__inisection('icingaweb2-module-reporting-backend')
.with_section_name('backend')
.with_target('/etc/icingaweb2/modules/reporting/config.ini')
.with_settings({ 'resource' => 'reporting' })
}

it {
is_expected.to contain_icingaweb2__inisection('icingaweb2-module-reporting-mail')
.with_section_name('mail')
.with_target('/etc/icingaweb2/modules/reporting/config.ini')
.with_settings({ 'from' => 'foo@icinga.com' })
}

it {
Expand Down
14 changes: 7 additions & 7 deletions spec/classes/modules/vspheredb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
.with_install_method('git')
.with_git_revision('v1.7.1')
.with_package_name('icingaweb2-module-vspheredb')
.with_settings('icingaweb2-module-vspheredb' => {
'section_name' => 'db',
'target' => '/etc/icingaweb2/modules/vspheredb/config.ini',
'settings' => {
'resource' => 'icingaweb2-module-vspheredb',
},
})
}

it {
is_expected.to contain_icingaweb2__inisection('icingaweb2-module-vspheredb')
.with_section_name('db')
.with_target('/etc/icingaweb2/modules/vspheredb/config.ini')
.with_settings({ 'resource' => 'icingaweb2-module-vspheredb' })
}

it {
Expand Down

0 comments on commit 72a4567

Please sign in to comment.