-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CheckPamUserDB: implement check to report DB location
Check the databases reported by ScanPamUserDB and print a report about them. It also includes the unit-tests. Signed-off-by: Iker Pedrosa <[email protected]>
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
repos/system_upgrade/el9toel10/actors/pamuserdb/checkpamuserdb/actor.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,18 @@ | ||
from leapp.actors import Actor | ||
from leapp.libraries.actor import checkpamuserdb | ||
from leapp.models import PamUserDbLocation, Report | ||
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag | ||
|
||
|
||
class CheckPamUserDb(Actor): | ||
""" | ||
Create report with the location of pam_userdb databases | ||
""" | ||
|
||
name = 'check_pam_user_db' | ||
consumes = (PamUserDbLocation,) | ||
produces = (Report,) | ||
tags = (ChecksPhaseTag, IPUWorkflowTag) | ||
|
||
def process(self): | ||
checkpamuserdb.process() |
29 changes: 29 additions & 0 deletions
29
repos/system_upgrade/el9toel10/actors/pamuserdb/checkpamuserdb/libraries/checkpamuserdb.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,29 @@ | ||
from leapp import reporting | ||
from leapp.libraries.stdlib import api | ||
from leapp.models import PamUserDbLocation | ||
from leapp.exceptions import StopActorExecutionError | ||
|
||
|
||
FMT_LIST_SEPARATOR = "\n - " | ||
|
||
|
||
def process(): | ||
msg = next(api.consume(PamUserDbLocation), None) | ||
if not msg: | ||
raise StopActorExecutionError('Expected PamUserDbLocation, but got None') | ||
|
||
if msg.locations: | ||
reporting.create_report([ | ||
reporting.Title('pam_userdb databases will be converted to GDBM'), | ||
reporting.Summary( | ||
'On RHEL 10, GDMB is used by pam_userdb as it\'s backend database,' | ||
' replacing BerkeleyDB. Existing pam_userdb databases will be' | ||
' converted to GDBM. The following databases will be converted:' | ||
'{sep}{locations}'.format(sep=FMT_LIST_SEPARATOR, locations=FMT_LIST_SEPARATOR.join(msg.locations))), | ||
reporting.Severity(reporting.Severity.INFO), | ||
reporting.Groups([reporting.Groups.SECURITY, reporting.Groups.AUTHENTICATION]) | ||
]) | ||
else: | ||
api.current_logger().debug( | ||
'No pam_userdb databases were located, thus nothing will be converted' | ||
) |
43 changes: 43 additions & 0 deletions
43
repos/system_upgrade/el9toel10/actors/pamuserdb/checkpamuserdb/tests/test_checkpamuserdb.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,43 @@ | ||
import pytest | ||
|
||
from leapp import reporting | ||
from leapp.exceptions import StopActorExecutionError | ||
from leapp.models import PamUserDbLocation | ||
from leapp.libraries.actor import checkpamuserdb | ||
from leapp.libraries.stdlib import api | ||
from leapp.libraries.common.testutils import create_report_mocked, logger_mocked | ||
|
||
|
||
def test_process_no_msg(monkeypatch): | ||
def consume_mocked(*args, **kwargs): | ||
yield None | ||
|
||
monkeypatch.setattr(api, 'consume', consume_mocked) | ||
|
||
with pytest.raises(StopActorExecutionError): | ||
checkpamuserdb.process() | ||
|
||
|
||
def test_process_no_location(monkeypatch): | ||
def consume_mocked(*args, **kwargs): | ||
yield PamUserDbLocation(locations=[]) | ||
|
||
monkeypatch.setattr(api, 'current_logger', logger_mocked()) | ||
monkeypatch.setattr(api, 'consume', consume_mocked) | ||
|
||
checkpamuserdb.process() | ||
assert ( | ||
'No pam_userdb databases were located, thus nothing will be converted' | ||
in api.current_logger.dbgmsg | ||
) | ||
|
||
|
||
def test_process_locations(monkeypatch): | ||
def consume_mocked(*args, **kwargs): | ||
yield PamUserDbLocation(locations=['/tmp/db1', '/tmp/db2']) | ||
|
||
monkeypatch.setattr(reporting, "create_report", create_report_mocked()) | ||
monkeypatch.setattr(api, 'consume', consume_mocked) | ||
|
||
checkpamuserdb.process() | ||
assert reporting.create_report.called == 1 |