b17d3e3575
- Fix the usage of custom macros on the spec file. - Fix RES7: different dependency names for python-PyYAML and python-MarkupSafe - Build both python2 and python3 binaries together. - Bugfix: errors in external pillar causes crash instead of report of them (bsc#1068446) - Fix 'user.present' when 'gid_from_name' is set but group does not exist. - Added: * bugfix-the-logic-according-to-the-exact-described-pu.patch * return-error-when-gid_from_name-and-group-does-not-e.patch - Fix "No service execution module loaded" issue (bsc#1065792) - Set SHELL environment variable Added: * fix-bsc-1065792.patch * set-shell-environment-variable-64.patch - Removed unnecessary logging on shutdown (bsc#1050003) - Renamed patch that adds grain fqdns Changed: * catching-error-when-pidfile-cannot-be-deleted Removed: * fix-for-pidfile-removal-logging Renamed: * add-fqdns-grains -> feat-add-grain-for-all-fqdns OBS-URL: https://build.opensuse.org/request/show/569868 OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=107
163 lines
8.2 KiB
Diff
163 lines
8.2 KiB
Diff
From 914cabfacd9c1209e3f0e7a613e8cc0d1617580b Mon Sep 17 00:00:00 2001
|
|
From: Jochen Breuer <jbreuer@suse.de>
|
|
Date: Mon, 11 Dec 2017 09:49:10 +0100
|
|
Subject: [PATCH] Fix for wrong version processing
|
|
|
|
Since version and epoch seem to be split by default now, the yum pkg info
|
|
processing should have changed.
|
|
|
|
* Fixes the version info processing for pkg installation.
|
|
* Test for installation with and without diff_attr.
|
|
---
|
|
salt/modules/yumpkg.py | 28 +++++++++------
|
|
tests/unit/modules/test_yumpkg.py | 72 +++++++++++++++++++++++++++++++++++++++
|
|
2 files changed, 90 insertions(+), 10 deletions(-)
|
|
|
|
diff --git a/salt/modules/yumpkg.py b/salt/modules/yumpkg.py
|
|
index 8b63bff4a3..027d680bff 100644
|
|
--- a/salt/modules/yumpkg.py
|
|
+++ b/salt/modules/yumpkg.py
|
|
@@ -588,7 +588,6 @@ def version_cmp(pkg1, pkg2, ignore_epoch=False):
|
|
|
|
salt '*' pkg.version_cmp '0.2-001' '0.2.0.1-002'
|
|
'''
|
|
-
|
|
return __salt__['lowpkg.version_cmp'](pkg1, pkg2, ignore_epoch=ignore_epoch)
|
|
|
|
|
|
@@ -1440,18 +1439,20 @@ def install(name=None,
|
|
else:
|
|
pkgstr = pkgpath
|
|
|
|
- # Lambda to trim the epoch from the currently-installed version if
|
|
- # no epoch is specified in the specified version
|
|
- norm_epoch = lambda x, y: x.split(':', 1)[-1] \
|
|
- if ':' not in y \
|
|
- else x
|
|
cver = old_as_list.get(pkgname, [])
|
|
if reinstall and cver:
|
|
for ver in cver:
|
|
- ver = norm_epoch(ver, version_num)
|
|
+ if diff_attr:
|
|
+ # Since diff_attr was provided, the version info
|
|
+ # is a dict.
|
|
+ ver2 = ver['version']
|
|
+ else:
|
|
+ # No diff_attr was provided, so version is directly
|
|
+ # in ver.
|
|
+ ver2 = ver
|
|
if salt.utils.compare_versions(ver1=version_num,
|
|
oper='==',
|
|
- ver2=ver,
|
|
+ ver2=ver2,
|
|
cmp_func=version_cmp):
|
|
# This version is already installed, so we need to
|
|
# reinstall.
|
|
@@ -1462,10 +1463,17 @@ def install(name=None,
|
|
to_install.append((pkgname, pkgstr))
|
|
else:
|
|
for ver in cver:
|
|
- ver = norm_epoch(ver, version_num)
|
|
+ if diff_attr:
|
|
+ # Since diff_attr was provided, the version info
|
|
+ # is a dict.
|
|
+ ver2 = ver['version']
|
|
+ else:
|
|
+ # No diff_attr was provided, so version is directly
|
|
+ # in ver.
|
|
+ ver2 = ver
|
|
if salt.utils.compare_versions(ver1=version_num,
|
|
oper='>=',
|
|
- ver2=ver,
|
|
+ ver2=ver2,
|
|
cmp_func=version_cmp):
|
|
to_install.append((pkgname, pkgstr))
|
|
break
|
|
diff --git a/tests/unit/modules/test_yumpkg.py b/tests/unit/modules/test_yumpkg.py
|
|
index cf754d6289..c5e8d746d5 100644
|
|
--- a/tests/unit/modules/test_yumpkg.py
|
|
+++ b/tests/unit/modules/test_yumpkg.py
|
|
@@ -27,6 +27,78 @@ class YumTestCase(TestCase, LoaderModuleMockMixin):
|
|
def setup_loader_modules(self):
|
|
return {yumpkg: {'rpm': None}}
|
|
|
|
+ def test_install_pkg(self):
|
|
+ '''
|
|
+ Test package installation.
|
|
+
|
|
+ :return:
|
|
+ '''
|
|
+ def _add_data(data, key, value):
|
|
+ data.setdefault(key, []).append(value)
|
|
+
|
|
+ rpm_out = [
|
|
+ 'python-urlgrabber_|-(none)_|-3.10_|-8.el7_|-noarch_|-(none)_|-1487838471',
|
|
+ 'alsa-lib_|-(none)_|-1.1.1_|-1.el7_|-x86_64_|-(none)_|-1487838475',
|
|
+ 'gnupg2_|-(none)_|-2.0.22_|-4.el7_|-x86_64_|-(none)_|-1487838477',
|
|
+ 'rpm-python_|-(none)_|-4.11.3_|-21.el7_|-x86_64_|-(none)_|-1487838477',
|
|
+ 'pygpgme_|-(none)_|-0.3_|-9.el7_|-x86_64_|-(none)_|-1487838478',
|
|
+ 'yum_|-(none)_|-3.4.3_|-150.el7.centos_|-noarch_|-(none)_|-1487838479',
|
|
+ 'lzo_|-(none)_|-2.06_|-8.el7_|-x86_64_|-(none)_|-1487838479',
|
|
+ 'qrencode-libs_|-(none)_|-3.4.1_|-3.el7_|-x86_64_|-(none)_|-1487838480',
|
|
+ 'ustr_|-(none)_|-1.0.4_|-16.el7_|-x86_64_|-(none)_|-1487838480',
|
|
+ 'shadow-utils_|-2_|-4.1.5.1_|-24.el7_|-x86_64_|-(none)_|-1487838481',
|
|
+ 'util-linux_|-(none)_|-2.23.2_|-33.el7_|-x86_64_|-(none)_|-1487838484',
|
|
+ 'openssh_|-(none)_|-6.6.1p1_|-33.el7_3_|-x86_64_|-(none)_|-1487838485',
|
|
+ 'virt-what_|-(none)_|-1.13_|-8.el7_|-x86_64_|-(none)_|-1487838486',
|
|
+ ]
|
|
+ with patch.dict(yumpkg.__grains__, {'osarch': 'x86_64', 'os': 'RedHat'}), \
|
|
+ patch.dict(yumpkg.__salt__, {'cmd.run': MagicMock(return_value=os.linesep.join(rpm_out))}), \
|
|
+ patch.dict(yumpkg.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 0})}), \
|
|
+ patch.dict(yumpkg.__salt__, {'pkg_resource.add_pkg': _add_data}), \
|
|
+ patch.dict(yumpkg.__salt__, {'pkg_resource.parse_targets': MagicMock(return_value=({'python-urlgrabber': '0.0.1'} , 'repository'))}), \
|
|
+ patch.dict(yumpkg.__salt__, {'pkg_resource.format_pkg_list': pkg_resource.format_pkg_list}), \
|
|
+ patch.dict(yumpkg.__salt__, {'config.get': MagicMock()}), \
|
|
+ patch.dict(yumpkg.__salt__, {'lowpkg.version_cmp': MagicMock(return_value=-1)}):
|
|
+ pkgs = yumpkg.install(name='python-urlgrabber')
|
|
+ self.assertEqual(pkgs, {})
|
|
+
|
|
+
|
|
+ def test_install_pkg_with_diff_attr(self):
|
|
+ '''
|
|
+ Test package installation with diff_attr.
|
|
+
|
|
+ :return:
|
|
+ '''
|
|
+ def _add_data(data, key, value):
|
|
+ data.setdefault(key, []).append(value)
|
|
+
|
|
+ rpm_out = [
|
|
+ 'python-urlgrabber_|-(none)_|-3.10_|-8.el7_|-noarch_|-(none)_|-1487838471',
|
|
+ 'alsa-lib_|-(none)_|-1.1.1_|-1.el7_|-x86_64_|-(none)_|-1487838475',
|
|
+ 'gnupg2_|-(none)_|-2.0.22_|-4.el7_|-x86_64_|-(none)_|-1487838477',
|
|
+ 'rpm-python_|-(none)_|-4.11.3_|-21.el7_|-x86_64_|-(none)_|-1487838477',
|
|
+ 'pygpgme_|-(none)_|-0.3_|-9.el7_|-x86_64_|-(none)_|-1487838478',
|
|
+ 'yum_|-(none)_|-3.4.3_|-150.el7.centos_|-noarch_|-(none)_|-1487838479',
|
|
+ 'lzo_|-(none)_|-2.06_|-8.el7_|-x86_64_|-(none)_|-1487838479',
|
|
+ 'qrencode-libs_|-(none)_|-3.4.1_|-3.el7_|-x86_64_|-(none)_|-1487838480',
|
|
+ 'ustr_|-(none)_|-1.0.4_|-16.el7_|-x86_64_|-(none)_|-1487838480',
|
|
+ 'shadow-utils_|-2_|-4.1.5.1_|-24.el7_|-x86_64_|-(none)_|-1487838481',
|
|
+ 'util-linux_|-(none)_|-2.23.2_|-33.el7_|-x86_64_|-(none)_|-1487838484',
|
|
+ 'openssh_|-(none)_|-6.6.1p1_|-33.el7_3_|-x86_64_|-(none)_|-1487838485',
|
|
+ 'virt-what_|-(none)_|-1.13_|-8.el7_|-x86_64_|-(none)_|-1487838486',
|
|
+ ]
|
|
+ with patch.dict(yumpkg.__grains__, {'osarch': 'x86_64', 'os': 'RedHat'}), \
|
|
+ patch.dict(yumpkg.__salt__, {'cmd.run': MagicMock(return_value=os.linesep.join(rpm_out))}), \
|
|
+ patch.dict(yumpkg.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 0})}), \
|
|
+ patch.dict(yumpkg.__salt__, {'pkg_resource.add_pkg': _add_data}), \
|
|
+ patch.dict(yumpkg.__salt__, {'pkg_resource.parse_targets': MagicMock(return_value=({'python-urlgrabber': '0.0.1'} , 'repository'))}), \
|
|
+ patch.dict(yumpkg.__salt__, {'pkg_resource.format_pkg_list': pkg_resource.format_pkg_list}), \
|
|
+ patch.dict(yumpkg.__salt__, {'config.get': MagicMock()}), \
|
|
+ patch.dict(yumpkg.__salt__, {'lowpkg.version_cmp': MagicMock(return_value=-1)}):
|
|
+ pkgs = yumpkg.install(name='python-urlgrabber', diff_attr=['version', 'epoch', 'release', 'arch'])
|
|
+ self.assertEqual(pkgs, {})
|
|
+
|
|
+
|
|
def test_list_pkgs(self):
|
|
'''
|
|
Test packages listing.
|
|
--
|
|
2.15.1
|
|
|
|
|