Skip to content

Commit 6a28860

Browse files
(PE-41341) Allow primary prostgres host to be the failure (#594)
1 parent f41500e commit 6a28860

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

.github/workflows/test-replace-failed-postgresql.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ jobs:
9999
version=${{ matrix.version }} \
100100
console_password=${{ secrets.CONSOLE_PASSWORD }} \
101101
code_manager_auto_configure=true
102+
- name: Uninstall on primary-pdb-postgresql to emulate it failing
103+
run: |
104+
primary_pdb_postgresql_host=$(yq '.groups[].targets[] | select(.vars.role == "primary-pdb-postgresql") | .name' spec/fixtures/litmus_inventory.yaml)
105+
bundle exec bolt plan run peadm::uninstall \
106+
--inventoryfile spec/fixtures/litmus_inventory.yaml \
107+
--modulepath spec/fixtures/modules \
108+
-t $primary_pdb_postgresql_host \
109+
--no-host-key-check
102110
- name: Replace failed PostgreSQL
103111
run: |
104112
echo ::group::prepare

plans/replace_failed_postgresql.pp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,23 @@
2828
$failed_postgresql_host,
2929
$replacement_postgresql_host,
3030
])
31-
3231
# verify we can connect to targets proded before proceeding
3332
run_command('hostname', $all_hosts)
3433

35-
# Get current peadm config before making modifications
36-
$peadm_config = run_task('peadm::get_peadm_config', $primary_host).first.value
37-
$compilers = $peadm_config['params']['compilers']
34+
# Try to get current peadm config before making modifications
35+
$peadm_config = run_task('peadm::get_peadm_config', $primary_host, { '_catch_errors' => true }).first.value
36+
37+
if $peadm_config == undef or getvar('peadm_config.params') == undef {
38+
out::message('Unable to get config - the failed postgresql host may be the primary')
39+
} else {
40+
$config_replica_host = $peadm_config['params']['replica_host']
41+
$postgresql_a_host = $peadm_config['role-letter']['postgresql']['A']
42+
$postgresql_b_host = $peadm_config['role-letter']['postgresql']['B']
3843

39-
# Bail if we are not running this against an XL deployment with DR enabled - the parameters also enforce this to some extent
40-
if $compilers.empty {
41-
fail_plan('Plan peadm::replace_failed_postgresql is only applicable for XL deployments with DR enabled')
44+
# Bail if we are not running this against an XL deployment with DR enabled - the parameters also enforce this to some extent
45+
if $config_replica_host == undef or $postgresql_a_host == undef or $postgresql_b_host == undef {
46+
fail_plan('Plan peadm::replace_failed_postgresql is only applicable for XL deployments with DR enabled')
47+
}
4248
}
4349

4450
$pe_hosts = peadm::flatten_compact([

spec/acceptance/peadm_spec/plans/test_replace_failed_postgres.pp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,8 @@
55
Peadm::SingleTargetSpec $failed_postgresql_host,
66
Peadm::SingleTargetSpec $replacement_postgresql_host,
77
) {
8-
# run infra status on the primary
9-
out::message("Running peadm::status on primary host ${primary_host}")
10-
$primary_status = run_plan('peadm::status', $primary_host, { 'format' => 'json' })
11-
out::message($primary_status)
12-
13-
if empty($primary_status['failed']) {
14-
out::message('Cluster is healthy, continuing')
15-
} else {
16-
fail_plan('Cluster is not healthy, aborting')
17-
}
8+
# run puppet once on working_postgresql_host - gives some time in CI
9+
run_task('peadm::puppet_runonce', $working_postgresql_host)
1810

1911
# replace the failed postgres server
2012
run_plan('peadm::replace_failed_postgresql',

0 commit comments

Comments
 (0)