diff --git a/repos/system_upgrade/el8toel9/actors/baculacheck/actor.py b/repos/system_upgrade/el8toel9/actors/baculacheck/actor.py new file mode 100644 index 0000000000..d206e3c04c --- /dev/null +++ b/repos/system_upgrade/el8toel9/actors/baculacheck/actor.py @@ -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() diff --git a/repos/system_upgrade/el8toel9/actors/baculacheck/libraries/baculacheck.py b/repos/system_upgrade/el8toel9/actors/baculacheck/libraries/baculacheck.py new file mode 100644 index 0000000000..110edba6aa --- /dev/null +++ b/repos/system_upgrade/el8toel9/actors/baculacheck/libraries/baculacheck.py @@ -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 /usr/libexec/bacula/update_bacula_tables to upgrade' + ' the Bacula dadabase after the system upgrade.' + ' The value of 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() diff --git a/repos/system_upgrade/el8toel9/actors/baculacheck/tests/test_baculacheck.py b/repos/system_upgrade/el8toel9/actors/baculacheck/tests/test_baculacheck.py new file mode 100644 index 0000000000..ec4e7f81cf --- /dev/null +++ b/repos/system_upgrade/el8toel9/actors/baculacheck/tests/test_baculacheck.py @@ -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. ', + 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