Skip to content

Commit

Permalink
Add baculacheck actor
Browse files Browse the repository at this point in the history
Check whether bacula-director is installed and informs about the
necessary conversion of Bacula catalog after upgrade.

Copied from the checkpostgresql and checkmariadb actors.
  • Loading branch information
pcahyna committed May 23, 2022
1 parent 85e0cea commit 49a45da
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
20 changes: 20 additions & 0 deletions repos/system_upgrade/el8toel9/actors/baculacheck/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.baculacheck import report_installed_packages
from leapp.models import InstalledRedHatSignedRPM, Report
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag


class BaculaCheck(Actor):
"""
Actor checking for presence of Bacula installation.
Provides user with information related to upgrading systems
with Bacula installed.
"""
name = 'bacula_check'
consumes = (InstalledRedHatSignedRPM,)
produces = (Report,)
tags = (ChecksPhaseTag, IPUWorkflowTag)

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

# Summary for bacula-director report
report_director_inst_summary = (
'Bacula director component will be upgraded. Since RHEL-9 includes'
' Bacula director 11, which is incompatible with version 9'
' included in RHEL-8, it is necessary to proceed with additional steps'
' for the complete upgrade of the Bacula backup database.'
)

report_director_inst_hint = (
'Back up your data before proceeding with the upgrade'
' and use the command "/usr/libexec/bacula/update_bacula_tables <dbtype>" to upgrade'
' the Bacula database after the system upgrade.'
' The value of <dbtype> depends on the database backend, possible values are'
' sqlite3, mysql, postgresql.'
)


def _report_director_installed():
"""
Create report on bacula-director package installation detection.
Should remind user about present Bacula director package
installation and warn them about necessary additional steps.
"""
reporting.create_report([
reporting.Title('bacula (bacula-director) has been detected on your system'),
reporting.Summary(report_director_inst_summary),
reporting.Severity(reporting.Severity.MEDIUM),
reporting.Tags([reporting.Tags.SERVICES]),
reporting.RelatedResource('package', 'bacula-director'),
reporting.Remediation(hint=report_director_inst_hint),
])


def report_installed_packages(_context=api):
"""
Create reports according to detected bacula packages.
Create the report if the bacula-director rpm (RH signed) is installed.
"""
has_director = has_package(InstalledRedHatSignedRPM, 'bacula-director', context=_context)

if has_director:
# bacula-director
_report_director_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.baculacheck import report_installed_packages
from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked
from leapp.libraries.stdlib import api
from leapp.models import InstalledRedHatSignedRPM, 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_director', [
(True), # with director
(False), # without director
])
def test_actor_execution(monkeypatch, has_director):
"""
Parametrized helper function for test_actor_* functions.
First generate list of RPM models based on set arguments. Then, run
the actor feeded with our RPM list. Finally, assert Reports
according to set arguments.
Parameters:
has_director (bool): bacula-director installed
"""

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

if has_director:
# Add bacula-director
rpms += [_generate_rpm_with_name('bacula-director')]

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

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

if has_director:
# Assert for bacula-director package installed
assert reporting.create_report.called == 1
else:
# Assert for no bacula packages installed
assert not reporting.create_report.called

0 comments on commit 49a45da

Please sign in to comment.