Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions almalinux8to9/actions/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
from .common import get_adapted_repository

_ALMA9_POSTGRES_VERSION = 13
_POSTGRES_REPO_FILE = "/etc/yum.repos.d/pgdg-redhat-all.repo"


def _is_modern_postgres_installed() -> bool:
return (
postgres.is_postgres_installed()
and postgres.get_postgres_major_version() >= _ALMA9_POSTGRES_VERSION
)


class AssertOutdatedPostgresNotInstalled(action.CheckAction):
Expand Down Expand Up @@ -149,6 +157,20 @@ def estimate_post_time(self) -> int:
return 3 * 60


class AssertModernPostgresRepositoryFilePresent(action.CheckAction):
def __init__(self):
self.name = "checking the modern postgresql repository file is present"
self.description = f"""A modern PostgreSQL is installed, but its repository file {_POSTGRES_REPO_FILE!r} is missing.
\tWithout it the conversion cannot reinstall PostgreSQL on AlmaLinux 9 and the packages would be removed silently.
\tPlease either place the PostgreSQL repository file at {_POSTGRES_REPO_FILE}, or remove PostgreSQL before the conversion.
"""

def _do_check(self) -> bool:
if not _is_modern_postgres_installed():
return True
return os.path.exists(_POSTGRES_REPO_FILE)


class PostgresReinstallModernPackage(action.ActiveAction):
# Leapp is going to remove PostgreSQL package from the system during conversion process.
# So during this action we shouldn't use any PostgreSQL related commands. Luckily data will not be removed
Expand All @@ -160,7 +182,7 @@ def _get_versions(self) -> typing.List[int]:
return [int(dataset) for dataset in os.listdir(postgres.get_pgsql_root_path()) if dataset.isnumeric()]

def _is_required(self) -> bool:
return postgres.is_postgres_installed() and any([major_version >= _ALMA9_POSTGRES_VERSION for major_version in self._get_versions()])
return _is_modern_postgres_installed()

def _is_service_active(self, service: str) -> bool:
res = subprocess.run(['/usr/bin/systemctl', 'is-active', service])
Expand All @@ -175,7 +197,7 @@ def _get_service_name(major_version: int) -> str:
return f'postgresql-{major_version}'

def _prepare_action(self) -> action.ActionResult:
leapp_configs.add_repositories_mapping_json(["/etc/yum.repos.d/pgdg-redhat-all.repo"],
leapp_configs.add_repositories_mapping_json([_POSTGRES_REPO_FILE],
do_adapt_repository=partial(get_adapted_repository, keep_id=False),
skip_disabled=True,
mapjson_path=leapp_configs.LEAPP_MAP_JSON_PATH,
Expand Down
1 change: 1 addition & 0 deletions almalinux8to9/upgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def get_check_actions(
"QMail is not supported on AlmaLinux 9 - consider switching to Postfix before conversion"),
custom_actions.AssertStatsToolNotUsed('webalizer'),
custom_actions.AssertMariadbRepoAvailable(),
custom_actions.AssertModernPostgresRepositoryFilePresent(),
common_actions.AssertNotInContainer(),
custom_actions.AssertPackagesUpToDate(),
custom_actions.AssertNoOutdatedLetsEncryptExtRepository(),
Expand Down
Loading