Skip to content

Commit d388618

Browse files
committedJun 22, 2021
add peadm_spec::add_replica test plan for peadm::add_replica
1 parent 47f7ced commit d388618

File tree

3 files changed

+56
-14
lines changed

3 files changed

+56
-14
lines changed
 

Diff for: ‎.github/workflows/test-add-replica.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
echo STEP_START=$(date +%s) >> $GITHUB_ENV
8484
echo ::endgroup::
8585
86-
- name: 'Provision test cluster'
86+
- name: 'Provision test cluster (specified architecture with added DR)'
8787
timeout-minutes: 15
8888
run: |
8989
echo ::group::prepare
@@ -143,7 +143,7 @@ jobs:
143143
timeout-minutes: 10
144144
run: |
145145
buildevents cmd $TRACE_ID $STEP_ID 'bolt plan run peadm_spec::add_replica' -- \
146-
bundle exec bolt plan run peadm_spec::add_replica \
146+
bundle exec bolt plan run peadm_spec::add_replica -v \
147147
--inventoryfile spec/fixtures/litmus_inventory.yaml \
148148
--modulepath spec/fixtures/modules
149149

Diff for: ‎plans/add_replica.pp

+28-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
# use case 1: the replica is gone,
2-
# use case 2: there is no replica,
3-
# both use cases: we have a fresh new VM we want to provision the replica to
4-
1+
# @summary Add a replica to a PE architecture or replace an existing one.
2+
# Supported use cases:
3+
# 1: the replica is gone,
4+
# 2: there is no replica,
5+
# both use cases: we have a fresh new VM we want to provision the replica to.
6+
# @param primary_host - The hostname and certname of the primary Puppet server
7+
# @param replica_host - The hostname and certname of the replica VM
8+
# @param replica_postgresql_host - The hostname and certname of the host with the replica PE-PosgreSQL database.
9+
# Can be a separate host in an XL architecture, or the replica host in standard or Large.
510
plan peadm::add_replica(
611
Peadm::SingleTargetSpec $primary_host,
712
Peadm::SingleTargetSpec $replica_host,
@@ -16,23 +21,34 @@
1621
$primary_avail_group_letter = $certdata['extensions'][peadm::oid('peadm_availability_group')]
1722
$replica_avail_group_letter = $primary_avail_group_letter ? { 'A' => 'B', default => 'A' }
1823

19-
# Stop puppet.service on replica postgresql host
20-
run_command('systemctl stop puppet.service', $replica_postgresql_target)
24+
# Stop puppet.service on replica postgresql host. Catch errors in case no puppet service is running
25+
run_command('systemctl stop puppet.service', $replica_postgresql_target, _catch_errors => true)
2126

2227
# stop pe-postgresql.service on replica postgresql host
23-
run_command('systemctl stop pe-postgresql.service', $replica_postgresql_target)
28+
run_command('systemctl stop pe-postgresql.service', $replica_postgresql_target, _catch_errors => true)
2429

25-
run_command("puppet infrastructure forget ${replica_target.peadm::certname()}", $primary_target)
30+
run_command("puppet infrastructure forget ${replica_target.peadm::certname()}", $primary_target, _catch_errors => true)
2631

2732
run_task('peadm::agent_install', $replica_target,
2833
server => $primary_target.peadm::certname(),
2934
install_flags => [
30-
"extension_requests:${peadm::oid('peadm_role')}='puppet/server'",
35+
"extension_requests:${peadm::oid('peadm_role')}=puppet/server",
3136
"extension_requests:${peadm::oid('peadm_availability_group')}=${replica_avail_group_letter}",
3237
"main:certname=${replica_target.peadm::certname()}",
3338
],
3439
)
3540

41+
# run puppet agent once ignoring possible cert errors
42+
run_task('peadm::puppet_runonce', $replica_target, _catch_errors => true)
43+
44+
# If necessary, manually submit a CSR
45+
# ignoring errors to simplify logic
46+
run_task('peadm::submit_csr', $replica_target, _catch_errors => true)
47+
48+
# On primary, if necessary, sign the certificate request
49+
run_task('peadm::sign_csr', $primary_target, certnames => [$replica_target.peadm::certname()] )
50+
51+
# On <replica_target>, run the puppet agent
3652
run_task('peadm::puppet_runonce', $replica_target)
3753

3854
# On the PE-PostgreSQL server in the <replacement-avail-group-letter> group
@@ -44,7 +60,7 @@
4460

4561
# pe-puppetdb-pe-puppetdb-map <replacement-replica-fqdn> pe-puppetdb
4662
# pe-puppetdb-pe-puppetdb-migrator-map <replacement-replica-fqdn> pe-puppetdb-migrator
47-
apply($replica_postgresql_target) {
63+
apply($replica_postgresql_target, _catch_errors => true) {
4864
file_line { 'pe-puppetdb-pe-puppetdb-map':
4965
path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf',
5066
line => "pe-puppetdb-pe-puppetdb-map ${replica_target.peadm::certname()} pe-puppetdb",
@@ -56,7 +72,7 @@
5672
}
5773

5874
# Restart pe-postgresql.service
59-
run_command('systemctl restart pe-postgresql.service', $replica_postgresql_target)
75+
run_command('systemctl restart pe-postgresql.service', $replica_postgresql_target, _catch_errors => true)
6076

6177
# Provision the new system as a replica
6278
run_task('peadm::provision_replica', $primary_target,
@@ -70,7 +86,7 @@
7086
)
7187

7288
# start puppet service on postgresql host
73-
run_command('systemctl stop puppet.service', $replica_postgresql_target)
89+
run_command('systemctl start puppet.service', $replica_postgresql_target)
7490

7591

7692
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
plan peadm_spec::add_replica(
2+
){
3+
4+
$t = get_targets('*')
5+
wait_until_available($t)
6+
7+
parallelize($t) |$target| {
8+
$fqdn = run_command('hostname -f', $target)
9+
$target.set_var('certname', $fqdn.first['stdout'].chomp)
10+
}
11+
12+
$primary_host = $t.filter |$n| { $n.vars['role'] == 'primary' }
13+
$replica_host = $t.filter |$n| { $n.vars['role'] == 'replica' }
14+
$replica_postgresql_host = $t.filter |$n| { $n.vars['role'] == 'replica-pdb-postgresql' }
15+
16+
if $replica_host == [] {
17+
fail_plan('"replica" role missing from inventory, cannot continue')
18+
}
19+
20+
run_plan('peadm::add_replica',
21+
primary_host => $primary_host,
22+
replica_host => $replica_host,
23+
replica_postgresql_host => $replica_postgresql_host ? { [] => $replica_host, default => $replica_postgresql_host }
24+
)
25+
26+
}

0 commit comments

Comments
 (0)