From f9cf46ddb01a2db9375ccc36997449949d6815fc Mon Sep 17 00:00:00 2001 From: Josh Partlow Date: Thu, 12 Dec 2024 21:01:34 +0000 Subject: [PATCH] (PE-39352) Adding patching service database to backup/restore plans 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. --- .../amend_recovery_defaults_by_pe_version.pp | 11 +++++-- ...validated_pe_version_for_backup_restore.pp | 3 +- plans/backup.pp | 2 ++ plans/restore.pp | 2 ++ spec/functions/migration_opts_default_spec.rb | 17 ++++++++++ spec/functions/recovery_opts_all_spec.rb | 33 +++++++++++++++++++ spec/functions/recovery_opts_default_spec.rb | 17 ++++++++++ spec/plans/backup_spec.rb | 24 ++++++++++++-- spec/plans/restore_spec.rb | 22 +++++++++++-- types/recovery_opts.pp | 1 + 10 files changed, 125 insertions(+), 7 deletions(-) diff --git a/functions/amend_recovery_defaults_by_pe_version.pp b/functions/amend_recovery_defaults_by_pe_version.pp index 881fd0c8..d6de2cb1 100644 --- a/functions/amend_recovery_defaults_by_pe_version.pp +++ b/functions/amend_recovery_defaults_by_pe_version.pp @@ -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, } diff --git a/functions/validated_pe_version_for_backup_restore.pp b/functions/validated_pe_version_for_backup_restore.pp index c84677de..73efc781 100644 --- a/functions/validated_pe_version_for_backup_restore.pp +++ b/functions/validated_pe_version_for_backup_restore.pp @@ -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' diff --git a/plans/backup.pp b/plans/backup.pp index cb15f77e..4e3e15a6 100644 --- a/plans/backup.pp +++ b/plans/backup.pp @@ -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 } diff --git a/plans/restore.pp b/plans/restore.pp index 518d08c0..8e8975f6 100644 --- a/plans/restore.pp +++ b/plans/restore.pp @@ -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 } diff --git a/spec/functions/migration_opts_default_spec.rb b/spec/functions/migration_opts_default_spec.rb index 066b3443..c9df7743 100644 --- a/spec/functions/migration_opts_default_spec.rb +++ b/spec/functions/migration_opts_default_spec.rb @@ -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 diff --git a/spec/functions/recovery_opts_all_spec.rb b/spec/functions/recovery_opts_all_spec.rb index ca4f5547..7d12ebda 100644 --- a/spec/functions/recovery_opts_all_spec.rb +++ b/spec/functions/recovery_opts_all_spec.rb @@ -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 diff --git a/spec/functions/recovery_opts_default_spec.rb b/spec/functions/recovery_opts_default_spec.rb index 7e5b0aba..7a775456 100644 --- a/spec/functions/recovery_opts_default_spec.rb +++ b/spec/functions/recovery_opts_default_spec.rb @@ -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 diff --git a/spec/plans/backup_spec.rb b/spec/plans/backup_spec.rb index 7f948cc2..20243f45 100644 --- a/spec/plans/backup_spec.rb +++ b/spec/plans/backup_spec.rb @@ -21,6 +21,7 @@ 'puppetdb' => false, 'rbac' => false, 'hac' => false, + 'patching' => false, } } end @@ -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 @@ -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 diff --git a/spec/plans/restore_spec.rb b/spec/plans/restore_spec.rb index 81359b41..960e49f0 100644 --- a/spec/plans/restore_spec.rb +++ b/spec/plans/restore_spec.rb @@ -45,6 +45,8 @@ 'orchestrator' => false, 'puppetdb' => false, 'rbac' => false, + 'hac' => false, + 'patching' => false, } } end @@ -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 @@ -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') diff --git a/types/recovery_opts.pp b/types/recovery_opts.pp index 1c20db3f..eacfd532 100644 --- a/types/recovery_opts.pp +++ b/types/recovery_opts.pp @@ -8,4 +8,5 @@ 'puppetdb' => Optional[Boolean], 'rbac' => Optional[Boolean], 'hac' => Optional[Boolean], + 'patching' => Optional[Boolean], }]