From a93f9d6a719a4066209515ea487026aa60c94f8e Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Mon, 3 Jun 2024 14:17:38 +0200 Subject: [PATCH] refresh collation version when pulp_ansible is installed --- definitions/procedures/restore/reindex_databases.rb | 6 ++++++ .../procedures/restore/reindex_databases_test.rb | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/definitions/procedures/restore/reindex_databases.rb b/definitions/procedures/restore/reindex_databases.rb index 7e3593f22..6fc39609b 100644 --- a/definitions/procedures/restore/reindex_databases.rb +++ b/definitions/procedures/restore/reindex_databases.rb @@ -1,6 +1,7 @@ module Procedures::Restore class ReindexDatabases < ForemanMaintain::Procedure include ForemanMaintain::Concerns::SystemService + include ForemanMaintain::Concerns::SystemHelpers metadata do description 'REINDEX databases' @@ -16,6 +17,11 @@ def run spinner.update('Reindexing the databases') execute!('runuser - postgres -c "reindexdb -a"') + if check_min_version('python3.11-pulp-ansible', '0.20.0') + execute!('runuser -c '\ + '\'echo "ALTER COLLATION pulp_ansible_semver REFRESH VERSION;"'\ + '| psql pulpcore\' postgres') + end end end end diff --git a/test/definitions/procedures/restore/reindex_databases_test.rb b/test/definitions/procedures/restore/reindex_databases_test.rb index e1520fb51..01b894a81 100644 --- a/test/definitions/procedures/restore/reindex_databases_test.rb +++ b/test/definitions/procedures/restore/reindex_databases_test.rb @@ -16,6 +16,19 @@ reindex_command = 'runuser - postgres -c "reindexdb -a"' subject.stubs(:'execute!').with(reindex_command).returns(0) + subject.stubs(:check_min_version).returns(false) + result = run_procedure(subject) + assert result.success?, 'the procedure was expected to succeed' + end + + it 'reindexes all DBs if DB is local and pulp-ansible is present' do + reindex_command = 'runuser - postgres -c "reindexdb -a"' + collate_command = 'runuser -c \'echo "ALTER COLLATION pulp_ansible_semver REFRESH VERSION;"'\ + '| psql pulpcore\' postgres' + + subject.stubs(:'execute!').with(reindex_command).returns(0) + subject.stubs(:check_min_version).with('python3.11-pulp-ansible', '0.20.0').returns(true) + subject.stubs(:'execute!').with(collate_command).returns(0) result = run_procedure(subject) assert result.success?, 'the procedure was expected to succeed' end