Skip to content

Commit

Permalink
(PE-39352) Adding patching service database to backup/restore plans
Browse files Browse the repository at this point in the history
2025.0 adds the pe-patching-service and pe-patching database. This
commit updates the recovery metadata to account for the pe-patching
database in 2025.0+ versions.
  • Loading branch information
jpartlow committed Dec 12, 2024
1 parent 94a2ac6 commit f9cf46d
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 7 deletions.
11 changes: 9 additions & 2 deletions functions/amend_recovery_defaults_by_pe_version.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ function peadm::amend_recovery_defaults_by_pe_version (
Boolean $opt_value,
) {
# work around puppet-lint check_unquoted_string_in_case
$semverrange = SemVerRange('>= 2023.7')
$pe_2025_0 = SemVerRange('>= 2025.0')
$pe_2023_7 = SemVerRange('>= 2023.7')
case $pe_version {
$semverrange: {
$pe_2025_0: {
$base_opts + {
'hac' => $opt_value,
'patching' => $opt_value,
}
}
$pe_2023_7: {
$base_opts + {
'hac' => $opt_value,
}
Expand Down
3 changes: 2 additions & 1 deletion functions/validated_pe_version_for_backup_restore.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function peadm::validated_pe_version_for_backup_restore(
default: {
$msg = @("WARN")
WARNING: Retrieved a missing or unparseable PE version of '${pe_version}'.
The host_action_collector database will be skipped from defaults.
Newer service databases released in 2023.7+ will be skipped from defaults.
(host-action-collector, patching)
|-WARN
out::message($msg)
'0.0.0'
Expand Down
2 changes: 2 additions & 0 deletions plans/backup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
'puppetdb' => $puppetdb_postgresql_target,
# (host-action-collector db will be filtered for pe version by recovery_opts)
'hac' => $primary_target,
# (patching db will be filtered for pe version by recovery_opts)
'patching' => $primary_target,
}.filter |$key,$_| {
$recovery_opts[$key] == true
}
Expand Down
2 changes: 2 additions & 0 deletions plans/restore.pp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
'puppetdb' => $puppetdb_postgresql_targets,
# (host-action-collector db will be filtered for pe version by recovery_opts)
'hac' => $primary_target,
# (patching db will be filtered for pe version by recovery_opts)
'patching' => $primary_target,
}.filter |$key,$_| {
$recovery_opts[$key] == true
}
Expand Down
17 changes: 17 additions & 0 deletions spec/functions/migration_opts_default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,21 @@
},
)
end

it 'returns 2025.0+ defaults with hac and patching' do
is_expected.to run.with_params('2025.0.0').and_return(
{
'activity' => true,
'ca' => true,
'classifier' => true,
'code' => false,
'config' => false,
'orchestrator' => true,
'puppetdb' => true,
'rbac' => true,
'hac' => true,
'patching' => true,
},
)
end
end
33 changes: 33 additions & 0 deletions spec/functions/recovery_opts_all_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,37 @@
},
)
end

it 'returns 2023.7+ defaults with hac if >2023.7 <2025.0' do
is_expected.to run.with_params('2024.9999.0').and_return(
{
'activity' => true,
'ca' => true,
'classifier' => true,
'code' => true,
'config' => true,
'orchestrator' => true,
'puppetdb' => true,
'rbac' => true,
'hac' => true,
},
)
end

it 'returns 2025.0+ defaults with hac and patching' do
is_expected.to run.with_params('2025.0.0').and_return(
{
'activity' => true,
'ca' => true,
'classifier' => true,
'code' => true,
'config' => true,
'orchestrator' => true,
'puppetdb' => true,
'rbac' => true,
'hac' => true,
'patching' => true,
},
)
end
end
17 changes: 17 additions & 0 deletions spec/functions/recovery_opts_default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,21 @@
},
)
end

it 'returns 2025.0+ defaults with hac and patching' do
is_expected.to run.with_params('2025.0.0').and_return(
{
'activity' => false,
'ca' => true,
'classifier' => false,
'code' => true,
'config' => true,
'orchestrator' => false,
'puppetdb' => true,
'rbac' => false,
'hac' => false,
'patching' => false,
},
)
end
end
24 changes: 22 additions & 2 deletions spec/plans/backup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'puppetdb' => false,
'rbac' => false,
'hac' => false,
'patching' => false,
}
}
end
Expand Down Expand Up @@ -119,7 +120,25 @@
end
end

