Skip to content

Commit

Permalink
Add actor for postgresql migration RHEL9->RHEL10
Browse files Browse the repository at this point in the history
  • Loading branch information
fila43 committed Nov 25, 2024
1 parent 3c3421a commit 4ad2739
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
20 changes: 20 additions & 0 deletions repos/system_upgrade/el9toel10/actors/postgresqlcheck/actor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from leapp.actors import Actor
from leapp.libraries.actor.postgresqlcheck import report_installed_packages
from leapp.models import DistributionSignedRPM, Report
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag


class PostgresqlCheck(Actor):
"""
Actor checking for presence of PostgreSQL installation.
Provides user with information related to upgrading systems
with PostgreSQL installed.
"""
name = 'postgresql_check'
consumes = (DistributionSignedRPM,)
produces = (Report,)
tags = (ChecksPhaseTag, IPUWorkflowTag)

def process(self):
report_installed_packages()
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from leapp import reporting
from leapp.libraries.common.rpms import has_package
from leapp.libraries.stdlib import api
from leapp.models import DistributionSignedRPM

# Summary for postgresql-server report
report_server_inst_summary = (
'PostgreSQL server component will be upgraded. Since RHEL-10 includes'
' PostgreSQL server 16 by default, which is incompatible with 13 and 15'
' included in RHEL-9, in those cases, it is necessary to proceed with additional steps'
' for the complete upgrade of the PostgreSQL data.'
'If the database has already been upgraded, meaning the system is already using PostgreSQL 16, then no further actions are required.'
)

report_server_inst_hint = (
'Back up your data before proceeding with the upgrade'
' and follow steps in the documentation section "Migrating to a RHEL 10 version of PostgreSQL"'
' after the upgrade.'
)

# Link URL for postgresql-server report
report_server_inst_link_url = 'https://access.redhat.com/articles/7097228'


def _report_server_installed():
"""
Create report on postgresql-server package installation detection.
Should remind user about present PostgreSQL server package
installation, warn them about necessary additional steps, and
redirect them to online documentation for the upgrade process.
"""
reporting.create_report([
reporting.Title('PostgreSQL (postgresql-server) has been detected on your system'),
reporting.Summary(report_server_inst_summary),
reporting.Severity(reporting.Severity.MEDIUM),
reporting.Groups([reporting.Groups.SERVICES]),
reporting.ExternalLink(title='Migrating to a RHEL 10 version of PostgreSQL',
url=report_server_inst_link_url),
reporting.RelatedResource('package', 'postgresql-server'),
reporting.Remediation(hint=report_server_inst_hint),
])


def report_installed_packages(_context=api):
"""
Create reports according to detected PostgreSQL packages.
Create the report if the postgresql-server rpm (RH signed) is installed.
"""
has_server = has_package(DistributionSignedRPM, 'postgresql-server', context=_context)

if has_server:
# postgresql-server
_report_server_installed()
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import pytest

from leapp import reporting
from leapp.libraries.actor.postgresqlcheck import report_installed_packages
from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked
from leapp.libraries.stdlib import api
from leapp.models import DistributionSignedRPM, RPM


def _generate_rpm_with_name(name):
"""
Generate new RPM model item with given name.
Parameters:
name (str): rpm name
Returns:
rpm (RPM): new RPM object with name parameter set
"""
return RPM(name=name,
version='0.1',
release='1.sm01',
epoch='1',
pgpsig='RSA/SHA256, Mon 01 Jan 1970 00:00:00 AM -03, Key ID 199e2f91fd431d51',
packager='Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>',
arch='noarch')


@pytest.mark.parametrize('has_server', [
(True), # with server
(False), # without server
])
def test_actor_execution(monkeypatch, has_server):
"""
Parametrized helper function for test_actor_* functions.
First generate list of RPM models based on set arguments. Then, run
the actor fed with our RPM list. Finally, assert Reports
according to set arguments.
Parameters:
has_server (bool): postgresql-server installed
"""

# Couple of random packages
rpms = [_generate_rpm_with_name('sed'),
_generate_rpm_with_name('htop')]

if has_server:
# Add postgresql-server
rpms += [_generate_rpm_with_name('postgresql-server')]

curr_actor_mocked = CurrentActorMocked(msgs=[DistributionSignedRPM(items=rpms)])
monkeypatch.setattr(api, 'current_actor', curr_actor_mocked)
monkeypatch.setattr(reporting, "create_report", create_report_mocked())

# Executed actor fed with out fake RPMs
report_installed_packages(_context=api)

if has_server:
# Assert for postgresql-server package installed
assert reporting.create_report.called == 1
else:
# Assert for no postgresql packages installed
assert not reporting.create_report.called

0 comments on commit 4ad2739

Please sign in to comment.