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 baculacheck actor #896

Merged
merged 4 commits into from
Aug 2, 2022
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
20 changes: 20 additions & 0 deletions repos/system_upgrade/common/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 the new version is'
' incompatible with the current version, 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]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pirat89 I am wondering if time has come to introduce the brand new Groups.POST group here https://github.com/oamg/leapp/blob/master/leapp/reporting/__init__.py#L143 ? WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a question. it's mixing work that is supposed to be done prior the upgrade and after the upgrade, however POST group should refer just to work supposed to be done after the upgrade.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well it will be common to do work both before and after the upgrade: back up your stuff before in case the conversion goes wrong and convert it to an incompatible format after.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pirat89 I'd say we are not ready to introduce Groups.POST yet - we should first take care of our contributors' guidelines and explain, how we expect this group to be used.
So I'd leave this PR as is.

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