Bug 847473 - Fix mock kernel version comparison
Summary: Fix mock kernel version comparison
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: mock
Version: rawhide
Hardware: All
OS: Linux
unspecified
low
Target Milestone: ---
Assignee: Clark Williams
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-08-11 20:58 UTC by Mike Miller
Modified: 2012-11-20 19:37 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-11-15 02:32:47 UTC
Type: Bug


Attachments (Terms of Use)

Description Mike Miller 2012-08-11 20:58:42 UTC
Description of problem:

Mock's comparison of kernel versions fails when the version has less than 3 version components (e.g. 3.4).

Version-Release number of selected component (if applicable):

git master

How reproducible:

Must be running a kernel with a version that has only 1 dot in it.

Steps to Reproduce:

python <<EOF
import mockbuild.util
print(mockbuild.util.cmpKernelEVR("3.4", "2.6.9"))
EOF
  
Actual results:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "<peak.util.decorators.rewrap wrapping mockbuild.util.cmpKernelEVR at 0x013DEB90>", line 3, in cmpKernelEVR
  File "mockbuild/trace_decorator.py", line 70, in trace
    result = func(*args, **kw)
  File "mockbuild/util.py", line 154, in cmpKernelEVR
    return rpmUtils.miscutils.compareEVR(evr1, evr2)
  File "/usr/lib/python2.7/dist-packages/rpmUtils/miscutils.py", line 36, in compareEVR
    def compareEVR((e1, v1, r1), (e2, v2, r2)):
ValueError: need more than 2 values to unpack


Expected results:

1

Additional info:

The following patch fixes the problem by calling the proper yum function, compareVerOnly, since this is just a version comparison, not an RPM EVR comparison. I also renamed the function to cmpKernelVer, although that can be backed out in the name of API compatibility.


From c8dd2363bda2d4ebe2bf6425c06ae9d1626f18df Mon Sep 17 00:00:00 2001
From: Mike Miller <mtmiller@ieee.org>
Date: Sat, 11 Aug 2012 16:35:41 -0400
Subject: [PATCH] Rename cmpKernelEVR->cmpKernelVer and fix comparison

Use rpmUtils.miscutils.compareVerOnly to correctly compare kernel
version strings.
---
 py/mockbuild/backend.py |    4 ++--
 py/mockbuild/mounts.py  |    2 +-
 py/mockbuild/util.py    |    6 ++----
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/py/mockbuild/backend.py b/py/mockbuild/backend.py
index 809244c..31bd790 100644
--- a/py/mockbuild/backend.py
+++ b/py/mockbuild/backend.py
@@ -458,12 +458,12 @@ class Root(object):
         os.chown(self.makeChrootPath('dev/ptmx'), pwd.getpwnam('root')[2], grp.getgrnam('tty')[2])
 
         # symlink /dev/fd in the chroot for everything except RHEL4
-        if mockbuild.util.cmpKernelEVR(kver, '2.6.9') > 0:
+        if mockbuild.util.cmpKernelVer(kver, '2.6.9') > 0:
             os.symlink("/proc/self/fd",   self.makeChrootPath("dev/fd"))
 
         os.umask(prevMask)
 
-        if mockbuild.util.cmpKernelEVR(kver, '2.6.29') >= 0:
+        if mockbuild.util.cmpKernelVer(kver, '2.6.29') >= 0:
             os.unlink(self.makeChrootPath('/dev/ptmx'))
             os.symlink("pts/ptmx", self.makeChrootPath('/dev/ptmx'))
         self.finish("device setup")
diff --git a/py/mockbuild/mounts.py b/py/mockbuild/mounts.py
index 0feae1f..a676a17 100644
--- a/py/mockbuild/mounts.py
+++ b/py/mockbuild/mounts.py
@@ -114,7 +114,7 @@ class Mounts(object):
                         FileSystemMountPoint(filetype='tmpfs', device='mock_chroot_shmfs', path=rootObj.makeChrootPath('/dev/shm')),
                       ]
         opts = 'gid=%d,mode=0620,ptmxmode=0666' % grp.getgrnam('tty').gr_gid
-        if mockbuild.util.cmpKernelEVR(os.uname()[2], '2.6.29') >= 0:
+        if mockbuild.util.cmpKernelVer(os.uname()[2], '2.6.29') >= 0:
             opts += ',newinstance'
         self.mounts.append(FileSystemMountPoint(filetype='devpts', device='mock_chroot_devpts', path=rootObj.makeChrootPath('/dev/pts'), options=opts))
 
diff --git a/py/mockbuild/util.py b/py/mockbuild/util.py
index 95d69c1..62da296 100644
--- a/py/mockbuild/util.py
+++ b/py/mockbuild/util.py
@@ -147,11 +147,9 @@ def getNEVRA(hdr):
     return (name, epoch, ver, rel, arch)
 
 decorate(traceLog())
