Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP2:GA
salt.23568
fix-exception-in-yumpkg.remove-for-not-installe...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File fix-exception-in-yumpkg.remove-for-not-installed-pac.patch of Package salt.23568
From ff850e983365aa96dd28080f52c15ff0797146a6 Mon Sep 17 00:00:00 2001 From: Victor Zhestkov <35733135+vzhestkov@users.noreply.github.com> Date: Thu, 24 Jun 2021 13:17:37 +0300 Subject: [PATCH] Fix exception in yumpkg.remove for not installed package (#381) --- salt/modules/yumpkg.py | 2 ++ tests/unit/modules/test_yumpkg.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/salt/modules/yumpkg.py b/salt/modules/yumpkg.py index 63969b82d4..9ea09a4bab 100644 --- a/salt/modules/yumpkg.py +++ b/salt/modules/yumpkg.py @@ -2019,6 +2019,8 @@ def remove(name=None, pkgs=None, **kwargs): # pylint: disable=W0613 old = list_pkgs() targets = [] for target in pkg_params: + if target not in old: + continue version_to_remove = pkg_params[target] installed_versions = old[target].split(",") diff --git a/tests/unit/modules/test_yumpkg.py b/tests/unit/modules/test_yumpkg.py index 237835f444..4fbc9f587f 100644 --- a/tests/unit/modules/test_yumpkg.py +++ b/tests/unit/modules/test_yumpkg.py @@ -746,6 +746,31 @@ class YumTestCase(TestCase, LoaderModuleMockMixin): call = cmd_mock.mock_calls[0][1][0] assert call == expected, call + def test_remove_not_existing(self): + """ + Test if no exception on removing not installed package + """ + name = "foo" + def list_pkgs_mock(): + return {} + cmd_mock = MagicMock( + return_value={"pid": 12345, "retcode": 0, "stdout": "", "stderr": ""} + ) + salt_mock = { + "cmd.run_all": cmd_mock, + "lowpkg.version_cmp": rpm.version_cmp, + "pkg_resource.parse_targets": MagicMock( + return_value=({name: None}, "repository") + ), + } + with patch.object(yumpkg, "list_pkgs", list_pkgs_mock), patch( + "salt.utils.systemd.has_scope", MagicMock(return_value=False) + ), patch.dict(yumpkg.__salt__, salt_mock): + + with patch.dict(yumpkg.__grains__, {"os": "CentOS", "osrelease": 7}): + yumpkg.remove(name) + cmd_mock.assert_not_called() + def test_install_with_epoch(self): ''' Tests that we properly identify a version containing an epoch as an -- 2.32.0
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