Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15-SP1:Update
salt.25404
add-rpm_vercmp-python-library-for-version-compa...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File add-rpm_vercmp-python-library-for-version-comparison.patch of Package salt.25404
From a15321796586b033d8fa8366074087ceddaa4d23 Mon Sep 17 00:00:00 2001 From: Alexander Graul <agraul@suse.com> Date: Wed, 19 Jan 2022 17:41:11 +0100 Subject: [PATCH] Add rpm_vercmp python library for version comparison - 3003.3 (#448) * Add rpm_vercmp python library for version comparison * Add rpm-vercmp to tiamat builds * Put GPG tests back to test_rpm_lowpkg Co-authored-by: Megan Wilhite <mwilhite@vmware.com> --- changelog/60814.added | 1 + tests/pytests/unit/modules/test_rpm_lowpkg.py | 326 ++++++++++++++---- 2 files changed, 263 insertions(+), 64 deletions(-) create mode 100644 changelog/60814.added diff --git a/changelog/60814.added b/changelog/60814.added new file mode 100644 index 0000000000..7a9ffe1b25 --- /dev/null +++ b/changelog/60814.added @@ -0,0 +1 @@ +Add the python rpm-vercmp library in the rpm_lowpkg.py module. diff --git a/tests/pytests/unit/modules/test_rpm_lowpkg.py b/tests/pytests/unit/modules/test_rpm_lowpkg.py index f19afa854e..c9d1ac2b1c 100644 --- a/tests/pytests/unit/modules/test_rpm_lowpkg.py +++ b/tests/pytests/unit/modules/test_rpm_lowpkg.py @@ -3,6 +3,7 @@ """ +import datetime import pytest import salt.modules.cmdmod import salt.modules.rpm_lowpkg as rpm @@ -250,92 +251,57 @@ def test_version_cmp_rpm_all_libraries(rpm_lib): assert 1 == rpm.version_cmp("3:2.9.1-8.el7.4", "3:2.9.1-7.el7.4") -def test_version_cmp_rpm(): +@patch("salt.modules.rpm_lowpkg.HAS_RPM", True) +@patch("salt.modules.rpm_lowpkg.rpm.labelCompare", return_value=-1) +@patch("salt.modules.rpm_lowpkg.log") +def test_version_cmp_rpm(mock_log, mock_labelCompare): """ Test package version if RPM-Python is installed :return: """ - mock_label = MagicMock(return_value=-1) - mock_log = MagicMock() - patch_label = patch("salt.modules.rpm_lowpkg.rpm.labelCompare", mock_label) - patch_log = patch("salt.modules.rpm_lowpkg.log", mock_log) - patch_rpm = patch("salt.modules.rpm_lowpkg.HAS_RPM", True) - with patch_label, patch_rpm, patch_log: - assert -1 == rpm.version_cmp("1", "2") - assert not mock_log.warning.called - assert mock_label.called + assert -1 == rpm.version_cmp("1", "2") + assert not mock_log.warning.called + assert mock_labelCompare.called -def test_version_cmp_rpmutils(): +@patch("salt.modules.rpm_lowpkg.HAS_RPM", False) +@patch("salt.modules.rpm_lowpkg.HAS_RPMUTILS", True) +@patch("salt.modules.rpm_lowpkg.HAS_PY_RPM", False) +@patch("salt.modules.rpm_lowpkg.rpmUtils", create=True) +@patch("salt.modules.rpm_lowpkg.log") +def test_version_cmp_rpmutils(mock_log, mock_rpmUtils): """ Test package version if rpmUtils.miscutils called :return: """ - mock_log = MagicMock() - mock_rpmUtils = MagicMock() mock_rpmUtils.miscutils = MagicMock() mock_rpmUtils.miscutils.compareEVR = MagicMock(return_value=-1) - patch_utils = patch("salt.modules.rpm_lowpkg.rpmUtils", mock_rpmUtils, create=True) - patch_rpm = patch("salt.modules.rpm_lowpkg.HAS_RPM", False) - patch_utils_lib = patch("salt.modules.rpm_lowpkg.HAS_RPMUTILS", True) - patch_py_rpm = patch("salt.modules.rpm_lowpkg.HAS_PY_RPM", False) - patch_log = patch("salt.modules.rpm_lowpkg.log", mock_log) - - with patch_utils, patch_rpm, patch_py_rpm, patch_utils_lib, patch_log: - assert -1 == rpm.version_cmp("1", "2") - assert mock_log.warning.called - assert mock_rpmUtils.miscutils.compareEVR.called + assert -1 == rpm.version_cmp("1", "2") + assert mock_log.warning.called + assert mock_rpmUtils.miscutils.compareEVR.called + assert ( + mock_log.warning.mock_calls[0][1][0] + == "Please install a package that provides rpm.labelCompare for more accurate version comparisons." + ) -def test_version_cmp_rpmdev_vercmp(): +@patch("salt.modules.rpm_lowpkg.HAS_RPM", False) +@patch("salt.modules.rpm_lowpkg.HAS_RPMUTILS", False) +@patch("salt.modules.rpm_lowpkg.HAS_PY_RPM", False) +@patch("salt.utils.path.which", return_value=True) +@patch("salt.modules.rpm_lowpkg.log") +def test_version_cmp_rpmdev_vercmp(mock_log, mock_which): """ Test package version if rpmdev-vercmp is installed :return: """ mock__salt__ = MagicMock(return_value={"retcode": 12}) - mock_log = MagicMock() - patch_rpm = patch("salt.modules.rpm_lowpkg.HAS_RPM", False) - patch_rpmutils = patch("salt.modules.rpm_lowpkg.HAS_RPMUTILS", False) - patch_py_rpm = patch("salt.modules.rpm_lowpkg.HAS_PY_RPM", False) - patch_which = patch("salt.utils.path.which", return_value=True) - patch_log = patch("salt.modules.rpm_lowpkg.log", mock_log) - - with patch_rpm, patch_rpmutils, patch_py_rpm, patch_which, patch_log: - with patch.dict(rpm.__salt__, {"cmd.run_all": mock__salt__}): - assert -1 == rpm.version_cmp("1", "2") - assert mock__salt__.called - assert mock_log.warning.called - assert ( - mock_log.warning.mock_calls[0][1][0] - == "Please install a package that provides rpm.labelCompare for more accurate version comparisons." - ) - assert ( - mock_log.warning.mock_calls[1][1][0] - == "Installing the rpmdevtools package may surface dev tools in production." - ) - - -def test_version_cmp_python(): - """ - Test package version if falling back to python - - :return: - """ - mock_log = MagicMock() - patch_rpm = patch("salt.modules.rpm_lowpkg.HAS_RPM", False) - patch_rpmutils = patch("salt.modules.rpm_lowpkg.HAS_RPMUTILS", False) - mock_version_cmp = MagicMock(return_value=-1) - patch_py_rpm = patch("salt.modules.rpm_lowpkg.HAS_PY_RPM", False) - patch_cmp = patch("salt.utils.versions.version_cmp", mock_version_cmp) - patch_which = patch("salt.utils.path.which", return_value=False) - patch_log = patch("salt.modules.rpm_lowpkg.log", mock_log) - - with patch_rpm, patch_rpmutils, patch_py_rpm, patch_cmp, patch_which, patch_log: + with patch.dict(rpm.__salt__, {"cmd.run_all": mock__salt__}): assert -1 == rpm.version_cmp("1", "2") - assert mock_version_cmp.called + assert mock__salt__.called assert mock_log.warning.called assert ( mock_log.warning.mock_calls[0][1][0] @@ -343,5 +309,237 @@ def test_version_cmp_python(): ) assert ( mock_log.warning.mock_calls[1][1][0] - == "Falling back on salt.utils.versions.version_cmp() for version comparisons" + == "Installing the rpmdevtools package may surface dev tools in production." ) + + +@patch("salt.modules.rpm_lowpkg.HAS_RPM", False) +@patch("salt.modules.rpm_lowpkg.HAS_RPMUTILS", False) +@patch("salt.modules.rpm_lowpkg.HAS_PY_RPM", False) +@patch("salt.utils.versions.version_cmp", return_value=-1) +@patch("salt.utils.path.which", return_value=False) +@patch("salt.modules.rpm_lowpkg.log") +def test_version_cmp_python(mock_log, mock_which, mock_version_cmp): + """ + Test package version if falling back to python + + :return: + """ + assert -1 == rpm.version_cmp("1", "2") + assert mock_version_cmp.called + assert mock_log.warning.called + assert ( + mock_log.warning.mock_calls[0][1][0] + == "Please install a package that provides rpm.labelCompare for more accurate version comparisons." + ) + assert ( + mock_log.warning.mock_calls[1][1][0] + == "Falling back on salt.utils.versions.version_cmp() for version comparisons" + ) + + +def test_list_gpg_keys_no_info(): + """ + Test list_gpg_keys with no extra information + """ + mock = MagicMock(return_value="\n".join(["gpg-pubkey-1", "gpg-pubkey-2"])) + with patch.dict(rpm.__salt__, {"cmd.run_stdout": mock}): + assert rpm.list_gpg_keys() == ["gpg-pubkey-1", "gpg-pubkey-2"] + assert not _called_with_root(mock) + + +def test_list_gpg_keys_no_info_root(): + """ + Test list_gpg_keys with no extra information and root + """ + mock = MagicMock(return_value="\n".join(["gpg-pubkey-1", "gpg-pubkey-2"])) + with patch.dict(rpm.__salt__, {"cmd.run_stdout": mock}): + assert rpm.list_gpg_keys(root="/mnt") == ["gpg-pubkey-1", "gpg-pubkey-2"] + assert _called_with_root(mock) + + +@patch("salt.modules.rpm_lowpkg.info_gpg_key") +def test_list_gpg_keys_info(info_gpg_key): + """ + Test list_gpg_keys with extra information + """ + info_gpg_key.side_effect = lambda x, root: {"Description": "key for {}".format(x)} + mock = MagicMock(return_value="\n".join(["gpg-pubkey-1", "gpg-pubkey-2"])) + with patch.dict(rpm.__salt__, {"cmd.run_stdout": mock}): + assert rpm.list_gpg_keys(info=True) == { + "gpg-pubkey-1": {"Description": "key for gpg-pubkey-1"}, + "gpg-pubkey-2": {"Description": "key for gpg-pubkey-2"}, + } + assert not _called_with_root(mock) + + +def test_info_gpg_key(): + """ + Test info_gpg_keys from a normal output + """ + info = """Name : gpg-pubkey +Version : 3dbdc284 +Release : 53674dd4 +Architecture: (none) +Install Date: Fri 08 Mar 2019 11:57:44 AM UTC +Group : Public Keys +Size : 0 +License : pubkey +Signature : (none) +Source RPM : (none) +Build Date : Mon 05 May 2014 10:37:40 AM UTC +Build Host : localhost +Packager : openSUSE Project Signing Key <opensuse@opensuse.org> +Summary : gpg(openSUSE Project Signing Key <opensuse@opensuse.org>) +Description : +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: rpm-4.14.2.1 (NSS-3) + +mQENBEkUTD8BCADWLy5d5IpJedHQQSXkC1VK/oAZlJEeBVpSZjMCn8LiHaI9Wq3G +3Vp6wvsP1b3kssJGzVFNctdXt5tjvOLxvrEfRJuGfqHTKILByqLzkeyWawbFNfSQ +93/8OunfSTXC1Sx3hgsNXQuOrNVKrDAQUqT620/jj94xNIg09bLSxsjN6EeTvyiO +mtE9H1J03o9tY6meNL/gcQhxBvwuo205np0JojYBP0pOfN8l9hnIOLkA0yu4ZXig +oKOVmf4iTjX4NImIWldT+UaWTO18NWcCrujtgHueytwYLBNV5N0oJIP2VYuLZfSD +VYuPllv7c6O2UEOXJsdbQaVuzU1HLocDyipnABEBAAG0NG9wZW5TVVNFIFByb2pl +Y3QgU2lnbmluZyBLZXkgPG9wZW5zdXNlQG9wZW5zdXNlLm9yZz6JATwEEwECACYC +GwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAUCU2dN1AUJHR8ElQAKCRC4iy/UPb3C +hGQrB/9teCZ3Nt8vHE0SC5NmYMAE1Spcjkzx6M4r4C70AVTMEQh/8BvgmwkKP/qI +CWo2vC1hMXRgLg/TnTtFDq7kW+mHsCXmf5OLh2qOWCKi55Vitlf6bmH7n+h34Sha +Ei8gAObSpZSF8BzPGl6v0QmEaGKM3O1oUbbB3Z8i6w21CTg7dbU5vGR8Yhi9rNtr +hqrPS+q2yftjNbsODagaOUb85ESfQGx/LqoMePD+7MqGpAXjKMZqsEDP0TbxTwSk +4UKnF4zFCYHPLK3y/hSH5SEJwwPY11l6JGdC1Ue8Zzaj7f//axUs/hTC0UZaEE+a +5v4gbqOcigKaFs9Lc3Bj8b/lE10Y +=i2TA +-----END PGP PUBLIC KEY BLOCK----- + +""" + mock = MagicMock(return_value=info) + with patch.dict(rpm.__salt__, {"cmd.run_stdout": mock}): + assert rpm.info_gpg_key("key") == { + "Name": "gpg-pubkey", + "Version": "3dbdc284", + "Release": "53674dd4", + "Architecture": None, + "Install Date": datetime.datetime(2019, 3, 8, 11, 57, 44), + "Group": "Public Keys", + "Size": 0, + "License": "pubkey", + "Signature": None, + "Source RPM": None, + "Build Date": datetime.datetime(2014, 5, 5, 10, 37, 40), + "Build Host": "localhost", + "Packager": "openSUSE Project Signing Key <opensuse@opensuse.org>", + "Summary": "gpg(openSUSE Project Signing Key <opensuse@opensuse.org>)", + "Description": """-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: rpm-4.14.2.1 (NSS-3) + +mQENBEkUTD8BCADWLy5d5IpJedHQQSXkC1VK/oAZlJEeBVpSZjMCn8LiHaI9Wq3G +3Vp6wvsP1b3kssJGzVFNctdXt5tjvOLxvrEfRJuGfqHTKILByqLzkeyWawbFNfSQ +93/8OunfSTXC1Sx3hgsNXQuOrNVKrDAQUqT620/jj94xNIg09bLSxsjN6EeTvyiO +mtE9H1J03o9tY6meNL/gcQhxBvwuo205np0JojYBP0pOfN8l9hnIOLkA0yu4ZXig +oKOVmf4iTjX4NImIWldT+UaWTO18NWcCrujtgHueytwYLBNV5N0oJIP2VYuLZfSD +VYuPllv7c6O2UEOXJsdbQaVuzU1HLocDyipnABEBAAG0NG9wZW5TVVNFIFByb2pl +Y3QgU2lnbmluZyBLZXkgPG9wZW5zdXNlQG9wZW5zdXNlLm9yZz6JATwEEwECACYC +GwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAUCU2dN1AUJHR8ElQAKCRC4iy/UPb3C +hGQrB/9teCZ3Nt8vHE0SC5NmYMAE1Spcjkzx6M4r4C70AVTMEQh/8BvgmwkKP/qI +CWo2vC1hMXRgLg/TnTtFDq7kW+mHsCXmf5OLh2qOWCKi55Vitlf6bmH7n+h34Sha +Ei8gAObSpZSF8BzPGl6v0QmEaGKM3O1oUbbB3Z8i6w21CTg7dbU5vGR8Yhi9rNtr +hqrPS+q2yftjNbsODagaOUb85ESfQGx/LqoMePD+7MqGpAXjKMZqsEDP0TbxTwSk +4UKnF4zFCYHPLK3y/hSH5SEJwwPY11l6JGdC1Ue8Zzaj7f//axUs/hTC0UZaEE+a +5v4gbqOcigKaFs9Lc3Bj8b/lE10Y +=i2TA +-----END PGP PUBLIC KEY BLOCK-----""", + } + assert not _called_with_root(mock) + + +def test_info_gpg_key_extended(): + """ + Test info_gpg_keys from an extended output + """ + info = """Name : gpg-pubkey +Version : 3dbdc284 +Release : 53674dd4 +Architecture: (none) +Install Date: Fri 08 Mar 2019 11:57:44 AM UTC +Group : Public Keys +Size : 0 +License : pubkey +Signature : (none) +Source RPM : (none) +Build Date : Mon 05 May 2014 10:37:40 AM UTC +Build Host : localhost +Packager : openSUSE Project Signing Key <opensuse@opensuse.org> +Summary : gpg(openSUSE Project Signing Key <opensuse@opensuse.org>) +Description : +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: rpm-4.14.2.1 (NSS-3) + +mQENBEkUTD8BCADWLy5d5IpJedHQQSXkC1VK/oAZlJEeBVpSZjMCn8LiHaI9Wq3G +3Vp6wvsP1b3kssJGzVFNctdXt5tjvOLxvrEfRJuGfqHTKILByqLzkeyWawbFNfSQ +93/8OunfSTXC1Sx3hgsNXQuOrNVKrDAQUqT620/jj94xNIg09bLSxsjN6EeTvyiO +mtE9H1J03o9tY6meNL/gcQhxBvwuo205np0JojYBP0pOfN8l9hnIOLkA0yu4ZXig +oKOVmf4iTjX4NImIWldT+UaWTO18NWcCrujtgHueytwYLBNV5N0oJIP2VYuLZfSD +VYuPllv7c6O2UEOXJsdbQaVuzU1HLocDyipnABEBAAG0NG9wZW5TVVNFIFByb2pl +Y3QgU2lnbmluZyBLZXkgPG9wZW5zdXNlQG9wZW5zdXNlLm9yZz6JATwEEwECACYC +GwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAUCU2dN1AUJHR8ElQAKCRC4iy/UPb3C +hGQrB/9teCZ3Nt8vHE0SC5NmYMAE1Spcjkzx6M4r4C70AVTMEQh/8BvgmwkKP/qI +CWo2vC1hMXRgLg/TnTtFDq7kW+mHsCXmf5OLh2qOWCKi55Vitlf6bmH7n+h34Sha +Ei8gAObSpZSF8BzPGl6v0QmEaGKM3O1oUbbB3Z8i6w21CTg7dbU5vGR8Yhi9rNtr +hqrPS+q2yftjNbsODagaOUb85ESfQGx/LqoMePD+7MqGpAXjKMZqsEDP0TbxTwSk +4UKnF4zFCYHPLK3y/hSH5SEJwwPY11l6JGdC1Ue8Zzaj7f//axUs/hTC0UZaEE+a +5v4gbqOcigKaFs9Lc3Bj8b/lE10Y +=i2TA +-----END PGP PUBLIC KEY BLOCK----- + +Distribution: (none) +""" + mock = MagicMock(return_value=info) + with patch.dict(rpm.__salt__, {"cmd.run_stdout": mock}): + assert rpm.info_gpg_key("key") == { + "Name": "gpg-pubkey", + "Version": "3dbdc284", + "Release": "53674dd4", + "Architecture": None, + "Install Date": datetime.datetime(2019, 3, 8, 11, 57, 44), + "Group": "Public Keys", + "Size": 0, + "License": "pubkey", + "Signature": None, + "Source RPM": None, + "Build Date": datetime.datetime(2014, 5, 5, 10, 37, 40), + "Build Host": "localhost", + "Packager": "openSUSE Project Signing Key <opensuse@opensuse.org>", + "Summary": "gpg(openSUSE Project Signing Key <opensuse@opensuse.org>)", + "Description": """-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: rpm-4.14.2.1 (NSS-3) + +mQENBEkUTD8BCADWLy5d5IpJedHQQSXkC1VK/oAZlJEeBVpSZjMCn8LiHaI9Wq3G +3Vp6wvsP1b3kssJGzVFNctdXt5tjvOLxvrEfRJuGfqHTKILByqLzkeyWawbFNfSQ +93/8OunfSTXC1Sx3hgsNXQuOrNVKrDAQUqT620/jj94xNIg09bLSxsjN6EeTvyiO +mtE9H1J03o9tY6meNL/gcQhxBvwuo205np0JojYBP0pOfN8l9hnIOLkA0yu4ZXig +oKOVmf4iTjX4NImIWldT+UaWTO18NWcCrujtgHueytwYLBNV5N0oJIP2VYuLZfSD +VYuPllv7c6O2UEOXJsdbQaVuzU1HLocDyipnABEBAAG0NG9wZW5TVVNFIFByb2pl +Y3QgU2lnbmluZyBLZXkgPG9wZW5zdXNlQG9wZW5zdXNlLm9yZz6JATwEEwECACYC +GwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAUCU2dN1AUJHR8ElQAKCRC4iy/UPb3C +hGQrB/9teCZ3Nt8vHE0SC5NmYMAE1Spcjkzx6M4r4C70AVTMEQh/8BvgmwkKP/qI +CWo2vC1hMXRgLg/TnTtFDq7kW+mHsCXmf5OLh2qOWCKi55Vitlf6bmH7n+h34Sha +Ei8gAObSpZSF8BzPGl6v0QmEaGKM3O1oUbbB3Z8i6w21CTg7dbU5vGR8Yhi9rNtr +hqrPS+q2yftjNbsODagaOUb85ESfQGx/LqoMePD+7MqGpAXjKMZqsEDP0TbxTwSk +4UKnF4zFCYHPLK3y/hSH5SEJwwPY11l6JGdC1Ue8Zzaj7f//axUs/hTC0UZaEE+a +5v4gbqOcigKaFs9Lc3Bj8b/lE10Y +=i2TA +-----END PGP PUBLIC KEY BLOCK-----""", + "Distribution": None, + } + assert not _called_with_root(mock) + + +def test_remove_gpg_key(): + """ + Test remove_gpg_key + """ + mock = MagicMock(return_value=0) + with patch.dict(rpm.__salt__, {"cmd.retcode": mock}): + assert rpm.remove_gpg_key("gpg-pubkey-1") + assert not _called_with_root(mock) -- 2.34.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor