[yum-commits] Branch 'yum-3_2_X' - 2 commits - test/simpleupdatetests.py test/testbase.py yum/depsolve.py

James Antill james at osuosl.org
Thu Aug 6 19:25:28 UTC 2009


 test/simpleupdatetests.py |   70 ++++++++++++++++++++++++++++++++++++++++++++++
 test/testbase.py          |   23 +++++++++++++--
 yum/depsolve.py           |   32 +++++++++++++--------
 3 files changed, 110 insertions(+), 15 deletions(-)

New commits:
commit 9e3e805b1cef91e6bed2c5632a87855368a84250
Author: James Antill <james at and.org>
Date:   Wed Aug 5 17:36:59 2009 -0400

     Fix the previous testcase, by:
    
    1. We always call into _compare_providers(), don't rely on
    NewestByNameArch to get the same result.
    
    2. Filter out nevra's, using repo comparison.
    
    ...this should fix the weird ncurses-lib problem, however the previous
    testcase doesn't model that exactly (it just shows a "problem" that if
    fixed will fix it).
     Also the #1 part of the fix probably isn't needed for real life, but is
    to fix the testcase because of the way the unittests use one repo. with
    packages from multiple repos. (without using MetaSack).

diff --git a/yum/depsolve.py b/yum/depsolve.py
index dc9b388..d6b1b02 100644
--- a/yum/depsolve.py
+++ b/yum/depsolve.py
@@ -554,18 +554,15 @@ class Depsolve(object):
                     self._last_req = pkg
                     return checkdeps, missingdep
 
-        # find out which arch of the ones we can choose from is closest
-        # to the arch of the requesting pkg
-        newest = provSack.returnNewestByNameArch()
-        if len(newest) > 1: # there's no way this can be zero
-                            
-            pkgresults = self._compare_providers(newest, requiringPo)
-            # take the first one...
-            best = pkgresults[0][0]                   
-                
-        elif len(newest) == 1:
-            best = newest[0]
-        
+        pkgs = provSack.returnPackages()
+        if len(pkgs) == 1: # Minor opt.
+            best = pkgs[0]
+        else:
+            #  Always do compare providers for multiple pkgs, it deals with
+            # newest etc. ... so no need to do NewestNameArch() ... and it
+            # stops compare_providers from being clever.
+            pkgresults = self._compare_providers(pkgs, requiringPo)
+            best = pkgresults[0][0]
         
         if self.rpmdb.contains(po=best): # is it already installed?
             missingdep = 1
@@ -1060,6 +1057,17 @@ class Depsolve(object):
             if y_dist == x_dist:
                 return None
             return x
+
+        #  Actual start of _compare_providers().
+
+        # Do a NameArch filtering, based on repo. __cmp__
+        unique_nevra_pkgs = {}
+        for pkg in pkgs:
+            if (pkg.pkgtup in unique_nevra_pkgs and
+                unique_nevra_pkgs[pkg.pkgtup].repo <= pkg.repo):
+                continue
+            unique_nevra_pkgs[pkg.pkgtup] = pkg
+        pkgs = unique_nevra_pkgs.values()
             
         pkgresults = {}
         ipkgresults = {}
commit d5538b02ab8f6e0a46213e3af071f30181701a18
Author: James Antill <james at and.org>
Date:   Wed Aug 5 17:32:55 2009 -0400

     Testcase to make sure a specifc nevra comes out of _compare_providers()
    
     This was to try and model the ncurses-libs weirdo in Fedora when the
    .x86_64 version was available from static repos. and normal repos, but
    the .i586 versiohn was only in one. Anyway...

diff --git a/test/simpleupdatetests.py b/test/simpleupdatetests.py
index d543013..f02cc75 100644
--- a/test/simpleupdatetests.py
+++ b/test/simpleupdatetests.py
@@ -694,3 +694,73 @@ class SimpleUpdateTests(OperationsTests):
                                      [pa1, pa2, pa3])
         self.assert_(res=='ok', msg)
         self.assertResult((pa1, pa2, pa3))