context '>= 2023.7.0' do
context '>= 2025.0.0' do
let(:pe_version) { '2025.0.0' }

include_context('all 2023.6.0 backups')

it 'runs with backup type custom, all backup params set to true' do
expect_out_message.with_params('# Backing up database pe-hac')
expect_out_message.with_params('# Backing up database pe-patching')

expect_command('/opt/puppetlabs/server/bin/pg_dump -Fd -Z3 -j4 -f /tmp/pe-backup-1970-01-01T000000Z/hac/pe-hac.dump.d "sslmode=verify-ca host=primary user=pe-hac sslcert=/etc/puppetlabs/puppetdb/ssl/primary.cert.pem sslkey=/etc/puppetlabs/puppetdb/ssl/primary.private_key.pem sslrootcert=/etc/puppetlabs/puppet/ssl/certs/ca.pem dbname=pe-hac"' + "\n")
expect_command('/opt/puppetlabs/server/bin/pg_dump -Fd -Z3 -j4 -f /tmp/pe-backup-1970-01-01T000000Z/patching/pe-patching.dump.d "sslmode=verify-ca host=primary user=pe-patching sslcert=/etc/puppetlabs/puppetdb/ssl/primary.cert.pem sslkey=/etc/puppetlabs/puppetdb/ssl/primary.private_key.pem sslrootcert=/etc/puppetlabs/puppet/ssl/certs/ca.pem dbname=pe-patching"' + "\n")

expect(run_plan('peadm::backup', all_backup_options)).to be_ok
end
end

context '>= 2023.7.0 < 2025.0' do
let(:pe_version) { '2023.7.0' }

include_context('all 2023.6.0 backups')

it 'runs with backup type custom, all backup params set to true' do
Expand Down Expand Up @@ -149,7 +168,8 @@
it 'warns that hac is ignored' do
expect_out_message.with_params(<<~MSG.strip)
WARNING: Retrieved a missing or unparseable PE version of ''.
The host_action_collector database will be skipped from defaults.
Newer service databases released in 2023.7+ will be skipped from defaults.
(host-action-collector, patching)
MSG

expect(run_plan('peadm::backup', all_backup_options)).to be_ok
Expand Down
22 changes: 20 additions & 2 deletions spec/plans/restore_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
'orchestrator' => false,
'puppetdb' => false,
'rbac' => false,
'hac' => false,
'patching' => false,
}
}
end
Expand Down Expand Up @@ -175,7 +177,22 @@ def expect_peadm_config_fallback(backup_dir, file)
end
end

context '>= 2023.7.0' do
context '>= 2025.0.0' do
let(:pe_version) { '2025.0.0' }

include_context('all 2023.6.0 backups')

it 'runs with backup type custom, all params set to true', valid_cluster: true do
expect_restore_for_db('hac', 'primary')
expect_restore_for_db('patching', 'primary')

expect(run_plan('peadm::restore', all_recovery_options)).to be_ok
end
end

context '>= 2023.7.0 < 2025.0' do
let(:pe_version) { '2023.7.0' }

include_context('all 2023.6.0 backups')

it 'runs with backup type custom, all params set to true', valid_cluster: true do
Expand Down Expand Up @@ -211,7 +228,8 @@ def expect_peadm_config_fallback(backup_dir, file)
it 'warns that hac is ignored', valid_cluster: false do
expect_out_message.with_params(<<~MSG.strip)
WARNING: Retrieved a missing or unparseable PE version of ''.
The host_action_collector database will be skipped from defaults.
Newer service databases released in 2023.7+ will be skipped from defaults.
(host-action-collector, patching)
MSG

expect_peadm_config_fallback(backup_dir, 'peadm_config.no_pe_version.json')
Expand Down
1 change: 1 addition & 0 deletions types/recovery_opts.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
'puppetdb' => Optional[Boolean],
'rbac' => Optional[Boolean],
'hac' => Optional[Boolean],
'patching' => Optional[Boolean],
}]

0 comments on commit f9cf46d

Please sign in to comment.