-
Notifications
You must be signed in to change notification settings - Fork 150
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
50 changes: 50 additions & 0 deletions
50
repos/system_upgrade/common/actors/baculacheck/libraries/baculacheck.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]), | ||
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() |
65 changes: 65 additions & 0 deletions
65
repos/system_upgrade/common/actors/baculacheck/tests/test_baculacheck.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.