SHA256
1
0
forked from pool/salt

Accepting request 574155 from systemsmanagement:saltstack

OBS-URL: https://build.opensuse.org/request/show/574155
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/salt?expand=0&rev=71
This commit is contained in:
Dominique Leuenberger 2018-02-09 14:48:16 +00:00 committed by Git OBS Bridge
commit 541df39a5b
25 changed files with 263 additions and 205 deletions

View File

@ -21,6 +21,6 @@ index 33cbb8fa0a..10b608cc7a 100644
return self.beacons.process(b_conf, self.opts['grains']) # pylint: disable=no-member
return []
--
2.15.1
2.13.6

View File

@ -1,4 +1,4 @@
From a94f7d5739fd38529ebf23a89e6afc164739dd8d Mon Sep 17 00:00:00 2001
From 35984b8055beccc94b3bd92b637c5435db822cc9 Mon Sep 17 00:00:00 2001
From: Hubert Mantel <mantel@suse.de>
Date: Mon, 27 Nov 2017 13:55:13 +0100
Subject: [PATCH] avoid excessive syslogging by watchdog cronjob (#58)
@ -21,6 +21,6 @@ index 2e418094ed..73a91ebd62 100755
/usr/bin/salt-daemon-watcher --with-init & disown
fi
--
2.15.1
2.13.6

View File

@ -64,6 +64,6 @@ index 3f4ef296a2..4dbf0d2c6f 100644
if 'metadata' in job:
--
2.15.1
2.13.6

View File

@ -1,4 +1,4 @@
From 0e1cac43dd8211186d6794602f6da77f612850a7 Mon Sep 17 00:00:00 2001
From 2388f136acc805f1ec605206d38db650a877be1c Mon Sep 17 00:00:00 2001
From: Bo Maryniuk <bo@suse.de>
Date: Tue, 21 Nov 2017 12:53:11 +0100
Subject: [PATCH] Bugfix the logic according to the exact described
@ -311,6 +311,6 @@ index 7f4f361c26..e5d10493da 100644
+ ({}, errors)]:
+ assert res == state._get_pillar_errors(kwargs=opts, pillar=ext_pillar)
--
2.15.1
2.13.6

View File

@ -1,4 +1,4 @@
From b31d8f3898149209097e01bbeefbfb70b5a0c395 Mon Sep 17 00:00:00 2001
From c586654ed4c20a69f164b208458163611408c54a Mon Sep 17 00:00:00 2001
From: Michael Calmer <mc@suse.de>
Date: Fri, 15 Dec 2017 09:53:10 +0100
Subject: [PATCH] cherrypy read() reads bytes from the wire and write
@ -112,6 +112,6 @@ index ea2845f46d..75785b8eb1 100644
if headers is not None:
h.update(headers)
--
2.15.1
2.13.6

View File

@ -71,6 +71,6 @@ index effdc2f230..519f753401 100755
self.salt_version = __version__ # pylint: disable=undefined-variable
self.description = 'Portable, distributed, remote execution and configuration management system'
--
2.15.1
2.13.6

View File

@ -1,4 +1,4 @@
From ba9f26cf00b0a767b7b25f156553a9e783aa895d Mon Sep 17 00:00:00 2001
From a1aec4e0d740c179657765ab30475d11f9950174 Mon Sep 17 00:00:00 2001
From: Michele Bologna <michele.bologna@suse.com>
Date: Thu, 14 Dec 2017 18:20:02 +0100
Subject: [PATCH] Feat: add grain for all FQDNs

View File

@ -1,4 +1,4 @@
From e6b1c05fb9e38e54ad30a540a32cd8491fee286b Mon Sep 17 00:00:00 2001
From 7e118cb36bacdc50606512adc562438fcc3257e2 Mon Sep 17 00:00:00 2001
From: Bo Maryniuk <bo@suse.de>
Date: Thu, 14 Dec 2017 16:21:40 +0100
Subject: [PATCH] Fix bsc#1065792
@ -20,6 +20,6 @@ index ff5300df6a..eaa9474f78 100644
return __virtualname__
else:
--
2.15.1
2.13.6

View File

@ -248,6 +248,6 @@ index 0000000000..493822a93c
+ kubernetes.kubernetes.client.ExtensionsV1beta1Api().
+ create_namespaced_deployment().to_dict.called)
--
2.15.1
2.13.6

View File

