Skip to content

Commit 4a40130

Browse files
(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.
1 parent 7d95c01 commit 4a40130

File tree

4 files changed

+72
-18
lines changed

4 files changed

+72
-18
lines changed

data/rspec.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
pe_databases::facts_tables_repack_timer:
2+
'Tue,Sat *-*-* 04:30:00'
3+
pe_databases::catalogs_tables_repack_timer:
4+
'Sun,Thu *-*-* 04:30:00'
5+
pe_databases::other_tables_repack_timer:
6+
'*-*-20 05:30:00'
7+
pe_databases::activity_tables_repack_timer:
8+
'Wed,Fri *-*-* 04:30:00'
9+
pe_databases::pg_repack::fact_tables:
10+
- factsets
11+
- fact_paths
12+
pe_databases::pg_repack::catalog_tables:
13+
- catalogs
14+
- catalog_resources
15+
- catalog_inputs
16+
- edges
17+
- certnames
18+
pe_databases::pg_repack::other_tables:
19+
- producers
20+
- resource_params
21+
- resource_params_cache
22+
pe_databases::pg_repack::activity_tables:
23+
- events
24+
- event_commits
25+
pe_databases::pg_repack::repack_log_level: 'INFO'
26+
pe_databases::pg_repack::enable_echo: false

hiera-rspec.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
version: 5
3+
4+
defaults: # Used for any hierarchy level that omits these keys.
5+
datadir: data # This path is relative to hiera.yaml's directory.
6+
data_hash: yaml_data # Use the built-in YAML backend.
7+
8+
hierarchy:
9+
- name: 'rspec'
10+
path: 'rspec.yaml'

manifests/pg_repack.pp

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
# @param activity_tables [Array] Array of 'activity' tables to repack
99
# @param disable_maintenance [Boolean] true or false (Default: false)
1010
# Disable or enable maintenance mode
11+
# @param repack_log_level [Enum] Desired output level of logs
12+
# @param enable_echo [Boolean] true or false (Default: true)
13+
# Enabling echo output in logs
1114
# @param jobs [Integer] How many jobs to run in parallel
1215
# @param facts_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'facts' tables
1316
# @param catalogs_tables_repack_timer [String]The Systemd timer for the pg_repack job affecting the 'catalog' tables
@@ -22,6 +25,8 @@
2225
Array $other_tables,
2326
Array $activity_tables,
2427
Boolean $disable_maintenance = false,
28+
Enum['INFO','NOTICE','WARNING','ERROR','LOG','FATAL','PANIC','DEBUG'] $repack_log_level='DEBUG',
29+
Boolean $enable_echo = true,
2530
Integer $jobs = $facts['processors']['count'] / 4,
2631
String[1] $facts_tables_repack_timer = $pe_databases::facts_tables_repack_timer,
2732
String[1] $catalogs_tables_repack_timer = $pe_databases::catalogs_tables_repack_timer,
@@ -36,7 +41,11 @@
3641
$postgresql_version = $facts['pe_postgresql_info']['installed_server_version']
3742
$repack_executable = "/opt/puppetlabs/server/apps/postgresql/${postgresql_version}/bin/pg_repack"
3843

39-
$repack_cmd = "${repack_executable} --jobs ${jobs}"
44+
if $enable_echo {
45+
$repack_cmd = "${repack_executable} --jobs ${jobs} --elevel ${repack_log_level} --echo"
46+
} else {
47+
$repack_cmd = "${repack_executable} --jobs ${jobs} --elevel ${repack_log_level}"
48+
}
4049

4150
pe_databases::collect { 'facts':
4251
disable_maintenance => $disable_maintenance,

spec/classes/pg_repack_spec.rb

+26-17
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,28 @@
2727
}
2828
}
2929
end
30+
let(:pre_condition) do
31+
<<-PRE_COND
32+
define puppet_enterprise::deprecated_parameter() {}
33+
34+
include pe_databases
35+
PRE_COND
36+
end
3037

3138
on_supported_os.each do |os, os_facts|
3239
context "on #{os}" do
33-
let(:pre_condition) do
34-
<<-PRE_COND
35-
define puppet_enterprise::deprecated_parameter() {}
36-
37-
include pe_databases
38-
PRE_COND
39-
end
4040
let(:facts) { os_facts }
4141

4242
it { is_expected.to compile }
4343
end
4444
end
4545

4646
context 'with default parameters' do
47-
let(:pre_condition) do
48-
<<-PRE_COND
49-
define puppet_enterprise::deprecated_parameter() {}
50-
51-
include pe_databases
52-
PRE_COND
53-
end
54-
5547
it {
5648
tables_hash.each do |name, val|
5749
is_expected.to contain_pe_databases__collect(name).with(
5850
disable_maintenance: false,
59-
command: "#{repack_cmd} #{val[:database]}",
51+
command: "#{repack_cmd} --elevel DEBUG --echo #{val[:database]}",
6052
# Strip the backslash character because this is not a regex
6153
on_cal: (val[:schedule]).to_s.tr('\\', ''),
6254
)
@@ -66,7 +58,7 @@
6658

6759
is_expected.to contain_file("/etc/systemd/system/pe_databases-#{name}.timer").with_content(%r{OnCalendar=#{val[:schedule]}})
6860
is_expected.to contain_file("/etc/systemd/system/pe_databases-#{name}.service").with_content(
69-
%r{ExecStart=#{repack_cmd} #{val[:database]} #{val[:tables]}},
61+
%r{ExecStart=#{repack_cmd} --elevel DEBUG --echo #{val[:database]} #{val[:tables]}},
7062
)
7163

7264
[
@@ -103,4 +95,21 @@ class {'pe_databases': facts_tables_repack_timer => 'Tue *-*-* 04:20:00'}
10395
)
10496
}
10597
end
98+
99+
context 'when customizing log parameters' do
100+
# Load the rspec hieradata. This data sets repack_log_level: 'INFO' and enable_echo: false
101+
let(:hiera_config) { 'hiera-rspec.yaml' }
102+
103+
it {
104+
# The command should have --elevel INFO and not contain --echo according to the hieradata
105+
is_expected.to contain_pe_databases__collect('facts').with(
106+
command: "#{repack_cmd} --elevel INFO #{tables_hash[:facts][:database]}",
107+
)
108+
109+
# The service file should have --elevel INFO and not contain --echo according to the hieradata
110+
is_expected.to contain_file('/etc/systemd/system/pe_databases-facts.service').with_content(
111+
%r{ExecStart=#{repack_cmd} --elevel INFO #{tables_hash[:facts][:database]} #{tables_hash[:facts][:tables]}},
112+
)
113+
}
114+
end
106115
end

0 commit comments

Comments
 (0)