From 2990f80ef181e7d7b16a8e65a3a3dcbc4e983093 Mon Sep 17 00:00:00 2001 From: Wyatt Alt Date: Tue, 15 Sep 2015 15:21:33 -0700 Subject: [PATCH] (PDB-1913) manage vardir This updates the module to manage vardir, and also makes room for general management of the global ini section. --- manifests/params.pp | 12 ++++-- manifests/server.pp | 24 +++++------ .../{config_ini.pp => command_processing.pp} | 14 +++---- .../server/{database_ini.pp => database.pp} | 2 +- manifests/server/global.pp | 20 ++++++++++ manifests/server/{jetty_ini.pp => jetty.pp} | 2 +- ...{read_database_ini.pp => read_database.pp} | 2 +- ...ini_spec.rb => command_processing_spec.rb} | 22 +++++----- spec/unit/classes/server/database_ini_spec.rb | 4 +- .../classes/server/db_connection_uri_spec.rb | 4 +- spec/unit/classes/server/global_ini_spec.rb | 40 +++++++++++++++++++ spec/unit/classes/server/jetty_ini_spec.rb | 6 +-- 12 files changed, 108 insertions(+), 44 deletions(-) rename manifests/server/{config_ini.pp => command_processing.pp} (71%) rename manifests/server/{database_ini.pp => database.pp} (99%) create mode 100644 manifests/server/global.pp rename manifests/server/{jetty_ini.pp => jetty.pp} (98%) rename manifests/server/{read_database_ini.pp => read_database.pp} (98%) rename spec/unit/classes/server/{config_ini_spec.rb => command_processing_spec.rb} (74%) create mode 100644 spec/unit/classes/server/global_ini_spec.rb diff --git a/manifests/params.pp b/manifests/params.pp index a920c4f..6a9b745 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -70,21 +70,24 @@ class puppetdb::params inherits puppetdb::globals { case $::osfamily { 'RedHat', 'Suse', 'Archlinux','Debian': { $confdir = '/etc/puppetdb/conf.d' - $database_embedded_path = '/var/lib/puppetdb/db/db' + $vardir = '/var/lib/puppetdb' + $database_embedded_path = '${vardir}/db/db' $puppet_confdir = pick($settings::confdir,'/etc/puppet') $puppet_service_name = 'puppetmaster' $ssl_dir = '/etc/puppetdb/ssl' } 'OpenBSD': { $confdir = '/etc/puppetdb/conf.d' - $database_embedded_path = '/var/db/puppetdb/db/db' + $vardir = '/var/db/puppetdb' + $database_embedded_path = '${vardir}/db/db' $puppet_confdir = pick($settings::confdir,'/etc/puppet') $puppet_service_name = 'puppetmasterd' $ssl_dir = '/etc/puppetdb/ssl' } 'FreeBSD': { $confdir = '/usr/local/etc/puppetdb/conf.d' - $database_embedded_path = '/var/db/puppetdb/db/db' + $vardir = '/var/db/puppetdb' + $database_embedded_path = '${vardir}/db/db' $puppet_confdir = pick($settings::confdir,'/usr/local/etc/puppet') $puppet_service_name = 'puppetmaster' $ssl_dir = '/usr/local/etc/puppetdb/ssl' @@ -115,7 +118,8 @@ class puppetdb::params inherits puppetdb::globals { } $terminus_package = 'puppetdb-termini' $test_url = '/pdb/meta/v1/version' - $database_embedded_path = '/opt/puppetlabs/server/data/puppetdb/db/db' + $vardir = '/opt/puppetlabs/server/data/puppetdb' + $database_embedded_path = '${vardir}/db/db' } case $::osfamily { diff --git a/manifests/server.pp b/manifests/server.pp index 7ffc354..6856925 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -131,7 +131,7 @@ class puppetdb::server ( } } - class { 'puppetdb::server::config_ini': + class { 'puppetdb::server::command_processing': command_threads => $command_threads, store_usage => $store_usage, temp_usage => $temp_usage, @@ -139,7 +139,7 @@ class puppetdb::server ( notify => Service[$puppetdb_service], } - class { 'puppetdb::server::database_ini': + class { 'puppetdb::server::database': database => $database, database_host => $database_host, database_port => $database_port, @@ -162,7 +162,7 @@ class puppetdb::server ( notify => Service[$puppetdb_service], } - class { 'puppetdb::server::read_database_ini': + class { 'puppetdb::server::read_database': database => $read_database, database_host => $read_database_host, database_port => $read_database_port, @@ -218,7 +218,7 @@ class puppetdb::server ( } } - class { 'puppetdb::server::jetty_ini': + class { 'puppetdb::server::jetty': listen_address => $listen_address, listen_port => $listen_port, ssl_listen_address => $ssl_listen_address, @@ -258,17 +258,17 @@ class puppetdb::server ( if $manage_firewall { Package[$puppetdb_package] -> Class['puppetdb::server::firewall'] -> - Class['puppetdb::server::config_ini'] -> - Class['puppetdb::server::database_ini'] -> - Class['puppetdb::server::read_database_ini'] -> - Class['puppetdb::server::jetty_ini'] -> + Class['puppetdb::server::command_processing'] -> + Class['puppetdb::server::database'] -> + Class['puppetdb::server::read_database'] -> + Class['puppetdb::server::jetty'] -> Service[$puppetdb_service] } else { Package[$puppetdb_package] -> - Class['puppetdb::server::config_ini'] -> - Class['puppetdb::server::database_ini'] -> - Class['puppetdb::server::read_database_ini'] -> - Class['puppetdb::server::jetty_ini'] -> + Class['puppetdb::server::command_processing'] -> + Class['puppetdb::server::database'] -> + Class['puppetdb::server::read_database'] -> + Class['puppetdb::server::jetty'] -> Service[$puppetdb_service] } } diff --git a/manifests/server/config_ini.pp b/manifests/server/command_processing.pp similarity index 71% rename from manifests/server/config_ini.pp rename to manifests/server/command_processing.pp index a28ebef..db1f8df 100644 --- a/manifests/server/config_ini.pp +++ b/manifests/server/command_processing.pp @@ -1,5 +1,5 @@ # PRIVATE CLASS - do not use directly -class puppetdb::server::config_ini ( +class puppetdb::server::command_processing ( $command_threads = $puppetdb::params::command_threads, $store_usage = $puppetdb::params::store_usage, $temp_usage = $puppetdb::params::temp_usage, @@ -21,36 +21,36 @@ class puppetdb::server::config_ini ( } if $command_threads { - ini_setting { 'puppetdb_config_command_processing_threads': + ini_setting { 'puppetdb_command_processing_threads': setting => 'threads', value => $command_threads, } } else { - ini_setting { 'puppetdb_config_command_processing_threads': + ini_setting { 'puppetdb_command_processing_threads': ensure => 'absent', setting => 'threads', } } if $store_usage { - ini_setting { 'puppetdb_config_command_processing_store_usage': + ini_setting { 'puppetdb_command_processing_store_usage': setting => 'store-usage', value => $store_usage, } } else { - ini_setting { 'puppetdb_config_command_processing_store_usage': + ini_setting { 'puppetdb_command_processing_store_usage': ensure => 'absent', setting => 'store-usage', } } if $temp_usage { - ini_setting { 'puppetdb_config_command_processing_temp_usage': + ini_setting { 'puppetdb_command_processing_temp_usage': setting => 'temp-usage', value => $temp_usage, } } else { - ini_setting { 'puppetdb_config_command_processing_temp_usage': + ini_setting { 'puppetdb_command_processing_temp_usage': ensure => 'absent', setting => 'temp-usage', } diff --git a/manifests/server/database_ini.pp b/manifests/server/database.pp similarity index 99% rename from manifests/server/database_ini.pp rename to manifests/server/database.pp index 9bdfd0a..e63593b 100644 --- a/manifests/server/database_ini.pp +++ b/manifests/server/database.pp @@ -1,5 +1,5 @@ # PRIVATE CLASS - do not use directly -class puppetdb::server::database_ini ( +class puppetdb::server::database ( $database = $puppetdb::params::database, $database_host = $puppetdb::params::database_host, $database_port = $puppetdb::params::database_port, diff --git a/manifests/server/global.pp b/manifests/server/global.pp new file mode 100644 index 0000000..253c331 --- /dev/null +++ b/manifests/server/global.pp @@ -0,0 +1,20 @@ +# PRIVATE CLASS - do not use directly +class puppetdb::server::global ( + $vardir = $puppetdb::params::vardir, +) inherits puppetdb::params { + + # Set the defaults + Ini_setting { + path => "${confdir}/config.ini", + ensure => 'present', + section => 'global', + require => File["${confdir}/config.ini"], + } + + if $vardir { + ini_setting { 'puppetdb_global_vardir': + setting => 'vardir', + value => $vardir, + } + } +} diff --git a/manifests/server/jetty_ini.pp b/manifests/server/jetty.pp similarity index 98% rename from manifests/server/jetty_ini.pp rename to manifests/server/jetty.pp index d02118a..7d03da4 100644 --- a/manifests/server/jetty_ini.pp +++ b/manifests/server/jetty.pp @@ -1,5 +1,5 @@ # PRIVATE CLASS - do not use directly -class puppetdb::server::jetty_ini ( +class puppetdb::server::jetty ( $listen_address = $puppetdb::params::listen_address, $listen_port = $puppetdb::params::listen_port, $ssl_listen_address = $puppetdb::params::ssl_listen_address, diff --git a/manifests/server/read_database_ini.pp b/manifests/server/read_database.pp similarity index 98% rename from manifests/server/read_database_ini.pp rename to manifests/server/read_database.pp index 8acb949..3c8d02a 100644 --- a/manifests/server/read_database_ini.pp +++ b/manifests/server/read_database.pp @@ -1,5 +1,5 @@ # PRIVATE CLASS - do not use directly -class puppetdb::server::read_database_ini ( +class puppetdb::server::read_database ( $database = $puppetdb::params::read_database, $database_host = $puppetdb::params::read_database_host, $database_port = $puppetdb::params::read_database_port, diff --git a/spec/unit/classes/server/config_ini_spec.rb b/spec/unit/classes/server/command_processing_spec.rb similarity index 74% rename from spec/unit/classes/server/config_ini_spec.rb rename to spec/unit/classes/server/command_processing_spec.rb index 15a0372..bd2b4bc 100644 --- a/spec/unit/classes/server/config_ini_spec.rb +++ b/spec/unit/classes/server/command_processing_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'puppetdb::server::config_ini', :type => :class do +describe 'puppetdb::server::command_processing', :type => :class do context 'on a supported platform' do let(:facts) do { @@ -8,24 +8,24 @@ describe 'puppetdb::server::config_ini', :type => :class do } end - it { should contain_class('puppetdb::server::config_ini') } + it { should contain_class('puppetdb::server::command_processing') } describe 'when using default values' do - it { should contain_ini_setting('puppetdb_config_command_processing_threads'). + it { should contain_ini_setting('puppetdb_command_processing_threads'). with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', 'section' => 'command-processing', 'setting' => 'threads' )} - it { should contain_ini_setting('puppetdb_config_command_processing_store_usage'). + it { should contain_ini_setting('puppetdb_command_processing_store_usage'). with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', 'section' => 'command-processing', 'setting' => 'store-usage' )} - it { should contain_ini_setting('puppetdb_config_command_processing_temp_usage'). + it { should contain_ini_setting('puppetdb_command_processing_temp_usage'). with( 'ensure' => 'absent', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', @@ -36,21 +36,21 @@ describe 'puppetdb::server::config_ini', :type => :class do describe 'when using legacy PuppetDB' do let (:pre_condition) { 'class { "puppetdb::globals": version => "2.2.0", }' } - it { should contain_ini_setting('puppetdb_config_command_processing_threads'). + it { should contain_ini_setting('puppetdb_command_processing_threads'). with( 'ensure' => 'absent', 'path' => '/etc/puppetdb/conf.d/config.ini', 'section' => 'command-processing', 'setting' => 'threads' )} - it { should contain_ini_setting('puppetdb_config_command_processing_store_usage'). + it { should contain_ini_setting('puppetdb_command_processing_store_usage'). with( 'ensure' => 'absent', 'path' => '/etc/puppetdb/conf.d/config.ini', 'section' => 'command-processing', 'setting' => 'store-usage' )} - it { should contain_ini_setting('puppetdb_config_command_processing_temp_usage'). + it { should contain_ini_setting('puppetdb_command_processing_temp_usage'). with( 'ensure' => 'absent', 'path' => '/etc/puppetdb/conf.d/config.ini', @@ -67,7 +67,7 @@ describe 'puppetdb::server::config_ini', :type => :class do 'temp_usage' => 2000, } end - it { should contain_ini_setting('puppetdb_config_command_processing_threads'). + it { should contain_ini_setting('puppetdb_command_processing_threads'). with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', @@ -75,7 +75,7 @@ describe 'puppetdb::server::config_ini', :type => :class do 'setting' => 'threads', 'value' => '10' )} - it { should contain_ini_setting('puppetdb_config_command_processing_store_usage'). + it { should contain_ini_setting('puppetdb_command_processing_store_usage'). with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', @@ -83,7 +83,7 @@ describe 'puppetdb::server::config_ini', :type => :class do 'setting' => 'store-usage', 'value' => '4000' )} - it { should contain_ini_setting('puppetdb_config_command_processing_temp_usage'). + it { should contain_ini_setting('puppetdb_command_processing_temp_usage'). with( 'ensure' => 'present', 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', diff --git a/spec/unit/classes/server/database_ini_spec.rb b/spec/unit/classes/server/database_ini_spec.rb index 74a0125..ffc9e35 100644 --- a/spec/unit/classes/server/database_ini_spec.rb +++ b/spec/unit/classes/server/database_ini_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'puppetdb::server::database_ini', :type => :class do +describe 'puppetdb::server::database', :type => :class do context 'on a supported platform' do let(:facts) do { @@ -11,7 +11,7 @@ describe 'puppetdb::server::database_ini', :type => :class do } end - it { should contain_class('puppetdb::server::database_ini') } + it { should contain_class('puppetdb::server::database') } describe 'when using default values' do it { should contain_ini_setting('puppetdb_psdatabase_username'). diff --git a/spec/unit/classes/server/db_connection_uri_spec.rb b/spec/unit/classes/server/db_connection_uri_spec.rb index 51a39cb..13805d0 100644 --- a/spec/unit/classes/server/db_connection_uri_spec.rb +++ b/spec/unit/classes/server/db_connection_uri_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'puppetdb::server::database_ini', :type => :class do +describe 'puppetdb::server::database', :type => :class do context 'on a supported platform' do let(:facts) do { @@ -56,7 +56,7 @@ describe 'puppetdb::server::database_ini', :type => :class do end end -describe 'puppetdb::server::read_database_ini', :type => :class do +describe 'puppetdb::server::read_database', :type => :class do context 'on a supported platform' do let(:facts) do { diff --git a/spec/unit/classes/server/global_ini_spec.rb b/spec/unit/classes/server/global_ini_spec.rb new file mode 100644 index 0000000..4d20d57 --- /dev/null +++ b/spec/unit/classes/server/global_ini_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'puppetdb::server::global', :type => :class do + context 'on a supported platform' do + let (:facts) do + { + :osfamily => 'RedHat', + :fqdn => 'foo.com', + } + end + + it { should contain_class('puppetdb::server::global') } + + describe 'when using default values' do + it { should contain_ini_setting('puppetdb_global_vardir'). + with( + 'ensure' => 'present', + 'path' => 'opt/puppetlabs/server/data/puppetdb', + 'path' => '/etc/puppetlabs/puppetdb/conf.d/config.ini', + 'section' => 'global', + 'setting' => 'vardir', + 'value' => '/opt/puppetlabs/server/data/puppetdb' + )} + + end + + describe 'when using a legacy puppetdb version' do + let (:pre_condition) { 'class { "puppetdb::globals": version => "2.2.0", }' } + it {should contain_ini_setting('puppetdb_global_vardir'). + with( + 'ensure' => 'present', + 'path' => 'opt/puppetlabs/server/data/puppetdb', + 'path' => '/etc/puppetdb/conf.d/config.ini', + 'section' => 'global', + 'setting' => 'vardir', + 'value' => '/var/lib/puppetdb' + )} + end + end +end diff --git a/spec/unit/classes/server/jetty_ini_spec.rb b/spec/unit/classes/server/jetty_ini_spec.rb index 0b8f8db..084a243 100644 --- a/spec/unit/classes/server/jetty_ini_spec.rb +++ b/spec/unit/classes/server/jetty_ini_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'puppetdb::server::jetty_ini', :type => :class do +describe 'puppetdb::server::jetty', :type => :class do context 'on a supported platform' do let(:facts) do { @@ -9,7 +9,7 @@ describe 'puppetdb::server::jetty_ini', :type => :class do } end - it { should contain_class('puppetdb::server::jetty_ini') } + it { should contain_class('puppetdb::server::jetty') } describe 'when using default values' do it { should contain_ini_setting('puppetdb_host'). @@ -158,7 +158,7 @@ describe 'puppetdb::server::jetty_ini', :type => :class do it 'should fail' do expect { - should contain_class('puppetdb::server::jetty_ini') + should contain_class('puppetdb::server::jetty') }.to raise_error(Puppet::Error) end end