Skip to content

Commit

Permalink
[RHELC-1330] Port list_non_red_hat_pkgs_left to Action framework (oam…
Browse files Browse the repository at this point in the history
…g#1292)

Port list_non_red_hat_pkgs_left to Action framework.

---------

Co-authored-by: Rodolfo Olivieri <[email protected]>
  • Loading branch information
2 people authored and pr-watson committed Aug 13, 2024
1 parent 424b7b8 commit 286a299
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 29 deletions.
43 changes: 43 additions & 0 deletions convert2rhel/actions/conversion/list_non_red_hat_pkgs_left.py
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)
2 changes: 0 additions & 2 deletions convert2rhel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,6 @@ def post_ponr_changes():

def post_ponr_conversion():
"""Perform main steps for system conversion."""
loggerinst.task("Convert: List remaining non-Red Hat packages")
pkghandler.list_non_red_hat_pkgs_left()
loggerinst.task("Convert: Configure the bootloader")
grub.post_ponr_set_efi_configuration()
loggerinst.task("Convert: Patch yum configuration file")
Expand Down
13 changes: 0 additions & 13 deletions convert2rhel/pkghandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,19 +536,6 @@ def get_vendor(pkg_obj):
return pkg_obj.vendor if pkg_obj.vendor else "N/A"


def list_non_red_hat_pkgs_left():
"""List all the packages that have not been replaced by the
Red Hat-signed ones during the conversion.
"""
loggerinst.info("Listing packages not signed by Red Hat")
non_red_hat_pkgs = get_installed_pkgs_w_different_fingerprint(system_info.fingerprints_rhel)
if non_red_hat_pkgs:
loggerinst.info("The following packages were left unchanged.\n")
print_pkg_info(non_red_hat_pkgs)
else:
loggerinst.info("All packages are now signed by Red Hat.")


def get_pkg_nevras(pkg_objects):
"""Get a list of package NEVRA strings from a list of PackageInformation objects."""
return [get_pkg_nevra(pkg_obj) for pkg_obj in pkg_objects]
Expand Down
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
3 changes: 0 additions & 3 deletions convert2rhel/unit_tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,16 @@ def test_show_eula_nonexisting_file(self, caplog, monkeypatch, tmpdir):


def test_post_ponr_conversion(monkeypatch):
list_non_red_hat_pkgs_left_mock = mock.Mock()
post_ponr_set_efi_configuration_mock = mock.Mock()
yum_conf_patch_mock = mock.Mock()
lock_releasever_in_rhel_repositories_mock = mock.Mock()

monkeypatch.setattr(pkghandler, "list_non_red_hat_pkgs_left", list_non_red_hat_pkgs_left_mock)
monkeypatch.setattr(grub, "post_ponr_set_efi_configuration", post_ponr_set_efi_configuration_mock)
monkeypatch.setattr(redhatrelease.YumConf, "patch", yum_conf_patch_mock)
monkeypatch.setattr(subscription, "lock_releasever_in_rhel_repositories", lock_releasever_in_rhel_repositories_mock)

main.post_ponr_conversion()

assert list_non_red_hat_pkgs_left_mock.call_count == 1
assert post_ponr_set_efi_configuration_mock.call_count == 1
assert yum_conf_patch_mock.call_count == 1
assert lock_releasever_in_rhel_repositories_mock.call_count == 1
Expand Down
11 changes: 0 additions & 11 deletions convert2rhel/unit_tests/pkghandler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,17 +1483,6 @@ def test_get_third_party_pkgs(fingerprint_orig_os, expected_count, expected_pkgs
assert len(pkgs) == expected_pkgs


def test_list_non_red_hat_pkgs_left(monkeypatch):
monkeypatch.setattr(pkghandler, "format_pkg_info", FormatPkgInfoMocked())
monkeypatch.setattr(
pkghandler, "get_installed_pkg_information", GetInstalledPkgInformationMocked(pkg_selection="fingerprints")
)
pkghandler.list_non_red_hat_pkgs_left()

assert len(pkghandler.format_pkg_info.call_args[0][0]) == 1
assert pkghandler.format_pkg_info.call_args[0][0][0].nevra.name == "pkg2"


@pytest.mark.parametrize(
("package_name", "subprocess_output", "expected", "expected_command"),
(
Expand Down

0 comments on commit 286a299

Please sign in to comment.