From e3036c81059d95f12e220ec95a7df828a6370e02 Mon Sep 17 00:00:00 2001 From: Neil Anderson Date: Mon, 28 Oct 2024 11:08:56 +0000 Subject: [PATCH] (PE-39215) Retreiving replica postgres from get_peadm_config - add_replica No longer requiring user to input replica postgres host and instead getting this from peadm config --- REFERENCE.md | 10 ---------- documentation/add_replica.md | 6 ------ documentation/automated_recovery.md | 3 +-- plans/add_replica.pp | 16 ++++++---------- spec/acceptance/peadm_spec/plans/add_replica.pp | 2 -- .../peadm_spec/plans/perform_failover.pp | 2 -- 6 files changed, 7 insertions(+), 32 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index d430b87c..547e6038 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1788,7 +1788,6 @@ The following parameters are available in the `peadm::add_replica` plan: * [`primary_host`](#-peadm--add_replica--primary_host) * [`replica_host`](#-peadm--add_replica--replica_host) -* [`replica_postgresql_host`](#-peadm--add_replica--replica_postgresql_host) * [`token_file`](#-peadm--add_replica--token_file) ##### `primary_host` @@ -1803,15 +1802,6 @@ Data type: `Peadm::SingleTargetSpec` - The hostname and certname of the replica VM -##### `replica_postgresql_host` - -Data type: `Optional[Peadm::SingleTargetSpec]` - -- The hostname and certname of the host with the replica PE-PosgreSQL database. -Can be a separate host in an XL architecture, or undef in Standard or Large. - -Default value: `undef` - ##### `token_file` Data type: `Optional[String]` diff --git a/documentation/add_replica.md b/documentation/add_replica.md index df6988b2..4f4d0665 100644 --- a/documentation/add_replica.md +++ b/documentation/add_replica.md @@ -64,12 +64,6 @@ The plan performs the following steps: - **Description:** The hostname and certname of the replica VM. -### `primary_postgresql_host` - -- **Type:** `Optional[Peadm::SingleTargetSpec]` -- **Description:** - The target specification for the primary PostgreSQL host that the new replica will synchronize with. This is the database server from which the replica will replicate data. - ### `token_file` - **Type:** `Optional[String]` diff --git a/documentation/automated_recovery.md b/documentation/automated_recovery.md index 08afe0fb..1e899760 100644 --- a/documentation/automated_recovery.md +++ b/documentation/automated_recovery.md @@ -14,7 +14,6 @@ Manual procedures are documented in [recovery.md](recovery.md) This procedure uses the following placeholder references. * _\_ - The FQDN and certname of the primary Puppet server -* _\_ - The FQDN and certname of the PE-PostgreSQL server which resides in the same availability group as the replacement replica Puppet server * _\_ - The FQDN and certname of the replacement replica Puppet server 1. Run `peadm::add_replica` plan to deploy replacement replica Puppet server @@ -24,7 +23,7 @@ This procedure uses the following placeholder references. 2. For Extra Large deployments - bolt plan run peadm::add_replica primary_host= replica_host= replica_postgresql_host= + bolt plan run peadm::add_replica primary_host= replica_host= ## Replace failed PE-PostgreSQL server (A or B side) diff --git a/plans/add_replica.pp b/plans/add_replica.pp index 0806f33f..0818e70c 100644 --- a/plans/add_replica.pp +++ b/plans/add_replica.pp @@ -4,23 +4,17 @@ # 2: The existing replica is broken, we have a fresh new VM we want to provision the replica to. # @param primary_host - The hostname and certname of the primary Puppet server # @param replica_host - The hostname and certname of the replica VM -# @param replica_postgresql_host - The hostname and certname of the host with the replica PE-PosgreSQL database. -# Can be a separate host in an XL architecture, or undef in Standard or Large. # @param token_file - (optional) the token file in a different location than the default. plan peadm::add_replica( # Standard or Large Peadm::SingleTargetSpec $primary_host, Peadm::SingleTargetSpec $replica_host, - # Extra Large - Optional[Peadm::SingleTargetSpec] $replica_postgresql_host = undef, - # Common Configuration Optional[String] $token_file = undef, ) { $primary_target = peadm::get_targets($primary_host, 1) $replica_target = peadm::get_targets($replica_host, 1) - $replica_postgresql_target = peadm::get_targets($replica_postgresql_host, 1) $code_manager_enabled = run_task('peadm::code_manager_enabled', $primary_target).first.value['code_manager_enabled'] @@ -28,14 +22,16 @@ fail('Code Manager must be enabled to add a replica. Please refer to the docs for more information on enabling Code Manager.') } + # Get current peadm config to ensure we forget active replicas + $peadm_config = run_task('peadm::get_peadm_config', $primary_target).first.value + + $replica_postgresql_target = $peadm_config['params']['replica_postgresql_host'] + run_command('systemctl stop puppet.service', peadm::flatten_compact([ $primary_target, $replica_postgresql_target, ])) - # Get current peadm config to ensure we forget active replicas - $peadm_config = run_task('peadm::get_peadm_config', $primary_target).first.value - # Make list of all possible replicas, configured and provided $replicas = peadm::flatten_compact([ $replica_host, @@ -65,7 +61,7 @@ # Wrap these things that operate on replica_postgresql_target in an if statement # to avoid failures retrieving PSQL version because you can't operate functions # on a return value of nil. - if $replica_postgresql_host { + if $replica_postgresql_target { # On the PE-PostgreSQL server in the group $psql_version = run_task('peadm::get_psql_version', $replica_postgresql_target).first.value['version'] diff --git a/spec/acceptance/peadm_spec/plans/add_replica.pp b/spec/acceptance/peadm_spec/plans/add_replica.pp index 7fc0f869..4d8037f9 100644 --- a/spec/acceptance/peadm_spec/plans/add_replica.pp +++ b/spec/acceptance/peadm_spec/plans/add_replica.pp @@ -10,7 +10,6 @@ $primary_host = $t.filter |$n| { $n.vars['role'] == 'primary' } $replica_host = $t.filter |$n| { $n.vars['role'] == 'spare-replica' } - $replica_postgresql_host = $t.filter |$n| { $n.vars['role'] == 'replica-pdb-postgresql' } if $replica_host == [] { fail_plan('"replica" role missing from inventory, cannot continue') @@ -19,6 +18,5 @@ run_plan('peadm::add_replica', primary_host => $primary_host, replica_host => $replica_host, - replica_postgresql_host => $replica_postgresql_host ? { [] => undef, default => $replica_postgresql_host }, ) } diff --git a/spec/acceptance/peadm_spec/plans/perform_failover.pp b/spec/acceptance/peadm_spec/plans/perform_failover.pp index 0e0afef1..55876577 100644 --- a/spec/acceptance/peadm_spec/plans/perform_failover.pp +++ b/spec/acceptance/peadm_spec/plans/perform_failover.pp @@ -59,7 +59,6 @@ out::message("Active nodes 2: ${res2.first['stdout']}") # add new replica - $replica_postgresql_host = $t.filter |$n| { $n.vars['role'] == 'primary-pdb-postgresql' }[0] $new_replica_host = $t.filter |$n| { $n.vars['role'] == 'spare-replica' }[0] if $new_replica_host == [] { @@ -76,7 +75,6 @@ run_plan('peadm::add_replica', primary_host => $replica_host.uri, replica_host => $new_replica_host.uri, - replica_postgresql_host => $replica_postgresql_host ? {[] => undef, default => $replica_postgresql_host.uri }, ) $res3 = run_command("/opt/puppetlabs/bin/puppet query \'${query}\'", $replica_host)