Skip to content

Commit

Permalink
BZ#2142270 - reindex the database *before* the installer runs
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Jan 27, 2023
1 parent f7c82a2 commit 8c014f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 9 additions & 7 deletions repos/system_upgrade/el7toel8/actors/satellite_upgrader/actor.py
Expand Up @@ -19,6 +19,15 @@ def process(self):
if not facts or not facts.has_foreman:
return

if facts.postgresql.local_postgresql:
api.current_actor().show_message('Re-indexing the database. This can take a while.')
try:
run(['sed', '-i', '/data_directory/d', '/var/lib/pgsql/data/postgresql.conf'])
run(['systemctl', 'start', 'postgresql'])
run(['runuser', '-u', 'postgres', '--', 'reindexdb', '-a'])
except (OSError, CalledProcessError) as e:
api.current_logger().error('Failed to reindex the database: {}'.format(str(e)))

installer_cmd = ['foreman-installer']
if facts.has_katello_installer:
installer_cmd.append('--disable-system-checks')
Expand All @@ -32,10 +41,3 @@ def process(self):
api.current_logger().error(
'Could not run the installer, please inspect the logs in /var/log/foreman-installer!'
)

if facts.postgresql.local_postgresql:
api.current_actor().show_message('Re-indexing the database. This can take a while.')
try:
run(['runuser', '-u', 'postgres', '--', 'reindexdb', '-a'])
except (OSError, CalledProcessError) as e:
api.current_logger().error('Failed to run `reindexdb`: {}'.format(str(e)))
Expand Up @@ -43,6 +43,8 @@ def test_run_reindexdb(monkeypatch, current_actor_context):
postgresql=SatellitePostgresqlFacts(local_postgresql=True)))
current_actor_context.run()
assert mocked_run.commands
assert len(mocked_run.commands) == 2
assert mocked_run.commands[0] == ['foreman-installer', '--disable-system-checks']
assert mocked_run.commands[1] == ['runuser', '-u', 'postgres', '--', 'reindexdb', '-a']
assert len(mocked_run.commands) == 4
assert mocked_run.commands[0] == ['sed', '-i', '/data_directory/d', '/var/lib/pgsql/data/postgresql.conf']
assert mocked_run.commands[1] == ['systemctl', 'start', 'postgresql']
assert mocked_run.commands[2] == ['runuser', '-u', 'postgres', '--', 'reindexdb', '-a']
assert mocked_run.commands[3] == ['foreman-installer', '--disable-system-checks']

0 comments on commit 8c014f1

Please sign in to comment.