-def cmpKernelEVR(str1, str2):
+def cmpKernelVer(str1, str2):
     'compare two kernel version strings and return -1, 0, 1 for less, equal, greater'
-    evr1 = str1.split('.', 2)
-    evr2 = str2.split('.', 2)
-    return rpmUtils.miscutils.compareEVR(evr1, evr2)
+    return rpmUtils.miscutils.compareVerOnly(str1, str2)
 
 decorate(traceLog())
 def getAddtlReqs(hdr, conf):
-- 
1.7.10.4

Comment 1 Clark Williams 2012-08-14 20:26:43 UTC
patch applied to git tree, queued for next release. 

Thanks.

Comment 2 Fedora Update System 2012-09-14 15:27:13 UTC
mock-1.1.27-2.el6 has been submitted as an update for Fedora EPEL 6.
https://admin.fedoraproject.org/updates/mock-1.1.27-2.el6

Comment 3 Fedora Update System 2012-09-14 15:28:23 UTC
mock-1.1.27-2.fc16 has been submitted as an update for Fedora 16.
https://admin.fedoraproject.org/updates/mock-1.1.27-2.fc16

Comment 4 Fedora Update System 2012-09-14 15:29:18 UTC
mock-1.0.35-1.el5 has been submitted as an update for Fedora EPEL 5.
https://admin.fedoraproject.org/updates/mock-1.0.35-1.el5

Comment 5 Fedora Update System 2012-09-14 15:30:20 UTC
mock-1.1.27-2.fc17 has been submitted as an update for Fedora 17.
https://admin.fedoraproject.org/updates/mock-1.1.27-2.fc17

Comment 6 Fedora Update System 2012-09-16 18:29:21 UTC
Package mock-1.1.27-2.el6:
* should fix your issue,
* was pushed to the Fedora EPEL 6 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=epel-testing mock-1.1.27-2.el6'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-EPEL-2012-12915/mock-1.1.27-2.el6
then log in and leave karma (feedback).

Comment 7 Todd Zullinger 2012-09-19 15:39:28 UTC
It seems like yum is too old on el6 to support compareVerOnly.  Am I missing something?

[build@build1 ~]$ rpm -q redhat-release-server mock
redhat-release-server-6Server-6.3.0.3.el6.x86_64
mock-1.1.27-2.el6.noarch

[build@build1 ~]$ mock -r fedora-17-i386 init
INFO: mock.py version 1.1.27 starting...
ERROR: 'module' object has no attribute 'compareVerOnly'
Traceback (most recent call last):
  File "/usr/sbin/mock", line 920, in <module>
    main(retParams)
  File "/usr/sbin/mock", line 744, in main
    chroot = mockbuild.backend.Root(config_opts, uidManager)
  File "<peak.util.decorators.rewrap wrapping mockbuild.backend.__init__ at 0x01482758>", line 3, in __init__
    def __init__(self, config, uidManager): return __decorated(self, config, uidManager)
  File "/usr/lib/python2.6/site-packages/mockbuild/trace_decorator.py", line 70, in trace
    result = func(*args, **kw)
  File "/usr/lib/python2.6/site-packages/mockbuild/backend.py", line 114, in __init__
    self.mounts = mockbuild.mounts.Mounts(self)
  File "<peak.util.decorators.rewrap wrapping mockbuild.mounts.__init__ at 0x01489578>", line 3, in __init__
    def __init__(self, rootObj): return __decorated(self, rootObj)
  File "/usr/lib/python2.6/site-packages/mockbuild/trace_decorator.py", line 70, in trace
    result = func(*args, **kw)
  File "/usr/lib/python2.6/site-packages/mockbuild/mounts.py", line 117, in __init__
    if mockbuild.util.cmpKernelVer(os.uname()[2], '2.6.29') >= 0:
  File "<peak.util.decorators.rewrap wrapping mockbuild.util.cmpKernelVer at 0x0147B050>", line 3, in cmpKernelVer
    def cmpKernelVer(str1, str2): return __decorated(str1, str2)
  File "/usr/lib/python2.6/site-packages/mockbuild/trace_decorator.py", line 70, in trace
    result = func(*args, **kw)
  File "/usr/lib/python2.6/site-packages/mockbuild/util.py", line 156, in cmpKernelVer
    return rpmUtils.miscutils.compareVerOnly(str1, str2)
AttributeError: 'module' object has no attribute 'compareVerOnly'

Comment 8 Mike Miller 2012-09-20 12:06:27 UTC
This is true, this fix is not appropriate for EL5 or EL6 as applied currently.

It looks like you are keeping EL6 in sync with Fedora so I assume you would rather have a consistent fix for all and not branch EL6 and back out this change, right?

Here's another patch against the current state of the sources to make it backwards compatible. I have tested this applied to the current mock on both EL5 and EL6.


