Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add actors for databases migration - postgresql/mariadb RHEL9 -> RHEL 10 #1316

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions repos/system_upgrade/el9toel10/actors/mariadbcheck/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.mariadbcheck import report_installed_packages
from leapp.models import DistributionSignedRPM, Report
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag


class MariadbCheck(Actor):
"""
Actor checking for presence of MariaDB installation.

Provides user with information related to upgrading systems
with MariaDB installed.
"""
name = 'mariadb_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,53 @@
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 mariadb-server report
report_server_inst_summary = (
'MariaDB server component will be upgraded. Since RHEL-10 includes'
' MariaDB server 10.11 by default, which is incompatible with 10.5'
' included in RHEL-9, it is necessary to proceed with additional steps'
' for the complete upgrade of the MariaDB data.'
)

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 MariaDB"'
' after the upgrade.'
)

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


def _report_server_installed():
"""
Create report on mariadb-server package installation detection.

Should remind user about present MariaDB server package
installation, warn them about necessary additional steps, and
redirect them to online documentation for the upgrade process.
"""
reporting.create_report([
reporting.Title('MariaDB (mariadb-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 MariaDB',
url=report_server_inst_link_url),
reporting.RelatedResource('package', 'mariadb-server'),
reporting.Remediation(hint=report_server_inst_hint),
])


def report_installed_packages(_context=api):
"""
Create reports according to detected MariaDB packages.

Create the report if the mariadb-server rpm (RH signed) is installed.
"""
has_server = has_package(DistributionSignedRPM, 'mariadb-server', context=_context)

if has_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.mariadbcheck 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): mariadb-server installed
"""

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

if has_server:
# Add mariadb-server
rpms += [_generate_rpm_with_name('mariadb-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 fake RPMs
report_installed_packages(_context=api)

if has_server:
# Assert for mariadb-server package installed
assert reporting.create_report.called == 1
else:
# Assert for no mariadb packages installed
assert not reporting.create_report.called
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
Loading