@ -1,162 +0,0 @@
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

View File

@ -1,4 +1,4 @@
From e9635560f2b0a213518c5023e0b6fb4a11e5570d Mon Sep 17 00:00:00 2001
From 1828df2c90f82db3b1c8a1cb968245f38e2380fe Mon Sep 17 00:00:00 2001
From: Mihai Dinca <mdinca@suse.de>
Date: Fri, 8 Dec 2017 13:34:06 +0100
Subject: [PATCH] Fix salt-master for old psutil
@ -21,6 +21,6 @@ index a32712860a..dee563455b 100644
_globals[attr] = getattr(_temp, attr)
except AttributeError:
--
2.15.1
2.13.6

View File

@ -206,6 +206,6 @@ index 535dfeedfc..6c9dca13cd 100644
+ finally:
+ minion.destroy()
--
2.15.1
2.13.6

View File

@ -787,6 +787,6 @@ index f3403e6e1c..41f3845646 100644
def test_list_patches(self):
'''
--
2.15.1
2.13.6

View File

@ -42,6 +42,6 @@ index e0f349931c..5c92b932ab 100644
--
2.15.1
2.13.6

View File

@ -1,4 +1,4 @@
From d68365a35dd00cced7cdc6eff2ad8a3b823c26f6 Mon Sep 17 00:00:00 2001
From c0a3f1a73c5ca49c94ba9eae94193baf2d08c7eb Mon Sep 17 00:00:00 2001
From: Michael Calmer <mc@suse.de>
Date: Thu, 7 Dec 2017 17:30:31 +0100
Subject: [PATCH] older logrotate need su directive
@ -20,6 +20,6 @@ index 0d99d1b801..625670942c 100644
missingok
rotate 7
--
2.15.1
2.13.6

View File

@ -1,4 +1,4 @@
From d21ea1062f1cd8da0e604288b369c7ff38919c78 Mon Sep 17 00:00:00 2001
From 01467c793bddad471ba425918064dffb0ee21bdf Mon Sep 17 00:00:00 2001
From: Michael Calmer <mc@suse.de>
Date: Tue, 19 Dec 2017 17:07:19 +0100
Subject: [PATCH] python3 compatibility fix - got bytes instead of string

View File

@ -1,4 +1,4 @@
From 5384cb815764af43f287bcb6ed49a9a68d5cd5c0 Mon Sep 17 00:00:00 2001
From 85ddadf0815071c0000fddca3f0b4a62da69bceb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
<psuarezhernandez@suse.com>
Date: Wed, 10 Jan 2018 11:59:33 +0000
@ -118,6 +118,6 @@ index 1317f12f97..ae9774a241 100644
def test_user_present_gid_from_name(self):
'''
--
2.15.1
2.13.6

View File

@ -20,6 +20,6 @@ index 7ca582dfb4..bf513e4dbd 100644
ExecStart=/usr/bin/salt-api
TimeoutStopSec=3
--
2.15.1
2.13.6

View File

@ -42,6 +42,6 @@ index 3cd002308e..0d99d1b801 100644
missingok
rotate 7
--
2.15.1
2.13.6

View File