From 680204c663c74386c9b491d69e0943f3cdd2370e Mon Sep 17 00:00:00 2001
From: Mike Miller <mtmiller@ieee.org>
Date: Thu, 20 Sep 2012 07:37:59 -0400
Subject: [PATCH] Fix cmpKernelVer to be backwards compatible

Replace compareVerOnly with its equivalent for systems without the
latest yum. This can be reverted once everyone is on yum >= 3.4.2.
---
 py/mockbuild/util.py |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/py/mockbuild/util.py b/py/mockbuild/util.py
index 14d043c..143a4eb 100644
--- a/py/mockbuild/util.py
+++ b/py/mockbuild/util.py
@@ -153,7 +153,7 @@ def getNEVRA(hdr):
 decorate(traceLog())
 def cmpKernelVer(str1, str2):
     'compare two kernel version strings and return -1, 0, 1 for less, equal, greater'
-    return rpmUtils.miscutils.compareVerOnly(str1, str2)
+    return rpmUtils.miscutils.compareEVR(('', str1, ''), ('', str2, ''))
 
 decorate(traceLog())
 def getAddtlReqs(hdr, conf):
-- 
1.7.10.4

Comment 9 Clark Williams 2012-09-21 15:07:05 UTC
How about something like this:

diff --git a/py/mockbuild/util.py b/py/mockbuild/util.py
index 14d043c..2fd88ba 100644
--- a/py/mockbuild/util.py
+++ b/py/mockbuild/util.py
@@ -153,7 +153,10 @@ def getNEVRA(hdr):
 decorate(traceLog())
 def cmpKernelVer(str1, str2):
     'compare two kernel version strings and return -1, 0, 1 for less, equal, greater'
-    return rpmUtils.miscutils.compareVerOnly(str1, str2)
+    try:
+        return rpmUtils.miscutils.compareVerOnly(str1, str2)
+    except AttributeError, e:
+        return rpmUtils.miscutils.compareEVR(str1, str2)
 
basically try to use the new compareVerOnly and if it's missing, drop back to compareEVR?

Comment 10 Mike Miller 2012-09-21 19:20:34 UTC
Yep, that is the right way to do it, except we still need to fix the call to compareEVR like I had posted in the previous comment. This form is taken from the definition of compareVerOnly in yum. This way the two calls are functionally identical.

diff --git a/py/mockbuild/util.py b/py/mockbuild/util.py
index 14d043c..73e2f63 100644
--- a/py/mockbuild/util.py
+++ b/py/mockbuild/util.py
@@ -153,7 +153,10 @@ def getNEVRA(hdr):
 decorate(traceLog())
 def cmpKernelVer(str1, str2):
     'compare two kernel version strings and return -1, 0, 1 for less, equal, greater'
-    return rpmUtils.miscutils.compareVerOnly(str1, str2)
+    try:
+        return rpmUtils.miscutils.compareVerOnly(str1, str2)
+    except AttributeError, e:
+        return rpmUtils.miscutils.compareEVR(('', str1, ''), ('', str2, ''))
 
 decorate(traceLog())
 def getAddtlReqs(hdr, conf):

Comment 11 Clark Williams 2012-09-24 17:18:07 UTC
ok, running the above form of compareEVR through the regression tests now.

Comment 12 Fedora Update System 2012-11-01 21:09:21 UTC
mock-1.1.28-1.el6 has been submitted as an update for Fedora EPEL 6.
https://admin.fedoraproject.org/updates/mock-1.1.28-1.el6

Comment 13 Fedora Update System 2012-11-01 21:10:43 UTC
mock-1.1.28-1.fc18 has been submitted as an update for Fedora 18.
https://admin.fedoraproject.org/updates/mock-1.1.28-1.fc18

Comment 14 Fedora Update System 2012-11-01 21:11:54 UTC
mock-1.0.36-1.el5 has been submitted as an update for Fedora EPEL 5.
https://admin.fedoraproject.org/updates/mock-1.0.36-1.el5

Comment 15 Fedora Update System 2012-11-01 21:13:01 UTC
mock-1.1.28-1.fc17 has been submitted as an update for Fedora 17.
https://admin.fedoraproject.org/updates/mock-1.1.28-1.fc17

Comment 16 Fedora Update System 2012-11-01 21:14:09 UTC
mock-1.1.28-1.fc16 has been submitted as an update for Fedora 16.
https://admin.fedoraproject.org/updates/mock-1.1.28-1.fc16

Comment 17 Fedora Update System 2012-11-15 02:32:49 UTC
mock-1.1.28-1.fc17 has been pushed to the Fedora 17 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 18 Fedora Update System 2012-11-15 02:35:06 UTC
mock-1.1.28-1.fc16 has been pushed to the Fedora 16 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 19 Fedora Update System 2012-11-20 19:37:25 UTC
mock-1.0.36-1.el5 has been pushed to the Fedora EPEL 5 stable repository.  If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.