(PUP-5802) Make the Yum package provider correctly parse epochs#4616
Conversation
Without this patch applied, the Yum package provider assumes all version epochs are "0", i.e. a package with version "1:1.2.3-4.el5" will be interpreted as having epoch "0" not "1". This causes version comparisons made by puppet to be incorrect when comparing packages of different epoch's. This bug is caused by the line: e = String(Bignum(e)) rescue '0' Bignum is not a function, so the line always throws an exception and the rescue is always invoked. This patch uses Integer instead of Bignum, rescues the specific exception needed (this is so that an epoch like "foo" is coerced into "0"), and provides a test for non-zero epochs
|
@mveytsman interesting! Thanks for the contribution! We've run into lots of trouble around Yum / DNF epoch parsing (fairly recently, even. See https://tickets.puppetlabs.com/browse/PUP-5549). We'll be wanting to have a careful look at this to make sure all is well in both Yum and DNF. From a glance, this seems sane, and we plan to take time to do more review on our end soon. |
|
So I tried this on CentOS 7 with That doesn't seem right. Do you get successful behavior? |
|
@MikaelSmith yeah, I thought that might be the case. Yum requires you to specify the When we specify the version '2:7.4.160' Puppet doesn't understand this constraint, as it doesn't have a field for architecture. We then end up calling: The only way to make this work is to sidestep version comparisons and hardcode your desired version like so: |
|
I'm fine merging this, but I'd like to understand the use-case it fixes @mveytsman |
|
Before this patch puppet's version comparison would ignore epochs. For instance, if a user had package with a version "1.2" installed, and asked to install "3:1.2", we would not recognize these as different versions.
puppet/lib/puppet/provider/package/yum.rb Lines 133 to 179 in b1d2551 |
|
@mveytsman would you mind pasting a manifest that this fixes? I'm trying to work up a reproducible test case but am having no luck thus far. |
|
@whopper I don't have one on hand -- I came across the issue reading the code after reading a blog post that references it http://blog.jasonantman.com/2014/07/how-yum-and-rpm-compare-versions/ and I found the bug through code review. The unit test I include, https://github.com/mveytsman/puppet/blob/fix/master/yumepochparsing/spec/unit/provider/package/yum_spec.rb#L54-L59, will fail without my patch, which is how i concluded that puppet always sets the epoch to 0. |
(PUP-5802) Make the Yum package provider correctly parse epochs
Without this patch applied, the Yum package provider assumes all version
epochs are "0", i.e. a package with version "1:1.2.3-4.el5" will be
interpreted as having epoch "0" not "1". This causes version comparisons
made by puppet to be incorrect when comparing packages of different
epoch's.
This bug is caused by the line:
Bignum is not a function, so the line always throws an exception and the
rescue is always invoked.
This patch uses Integer instead of Bignum, rescues the specific
exception needed (this is so that an epoch like "foo" is coerced into
"0"), and provides a test for non-zero epochs