@ -1,7 +1,24 @@
-------------------------------------------------------------------
Wed Feb 07 13:23:51 UTC 2018 - Mihai Dinca <mdinca@suse.de>
- Prevent queryformat pattern from expanding (bsc#1079048)
-------------------------------------------------------------------
Thu Feb 01 12:38:12 UTC 2018 - jbreuer@suse.de
- Fix epoch handling for Rhel 6 and 7 (bsc#1068566)
- Reverting to current API for split_input
- Added:
* yumpkg-don-t-use-diff_attr-when-determining-install-.patch
- Removed:
* fix-for-wrong-version-processing.patch
-------------------------------------------------------------------
Fri Jan 26 13:54:50 UTC 2018 - pablo.suarezhernandez@suse.com
- Fix for wrong version processing during yum pkg install
- Fix for wrong version processing during yum pkg install (bsc#1068566)
- Feat: add grain for all FQDNs (bsc#1063419)
- Added:
@ -112,7 +129,7 @@ Wed Dec 13 16:22:25 UTC 2017 - mihai.dinca@suse.com
-------------------------------------------------------------------
Wed Dec 13 16:15:53 UTC 2017 - mihai.dinca@suse.com
- Older logrotate need su directive
- Older logrotate need su directive (bsc#1071322)
* Added:
older-logrotate-need-su-directive.patch

View File

@ -77,17 +77,17 @@ Patch9: activate-all-beacons-sources-config-pillar-grains.patch
Patch10: fix-for-delete_deployment-in-kubernetes-module.patch
Patch11: catching-error-when-pidfile-cannot-be-deleted.patch
Patch12: avoid-excessive-syslogging-by-watchdog-cronjob-58.patch
Patch13: fix-for-wrong-version-processing.patch
Patch14: older-logrotate-need-su-directive.patch
Patch15: fix-salt-master-for-old-psutil.patch
Patch16: split-only-strings-if-they-are-such.patch
Patch17: cherrypy-read-reads-bytes-from-the-wire-and-write-th.patch
Patch19: python3-compatibility-fix-got-bytes-instead-of-strin.patch
Patch20: feat-add-grain-for-all-fqdns.patch
Patch21: fix-bsc-1065792.patch
Patch22: set-shell-environment-variable-64.patch
Patch23: bugfix-the-logic-according-to-the-exact-described-pu.patch
Patch24: return-error-when-gid_from_name-and-group-does-not-e.patch
Patch13: older-logrotate-need-su-directive.patch
Patch14: fix-salt-master-for-old-psutil.patch
Patch15: split-only-strings-if-they-are-such.patch
Patch16: cherrypy-read-reads-bytes-from-the-wire-and-write-th.patch
Patch17: python3-compatibility-fix-got-bytes-instead-of-strin.patch
Patch19: feat-add-grain-for-all-fqdns.patch
Patch20: fix-bsc-1065792.patch
Patch21: set-shell-environment-variable-64.patch
Patch22: bugfix-the-logic-according-to-the-exact-described-pu.patch
Patch23: return-error-when-gid_from_name-and-group-does-not-e.patch
Patch24: yumpkg-don-t-use-diff_attr-when-determining-install-.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: logrotate
@ -904,7 +904,7 @@ if [ $1 -eq 2 ] ; then
true
fi
%if %{with systemd}
if [ `rpm -q systemd --queryformat="%{VERSION}"` -lt 228 ]; then
if [ `rpm -q systemd --queryformat="%%{VERSION}"` -lt 228 ]; then
# On systemd < 228 the 'TasksTask' attribute is not available.
# Removing TasksMax from salt-master.service on SLE12SP1 LTSS (bsc#985112)
sed -i '/TasksMax=infinity/d' %{_unitdir}/salt-master.service

View File

@ -1,4 +1,4 @@
From 7f207ed0aa45063e90db2452a311b91f34b1b7e2 Mon Sep 17 00:00:00 2001
From 38f5221734b84d8d3188db82ff4873cd89a4a85c Mon Sep 17 00:00:00 2001
From: Johannes Renner <jrenner@suse.com>
Date: Thu, 11 Jan 2018 15:55:25 +0100
Subject: [PATCH] Set SHELL environment variable (#64)

View File

@ -1,4 +1,4 @@
From 358d18a0cc635b04503d5392ce337227c1f191af Mon Sep 17 00:00:00 2001
From 3fa025fc994d307e08ef271ca8463fe837891a63 Mon Sep 17 00:00:00 2001
From: Bo Maryniuk <bo@suse.de>
Date: Thu, 14 Dec 2017 14:43:52 +0100
Subject: [PATCH] Split only strings, if they are such
@ -45,6 +45,6 @@ index e7abceb134..a59c45331f 100644
self.as_list = details['as_list']
if details['with_lists']:
--
2.15.1
2.13.6

View File

@ -24,6 +24,6 @@ index 480361fe23..00174c072f 100644
if [ ! -d "$(dirname ${_salt_cache_functions})" ]; then
--
2.15.1
2.13.6

View File

@ -0,0 +1,203 @@
From ea9c1f9a83b42b773579d5ef34dc29249bcd680a Mon Sep 17 00:00:00 2001
From: Erik Johnson <palehose@gmail.com>
Date: Thu, 4 Jan 2018 16:10:18 -0600
Subject: [PATCH] yumpkg: don't use diff_attr when determining
install/downgrade targets
Doing so breaks epoch handling, and is unnecessary anyway since the
diff_attr is only used for the return data.
Additionally, this tweaks the "attr" argument in both yumpkg and
zypper's list_pkgs func so that it will accept a comma-separated list as
well as a Python list, and makes a DRY tweak so that we're only
returning and formatting the return data in one place in the function.
---
salt/modules/yumpkg.py | 83 ++++++++++++++++++++++++++++----------------------
salt/modules/zypper.py | 45 +++++++++++++++------------
2 files changed, 73 insertions(+), 55 deletions(-)
diff --git a/salt/modules/yumpkg.py b/salt/modules/yumpkg.py
index 8b63bff4a3..89aceb21cb 100644
--- a/salt/modules/yumpkg.py
+++ b/salt/modules/yumpkg.py
@@ -622,6 +622,7 @@ def list_pkgs(versions_as_list=False, **kwargs):
.. code-block:: bash
salt '*' pkg.list_pkgs
+ salt '*' pkg.list_pkgs attr=version,arch
salt '*' pkg.list_pkgs attr='["version", "arch"]'
'''
versions_as_list = salt.utils.is_true(versions_as_list)
@@ -630,42 +631,52 @@ def list_pkgs(versions_as_list=False, **kwargs):
for x in ('removed', 'purge_desired')]):
return {}
- attr = kwargs.get("attr")
- if 'pkg.list_pkgs' in __context__:
- cached = __context__['pkg.list_pkgs']
- return __salt__['pkg_resource.format_pkg_list'](cached, versions_as_list, attr)
+ attr = kwargs.get('attr')
+ if attr is not None:
+ attr = salt.utils.split_input(attr)
- ret = {}
- cmd = ['rpm', '-qa', '--queryformat',
- salt.utils.pkg.rpm.QUERYFORMAT.replace('%{REPOID}', '(none)') + '\n']
- output = __salt__['cmd.run'](cmd,
- python_shell=False,
- output_loglevel='trace')
- for line in output.splitlines():
- pkginfo = salt.utils.pkg.rpm.parse_pkginfo(
- line,
- osarch=__grains__['osarch']
- )
- if pkginfo is not None:
- # see rpm version string rules available at https://goo.gl/UGKPNd
- pkgver = pkginfo.version
- epoch = ''
- release = ''
- if ':' in pkgver:
- epoch, pkgver = pkgver.split(":", 1)
- if '-' in pkgver:
- pkgver, release = pkgver.split("-", 1)
- all_attr = {'epoch': epoch, 'version': pkgver, 'release': release,
- 'arch': pkginfo.arch, 'install_date': pkginfo.install_date,
- 'install_date_time_t': pkginfo.install_date_time_t}
- __salt__['pkg_resource.add_pkg'](ret, pkginfo.name, all_attr)
-
- for pkgname in ret:
- ret[pkgname] = sorted(ret[pkgname], key=lambda d: d['version'])
-
- __context__['pkg.list_pkgs'] = ret
+ contextkey = 'pkg.list_pkgs'
- return __salt__['pkg_resource.format_pkg_list'](ret, versions_as_list, attr)
+ if contextkey not in __context__:
+ ret = {}
+ cmd = ['rpm', '-qa', '--queryformat',
+ salt.utils.pkg.rpm.QUERYFORMAT.replace('%{REPOID}', '(none)') + '\n']
+ output = __salt__['cmd.run'](cmd,
+ python_shell=False,
+ output_loglevel='trace')
+ for line in output.splitlines():
+ pkginfo = salt.utils.pkg.rpm.parse_pkginfo(
+ line,
+ osarch=__grains__['osarch']
+ )
+ if pkginfo is not None:
+ # see rpm version string rules available at https://goo.gl/UGKPNd
+ pkgver = pkginfo.version
+ epoch = ''
+ release = ''
+ if ':' in pkgver:
+ epoch, pkgver = pkgver.split(":", 1)
+ if '-' in pkgver:
+ pkgver, release = pkgver.split("-", 1)
+ all_attr = {
+ 'epoch': epoch,
+ 'version': pkgver,
+ 'release': release,
+ 'arch': pkginfo.arch,
+ 'install_date': pkginfo.install_date,
+ 'install_date_time_t': pkginfo.install_date_time_t
+ }
+ __salt__['pkg_resource.add_pkg'](ret, pkginfo.name, all_attr)
+
+ for pkgname in ret:
+ ret[pkgname] = sorted(ret[pkgname], key=lambda d: d['version'])
+
+ __context__[contextkey] = ret
+
+ return __salt__['pkg_resource.format_pkg_list'](
+ __context__[contextkey],
+ versions_as_list,
+ attr)
def list_repo_pkgs(*args, **kwargs):
@@ -1311,11 +1322,11 @@ def install(name=None,
log.warning('"version" parameter will be ignored for multiple '
'package targets')
- diff_attr = kwargs.get("diff_attr")
+ diff_attr = kwargs.get('diff_attr')
old = list_pkgs(versions_as_list=False, attr=diff_attr) if not downloadonly else list_downloaded()
# Use of __context__ means no duplicate work here, just accessing
# information already in __context__ from the previous call to list_pkgs()
- old_as_list = list_pkgs(versions_as_list=True, attr=diff_attr) if not downloadonly else list_downloaded()
+ old_as_list = list_pkgs(versions_as_list=True) if not downloadonly else list_downloaded()
to_install = []
to_downgrade = []
diff --git a/salt/modules/zypper.py b/salt/modules/zypper.py
index b440af08a4..ffe38be17d 100644
--- a/salt/modules/zypper.py
+++ b/salt/modules/zypper.py
@@ -685,6 +685,7 @@ def list_pkgs(versions_as_list=False, **kwargs):
.. code-block:: bash
salt '*' pkg.list_pkgs
+ salt '*' pkg.list_pkgs attr=version,arch
salt '*' pkg.list_pkgs attr='["version", "arch"]'
'''
versions_as_list = salt.utils.is_true(versions_as_list)
@@ -693,30 +694,36 @@ def list_pkgs(versions_as_list=False, **kwargs):
for x in ('removed', 'purge_desired')]):
return {}
- attr = kwargs.get("attr")
- if 'pkg.list_pkgs' in __context__:
- cached = __context__['pkg.list_pkgs']
- return __salt__['pkg_resource.format_pkg_list'](cached, versions_as_list, attr)
+ attr = kwargs.get('attr')
+ if attr is not None:
+ attr = salt.utils.split_input(attr)
- cmd = ['rpm', '-qa', '--queryformat', (
- "%{NAME}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-"
- "%|EPOCH?{%{EPOCH}}:{}|_|-%{INSTALLTIME}\\n")]
- ret = {}
- for line in __salt__['cmd.run'](cmd, output_loglevel='trace', python_shell=False).splitlines():
- name, pkgver, rel, arch, epoch, install_time = line.split('_|-')
- install_date = datetime.datetime.utcfromtimestamp(int(install_time)).isoformat() + "Z"
- install_date_time_t = int(install_time)
+ contextkey = 'pkg.list_pkgs'
+
+ if contextkey not in __context__:
+
+ cmd = ['rpm', '-qa', '--queryformat', (
+ "%{NAME}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-"
+ "%|EPOCH?{%{EPOCH}}:{}|_|-%{INSTALLTIME}\\n")]
+ ret = {}
+ for line in __salt__['cmd.run'](cmd, output_loglevel='trace', python_shell=False).splitlines():
+ name, pkgver, rel, arch, epoch, install_time = line.split('_|-')
+ install_date = datetime.datetime.utcfromtimestamp(int(install_time)).isoformat() + "Z"
+ install_date_time_t = int(install_time)
- all_attr = {'epoch': epoch, 'version': pkgver, 'release': rel, 'arch': arch,
- 'install_date': install_date, 'install_date_time_t': install_date_time_t}
- __salt__['pkg_resource.add_pkg'](ret, name, all_attr)
+ all_attr = {'epoch': epoch, 'version': pkgver, 'release': rel, 'arch': arch,
+ 'install_date': install_date, 'install_date_time_t': install_date_time_t}
+ __salt__['pkg_resource.add_pkg'](ret, name, all_attr)
- for pkgname in ret:
- ret[pkgname] = sorted(ret[pkgname], key=lambda d: d['version'])
+ for pkgname in ret:
+ ret[pkgname] = sorted(ret[pkgname], key=lambda d: d['version'])
- __context__['pkg.list_pkgs'] = ret
+ __context__[contextkey] = ret
- return __salt__['pkg_resource.format_pkg_list'](ret, versions_as_list, attr)
+ return __salt__['pkg_resource.format_pkg_list'](
+ __context__[contextkey],
+ versions_as_list,
+ attr)
def _get_configured_repos():
--
2.13.6