From 4a401308f79532fbadcd1dbdb7c8c38977bad057 Mon Sep 17 00:00:00 2001 From: Aaron McCracken Date: Mon, 29 Jan 2024 09:05:28 +0000 Subject: [PATCH] (SUP-4666) Implementation of conditional logic for enabling debug, echo WITH acceptance test modifications. Add rspec specific hierarchy and tests to cover new repack log parameters. This commit uses the new rspec specific hieradata to change the parameters to the pg_repack class and tests them. --- data/rspec.yaml | 26 ++++++++++++++++++++ hiera-rspec.yaml | 10 ++++++++ manifests/pg_repack.pp | 11 ++++++++- spec/classes/pg_repack_spec.rb | 43 ++++++++++++++++++++-------------- 4 files changed, 72 insertions(+), 18 deletions(-) create mode 100644 data/rspec.yaml create mode 100644 hiera-rspec.yaml diff --git a/data/rspec.yaml b/data/rspec.yaml new file mode 100644 index 0000000..48896a1 --- /dev/null +++ b/data/rspec.yaml @@ -0,0 +1,26 @@ +pe_databases::facts_tables_repack_timer: + 'Tue,Sat *-*-* 04:30:00' +pe_databases::catalogs_tables_repack_timer: + 'Sun,Thu *-*-* 04:30:00' +pe_databases::other_tables_repack_timer: + '*-*-20 05:30:00' +pe_databases::activity_tables_repack_timer: + 'Wed,Fri *-*-* 04:30:00' +pe_databases::pg_repack::fact_tables: + - factsets + - fact_paths +pe_databases::pg_repack::catalog_tables: + - catalogs + - catalog_resources + - catalog_inputs + - edges + - certnames +pe_databases::pg_repack::other_tables: + - producers + - resource_params + - resource_params_cache +pe_databases::pg_repack::activity_tables: + - events + - event_commits +pe_databases::pg_repack::repack_log_level: 'INFO' +pe_databases::pg_repack::enable_echo: false diff --git a/hiera-rspec.yaml b/hiera-rspec.yaml new file mode 100644 index 0000000..30b09fb --- /dev/null +++ b/hiera-rspec.yaml @@ -0,0 +1,10 @@ +--- +version: 5 + +defaults: # Used for any hierarchy level that omits these keys. + datadir: data # This path is relative to hiera.yaml's directory. + data_hash: yaml_data # Use the built-in YAML backend. + +hierarchy: + - name: 'rspec' + path: 'rspec.yaml' diff --git a/manifests/pg_repack.pp b/manifests/pg_repack.pp index d792f99..a41bcca 100644 --- a/manifests/pg_repack.pp +++ b/manifests/pg_repack.pp @@ -8,6 +8,9 @@ # @param activity_tables [Array] Array of 'activity' tables to repack # @param disable_maintenance [Boolean] true or false (Default: false) # Disable or enable maintenance mode +# @param repack_log_level [Enum] Desired output level of logs +# @param enable_echo [Boolean] true or false (Default: true) +# Enabling echo output in logs # @param jobs [Integer] How many jobs to run in parallel # @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 @@ -22,6 +25,8 @@ Array $other_tables, Array $activity_tables, Boolean $disable_maintenance = false, + Enum['INFO','NOTICE','WARNING','ERROR','LOG','FATAL','PANIC','DEBUG'] $repack_log_level='DEBUG', + Boolean $enable_echo = true, 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, @@ -36,7 +41,11 @@ $postgresql_version = $facts['pe_postgresql_info']['installed_server_version'] $repack_executable = "/opt/puppetlabs/server/apps/postgresql/${postgresql_version}/bin/pg_repack" - $repack_cmd = "${repack_executable} --jobs ${jobs}" + if $enable_echo { + $repack_cmd = "${repack_executable} --jobs ${jobs} --elevel ${repack_log_level} --echo" + } else { + $repack_cmd = "${repack_executable} --jobs ${jobs} --elevel ${repack_log_level}" + } pe_databases::collect { 'facts': disable_maintenance => $disable_maintenance, diff --git a/spec/classes/pg_repack_spec.rb b/spec/classes/pg_repack_spec.rb index 9522c9b..1c51e72 100644 --- a/spec/classes/pg_repack_spec.rb +++ b/spec/classes/pg_repack_spec.rb @@ -27,16 +27,16 @@ } } end + let(:pre_condition) do + <<-PRE_COND + define puppet_enterprise::deprecated_parameter() {} + + include pe_databases + PRE_COND + end on_supported_os.each do |os, os_facts| context "on #{os}" do - let(:pre_condition) do - <<-PRE_COND - define puppet_enterprise::deprecated_parameter() {} - - include pe_databases - PRE_COND - end let(:facts) { os_facts } it { is_expected.to compile } @@ -44,19 +44,11 @@ end context 'with default parameters' do - let(:pre_condition) do - <<-PRE_COND - define puppet_enterprise::deprecated_parameter() {} - - include pe_databases - PRE_COND - end - it { tables_hash.each do |name, val| is_expected.to contain_pe_databases__collect(name).with( disable_maintenance: false, - command: "#{repack_cmd} #{val[:database]}", + command: "#{repack_cmd} --elevel DEBUG --echo #{val[:database]}", # Strip the backslash character because this is not a regex on_cal: (val[:schedule]).to_s.tr('\\', ''), ) @@ -66,7 +58,7 @@ 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[:database]} #{val[:tables]}}, + %r{ExecStart=#{repack_cmd} --elevel DEBUG --echo #{val[:database]} #{val[:tables]}}, ) [ @@ -103,4 +95,21 @@ class {'pe_databases': facts_tables_repack_timer => 'Tue *-*-* 04:20:00'} ) } end + + context 'when customizing log parameters' do + # Load the rspec hieradata. This data sets repack_log_level: 'INFO' and enable_echo: false + let(:hiera_config) { 'hiera-rspec.yaml' } + + it { + # The command should have --elevel INFO and not contain --echo according to the hieradata + is_expected.to contain_pe_databases__collect('facts').with( + command: "#{repack_cmd} --elevel INFO #{tables_hash[:facts][:database]}", + ) + + # The service file should have --elevel INFO and not contain --echo according to the hieradata + is_expected.to contain_file('/etc/systemd/system/pe_databases-facts.service').with_content( + %r{ExecStart=#{repack_cmd} --elevel INFO #{tables_hash[:facts][:database]} #{tables_hash[:facts][:tables]}}, + ) + } + end end