16547544 get_pkg_list(LIST_UPGRADABLE) can return packages without newer versions
authorShawn Walker <shawn.walker@oracle.com>
Mon, 25 Mar 2013 17:14:06 -0700
changeset 2878 bb1d23c3e089
parent 2876 fd422f3cc04f
child 2879 6b5e07c2cc4e
16547544 get_pkg_list(LIST_UPGRADABLE) can return packages without newer versions
src/modules/client/image.py
src/tests/api/t_api_list.py
--- a/src/modules/client/image.py	Thu Feb 28 16:50:44 2013 -0800
+++ b/src/modules/client/image.py	Mon Mar 25 17:14:06 2013 -0700
@@ -21,7 +21,7 @@
 #
 
 #
-# Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
 #
 
 import M2Crypto as m2
@@ -3027,7 +3027,8 @@
                 # by usage of the SAT solver.
                 newest = {}
                 for pfx, cat in [(None, old_icat)] + pub_cats:
-                        for f in cat.fmris(last=True, pubs=[pfx]):
+                        for f in cat.fmris(last=True,
+                            pubs=pfx and [pfx] or EmptyI):
                                 nver, snver = newest.get(f.pkg_name, (None,
                                     None))
                                 if f.version > nver:
--- a/src/tests/api/t_api_list.py	Thu Feb 28 16:50:44 2013 -0800
+++ b/src/tests/api/t_api_list.py	Mon Mar 25 17:14:06 2013 -0700
@@ -21,7 +21,7 @@
 #
 
 #
-# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
 #
 
 import testutils
@@ -179,7 +179,7 @@
 
         def setUp(self):
                 pkg5unittest.ManyDepotTestCase.setUp(self, ["test1", "test2",
-                    "test3"])
+                    "test3", "test1"])
 
                 pkg_data = ""
                 for p in self.packages:
@@ -238,8 +238,8 @@
 
                         pkg_data += "close\n"
 
-                rurl1 = self.dcs[1].get_repo_url()
-                plist = self.pkgsend_bulk(rurl1, pkg_data)
+                self.rurl1 = self.dcs[1].get_repo_url()
+                plist = self.pkgsend_bulk(self.rurl1, pkg_data)
 
                 # Ensure that the second repo's packages have exactly the same
                 # timestamps as those in the first ... by copying the repo over.
@@ -267,11 +267,16 @@
                 # The third repository should remain empty and not be
                 # published to.
 
+                # The fourth should be for test1, but have only the oldest
+                # version of the 'apple' package.
+                self.rurl4 = self.dcs[4].get_repo_url()
+                self.pkgrecv(self.rurl1, "-d %s %s" % (self.rurl4, plist[0]))
+
                 # Next, create the image and configure publishers.
-                self.image_create(rurl1, prefix="test1",
+                self.image_create(self.rurl1, prefix="test1",
                     variants={ "variant.mumble": "true" })
-                rurl2 = self.dcs[2].get_repo_url()
-                self.pkg("set-publisher -g " + rurl2 + " test2")
+                self.rurl2 = self.dcs[2].get_repo_url()
+                self.pkg("set-publisher -g " + self.rurl2 + " test2")
 
         def assertPrettyEqual(self, actual, expected):
                 if actual == expected:
@@ -1262,7 +1267,19 @@
                 ]
                 self.assertPrettyEqual(returned, expected)
 
+                # Verify the results for LIST_UPGRADABLE when publisher
+                # repository no longer has installed package.
+                self.pkg("unset-publisher test2")
+                self.pkg("set-publisher -G '*' -g %s test1" % self.rurl4)
+                api_obj = self.get_img_api_obj()
+
+                returned = self.__get_returned(api_obj.LIST_UPGRADABLE,
+                    api_obj=api_obj)
+                self.assertPrettyEqual(returned, [])
+
                 # Reset image state for following tests.
+                self.pkg("set-publisher -G '*' -g " + self.rurl1 + " test1")
+                self.pkg("set-publisher -p " + self.rurl2)
                 for pd in api_obj.gen_plan_uninstall(["*"]):
                         continue
                 api_obj.prepare()