diff --git a/manifests/config.pp b/manifests/config.pp index 564fc8f2d..4b60e32e6 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -13,9 +13,7 @@ # class icinga2::config { - if defined($caller_module_name) and $module_name != $caller_module_name { - fail("icinga2::config is a private class of the module icinga2, you're not permitted to use it.") - } + assert_private() $constants = prefix($::icinga2::_constants, 'const ') $conf_dir = $::icinga2::params::conf_dir diff --git a/manifests/debian/dbconfig.pp b/manifests/debian/dbconfig.pp index 24ab14fc1..99cb81f17 100644 --- a/manifests/debian/dbconfig.pp +++ b/manifests/debian/dbconfig.pp @@ -8,9 +8,7 @@ $ssl = false, ) { - if defined($caller_module_name) and $module_name != $caller_module_name and $caller_module_name != '' { - fail("icinga2::debian::dbconfig is a private define resource of the module icinga2, you're not permitted to use it.") - } + assert_private() validate_re($dbtype, [ '^mysql$', '^pgsql$' ], "${dbtype} isn't supported. Valid values are 'mysql' and 'pgsql'.") diff --git a/manifests/feature.pp b/manifests/feature.pp index b50ec2afa..d886d2649 100644 --- a/manifests/feature.pp +++ b/manifests/feature.pp @@ -8,13 +8,7 @@ $feature = $title, ) { - if defined($caller_module_name) and $module_name != $caller_module_name and $caller_module_name != '' { - fail("icinga2::feature is a private define resource of the module icinga2, you're not permitted to use it.") - } - - if ! defined(Class['::icinga2']) { - fail('You must include the icinga2 base class before using any icinga2 feature class!') - } + assert_private() validate_re($ensure, [ '^present$', '^absent$' ], "${ensure} isn't supported. Valid values are 'present' and 'absent'.") diff --git a/manifests/install.pp b/manifests/install.pp index 3d0c9d278..71c057394 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -14,9 +14,7 @@ # class icinga2::install { - if defined($caller_module_name) and $module_name != $caller_module_name { - fail("icinga2::install is a private class of the module icinga2, you're not permitted to use it.") - } + assert_private() $package = $::icinga2::params::package $conf_dir = $::icinga2::params::conf_dir diff --git a/manifests/object.pp b/manifests/object.pp index 6c356de3c..8fced1297 100644 --- a/manifests/object.pp +++ b/manifests/object.pp @@ -77,9 +77,7 @@ $attrs = {}, ) { - if defined($caller_module_name) and $module_name != $caller_module_name and $caller_module_name != '' { - fail("icinga2::object is a private define resource of the module icinga2, you're not permitted to use it.") - } + assert_private() include ::icinga2::params diff --git a/manifests/repo.pp b/manifests/repo.pp index 4fd01a86c..897e445b8 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -16,9 +16,7 @@ # class icinga2::repo { - if defined($caller_module_name) and $module_name != $caller_module_name { - fail("icinga2::repo is a private class of the module icinga2, you're not permitted to use it.") - } + assert_private() if $::icinga2::manage_repo and $::icinga2::manage_package { diff --git a/manifests/service.pp b/manifests/service.pp index 04c664b2b..b06c542dd 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -16,9 +16,7 @@ # class icinga2::service { - if defined($caller_module_name) and $module_name != $caller_module_name { - fail("icinga2::service is a private class of the module icinga2, you're not permitted to use it.") - } + assert_private() $ensure = $::icinga2::ensure $enable = $::icinga2::enable diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fda28e6bc..70db1fba0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,4 +10,9 @@ default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__)) default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__)) c.default_facts = default_facts + + c.before(:each) do + # Stub assert_private function from stdlib to not fail within this test + Puppet::Parser::Functions.newfunction(:assert_private) { |_| } + end end