+
+    #  What I was trying to model here is a problem where the Fedora builders
+    # tried to install "ncurses-libs" and got a choice of:
+    # ncurses-libs-1.x86_64, ncurses-libs-1.i586, ncurses-libs-1.x86_64
+    # ...and the we should have picked one of the .x86_64 packages in
+    # _compare_providers(), but we picked the .i586 one.
+    #  However that didn't happen, as the testcases "just worked".
+    #  But from experimenting it was observed that if you just had one .x86_64
+    # and one .i586 then _compare_providers() got the right answer. So these
+    # testcases model that problem in _compare_providers(), kinda.
+    #  Then we can fix that problem, which should also fix the original problem
+    # whatever the hell that was.
+    def testUpdateMultiAvailPkgs1(self):
+        pa1 = FakePackage('A', '1', '1', '0', 'x86_64')
+        pa1.addRequires('blah', 'EQ', ('0', '1', '1'))
+        pa2 = FakePackage('B', '1', '1', '0', 'i586')
+        pa2.addProvides('blah', 'EQ', ('0', '1', '1'))
+        pa3 = FakePackage('B', '1', '1', '0', 'x86_64', repo=FakeRepo('one'))
+        pa3.addProvides('blah', 'EQ', ('0', '1', '1'))
+        pa4 = FakePackage('B', '1', '1', '0', 'x86_64', repo=FakeRepo('two'))
+        pa4.addProvides('blah', 'EQ', ('0', '1', '1'))
+
+        res, msg = self.runOperation(['install', 'A'],
+                                     [],
+                                     [pa1, pa2, pa3, pa4])
+        self.assert_(res=='ok', msg)
+        self.assertResult((pa1, pa3))
+
+    def testUpdateMultiAvailPkgs2(self):
+        pa1 = FakePackage('A', '1', '1', '0', 'x86_64')
+        pa1.addRequires('blah', 'EQ', ('0', '1', '1'))
+        pa2 = FakePackage('B', '1', '1', '0', 'i586')
+        pa2.addProvides('blah', 'EQ', ('0', '1', '1'))
+        pa3 = FakePackage('B', '1', '1', '0', 'x86_64', repo=FakeRepo('one'))
+        pa3.addProvides('blah', 'EQ', ('0', '1', '1'))
+        pa4 = FakePackage('B', '1', '1', '0', 'x86_64', repo=FakeRepo('two'))
+        pa4.addProvides('blah', 'EQ', ('0', '1', '1'))
+
+        res, msg = self.runOperation(['install', 'A'],
+                                     [],
+                                     [pa1, pa2, pa4, pa3])
+        self.assert_(res=='ok', msg)
+        self.assertResult((pa1, pa3))
+
+    def testUpdateMultiAvailPkgs3(self):
+        pa1 = FakePackage('A', '1', '1', '0', 'x86_64')
+        pa1.addRequires('B', 'EQ', ('0', '1', '1'))
+        pa2 = FakePackage('B', '1', '1', '0', 'i386')
+        pa3 = FakePackage('B', '1', '1', '0', 'x86_64', repo=FakeRepo('one'))
+        pa4 = FakePackage('B', '1', '1', '0', 'x86_64', repo=FakeRepo('two'))
+
+        res, msg = self.runOperation(['install', 'A'],
+                                     [],
+                                     [pa1, pa2, pa3, pa4])
+        self.assert_(res=='ok', msg)
+        self.assertResult((pa1, pa3))
+
+
+    def testUpdateMultiAvailPkgs4(self):
+        pa1 = FakePackage('A', '1', '1', '0', 'x86_64')
+        pa1.addRequires('B', 'EQ', ('0', '1', '1'))
+        pa2 = FakePackage('B', '1', '1', '0', 'i386')
+        pa3 = FakePackage('B', '1', '1', '0', 'x86_64', repo=FakeRepo('one'))
+        pa4 = FakePackage('B', '1', '1', '0', 'x86_64', repo=FakeRepo('two'))
+
+        res, msg = self.runOperation(['install', 'A'],
+                                     [],
+                                     [pa1, pa2, pa4, pa3])
+        self.assert_(res=='ok', msg)
+        self.assertResult((pa1, pa3))
diff --git a/test/testbase.py b/test/testbase.py
index d91c01c..cadc28b 100644
--- a/test/testbase.py
+++ b/test/testbase.py
@@ -49,6 +49,17 @@ class FakeRepo(object):
     def __init__(self, id=None,sack=None):
         self.id = id
         self.sack = sack
+        self.cost = 1000
+
+    def __cmp__(self, other):
+        """ Sort base class repos. by alphanumeric on their id, also
+            see __cmp__ in YumRepository(). """
+        if self.id > other.id:
+            return 1
+        elif self.id < other.id:
+            return -1
+        else:
+            return 0
 
 class FakePackage(packages.YumAvailablePackage):
 
@@ -290,10 +301,14 @@ class DepsolveTests(_DepsolveTestsBase):
         for po in self.rpmdb:
             po.repoid = po.repo.id = "installed"
         for po in self.xsack:
-            po.repoid = po.repo.id = "TestRepository"
+            if po.repo.id is None:
+                po.repo.id = "TestRepository"
+            po.repoid = po.repo.id
         for txmbr in self.tsInfo:
             if txmbr.ts_state in ('u', 'i'):
-                txmbr.po.repoid = txmbr.po.repo.id = "TestRepository"
+                if txmbr.po.repo.id is None:
+                    txmbr.po.repo.id = "TestRepository"
+                txmbr.po.repoid = txmbr.po.repo.id
             else:
                 txmbr.po.repoid = txmbr.po.repo.id = "installed"
 
@@ -338,7 +353,9 @@ class OperationsTests(_DepsolveTestsBase):
             po.repoid = po.repo.id = "installed"
             self.depsolver.rpmdb.addPackage(po)
         for po in available:
-            po.repoid = po.repo.id = "TestRepository"
+            if po.repo.id is None:
+                po.repo.id = "TestRepository"
+            po.repoid = po.repo.id
             self.depsolver._pkgSack.addPackage(po)
 
         self.depsolver.basecmd = args[0]


More information about the Yum-commits mailing list