-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RHELC-1330] Port list_non_red_hat_pkgs_left to Action framework (#1292)
Port list_non_red_hat_pkgs_left to Action framework. --------- Co-authored-by: Rodolfo Olivieri <[email protected]>
- Loading branch information
Showing
6 changed files
with
97 additions
and
29 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
convert2rhel/actions/conversion/list_non_red_hat_pkgs_left.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 @@ | ||
# Copyright(C) 2024 Red Hat, Inc. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
__metaclass__ = type | ||
|
||
import logging | ||
|
||
from convert2rhel import actions | ||
from convert2rhel.pkghandler import get_installed_pkgs_w_different_fingerprint, print_pkg_info | ||
from convert2rhel.systeminfo import system_info | ||
|
||
|
||
loggerinst = logging.getLogger(__name__) | ||
|
||
|
||
class ListNonRedHatPkgsLeft(actions.Action): | ||
id = "LIST_NON_RED_HAT_PKGS_LEFT" | ||
|
||
def run(self): | ||
"""List all the packages that have not been replaced by the | ||
Red Hat-signed ones during the conversion. | ||
""" | ||
super(ListNonRedHatPkgsLeft, self).run() | ||
loggerinst.info("Listing packages not signed by Red Hat") | ||
non_red_hat_pkgs = get_installed_pkgs_w_different_fingerprint(system_info.fingerprints_rhel) | ||
if not non_red_hat_pkgs: | ||
loggerinst.info("All packages are now signed by Red Hat.") | ||
return | ||
|
||
loggerinst.info("The following packages were left unchanged.\n") | ||
print_pkg_info(non_red_hat_pkgs) |
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
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
54 changes: 54 additions & 0 deletions
54
convert2rhel/unit_tests/actions/conversion/list_non_red_hat_pkgs_left_test.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,54 @@ | ||
# Copyright(C) 2024 Red Hat, Inc. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
__metaclass__ = type | ||
|
||
|
||
import pytest | ||
import six | ||
|
||
from convert2rhel.actions.conversion import list_non_red_hat_pkgs_left | ||
|
||
|
||
six.add_move(six.MovedModule("mock", "mock", "unittest.mock")) | ||
|
||
from convert2rhel import pkghandler | ||
from convert2rhel.unit_tests import FormatPkgInfoMocked, GetInstalledPkgInformationMocked | ||
|
||
|
||
@pytest.fixture | ||
def list_non_red_hat_pkgs_left_instance(): | ||
return list_non_red_hat_pkgs_left.ListNonRedHatPkgsLeft() | ||
|
||
|
||
def test_list_non_red_hat_pkgs_left(list_non_red_hat_pkgs_left_instance, monkeypatch): | ||
monkeypatch.setattr(pkghandler, "format_pkg_info", FormatPkgInfoMocked()) | ||
monkeypatch.setattr( | ||
pkghandler, "get_installed_pkg_information", GetInstalledPkgInformationMocked(pkg_selection="fingerprints") | ||
) | ||
list_non_red_hat_pkgs_left_instance.run() | ||
|
||
assert len(pkghandler.format_pkg_info.call_args[0][0]) == 1 | ||
assert pkghandler.format_pkg_info.call_args[0][0][0].nevra.name == "pkg2" | ||
|
||
|
||
def test_no_non_red_hat_pkgs_left(list_non_red_hat_pkgs_left_instance, monkeypatch, caplog): | ||
monkeypatch.setattr(pkghandler, "format_pkg_info", FormatPkgInfoMocked()) | ||
monkeypatch.setattr( | ||
pkghandler, "get_installed_pkg_information", GetInstalledPkgInformationMocked(pkg_selection="empty") | ||
) | ||
list_non_red_hat_pkgs_left_instance.run() | ||
|
||
assert "All packages are now signed by Red Hat." in caplog.records[-1].message |
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
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