salt icon indicating copy to clipboard operation
salt copied to clipboard

pkg.latest not updating the package on CentOS though yum reports an update available

Open rvora opened this issue 11 years ago • 18 comments

I have an RPM installed with with version 0.2 (foo-0.2-001.noarch). Now I have a new version available in my local customrepo but state.highstate using pkg.latest refuses to update the package.

#  yum list foo
Installed Packages
foo.noarch                                                       0.2-001                                                            @customrepo
Available Packages
foo.noarch                                                       0.2.0.1-002                                                        customrepo

Yum install also identifies this as an update.

# yum install foo
.....

==================================================================================================================================================
Updating:
 foo                          noarch                          0.2.0.1-002                            customrepo                          1.1 M

However, Salt pkg.latest says package is already up to date even though yum check-update shows an update is available.

2015-03-22 21:20:14,509 [salt.state                                          ][INFO    ] Executing state pkg.latest for foo
2015-03-22 21:20:14,510 [salt.loaded.int.module.cmdmod                       ][INFO    ] Executing command 'yum -q clean expire-cache' in directory '/root'
2015-03-22 21:20:14,687 [salt.loaded.int.module.cmdmod                       ][DEBUG   ] output:
2015-03-22 21:20:14,688 [salt.loaded.int.module.cmdmod                       ][INFO    ] Executing command 'yum -q check-update ' in directory '/root'
2015-03-22 21:20:16,739 [salt.loaded.int.module.cmdmod                       ][DEBUG   ] output:
foo.noarch                       0.2.0.1-002                       customrepo
2015-03-22 21:20:16,741 [salt.loaded.int.module.cmdmod                       ][INFO    ] Executing command "repoquery --plugins --queryformat '%{NAME}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-%{REPOID}'   --pkgnarrow=available foo" in directory '/root'
2015-03-22 21:20:17,222 [salt.state                                          ][INFO    ] Package foo is already up-to-date.

Walking through the code in salt/states/pkg.py I think the problem is in salt.utils.compare_versions which calls version_cmp which uses distutils.version.LooseVersion:

>>> import distutils.version
>>> v1="0.2-001"
>>> v2="0.2.1-003"
>>> distutils.version.LooseVersion(v1) < distutils.version.LooseVersion(v2)
False

Obviously, yum thinks the package is an upgrade but this comparison fails so Salt does not run salt['pkg.install'].

I think you need a different version_cmp for yumpkg.py (analogous to aptpkg.py:version_cmp) - something like the following to leverage the rpmUtils's built in compare function instead of using distutils - which is not RPM version / release semantics aware:

import rpmUtils.miscutils

def version_cmp(pkg1, pkg2):
    evr1 = rpmUtils.miscutils.stringToVersion(pkg1)
    evr2 = rpmUtils.miscutils.stringToVersion(pkg2)
    return rpmUtils.miscutils.compareEVR(evr1, evr2)

rvora avatar Mar 23 '15 21:03 rvora

Thinking a bit differently, why does Salt need to run version_cmp to check there is a newer version when Yum is already telling you there is an update available? Sounds like Salt is trying too hard and fails in some cases.

I also wonder how this code has been working for so long.

rvora avatar Mar 23 '15 21:03 rvora

Good catch @rvora. I think this sounds like a reasonable approach to me, but @terminalmage might know more about this particular piece of code.

rallytime avatar Mar 24 '15 02:03 rallytime

I'm also still seeing this issue on Centos 7.1. Any chance to get it in the next release?

           Salt: 2015.5.2
         Python: 2.7.5 (default, Jun 17 2014, 18:11:42)
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
 msgpack-python: 0.4.4
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 14.3.1
           RAET: Not Installed
            ZMQ: 3.2.5
           Mako: Not Installed
install packages:
  pkg.latest:
    - refresh: True
    - pkgs:
       - salt-minion
[root@localhost ~]# rpm -qa salt-minion
salt-minion-2015.5.0-1.el7.noarch
[INFO    ] Loading fresh modules for state activity
[INFO    ] Fetching file from saltenv 'base', ** done ** 'packages/basepkgversion_server.sls'
[INFO    ] Running state [install packages] at time 16:32:26.364813
[INFO    ] Executing state pkg.latest for install packages
[INFO    ] Executing command "repoquery --plugins --queryformat '%{NAME}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-%{REPOID}' --all --pkgnarrow=installed" in directory '/root'
[INFO    ] Executing command 'yum -q clean expire-cache   ' in directory '/root'
[INFO    ] Executing command 'yum -q check-update   ' in directory '/root'
[INFO    ] Executing command "repoquery --plugins --queryformat '%{NAME}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-%{REPOID}'   --pkgnarrow=available salt-minion" in directory '/root'
[INFO    ] Package salt-minion is already up-to-date.
[INFO    ] Completed state [install packages] at time 16:32:28.818388
local:
----------
          ID: install packages
    Function: pkg.latest
      Result: True
     Comment: Package salt-minion is already up-to-date.
     Started: 16:32:26.364813
    Duration: 2453.575 ms
     Changes:   

