puppetlabs-puppetdb
puppetlabs-puppetdb copied to clipboard
Set data types for puppetdb parameters
Summary: Enable data type validation for parameters in puppetdb classes and defined types. The goal is to refine user inputs to reduce risk of misconfiguration or failure to apply.
Each data type was configured based on default values supplied within the params.pp class, unit/acceptance tests and alternative values recommended in PuppetDB docs.
Changes:
- Data types have been added to the parameters for both classes and defined types
- Stdlib types provide validation for complex inputs (e.g.
Stdlib::Host,Stdlib::Port::User) - Data values supplied by unit and acceptance tests were reviewed to ensure parameters supported expected input value types
- Unit test param inputs refined to support expected data types.
Potential for Breaking Change:
- Data type validation may render some user inputs invalid (i.e. Strings provided where Integer expected).
- To guard against this some parameters use
Variantto support historicalStringusage withPatternmatching
Related Issues: resolves #105
Testing:
- [x] Mend tests are expected to fail on forked repositories due to missing secrets.
- [x] All CI tests (unit and acceptance) are passing.
FWIW, I would remove the maintenance label so the change does show up in the change log and release notes.
As open_ssl_listen_port is no longer optional both params.pp and the unit test shared-examples have been updated to default to false instead of undef|nil.
is there any blocker in getting this PR merged now that's approved?
is there any blocker in getting this PR merged now that's approved?
Should be good to go, I haven't had a chance to test on live node so I haven't merged. Passing all unit tests.
Tested changes with a development environment Puppetserver. Confirmed invalid data such as the example from #105 will return a compile time error.
class { 'puppetdb':
listen_port => 'localhost',
}
$ puppet agent -t
Info: Using environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Notice: Requesting catalog from puppet:8140 (127.0.0.1)
Notice: Catalog compiled by puppet-testing
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Class[Puppetdb]: parameter 'listen_port' expects a value of type Stdlib::Port::User = Integer[1024, 49151] or Pattern[/\A[0-9]+\Z/], got String (file: /etc/puppet/code/environments/production/manifests/site.pp, line: 32, column: 3) on node puppet-testing
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
When data is valid, this module works as expected compiling and implementing changes. Confirmed working with Strings and Integers with pattern matching (where used).
class { 'puppetdb':
ssl_listen_port => 8000, # or '8000'
}
class { 'puppetdb::master::config':
puppetdb_port => 8000, # or '8000'
}
puppet agent -t
Info: Using environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Notice: Requesting catalog from puppet:8140 (127.0.0.1)
Notice: Catalog compiled by puppet-testing
Info: Caching catalog for puppet-testing
Info: Applying configuration version '1760595330'
Notice: /Stage[main]/Puppetdb::Server::Jetty/Ini_setting[puppetdb_sslport]/value: value changed 8081 to 8000
Info: Class[Puppetdb::Server::Jetty]: Scheduling refresh of Service[puppetdb]
Notice: /Stage[main]/Puppetdb::Server/Service[puppetdb]: Triggered 'refresh' from 1 event
Notice: /Stage[main]/Puppetdb::Master::Puppetdb_conf/Ini_setting[puppetdbserver_urls]/value: value changed https://puppet-testing:8081/ to https://puppet-testing:8000/
Info: Class[Puppetdb::Master::Puppetdb_conf]: Scheduling refresh of Service[puppetserver]
Notice: /Stage[main]/Puppetdb::Master::Config/Service[puppetserver]: Triggered 'refresh' from 1 event
Notice: Applied catalog in 43.43 seconds