Skip to content

Commit 513c14e

Browse files
ragingraCoMfUcIoS
authored andcommitted
(PE-38814) add_compiler - Making primary_postgresql_host and avail_group_letter optional (#468)
* (PE-38814) add_compiler - Making primary_postgresql_host and avail_group_letter optional primary_postgresql_host, if not provided will be determined through get_peadm_config avail_group_letter, is defaulting to A * Updating spec tests for add compiler Removing optional from avail_group_letter as not required with enum default value * Updating reference.md * Fixing linting issues --------- Co-authored-by: Neil Anderson <[email protected]>
1 parent fd07fd6 commit 513c14e

File tree

3 files changed

+122
-40
lines changed

3 files changed

+122
-40
lines changed

REFERENCE.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,8 @@ Data type: `Enum['A', 'B']`
15751575

15761576
_ Either A or B; whichever of the two letter designations the compiler is being assigned to
15771577

1578+
Default value: `'A'`
1579+
15781580
##### <a name="-peadm--add_compiler--compiler_host"></a>`compiler_host`
15791581

15801582
Data type: `Peadm::SingleTargetSpec`
@@ -1597,10 +1599,12 @@ _ The hostname and certname of the primary Puppet server
15971599

15981600
##### <a name="-peadm--add_compiler--primary_postgresql_host"></a>`primary_postgresql_host`
15991601

1600-
Data type: `Peadm::SingleTargetSpec`
1602+
Data type: `Optional[Peadm::SingleTargetSpec]`
16011603

16021604
_ The hostname and certname of the PE-PostgreSQL server with availability group $avail_group_letter
16031605

1606+
Default value: `undef`
1607+
16041608
### <a name="peadm--add_database"></a>`peadm::add_database`
16051609

16061610
The peadm::add_database class.

plans/add_compiler.pp

+24-3
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,41 @@
77
# @param primary_host _ The hostname and certname of the primary Puppet server
88
# @param primary_postgresql_host _ The hostname and certname of the PE-PostgreSQL server with availability group $avail_group_letter
99
plan peadm::add_compiler(
10-
Enum['A', 'B'] $avail_group_letter,
10+
Enum['A', 'B'] $avail_group_letter = 'A' ,
1111
Optional[String[1]] $dns_alt_names = undef,
1212
Peadm::SingleTargetSpec $compiler_host,
1313
Peadm::SingleTargetSpec $primary_host,
14-
Peadm::SingleTargetSpec $primary_postgresql_host,
14+
Optional[Peadm::SingleTargetSpec] $primary_postgresql_host = undef,
1515
) {
1616
$compiler_target = peadm::get_targets($compiler_host, 1)
1717
$primary_target = peadm::get_targets($primary_host, 1)
18-
$primary_postgresql_target = peadm::get_targets($primary_postgresql_host, 1)
1918

2019
# Get current peadm config to determine where to setup additional rules for
2120
# compiler's secondary PuppetDB instances
2221
$peadm_config = run_task('peadm::get_peadm_config', $primary_target).first.value
2322

23+
if $primary_postgresql_host == undef {
24+
# get the external PostgreSQL host for the specified availability group
25+
$external_postgresql_host = $avail_group_letter ? {
26+
'A' => $peadm_config['params']['primary_postgresql_host'],
27+
default => $peadm_config['params']['replica_postgresql_host'],
28+
}
29+
30+
# If the external_postgresql_host is undef, use the server for that availability group
31+
$postgresql_host = $external_postgresql_host ? {
32+
undef => $peadm_config['role-letter']['server'][$avail_group_letter],
33+
default => $external_postgresql_host,
34+
}
35+
36+
if $postgresql_host == undef {
37+
fail_plan("No PostgreSQL host found for availability group ${avail_group_letter}")
38+
}
39+
40+
$primary_postgresql_target = peadm::get_targets($postgresql_host, 1)
41+
} else {
42+
$primary_postgresql_target = peadm::get_targets($primary_postgresql_host, 1)
43+
}
44+
2445
# Return the opposite server than the compiler to be added so it can be
2546
# configured with the appropriate rules for Puppet Server access from
2647
# compiler

spec/plans/add_compiler_spec.rb

+93-36
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,133 @@
55

66
def allow_standard_non_returning_calls
77
allow_apply
8-
allow_any_task
98
allow_any_command
9+
execute_no_plan
10+
allow_out_message
1011
end
1112

1213
describe 'basic functionality' do
1314
let(:params) do
1415
{
1516
'primary_host' => 'primary',
1617
'compiler_host' => 'compiler',
17-
'avail_group_letter' => 'A',
18-
'primary_postgresql_host' => 'primary_postgresql',
1918
}
2019
end
2120

21+
let(:params_with_avail_group_b) do
22+
params.merge({ 'avail_group_letter' => 'B' })
23+
end
24+
25+
let(:params_with_primary_postgresql_host) do
26+
params.merge({ 'primary_postgresql_host' => 'custom_postgresql' })
27+
end
28+
2229
let(:cfg) do
2330
{
2431
'params' => {
25-
'primary_host' => 'primary'
32+
'primary_host' => 'primary',
33+
'replica_host' => nil,
34+
'primary_postgresql_host' => nil,
35+
'replica_postgresql_host' => nil
2636
},
2737
'role-letter' => {
2838
'server' => {
2939
'A' => 'server_a',
30-
'B' => 'server_b'
40+
'B' => nil
41+
},
42+
'postgresql': {
43+
'A' => nil,
44+
'B' => nil
3145
}
3246
}
3347
}
3448
end
35-
let(:certdata) { { 'certname' => 'primary', 'extensions' => { '1.3.6.1.4.1.34380.1.1.9813' => 'A' } } }
3649

3750
it 'runs successfully when no alt-names are specified' do
3851
allow_standard_non_returning_calls
3952

4053
expect_task('peadm::get_peadm_config').always_return(cfg)
54+
expect_task('peadm::get_psql_version').with_targets(['server_a'])
55+
56+
expect_plan('peadm::subplans::component_install')
57+
expect_plan('peadm::util::copy_file').be_called_times(1)
58+
expect_task('peadm::puppet_runonce').with_targets(['compiler'])
59+
expect_task('peadm::puppet_runonce').with_targets(['server_a'])
60+
expect(run_plan('peadm::add_compiler', params)).to be_ok
61+
end
62+
63+
it 'handles different avail_group_letter values' do
64+
allow_standard_non_returning_calls
65+
cfg['role-letter']['server']['B'] = 'server_b'
66+
67+
expect_task('peadm::get_peadm_config').always_return(cfg)
68+
expect_task('peadm::get_psql_version').with_targets(['server_b'])
4169

42-
# TODO: Due to difficulty mocking get_targets, with_params modifier has been commented out
4370
expect_plan('peadm::subplans::component_install')
44-
# .with_params({
45-
# 'targets' => 'compiler',
46-
# 'primary_host' => 'primary',
47-
# 'avail_group_letter' => 'A',
48-
# 'dns_alt_names' => nil,
49-
# 'role' => 'pe_compiler'
50-
# })
71+
expect_plan('peadm::util::copy_file').be_called_times(1)
72+
expect_task('peadm::puppet_runonce').with_targets(['compiler'])
73+
expect_task('peadm::puppet_runonce').with_targets(['server_a'])
74+
expect_task('peadm::puppet_runonce').with_targets(['server_b'])
75+
expect(run_plan('peadm::add_compiler', params_with_avail_group_b)).to be_ok
76+
end
77+
78+
it 'handles specified primary_postgresql_host' do
79+
allow_standard_non_returning_calls
5180

81+
expect_task('peadm::get_peadm_config').always_return(cfg)
82+
expect_task('peadm::get_psql_version').with_targets(['custom_postgresql'])
83+
84+
expect_plan('peadm::subplans::component_install')
5285
expect_plan('peadm::util::copy_file').be_called_times(1)
86+
expect_task('peadm::puppet_runonce').with_targets(['compiler'])
87+
expect_task('peadm::puppet_runonce').with_targets(['custom_postgresql'])
88+
expect(run_plan('peadm::add_compiler', params_with_primary_postgresql_host)).to be_ok
89+
end
90+
91+
it 'handles external postgresql host group A' do
92+
allow_standard_non_returning_calls
93+
cfg['params']['primary_postgresql_host'] = 'external_postgresql'
94+
cfg['params']['replica_postgresql_host'] = 'external_postgresql'
95+
96+
expect_task('peadm::get_peadm_config').always_return(cfg)
97+
expect_task('peadm::get_psql_version').with_targets(['external_postgresql'])
98+
99+
expect_plan('peadm::subplans::component_install')
100+
expect_plan('peadm::util::copy_file').be_called_times(1)
101+
expect_task('peadm::puppet_runonce').with_targets(['compiler'])
102+
expect_task('peadm::puppet_runonce').with_targets(['external_postgresql'])
53103
expect(run_plan('peadm::add_compiler', params)).to be_ok
54104
end
55105

56-
context 'with alt-names' do
57-
let(:params2) do
58-
params.merge({ 'dns_alt_names' => 'foo,bar' })
59-
end
60-
61-
it 'runs successfully when alt-names are specified' do
62-
allow_standard_non_returning_calls
63-
expect_task('peadm::get_peadm_config').always_return(cfg)
64-
65-
# TODO: Due to difficulty mocking get_targets, with_params modifier has been commented out
66-
expect_plan('peadm::subplans::component_install')
67-
# .with_params({
68-
# 'targets' => 'compiler',
69-
# 'primary_host' => 'primary',
70-
# 'avail_group_letter' => 'A',
71-
# 'dns_alt_names' => 'foo,bar',
72-
# 'role' => 'pe_compiler'
73-
# })
74-
75-
expect_plan('peadm::util::copy_file').be_called_times(1)
76-
expect(run_plan('peadm::add_compiler', params2)).to be_ok
77-
end
106+
it 'handles external postgresql host group A with replica' do
107+
allow_standard_non_returning_calls
108+
cfg['params']['primary_postgresql_host'] = 'external_postgresql'
109+
cfg['role-letter']['server']['B'] = 'replica'
110+
111+
expect_task('peadm::get_peadm_config').always_return(cfg)
112+
expect_task('peadm::get_psql_version').with_targets(['external_postgresql'])
113+
114+
expect_plan('peadm::subplans::component_install')
115+
expect_plan('peadm::util::copy_file').be_called_times(1)
116+
expect_task('peadm::puppet_runonce').with_targets(['compiler'])
117+
expect_task('peadm::puppet_runonce').with_targets(['external_postgresql'])
118+
expect_task('peadm::puppet_runonce').with_targets(['replica'])
119+
expect(run_plan('peadm::add_compiler', params)).to be_ok
120+
end
121+
122+
it 'handles external postgresql host group B' do
123+
allow_standard_non_returning_calls
124+
cfg['params']['replica_postgresql_host'] = 'replica_external_postgresql'
125+
126+
expect_task('peadm::get_peadm_config').always_return(cfg)
127+
expect_task('peadm::get_psql_version').with_targets(['replica_external_postgresql'])
128+
129+
expect_plan('peadm::subplans::component_install')
130+
expect_plan('peadm::util::copy_file').be_called_times(1)
131+
expect_task('peadm::puppet_runonce').with_targets(['compiler'])
132+
expect_task('peadm::puppet_runonce').with_targets(['replica_external_postgresql'])
133+
expect_task('peadm::puppet_runonce').with_targets(['server_a'])
134+
expect(run_plan('peadm::add_compiler', params_with_avail_group_b)).to be_ok
78135
end
79136
end
80137
end

0 commit comments

Comments
 (0)