From cec85912c6f85b471e933bed662184c1cdd80aab Mon Sep 17 00:00:00 2001 From: Evgeny Soynov Date: Tue, 6 Oct 2020 10:34:22 +0200 Subject: [PATCH] Change set_parameter to be either as a string or an array --- manifests/server.pp | 158 ++++++++++++++++----------------- spec/classes/server_spec.rb | 14 ++- templates/mongodb.conf.2.6.erb | 6 +- 3 files changed, 95 insertions(+), 83 deletions(-) diff --git a/manifests/server.pp b/manifests/server.pp index 9872580e6..9e0ec7d49 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -1,84 +1,84 @@ # This installs a MongoDB server. See README.md for more details. class mongodb::server ( - Variant[Boolean, String] $ensure = $mongodb::params::ensure, - String $user = $mongodb::params::user, - String $group = $mongodb::params::group, - Stdlib::Absolutepath $config = $mongodb::params::config, - Stdlib::Absolutepath $dbpath = $mongodb::params::dbpath, - Boolean $dbpath_fix = $mongodb::params::dbpath_fix, - Optional[Stdlib::Absolutepath] $pidfilepath = $mongodb::params::pidfilepath, - String $pidfilemode = $mongodb::params::pidfilemode, - Boolean $manage_pidfile = $mongodb::params::manage_pidfile, - String $rcfile = $mongodb::params::rcfile, - Boolean $service_manage = $mongodb::params::service_manage, - Optional[String] $service_provider = $mongodb::params::service_provider, - Optional[String] $service_name = $mongodb::params::service_name, - Boolean $service_enable = $mongodb::params::service_enable, - Enum['stopped', 'running'] $service_ensure = $mongodb::params::service_ensure, - Optional[Enum['stopped', 'running']] $service_status = $mongodb::params::service_status, - Variant[Boolean, String] $package_ensure = $mongodb::params::package_ensure, - String $package_name = $mongodb::params::server_package_name, - Variant[Boolean, Stdlib::Absolutepath] $logpath = $mongodb::params::logpath, - Array[Stdlib::Compat::Ip_address] $bind_ip = $mongodb::params::bind_ip, - Optional[Boolean] $ipv6 = undef, - Boolean $logappend = true, - Optional[String] $system_logrotate = undef, - Optional[Boolean] $fork = $mongodb::params::fork, - Optional[Integer[1, 65535]] $port = undef, - Optional[Boolean] $journal = $mongodb::params::journal, - Optional[Boolean] $nojournal = undef, - Optional[Boolean] $smallfiles = undef, - Optional[Boolean] $cpu = undef, - Boolean $auth = false, - Optional[Boolean] $noauth = undef, - Optional[Boolean] $verbose = undef, - Optional[String] $verbositylevel = undef, - Optional[Boolean] $objcheck = undef, - Optional[Boolean] $quota = undef, - Optional[Integer] $quotafiles = undef, - Optional[Integer[0, 7]] $diaglog = undef, - Optional[Boolean] $directoryperdb = undef, - $profile = undef, - Optional[Integer] $maxconns = undef, - Optional[Integer] $oplog_size = undef, - $nohints = undef, - Optional[Boolean] $nohttpinterface = undef, - Optional[Boolean] $noscripting = undef, - Optional[Boolean] $notablescan = undef, - Optional[Boolean] $noprealloc = undef, - Optional[Integer] $nssize = undef, - $mms_token = undef, - $mms_name = undef, - $mms_interval = undef, - Optional[String] $replset = undef, - Optional[Hash] $replset_config = undef, - Optional[Array] $replset_members = undef, - Optional[Boolean] $configsvr = undef, - Optional[Boolean] $shardsvr = undef, - Optional[Boolean] $rest = undef, - Optional[Boolean] $quiet = undef, - Optional[Integer] $slowms = undef, - Optional[Stdlib::Absolutepath] $keyfile = undef, - Optional[String[6]] $key = undef, - Optional[String] $set_parameter = undef, - Optional[Boolean] $syslog = undef, - $config_content = undef, - Optional[String] $config_template = undef, - Optional[Hash] $config_data = undef, - Optional[Boolean] $ssl = undef, - Optional[Stdlib::Absolutepath] $ssl_key = undef, - Optional[Stdlib::Absolutepath] $ssl_ca = undef, - Boolean $ssl_weak_cert = false, - Boolean $ssl_invalid_hostnames = false, - Enum['requireSSL', 'preferSSL', 'allowSSL'] $ssl_mode = 'requireSSL', - Boolean $restart = $mongodb::params::restart, - Optional[String] $storage_engine = undef, - Boolean $create_admin = $mongodb::params::create_admin, - String $admin_username = $mongodb::params::admin_username, - Optional[String] $admin_password = undef, - Boolean $handle_creds = $mongodb::params::handle_creds, - Boolean $store_creds = $mongodb::params::store_creds, - Array $admin_roles = $mongodb::params::admin_roles, + Variant[Boolean, String] $ensure = $mongodb::params::ensure, + String $user = $mongodb::params::user, + String $group = $mongodb::params::group, + Stdlib::Absolutepath $config = $mongodb::params::config, + Stdlib::Absolutepath $dbpath = $mongodb::params::dbpath, + Boolean $dbpath_fix = $mongodb::params::dbpath_fix, + Optional[Stdlib::Absolutepath] $pidfilepath = $mongodb::params::pidfilepath, + String $pidfilemode = $mongodb::params::pidfilemode, + Boolean $manage_pidfile = $mongodb::params::manage_pidfile, + String $rcfile = $mongodb::params::rcfile, + Boolean $service_manage = $mongodb::params::service_manage, + Optional[String] $service_provider = $mongodb::params::service_provider, + Optional[String] $service_name = $mongodb::params::service_name, + Boolean $service_enable = $mongodb::params::service_enable, + Enum['stopped', 'running'] $service_ensure = $mongodb::params::service_ensure, + Optional[Enum['stopped', 'running']] $service_status = $mongodb::params::service_status, + Variant[Boolean, String] $package_ensure = $mongodb::params::package_ensure, + String $package_name = $mongodb::params::server_package_name, + Variant[Boolean, Stdlib::Absolutepath] $logpath = $mongodb::params::logpath, + Array[Stdlib::Compat::Ip_address] $bind_ip = $mongodb::params::bind_ip, + Optional[Boolean] $ipv6 = undef, + Boolean $logappend = true, + Optional[String] $system_logrotate = undef, + Optional[Boolean] $fork = $mongodb::params::fork, + Optional[Integer[1, 65535]] $port = undef, + Optional[Boolean] $journal = $mongodb::params::journal, + Optional[Boolean] $nojournal = undef, + Optional[Boolean] $smallfiles = undef, + Optional[Boolean] $cpu = undef, + Boolean $auth = false, + Optional[Boolean] $noauth = undef, + Optional[Boolean] $verbose = undef, + Optional[String] $verbositylevel = undef, + Optional[Boolean] $objcheck = undef, + Optional[Boolean] $quota = undef, + Optional[Integer] $quotafiles = undef, + Optional[Integer[0, 7]] $diaglog = undef, + Optional[Boolean] $directoryperdb = undef, + $profile = undef, + Optional[Integer] $maxconns = undef, + Optional[Integer] $oplog_size = undef, + $nohints = undef, + Optional[Boolean] $nohttpinterface = undef, + Optional[Boolean] $noscripting = undef, + Optional[Boolean] $notablescan = undef, + Optional[Boolean] $noprealloc = undef, + Optional[Integer] $nssize = undef, + $mms_token = undef, + $mms_name = undef, + $mms_interval = undef, + Optional[String] $replset = undef, + Optional[Hash] $replset_config = undef, + Optional[Array] $replset_members = undef, + Optional[Boolean] $configsvr = undef, + Optional[Boolean] $shardsvr = undef, + Optional[Boolean] $rest = undef, + Optional[Boolean] $quiet = undef, + Optional[Integer] $slowms = undef, + Optional[Stdlib::Absolutepath] $keyfile = undef, + Optional[String[6]] $key = undef, + Optional[Variant[String[1], Array[String[1]]]] $set_parameter = undef, + Optional[Boolean] $syslog = undef, + $config_content = undef, + Optional[String] $config_template = undef, + Optional[Hash] $config_data = undef, + Optional[Boolean] $ssl = undef, + Optional[Stdlib::Absolutepath] $ssl_key = undef, + Optional[Stdlib::Absolutepath] $ssl_ca = undef, + Boolean $ssl_weak_cert = false, + Boolean $ssl_invalid_hostnames = false, + Enum['requireSSL', 'preferSSL', 'allowSSL'] $ssl_mode = 'requireSSL', + Boolean $restart = $mongodb::params::restart, + Optional[String] $storage_engine = undef, + Boolean $create_admin = $mongodb::params::create_admin, + String $admin_username = $mongodb::params::admin_username, + Optional[String] $admin_password = undef, + Boolean $handle_creds = $mongodb::params::handle_creds, + Boolean $store_creds = $mongodb::params::store_creds, + Array $admin_roles = $mongodb::params::admin_roles, ) inherits mongodb::params { contain mongodb::server::install contain mongodb::server::config diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 05fa01d79..90a5d9d70 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -152,14 +152,24 @@ it { is_expected.to contain_file('/root/.mongorc.js') } end - describe 'when specifying set_parameter value' do + describe 'when specifying set_parameter array value' do + let :params do + { + set_parameter: ['textSearchEnable=true'] + } + end + + it { is_expected.to contain_file(config_file).with_content(%r{^setParameter:\n textSearchEnable=true}) } + end + + describe 'when specifying set_parameter string value' do let :params do { set_parameter: 'textSearchEnable=true' } end - it { is_expected.to contain_file(config_file).with_content(%r{^setParameter: textSearchEnable=true}) } + it { is_expected.to contain_file(config_file).with_content(%r{^setParameter:\n textSearchEnable=true}) } end describe 'with journal:' do diff --git a/templates/mongodb.conf.2.6.erb b/templates/mongodb.conf.2.6.erb index 3da682a77..32c38be3f 100644 --- a/templates/mongodb.conf.2.6.erb +++ b/templates/mongodb.conf.2.6.erb @@ -150,9 +150,11 @@ operationProfiling.mode: all operationProfiling.slowOpThresholdMs: <%= @slowms %> <% end -%> - <% if @set_parameter -%> -setParameter: <%= @set_parameter %> +setParameter: +<% [@set_parameter].flatten.each do |v| -%> + <%= v %> +<% end -%> <% end -%> <% if @config_data -%>