-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RHELC-1070] Duplicate package check for preconversion analysis
- Loading branch information
Showing
2 changed files
with
111 additions
and
0 deletions.
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,50 @@ | ||
# Copyright(C) 2023 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, utils | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Duplicate_Packages(actions.Action): | ||
id = "DUPLICATE_PACKAGES" | ||
|
||
def run(self): | ||
"""Ensure that there are no duplicate system packages installed.""" | ||
super(Duplicate_Packages, self).run() | ||
|
||
logger.task("Prepare: Check if there are any duplicate installed packages on the system") | ||
|
||
output, _ = utils.run_subprocess(["package-cleanup", "--dupes", "--quiet"], print_output=False) | ||
|
||
duplicate_packages = output.split("\n") | ||
duplicate_packages = filter(None, duplicate_packages) | ||
|
||
if duplicate_packages: | ||
self.set_result( | ||
level="ERROR", | ||
id="DUPLICATE_PACKAGES_FOUND", | ||
title="Duplicate packages found on the system", | ||
description="The system contains one or more packages with multiple versions.", | ||
diagnosis="The following packages have multiple versions: %s." % ", ".join(duplicate_packages), | ||
remediation="This error can be resolved by removing duplicate versions of the listed packages." | ||
" The command 'package-cleanup' can be used to automatically remove duplicate packages" | ||
" on the system.", | ||
) |
61 changes: 61 additions & 0 deletions
61
convert2rhel/unit_tests/actions/system_checks/duplicate_packages_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,61 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright(C) 2023 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 | ||
|
||
from convert2rhel import actions, unit_tests, utils | ||
from convert2rhel.actions.system_checks import duplicate_packages | ||
from convert2rhel.unit_tests import RunSubprocessMocked | ||
|
||
|
||
@pytest.fixture | ||
def duplicate_packages_action(): | ||
return duplicate_packages.Duplicate_Packages() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("output", "expected"), | ||
( | ||
( | ||
"package1.x86_64\npackage1.s390x\npackage2.x86_64\npackage2.ppc64le\n", | ||
["package1.x86_64", "package1.s390x", "package2.x86_64", "package2.ppc64le"], | ||
), | ||
( | ||
"package1.x86_64\npackage1.i686\npackage1.s390x\npackage2.x86_64\npackage2.ppc64le\n", | ||
["package1.x86_64", "package1.i686", "package1.s390x", "package2.x86_64", "package2.ppc64le"], | ||
), | ||
), | ||
) | ||
def test_duplicate_packages_error(monkeypatch, output, expected, duplicate_packages_action): | ||
|
||
monkeypatch.setattr(utils, "run_subprocess", RunSubprocessMocked(return_value=(output, 0))) | ||
duplicate_packages_action.run() | ||
|
||
unit_tests.assert_actions_result( | ||
duplicate_packages_action, | ||
level="ERROR", | ||
id="DUPLICATE_PACKAGES_FOUND", | ||
title="Duplicate packages found on the system", | ||
description="The system contains one or more packages with multiple versions.", | ||
diagnosis="The following packages have multiple versions: %s." % ", ".join(expected), | ||
remediation="This error can be resolved by removing duplicate versions of the listed packages." | ||
" The command 'package-cleanup' can be used to automatically remove duplicate packages" | ||
" on the system.", | ||
) |