From 05ff303a7f706ae7a15733c29a9136bd7fc6c337 Mon Sep 17 00:00:00 2001 From: Victor Zhestkov Date: Fri, 18 Feb 2022 11:37:46 +0300 Subject: [PATCH] Normalize the package name only once on install/remove --- salt/modules/yumpkg.py | 46 ++++++++++++++++++++++++++---------------- salt/states/pkg.py | 6 ++++-- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/salt/modules/yumpkg.py b/salt/modules/yumpkg.py index 9ea09a4bab8..ae60b9cab67 100644 --- a/salt/modules/yumpkg.py +++ b/salt/modules/yumpkg.py @@ -1533,14 +1533,15 @@ def install(name=None, if ignore_epoch is True: version_num = version_num.split(':', 1)[-1] arch = '' - try: - namepart, archpart = pkgname.rsplit('.', 1) - except ValueError: - pass - else: - if archpart in salt.utils.pkg.rpm.ARCHES: - arch = '.' + archpart - pkgname = namepart + if normalize: + try: + namepart, archpart = pkgname.rsplit('.', 1) + except ValueError: + pass + else: + if archpart in salt.utils.pkg.rpm.ARCHES: + arch = '.' + archpart + pkgname = namepart if '*' in version_num: # Resolve wildcard matches @@ -1970,7 +1971,7 @@ def update(name=None, return upgrade(name, pkgs, refresh, skip_verify, normalize, minimal, obsoletes, **kwargs) -def remove(name=None, pkgs=None, **kwargs): # pylint: disable=W0613 +def remove(name=None, pkgs=None, normalize=True, **kwargs): # pylint: disable=W0613 ''' .. versionchanged:: 2015.8.12,2016.3.3,2016.11.0 On minions running systemd>=205, `systemd-run(1)`_ is now used to @@ -2000,6 +2001,16 @@ def remove(name=None, pkgs=None, **kwargs): # pylint: disable=W0613 .. versionadded:: 0.16.0 + normalize : True + Normalize the package name by removing the architecture. This is useful + for poorly created packages which might include the architecture as an + actual part of the name such as kernel modules which match a specific + kernel version. + + .. code-block:: bash + + salt -G role:nsd pkg.install gpfs.gplbin-2.6.32-279.31.1.el6.x86_64 normalize=False + Returns a dict containing the changes. @@ -2030,14 +2041,15 @@ def remove(name=None, pkgs=None, **kwargs): # pylint: disable=W0613 elif target in old and version_to_remove in installed_versions: arch = '' pkgname = target - try: - namepart, archpart = target.rsplit('.', 1) - except ValueError: - pass - else: - if archpart in salt.utils.pkg.rpm.ARCHES: - arch = '.' + archpart - pkgname = namepart + if normalize: + try: + namepart, archpart = pkgname.rsplit('.', 1) + except ValueError: + pass + else: + if archpart in salt.utils.pkg.rpm.ARCHES: + arch = '.' + archpart + pkgname = namepart # Since we don't always have the arch info, epoch information has to parsed out. But # a version check was already performed, so we are removing the right version. targets.append( diff --git a/salt/states/pkg.py b/salt/states/pkg.py index 25b51aaf149..0d1137f454d 100644 --- a/salt/states/pkg.py +++ b/salt/states/pkg.py @@ -1782,7 +1782,7 @@ def installed( pkgs=pkgs, sources=sources, reinstall=bool(to_reinstall), - normalize=normalize, + normalize=False, update_holds=update_holds, ignore_epoch=ignore_epoch, **kwargs) @@ -2743,7 +2743,9 @@ def _uninstall( 'comment': 'The following packages will be {0}d: ' '{1}.'.format(action, ', '.join(targets))} - changes = __salt__['pkg.{0}'.format(action)](name, pkgs=pkgs, version=version, **kwargs) + changes = __salt__['pkg.{0}'.format(action)]( + name, pkgs=pkgs, version=version, normalize=False, **kwargs + ) new = __salt__['pkg.list_pkgs'](versions_as_list=True, **kwargs) failed = [] for param in pkg_params: