diff --git a/manifests/management/mongodb.pp b/manifests/management/mongodb.pp new file mode 100644 index 0000000..b118d81 --- /dev/null +++ b/manifests/management/mongodb.pp @@ -0,0 +1,89 @@ +# == class: zaqar::management::mongodb +# +# [*uri*] +# Mongodb Connection URI. Required. +# +# [*ssl_keyfile*] +# The private keyfile used to identify the local connection against +# mongod. Default $::os_service_default +# Defaults to $::os_service_default. +# +# [*ssl_certfile*] +# The certificate file used to identify the local connection against +# mongod. (string value) +# Defaults to $::os_service_default. +# +# [*ssl_cert_reqs*] +# Specifies whether a certificate is required from the other side of +# the connection, and whether it will be validated if provided. It +# must be one of the three values ``CERT_NONE``(certificates ignored), +# ``CERT_OPTIONAL``(not required, but validated if provided), or +# ``CERT_REQUIRED``(required and validated). +# Defaults to $::os_service_default. +# +# [*ssl_ca_certs*] +# The ca_certs file contains a set of concatenated "certification +# authority" certificates, which are used to validate certificates +# passed from the other end of the connection. +# Defaults to $::os_service_default. +# +# [*database*] +# Database name. (string value). Defaults to $::os_service_default. +# +# [*max_attempts*] +# Maximum number of times to retry a failed operation. Currently only +# used for retrying a message post. +# Defaults to $::os_service_default. +# +# [*max_retry_sleep*] +# Maximum sleep interval between retries (actual sleep time increases +# linearly according to number of attempts performed). +# Defaults to $::os_service_default. +# +# [*max_retry_jitter*] +# Maximum jitter interval, to be added to the sleep interval, in order +# to decrease probability that parallel requests will retry at the +# same instant. (floating point value) +# Defaults to $::os_service_default. +# +# [*max_reconnect_attempts*] +# Maximum number of times to retry an operation that failed due to a +# primary node failover. (integer value) +# Defaults to $::os_service_default. +# +# [*reconnect_sleep*] +# Base sleep interval between attempts to reconnect after a primary +# node failover. The actual sleep time increases exponentially (power +# of 2) each time the operation is retried. (floating point value) +# Defaults to $::os_service_default. +# +class zaqar::management::mongodb( + $uri, + $ssl_keyfile = $::os_service_default, + $ssl_certfile = $::os_service_default, + $ssl_cert_reqs = $::os_service_default, + $ssl_ca_certs = $::os_service_default, + $database = $::os_service_default, + $max_attempts = $::os_service_default, + $max_retry_sleep = $::os_service_default, + $max_retry_jitter = $::os_service_default, + $max_reconnect_attempts = $::os_service_default, + $reconnect_sleep = $::os_service_default, +) { + + zaqar_config { + 'drivers/management_store': value => 'mongodb'; + 'drivers:management_store:mongodb/uri': value => $uri, secret => true; + 'drivers:management_store:mongodb/ssl_keyfile': value => $ssl_keyfile; + 'drivers:management_store:mongodb/ssl_certfile': value => $ssl_certfile; + 'drivers:management_store:mongodb/ssl_cert_reqs': value => $ssl_cert_reqs; + 'drivers:management_store:mongodb/ssl_ca_certs': value => $ssl_ca_certs; + 'drivers:management_store:mongodb/database': value => $database; + 'drivers:management_store:mongodb/max_attempts': value => $max_attempts; + 'drivers:management_store:mongodb/max_retry_sleep': value => $max_retry_sleep; + 'drivers:management_store:mongodb/max_retry_jitter': value => $max_retry_jitter; + 'drivers:management_store:mongodb/max_reconnect_attempts': value => $max_reconnect_attempts; + 'drivers:management_store:mongodb/reconnect_sleep': value => $reconnect_sleep; + } + +} diff --git a/spec/classes/zaqar_management_mongodb_spec.rb b/spec/classes/zaqar_management_mongodb_spec.rb new file mode 100644 index 0000000..443b973 --- /dev/null +++ b/spec/classes/zaqar_management_mongodb_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe 'zaqar::management::mongodb' do + + let :req_params do + { + :uri => 'mongodb://127.0.0.1:27017', + } + end + + let :facts do + { :osfamily => 'RedHat' } + end + + describe 'with only required params' do + let :params do + req_params + end + + it 'should config mongo management driver' do + is_expected.to contain_zaqar_config('drivers/management_store').with( + :value => 'mongodb' + ) + is_expected.to contain_zaqar_config('drivers:management_store:mongodb/uri').with( + :value => 'mongodb://127.0.0.1:27017' + ) + end + + end + + describe 'with custom values' do + let :params do + req_params.merge!({ + :ssl_keyfile => 'keyfile', + :ssl_certfile => 'certfile', + :ssl_cert_reqs => 'cert_reqs', + :ssl_ca_certs => 'ca_certs', + :database => 'zaqar_db', + :max_attempts => '1', + :max_retry_sleep => '2', + :max_retry_jitter => '3', + :max_reconnect_attempts => '4', + :reconnect_sleep => '5', + }) + end + + it 'configures custom values' do + is_expected.to contain_zaqar_config('drivers:management_store:mongodb/ssl_keyfile').with_value('keyfile') + is_expected.to contain_zaqar_config('drivers:management_store:mongodb/ssl_certfile').with_value('certfile') + is_expected.to contain_zaqar_config('drivers:management_store:mongodb/ssl_cert_reqs').with_value('cert_reqs') + is_expected.to contain_zaqar_config('drivers:management_store:mongodb/ssl_ca_certs').with_value('ca_certs') + is_expected.to contain_zaqar_config('drivers:management_store:mongodb/database').with_value('zaqar_db') + is_expected.to contain_zaqar_config('drivers:management_store:mongodb/max_attempts').with_value('1') + is_expected.to contain_zaqar_config('drivers:management_store:mongodb/max_retry_sleep').with_value('2') + is_expected.to contain_zaqar_config('drivers:management_store:mongodb/max_retry_jitter').with_value('3') + is_expected.to contain_zaqar_config('drivers:management_store:mongodb/max_reconnect_attempts').with_value('4') + is_expected.to contain_zaqar_config('drivers:management_store:mongodb/reconnect_sleep').with_value('5') + end + end + +end