Summary
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1
[root@localhost ~]# yum upgrade salt-minion
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package salt-minion.noarch 0:2015.5.0-1.el7 will be updated
---> Package salt-minion.noarch 0:2015.5.2-3.el7 will be an update
--> Processing Dependency: salt = 2015.5.2-3.el7 for package: salt-minion-2015.5.2-3.el7.noarch
--> Running transaction check
---> Package salt.noarch 0:2015.5.0-1.el7 will be updated
---> Package salt.noarch 0:2015.5.2-3.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================================================================================================================
Package                                                   Arch                                                 Version                                                        Repository                                           Size
=========================================================================================================================================================================================================================================
Updating:
salt-minion                                               noarch                                               2015.5.2-3.el7                                                 epel7                                                24 k
Updating for dependencies:
salt                                                      noarch                                               2015.5.2-3.el7                                                 epel7                                               3.9 M

Transaction Summary
=========================================================================================================================================================================================================================================
Upgrade  1 Package (+1 Dependent package)

Total download size: 3.9 M
Is this ok [y/d/N]:

jmiller0 avatar Jul 01 '15 20:07 jmiller0

pkg state is such a basic and core functionality of any configuration management system. How can SaltStack let this functionality be broken for such a long time? @rallytime who do we need to ping to bump the priority on this fix?

rvora avatar Jul 20 '15 21:07 rvora

@rvora Priority has been bumped. Thanks for bringing this up again - we'll be sure to take a look.

rallytime avatar Jul 20 '15 21:07 rallytime

We're doing a version_cmp in the pkg state to make the state idempotent. We shouldn't be running pkg.install if there is nothing to install, so if 10 packages are listed in the pkg.latest state and 3 of them have updates, we only run pkg.install on the 3 that need to be updated.

I've added a version_cmp function for yumpkg.py, based on @rvora's recommendation. Thanks for the report, and apologies for the delay on this fix.

terminalmage avatar Jul 22 '15 04:07 terminalmage

Using the new function, we can see that the versions are now accurately compared:

[root@cent6 salt]# salt-call pkg.version_cmp '0.2-001' '0.2.0.1-002'
local:
    -1

terminalmage avatar Jul 22 '15 04:07 terminalmage

Going to close this since #25603 was merged. Thanks for the report and the investigative work.

terminalmage avatar Jul 23 '15 16:07 terminalmage

It seems like this patch did not get applied to releases after the 2015.5 branch. Therefore this issue continues to exist in 2015.8 and 2016.3 branches. I think this issue should be reopened until this patch is applied to those branches as well.

mgresser avatar Jun 30 '16 15:06 mgresser

I'm not sure why you would think the patch was not applied, as the function I added in #25603 exists (and works properly) in both of the latest 2015.8 and 2016.3 releases:

[root@cent7 ~]# salt-call --version
salt-call 2015.8.10 (Beryllium)
[root@cent7 ~]# salt-call --local pkg.version_cmp '0.2-001' '0.2.0.1-002'
local:
    -1
[root@cent7 ~]# salt-call --version
salt-call 2016.3.1 (Boron)
[root@cent7 ~]# salt-call --local pkg.version_cmp '0.2-001' '0.2.0.1-002'
local:
    -1

If you can point to a specific use case in which pkg.latest does not work as expected, please open a new issue.

terminalmage avatar Jun 30 '16 16:06 terminalmage

I looked at yumpkg.py in 2015.8 and 2016.3 and don't see any of the code for using rpmUtils in either version.

mgresser avatar Jun 30 '16 16:06 mgresser

That's because it was moved to rpm.py, the lowpkg virtual module for yumpkg.py.

https://github.com/saltstack/salt/blob/v2015.8.10/salt/modules/rpm.py#L574-L604

Can you point to a replicable use case in which pkg.latest doesn't work in a 2015.8 or 2016.3 release?

terminalmage avatar Jun 30 '16 16:06 terminalmage

When I run the same from CentOS5:

[root@Centos5 ~]# salt-call --version salt-call 2015.8.10 (Beryllium) [root@Centos5 ~]# salt-call --local pkg.version_cmp '0.2-001' '0.2.0.1-002' [WARNING ] Failed to compare version '0.2-001' to '0.2.0.1-002' using RPM: 'module' object has no attribute 'labelCompare' local: 1 [root@Centos5 ~]# rpm -qa | grep rpmdevtools rpmdevtools-6.8-1.el5

mgresser avatar Jun 30 '16 17:06 mgresser

This is an entirely different issue, likely being caused by an older version of rpm. Please open a new issue and @ mention me.

terminalmage avatar Jun 30 '16 17:06 terminalmage

@mgresser To be honest, I don't think this is going to be fixed for CentOS 5. I'm not sure how you even got that error, since there is no rpm module available in python 2.6 in CentOS 5. The code added in #25603 in version_cmp relies on either the rpm or rpmUtils.miscutils modules, and on CentOS 5 the system Python is version 2.4.3. So in Salt, these imports should fail:

[root@erik-cent5 ~]# python2.6 -c 'import rpm'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named rpm
[root@erik-cent5 ~]# python2.6 -c 'import rpmUtils.miscutils'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named rpmUtils.miscutils

terminalmage avatar Jun 30 '16 18:06 terminalmage

So this means that Salt can't use these modules. The only way you'd get the warning message you saw is if you have a module called rpm in your pythonpath.

terminalmage avatar Jun 30 '16 18:06 terminalmage

Looks like rpmdev-vercmp is a CLI frontend that we can use as a last resort, so a fix for Cent5 should be possible. Please file a new issue and I'll take care of it.

terminalmage avatar Jun 30 '16 18:06 terminalmage

Thanks, moving this discussion to the issue @Ch3LL linked to.

mgresser avatar Jun 30 '16 19:06 mgresser