diff --git a/.fixtures.yml b/.fixtures.yml index 1036506..7465c7e 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -9,3 +9,4 @@ fixtures: ruby_task_helper: 'https://git@github.com/puppetlabs/puppetlabs-ruby_task_helper' stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib' facts: 'https://github.com/puppetlabs/puppetlabs-facts' + diff --git a/functions/version_based_databases.pp b/functions/version_based_databases.pp deleted file mode 100644 index 65bf858..0000000 --- a/functions/version_based_databases.pp +++ /dev/null @@ -1,22 +0,0 @@ -# Function: version_based_databases -# -# Results: -# -# $databases: a version-specific array of databases. - -function pe_databases::version_based_databases() >> Array[String] { - $databases = [ - 'pe-activity', - 'pe-classifier', - 'pe-inventory', - 'pe-orchestrator', - 'pe-postgres', - 'pe-rbac', - ] - - if (versioncmp($facts['pe_server_version'], '2019.0.0') < 0) { - return $databases - ['pe-inventory'] - } else { - return $databases - } -} diff --git a/manifests/init.pp b/manifests/init.pp index 08cea4f..4093a12 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -4,34 +4,28 @@ # Manage the inclusion of the pg_repack class # @param disable_maintenance [Boolean] true or false (Default: false) # Disable or enable maintenance mode -# @param manage_postgresql_settings [Boolean] true or false (Default: true) -# Manage PostgreSQL settings -# @param manage_table_settings [Boolean] true or false (Default: false) -# Manage table settings # @param install_dir [String] Directory to install module into (Default: "/opt/puppetlabs/pe_databases") # @param scripts_dir [String] Directory to install scripts into (Default: "${install_dir}/scripts") # @param facts_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'facts' tables # @param catalogs_tables_repack_timer [String]The Systemd timer for the pg_repack job affecting the 'catalog' tables # @param other_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'other' tables -# @param reports_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'reports' tables -# @param resource_events_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'resource_events' tables class pe_databases ( Boolean $manage_database_maintenance = true, Boolean $disable_maintenance = false, - Boolean $manage_postgresql_settings = true, - Boolean $manage_table_settings = false, + Optional[Boolean] $manage_postgresql_settings = undef, + Optional[Boolean] $manage_table_settings = undef, String[1] $install_dir = '/opt/puppetlabs/pe_databases', String[1] $scripts_dir = "${install_dir}/scripts", String[1] $facts_tables_repack_timer = 'Tue,Sat *-*-* 04:30:00', String[1] $catalogs_tables_repack_timer = 'Sun,Thu *-*-* 04:30:00', String[1] $other_tables_repack_timer = '*-*-20 05:30:00', - String[1] $reports_tables_repack_timer = '*-*-10 05:30:00', - String[1] $resource_events_tables_repack_timer = '*-*-15 05:30:00', + Optional[String] $reports_tables_repack_timer = undef, + Optional[String] $resource_events_tables_repack_timer = undef, ) { - $psql_version = $facts['pe_postgresql_info']['installed_server_version'] ? { - undef => undef, - default => String($facts['pe_postgresql_info']['installed_server_version']) - } + puppet_enterprise::deprecated_parameter{'pe_databases::manage_postgresql_settings': } + puppet_enterprise::deprecated_parameter{'pe_databases::manage_table_settings': } + puppet_enterprise::deprecated_parameter{'pe_databases::reports_tables_repack_timer': } + puppet_enterprise::deprecated_parameter{'pe_databases::resource_events_tables_repack_timer': } file { [$install_dir, $scripts_dir]: ensure => directory, @@ -45,23 +39,9 @@ } if $facts.dig('pe_databases', 'have_systemd') { - if versioncmp('2019.0.2', $facts['pe_server_version']) <= 0 { - if $manage_database_maintenance { - class { 'pe_databases::pg_repack': - disable_maintenance => $disable_maintenance, - } - if $manage_table_settings { - # This is to provide for situations, like PE XL, - # where the pe-puppetdb database does not exist on the PostgreSQL system being tuned. - # In PE XL, the Primary and Replica run PostgreSQL for all databases *except* for pe-puppetdb. - include pe_databases::postgresql_settings::table_settings - } - } - } - else { - notify { 'pe_databases_version_warn': - message => 'This module only supports PE 2019.0.2 and later', - loglevel => warning, + if $manage_database_maintenance { + class { 'pe_databases::pg_repack': + disable_maintenance => $disable_maintenance, } } } diff --git a/manifests/pg_repack.pp b/manifests/pg_repack.pp index ed74e08..e3ac5dd 100644 --- a/manifests/pg_repack.pp +++ b/manifests/pg_repack.pp @@ -9,71 +9,45 @@ # @param facts_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'facts' tables # @param catalogs_tables_repack_timer [String]The Systemd timer for the pg_repack job affecting the 'catalog' tables # @param other_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'other' tables -# @param reports_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'reports' tables -# @param resource_events_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'resource_events' tables class pe_databases::pg_repack ( - Boolean $disable_maintenance = false, - Integer $jobs = $facts['processors']['count'] / 4, - String[1] $facts_tables_repack_timer = $pe_databases::facts_tables_repack_timer, - String[1] $catalogs_tables_repack_timer = $pe_databases::catalogs_tables_repack_timer, - String[1] $other_tables_repack_timer = $pe_databases::other_tables_repack_timer, - String[1] $reports_tables_repack_timer = $pe_databases::reports_tables_repack_timer, - String[1] $resource_events_tables_repack_timer = $pe_databases::resource_events_tables_repack_timer, + Boolean $disable_maintenance = false, + Integer $jobs = $facts['processors']['count'] / 4, + String[1] $facts_tables_repack_timer = $pe_databases::facts_tables_repack_timer, + String[1] $catalogs_tables_repack_timer = $pe_databases::catalogs_tables_repack_timer, + String[1] $other_tables_repack_timer = $pe_databases::other_tables_repack_timer, + Optional[String] $reports_tables_repack_timer = undef, + Optional[String] $resource_events_tables_repack_timer = undef, ) { - # PE 2019.1 starting shipping versioned pe-postgres packages where all paths are versioned. - # So, prior to 2019.1 use a non-versioned path, and after use a versioned path. - # TODO: Use $pe_databases::psql_version after identifying why it is cast to ${psql_version}00000 in spec tests. + puppet_enterprise::deprecated_parameter{'pe_databases::pg_repack::reports_tables_repack_timer': } + puppet_enterprise::deprecated_parameter{'pe_databases::pg_repack::resource_events_tables_repack_timer': } + $postgresql_version = $facts['pe_postgresql_info']['installed_server_version'] - $repack_executable = versioncmp('2019.1.0', $facts['pe_server_version']) ? { - 1 => '/opt/puppetlabs/server/apps/postgresql/bin/pg_repack', - default => "/opt/puppetlabs/server/apps/postgresql/${postgresql_version}/bin/pg_repack" - } + $repack_executable = "/opt/puppetlabs/server/apps/postgresql/${postgresql_version}/bin/pg_repack" - $repack = "${repack_executable} -d pe-puppetdb" - $repack_jobs = "--jobs ${jobs}" + $repack_cmd = "${repack_executable} -d pe-puppetdb --jobs ${jobs}" - $facts_tables = '-t factsets -t fact_paths' - $catalogs_tables = versioncmp($facts['pe_server_version'], '2019.8.1') ? { - 1 => '-t catalogs -t catalog_resources -t catalog_inputs -t edges -t certnames', - default => '-t catalogs -t catalog_resources -t edges -t certnames' } - $other_tables = '-t producers -t resource_params -t resource_params_cache' - $reports_table = '-t reports' - $resource_events_table = '-t resource_events' + $fact_tables = '-t factsets -t fact_paths' + $catalog_tables = '-t catalogs -t catalog_resources -t catalog_inputs -t edges -t certnames' + $other_tables = '-t producers -t resource_params -t resource_params_cache' pe_databases::collect { 'facts': disable_maintenance => $disable_maintenance, - command => "${repack} ${repack_jobs} ${facts_tables}", + command => "${repack_cmd} ${fact_tables}", on_cal => $facts_tables_repack_timer, } pe_databases::collect { 'catalogs': disable_maintenance => $disable_maintenance, - command => "${repack} ${repack_jobs} ${catalogs_tables}", + command => "${repack_cmd} ${catalog_tables}", on_cal => $catalogs_tables_repack_timer, } pe_databases::collect { 'other': disable_maintenance => $disable_maintenance, - command => "${repack} ${repack_jobs} ${other_tables}", + command => "${repack_cmd} ${other_tables}", on_cal => $other_tables_repack_timer, } - if versioncmp($facts['pe_server_version'], '2019.7.0') < 0 { - pe_databases::collect { 'reports': - disable_maintenance => $disable_maintenance, - command => "${repack} ${repack_jobs} ${reports_table}", - on_cal => $reports_tables_repack_timer, - } - } - - if versioncmp($facts['pe_server_version'], '2019.3.0') < 0 { - pe_databases::collect { 'resource_events': - disable_maintenance => $disable_maintenance, - command => "${repack} ${repack_jobs} ${resource_events_table}", - on_cal => $resource_events_tables_repack_timer, - } - } - # Ensure legacy vaccum and pg_repack crons are purged. # If someone upgrades from an ancient v0.x version of the pe_databases module to 2.0 or newer, # the old cron jobs running vaccuum full will not be cleaned up. This can result in a deadlock diff --git a/manifests/postgresql_settings.pp b/manifests/postgresql_settings.pp deleted file mode 100644 index 43a85a8..0000000 --- a/manifests/postgresql_settings.pp +++ /dev/null @@ -1,126 +0,0 @@ -# Tune PostgreSQL -# -# @summary -# Tune PostgreSQL settings -# -# @param maintenance_work_mem [String] Increase to improve speed of speed of vacuuming and reindexing (Example "1GB") -# @param work_mem [String] Allows PostgreSQL to do larger in-memory sorts (Default: "4MB") -# @param autovacumn_work_mem [String] Similar to but for maintenance_work_mem autovacuum processes only (Example "256MB") -# @param autovacuum_max_workers [Integer] Maximum number of autovacuum processes to run concurrently (Default: 3) -# -class pe_databases::postgresql_settings ( - # lint:ignore:140chars - Float[0,1] $autovacuum_vacuum_scale_factor = 0.08, - Float[0,1] $autovacuum_analyze_scale_factor = 0.04, - Integer $autovacuum_max_workers = max(3, min(8, $facts['processors']['count'] / 3)), - Integer $log_autovacuum_min_duration = -1, - Integer $log_temp_files = -1, - String $work_mem = '8MB', - Integer $max_connections = 1000, - Hash $arbitrary_postgresql_conf_settings = {}, - Float[0,1] $checkpoint_completion_target = 0.9, - Integer $checkpoint_segments = 128, - Boolean $manage_postgresql_service = true, - Boolean $all_in_one_pe_install = true, - Boolean $manage_reports_autovacuum_cost_delay = true, - Optional[Float[0,1]] $factsets_autovacuum_vacuum_scale_factor = 0.80, - Optional[Float[0,1]] $reports_autovacuum_vacuum_scale_factor = 0.01, - String $maintenance_work_mem = $all_in_one_pe_install ? { - false => "${facts['memory']['system']['total_bytes'] / 1024 / 1024 / 3}MB", - true => "${facts['memory']['system']['total_bytes'] / 1024 / 1024 / 8}MB", - }, - String $autovacuum_work_mem = $all_in_one_pe_install ? { - false => "${facts['memory']['system']['total_bytes'] / 1024 / 1024 / 3 / $autovacuum_max_workers}MB", - true => "${facts['memory']['system']['total_bytes'] / 1024 / 1024 / 8 / $autovacuum_max_workers}MB", - }, - String $psql_version = $pe_databases::psql_version, - # lint:endignore -) { - $postgresql_service_resource_name = 'postgresqld' - $postgresql_service_name = 'pe-postgresql' - $notify_postgresql_service = $manage_postgresql_service ? { - true => Service[$postgresql_service_resource_name], - default => undef, - } - $notify_console_services = $all_in_one_pe_install ? { - true => Service['pe-console-services'], - default => undef, - } - - if $manage_postgresql_service { - service { $postgresql_service_resource_name : - ensure => running, - name => $postgresql_service_name, - enable => true, - notify => $notify_console_services, - } - } - - # The value attribute of postgresql_conf requires a string despite validating a float above. - # https://tickets.puppetlabs.com/browse/MODULES-2960 - # http://www.postgresql.org/docs/9.4/static/runtime-config-autovacuum.html - - Pe_postgresql_conf { - ensure => present, - target => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/postgresql.conf", - notify => $notify_postgresql_service, - } - - pe_postgresql_conf { 'autovacuum_vacuum_scale_factor' : - value => sprintf('%#.2f', $autovacuum_vacuum_scale_factor), - } - - pe_postgresql_conf { 'autovacuum_analyze_scale_factor' : - value => sprintf('%#.2f', $autovacuum_analyze_scale_factor), - } - - pe_postgresql_conf { 'autovacuum_max_workers' : - value => String($autovacuum_max_workers), - } - - pe_postgresql_conf { 'autovacuum_work_mem' : - value => String($autovacuum_work_mem), - } - - pe_postgresql_conf { 'log_autovacuum_min_duration' : - value => String($log_autovacuum_min_duration), - } - - pe_postgresql_conf { 'log_temp_files' : - value => String($log_temp_files), - } - - pe_postgresql_conf { 'maintenance_work_mem' : - value => String($maintenance_work_mem), - } - - pe_postgresql_conf { 'work_mem' : - value => String($work_mem), - } - - pe_postgresql_conf { 'max_connections' : - value => String($max_connections), - } - - pe_postgresql_conf { 'checkpoint_completion_target' : - value => sprintf('%#.2f', $checkpoint_completion_target), - } - - $checkpoint_segments_ensure = $psql_version ? { - '9.4' => 'present', - default => 'absent', - } - - pe_postgresql_conf { 'checkpoint_segments' : - ensure => $checkpoint_segments_ensure, - value => String($checkpoint_segments), - } - - if !empty($arbitrary_postgresql_conf_settings) { - $arbitrary_postgresql_conf_settings.each | $key, $value | { - pe_postgresql_conf { $key : - value => String($value), - } - } - } -} diff --git a/manifests/postgresql_settings/table_settings.pp b/manifests/postgresql_settings/table_settings.pp deleted file mode 100644 index e091fa3..0000000 --- a/manifests/postgresql_settings/table_settings.pp +++ /dev/null @@ -1,54 +0,0 @@ -# Tune PostgreSQL table settings -# -# @summary -# Tune PostgreSQL table settings -# -class pe_databases::postgresql_settings::table_settings ( - # lint:ignore:140chars - Boolean $manage_reports_autovacuum_cost_delay = lookup('pe_databases::postgresql_settings::manage_reports_autovacuum_cost_delay', { 'default_value' => true }), - Optional[Float[0,1]] $factsets_autovacuum_vacuum_scale_factor = lookup('pe_databases::postgresql_settings::factsets_autovacuum_vacuum_scale_factor', { 'default_value' => 0.80 }), - Optional[Float[0,1]] $reports_autovacuum_vacuum_scale_factor = lookup('pe_databases::postgresql_settings::reports_autovacuum_vacuum_scale_factor', { 'default_value' => 0.01 }), - Optional[Float[0,1]] $catalogs_autovacuum_vacuum_scale_factor = 0.75, - Optional[Float[0,1]] $certnames_autovacuum_vacuum_scale_factor = 0.75, - # lint:endignore -) { - if $manage_reports_autovacuum_cost_delay { - pe_databases::set_puppetdb_table_autovacuum_cost_delay_zero { 'reports' : } - } - - if !empty($factsets_autovacuum_vacuum_scale_factor) { - pe_databases::set_table_attribute { "Set autovacuum_vacuum_scale_factor=${factsets_autovacuum_vacuum_scale_factor} for factsets" : - db => 'pe-puppetdb', - table_name => 'factsets', - table_attribute => 'autovacuum_vacuum_scale_factor', - table_attribute_value => sprintf('%#.2f', $factsets_autovacuum_vacuum_scale_factor), - } - } - - if !empty($reports_autovacuum_vacuum_scale_factor) { - pe_databases::set_table_attribute { "Set autovacuum_vacuum_scale_factor=${reports_autovacuum_vacuum_scale_factor} for reports" : - db => 'pe-puppetdb', - table_name => 'reports', - table_attribute => 'autovacuum_vacuum_scale_factor', - table_attribute_value => sprintf('%#.2f', $reports_autovacuum_vacuum_scale_factor), - } - } - - if !empty($catalogs_autovacuum_vacuum_scale_factor) { - pe_databases::set_table_attribute { "Set autovacuum_vacuum_scale_factor=${catalogs_autovacuum_vacuum_scale_factor} for catalogs" : - db => 'pe-puppetdb', - table_name => 'catalogs', - table_attribute => 'autovacuum_vacuum_scale_factor', - table_attribute_value => sprintf('%#.2f', $catalogs_autovacuum_vacuum_scale_factor), - } - } - - if !empty($certnames_autovacuum_vacuum_scale_factor) { - pe_databases::set_table_attribute { "Set autovacuum_vacuum_scale_factor=${certnames_autovacuum_vacuum_scale_factor} for certnames" : - db => 'pe-puppetdb', - table_name => 'certnames', - table_attribute => 'autovacuum_vacuum_scale_factor', - table_attribute_value => sprintf('%#.2f', $certnames_autovacuum_vacuum_scale_factor), - } - } -} diff --git a/manifests/set_puppetdb_table_autovacuum_cost_delay_zero.pp b/manifests/set_puppetdb_table_autovacuum_cost_delay_zero.pp deleted file mode 100644 index 496d633..0000000 --- a/manifests/set_puppetdb_table_autovacuum_cost_delay_zero.pp +++ /dev/null @@ -1,17 +0,0 @@ -# Defined type for PostgreSQL autovacuum_cost_delay -# -# @summary -# Defined type for PostgreSQL autovacuum_cost_delay -# -# @param table_name [String] -# Name of the table -define pe_databases::set_puppetdb_table_autovacuum_cost_delay_zero ( - String $table_name = $title, -) { - pe_databases::set_table_attribute { "Set autovacuum_cost_delay=0 for ${table_name}" : - db => 'pe-puppetdb', - table_name => $table_name, - table_attribute => 'autovacuum_vacuum_cost_delay', - table_attribute_value => '0', - } -} diff --git a/manifests/set_table_attribute.pp b/manifests/set_table_attribute.pp deleted file mode 100644 index b4c490f..0000000 --- a/manifests/set_table_attribute.pp +++ /dev/null @@ -1,31 +0,0 @@ -# Defined type for PostgreSQL table attributes -# -# @summary -# Defined type for PostgreSQL table attributes -# -# @param db [String] -# Name of the database, this is pe-puppetdb for the uses of this module. -# @param table_name [String] -# Name of the table in the database. -# @param table_attribute [String] -# Set to the table attribute value. -# @param table_attribute_value [String] -# Value of setting for the table set in table_settings.pp -# -define pe_databases::set_table_attribute ( - String $db, - String $table_name, - String $table_attribute, - String $table_attribute_value, -) { - # lint:ignore:140chars - pe_postgresql_psql { "Set ${table_attribute}=${table_attribute_value} for ${table_name}" : - command => "ALTER TABLE ${table_name} SET ( ${table_attribute} = ${table_attribute_value} )", - unless => "SELECT reloptions FROM pg_class WHERE relname = '${table_name}' AND CAST(reloptions as text) LIKE '%${table_attribute}=${table_attribute_value}%'", - db => $db, - psql_user => 'pe-postgres', - psql_group => 'pe-postgres', - psql_path => '/opt/puppetlabs/server/bin/psql', - } - # lint:endignore -} diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index debdb87..265eb28 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -3,23 +3,59 @@ describe 'pe_databases' do on_supported_os.each do |os, os_facts| context "on #{os}" do + let(:pre_condition) do + <<-PRE_COND + define puppet_enterprise::deprecated_parameter() {} + PRE_COND + end let(:facts) { os_facts } it { is_expected.to compile } end end - context 'on latest PE release' do - it { is_expected.to contain_class('pe_databases::pg_repack') } - end + context 'with default parameters' do + let(:pre_condition) do + <<-PRE_COND + define puppet_enterprise::deprecated_parameter() {} + PRE_COND + end + + it { + is_expected.to contain_class('pe_databases::pg_repack').with(disable_maintenance: false) - context 'on unsupported PE release' do - let(:facts) { { pe_server_version: '2019.0.1' } } + is_expected.to contain_file('/opt/puppetlabs/pe_databases').with( + ensure: 'directory', + mode: '0755', + ) + is_expected.to contain_file('/opt/puppetlabs/pe_databases/scripts').with( + ensure: 'directory', + mode: '0755', + ) - it { is_expected.to contain_notify('pe_databases_version_warn') } + is_expected.to contain_exec('pe_databases_daemon_reload').with( + command: 'systemctl daemon-reload', + path: ['/bin', '/usr/bin'], + refreshonly: true, + ) + + [ + 'pe_databases::manage_postgresql_settings', + 'pe_databases::manage_table_settings', + 'pe_databases::reports_tables_repack_timer', + 'pe_databases::resource_events_tables_repack_timer', + ].each do |deprecated_param| + is_expected.to contain_puppet_enterprise__deprecated_parameter(deprecated_param) + end + } end context 'when systemd is not the init provider' do + let(:pre_condition) do + <<-PRE_COND + define puppet_enterprise::deprecated_parameter() {} + PRE_COND + end let(:facts) { { pe_databases: { have_systemd: false } } } it { is_expected.to contain_notify('pe_databases_systemd_warn') } diff --git a/spec/classes/pg_repack_spec.rb b/spec/classes/pg_repack_spec.rb index c37aba1..74f29b3 100644 --- a/spec/classes/pg_repack_spec.rb +++ b/spec/classes/pg_repack_spec.rb @@ -1,73 +1,98 @@ require 'spec_helper' describe 'pe_databases::pg_repack' do + let(:facts) { { processors: { count: 4 } } } + let(:repack_cmd) { '/opt/puppetlabs/server/apps/postgresql/11/bin/pg_repack -d pe-puppetdb --jobs 1' } + let(:tables_hash) do + { + facts: { + tables: '-t factsets -t fact_paths', + schedule: 'Tue,Sat \*-\*-\* 04:30:00' + }, + catalogs: { + tables: '-t catalogs -t catalog_resources -t catalog_inputs -t edges -t certnames', + schedule: 'Sun,Thu \*-\*-\* 04:30:00', + }, + other: { + tables: '-t producers -t resource_params -t resource_params_cache', + schedule: '\*-\*-20 05:30:00', + } + } + end + on_supported_os.each do |os, os_facts| context "on #{os}" do let(:pre_condition) do - "class { 'pe_databases': - manage_postgresql_settings => false, - manage_table_settings => false, - }" + <<-PRE_COND + define puppet_enterprise::deprecated_parameter() {} + + include pe_databases + PRE_COND end let(:facts) { os_facts } it { is_expected.to compile } - context 'on < PE 2019.3.0' do - before :each do - facts['pe_server_version'] = '2019.1.0' - facts['pe_postgresql_info']['installed_server_version'] = 9.6 - end - it { - # TODO: postgres versions - is_expected.to contain_service('pe_databases-resource_events.timer').with_ensure('running') - is_expected.to contain_service('pe_databases-reports.timer').with_ensure('running') - } - end + end + end - context 'on < PE 2019.3.0 with postgresql 11' do - before :each do - facts['pe_server_version'] = '2019.2.0' - facts['pe_postgresql_info']['installed_server_version'] = 11 - end - it { - # TODO: postgres versions - is_expected.to contain_service('pe_databases-resource_events.timer').with_ensure('running') - is_expected.to contain_service('pe_databases-reports.timer').with_ensure('running') - } - end + context 'with default parameters' do + let(:pre_condition) do + <<-PRE_COND + define puppet_enterprise::deprecated_parameter() {} - context 'on < PE 2019.7.0' do - before :each do - facts['pe_server_version'] = '2019.5.0' - facts['pe_postgresql_info']['installed_server_version'] = 11 - end - it { - # TODO: postgres versions - is_expected.to contain_service('pe_databases-reports.timer').with_ensure('running') - is_expected.not_to contain_service('pe_databases-resource_events.timer').with_ensure('running') - } - end + include pe_databases + PRE_COND + end - context 'on >= PE 2019.7.0' do - before :each do - facts['pe_server_version'] = '2019.7.0' - facts['pe_postgresql_info']['installed_server_version'] = 11 - end - it { - is_expected.not_to contain_service('pe_databases-reports.timer').with_ensure('running') - is_expected.not_to contain_service('pe_databases-resource_events.timer').with_ensure('running') - } - end + it { + tables_hash.each do |name, val| + is_expected.to contain_pe_databases__collect(name).with( + disable_maintenance: false, + command: "#{repack_cmd} #{val[:tables]}", + # Strip the backslash character because this is not a regex + on_cal: (val[:schedule]).to_s.tr('\\', ''), + ) + + is_expected.to contain_service("pe_databases-#{name}.timer").with_ensure('running') + is_expected.to contain_service("pe_databases-#{name}.service") + + is_expected.to contain_file("/etc/systemd/system/pe_databases-#{name}.timer").with_content(%r{OnCalendar=#{val[:schedule]}}) + is_expected.to contain_file("/etc/systemd/system/pe_databases-#{name}.service").with_content( + %r{ExecStart=#{repack_cmd} #{val[:tables]}}, + ) - context 'on >= PE 2019.8.2' do - before :each do - facts['pe_server_version'] = '2019.8.2' - facts['pe_postgresql_info']['installed_server_version'] = 11 + [ + 'pe_databases::pg_repack::reports_tables_repack_timer', + 'pe_databases::pg_repack::resource_events_tables_repack_timer', + ].each do |deprecated_param| + is_expected.to contain_puppet_enterprise__deprecated_parameter(deprecated_param) end - it { - is_expected.to contain_service('pe_databases-catalogs.timer').with_ensure('running') - } end + + ['pg_repack facts tables', 'pg_repack catalogs tables', 'pg_repack other tables', + 'pg_repack reports tables', 'pg_repack resource_events tables', + 'VACUUM FULL facts tables', + 'VACUUM FULL catalogs tables', + 'VACUUM FULL other tables', + 'Maintain PE databases'].each do |cron| + is_expected.to contain_cron(cron).with(ensure: 'absent') + end + } + end + + context 'when customizing timers' do + let(:pre_condition) do + <<-PRE_COND + define puppet_enterprise::deprecated_parameter() {} + + class {'pe_databases': facts_tables_repack_timer => 'Tue *-*-* 04:20:00'} + PRE_COND end + + it { + is_expected.to contain_pe_databases__collect('facts').with( + on_cal: 'Tue *-*-* 04:20:00', + ) + } end end diff --git a/spec/defines/collect_spec.rb b/spec/defines/collect_spec.rb new file mode 100644 index 0000000..6f46658 --- /dev/null +++ b/spec/defines/collect_spec.rb @@ -0,0 +1,59 @@ +require 'spec_helper' + +describe 'pe_databases::collect' do + context 'when repacking tables' do + let(:pre_condition) do + <<-PRE_COND + define puppet_enterprise::deprecated_parameter() {} + include pe_databases + PRE_COND + end + let(:title) { 'test' } + let(:params) do + { + command: 'foo', + on_cal: 'bar', + } + end + + it { + is_expected.to contain_service('pe_databases-test.timer').with_ensure('running') + is_expected.to contain_service('pe_databases-test.service') + + is_expected.to contain_file('/etc/systemd/system/pe_databases-test.timer').with_content(%r{bar}) + is_expected.to contain_file('/etc/systemd/system/pe_databases-test.service').with_content( + %r{ExecStart=foo}, + ) + + is_expected.to contain_service('pe_databases-test.service').that_notifies( + 'Exec[pe_databases_daemon_reload]', + ) + is_expected.to contain_service('pe_databases-test.timer').that_subscribes_to( + 'File[/etc/systemd/system/pe_databases-test.timer]', + ) + } + end + + context 'when disabling maintenance' do + let(:pre_condition) do + <<-PRE_COND + define puppet_enterprise::deprecated_parameter() {} + include pe_databases + PRE_COND + end + let(:title) { 'test' } + let(:params) do + { + disable_maintenance: true, + command: 'foo', + on_cal: 'bar', + } + end + + it { + is_expected.to contain_file('/etc/systemd/system/pe_databases-test.timer').with_ensure('absent') + is_expected.to contain_file('/etc/systemd/system/pe_databases-test.service').with_ensure('absent') + is_expected.to contain_service('pe_databases-test.timer').with_ensure('stopped') + } + end +end