{"action":"created","issue":{"url":"https://api.github.com/repos/saltstack/salt/issues/21912","labels_url":"https://api.github.com/repos/saltstack/salt/issues/21912/labels{/name}","comments_url":"https://api.github.com/repos/saltstack/salt/issues/21912/comments","events_url":"https://api.github.com/repos/saltstack/salt/issues/21912/events","html_url":"https://github.com/saltstack/salt/issues/21912","id":63838065,"number":21912,"title":"pkg.latest not updating the package on CentOS though yum reports an update available","user":{"login":"rvora","id":2090822,"avatar_url":"https://avatars.githubusercontent.com/u/2090822?v=3","gravatar_id":"","url":"https://api.github.com/users/rvora","html_url":"https://github.com/rvora","followers_url":"https://api.github.com/users/rvora/followers","following_url":"https://api.github.com/users/rvora/following{/other_user}","gists_url":"https://api.github.com/users/rvora/gists{/gist_id}","starred_url":"https://api.github.com/users/rvora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rvora/subscriptions","organizations_url":"https://api.github.com/users/rvora/orgs","repos_url":"https://api.github.com/users/rvora/repos","events_url":"https://api.github.com/users/rvora/events{/privacy}","received_events_url":"https://api.github.com/users/rvora/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/saltstack/salt/labels/Bug","name":"Bug","color":"e11d21"},{"url":"https://api.github.com/repos/saltstack/salt/labels/Medium%20Severity","name":"Medium Severity","color":"fad8c7"},{"url":"https://api.github.com/repos/saltstack/salt/labels/P1","name":"P1","color":"2181ee"},{"url":"https://api.github.com/repos/saltstack/salt/labels/Packaging","name":"Packaging","color":"006b75"},{"url":"https://api.github.com/repos/saltstack/salt/labels/Platform","name":"Platform","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/saltstack/salt/milestones/13","html_url":"https://github.com/saltstack/salt/milestones/Approved","labels_url":"https://api.github.com/repos/saltstack/salt/milestones/13/labels","id":9265,"number":13,"title":"Approved","description":"All issues that are ready to be worked on, both bugs and features.","creator":{"login":"thatch45","id":507599,"avatar_url":"https://avatars.githubusercontent.com/u/507599?v=3","gravatar_id":"","url":"https://api.github.com/users/thatch45","html_url":"https://github.com/thatch45","followers_url":"https://api.github.com/users/thatch45/followers","following_url":"https://api.github.com/users/thatch45/following{/other_user}","gists_url":"https://api.github.com/users/thatch45/gists{/gist_id}","starred_url":"https://api.github.com/users/thatch45/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thatch45/subscriptions","organizations_url":"https://api.github.com/users/thatch45/orgs","repos_url":"https://api.github.com/users/thatch45/repos","events_url":"https://api.github.com/users/thatch45/events{/privacy}","received_events_url":"https://api.github.com/users/thatch45/received_events","type":"User","site_admin":false},"open_issues":2432,"closed_issues":2309,"state":"open","created_at":"2011-05-14T04:00:56Z","updated_at":"2015-07-20T20:59:53Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2015-03-23T21:34:31Z","updated_at":"2015-07-20T21:00:40Z","closed_at":null,"body":"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.\r\n\r\n```bash\r\n#  yum list foo\r\nInstalled Packages\r\nfoo.noarch                                                       0.2-001                                                            @customrepo\r\nAvailable Packages\r\nfoo.noarch                                                       0.2.0.1-002                                                        customrepo\r\n```\r\n\r\nYum install also identifies this as an update.\r\n\r\n```bash\r\n# yum install foo\r\n.....\r\n\r\n==================================================================================================================================================\r\nUpdating:\r\n foo                          noarch                          0.2.0.1-002                            customrepo                          1.1 M\r\n\r\nHowever, Salt pkg.latest says package is already up to date even though yum check-update shows an update is available.\r\n\r\n2015-03-22 21:20:14,509 [salt.state                                          ][INFO    ] Executing state pkg.latest for foo\r\n2015-03-22 21:20:14,510 [salt.loaded.int.module.cmdmod                       ][INFO    ] Executing command 'yum -q clean expire-cache' in directory '/root'\r\n2015-03-22 21:20:14,687 [salt.loaded.int.module.cmdmod                       ][DEBUG   ] output:\r\n2015-03-22 21:20:14,688 [salt.loaded.int.module.cmdmod                       ][INFO    ] Executing command 'yum -q check-update ' in directory '/root'\r\n2015-03-22 21:20:16,739 [salt.loaded.int.module.cmdmod                       ][DEBUG   ] output:\r\nfoo.noarch                       0.2.0.1-002                       customrepo\r\n2015-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'\r\n2015-03-22 21:20:17,222 [salt.state                                          ][INFO    ] Package foo is already up-to-date.\r\n```\r\n\r\nWalking 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:\r\n\r\n```\r\n>>> import distutils.version\r\n>>> v1=\"0.2-001\"\r\n>>> v2=\"0.2.1-003\"\r\n>>> distutils.version.LooseVersion(v1) < distutils.version.LooseVersion(v2)\r\nFalse\r\n```\r\n\r\nObviously, yum thinks the package is an upgrade but this comparison fails so Salt does not run __salt__['pkg.install'].\r\n\r\nI 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:\r\n\r\n```python\r\nimport rpmUtils.miscutils\r\n\r\ndef version_cmp(pkg1, pkg2):\r\n    evr1 = rpmUtils.miscutils.stringToVersion(pkg1)\r\n    evr2 = rpmUtils.miscutils.stringToVersion(pkg2)\r\n    return rpmUtils.miscutils.compareEVR(evr1, evr2)\r\n```"},"comment":{"url":"https://api.github.com/repos/saltstack/salt/issues/comments/123036475","html_url":"https://github.com/saltstack/salt/issues/21912#issuecomment-123036475","issue_url":"https://api.github.com/repos/saltstack/salt/issues/21912","id":123036475,"user":{"login":"rvora","id":2090822,"avatar_url":"https://avatars.githubusercontent.com/u/2090822?v=3","gravatar_id":"","url":"https://api.github.com/users/rvora","html_url":"https://github.com/rvora","followers_url":"https://api.github.com/users/rvora/followers","following_url":"https://api.github.com/users/rvora/following{/other_user}","gists_url":"https://api.github.com/users/rvora/gists{/gist_id}","starred_url":"https://api.github.com/users/rvora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rvora/subscriptions","organizations_url":"https://api.github.com/users/rvora/orgs","repos_url":"https://api.github.com/users/rvora/repos","events_url":"https://api.github.com/users/rvora/events{/privacy}","received_events_url":"https://api.github.com/users/rvora/received_events","type":"User","site_admin":false},"created_at":"2015-07-20T21:00:40Z","updated_at":"2015-07-20T21:00:40Z","body":"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?"}}