15949886 pkg traceback when using -g for repository with no packages s12b16
authorShawn Walker <shawn.walker@oracle.com>
Tue, 19 Feb 2013 14:58:42 -0800
changeset 2862 1ec958dbd40a
parent 2861 a9b6910ed2e0
child 2863 3ada267d5a98
15949886 pkg traceback when using -g for repository with no packages
src/modules/client/api.py
src/tests/cli/t_pkg_composite.py
--- a/src/modules/client/api.py	Mon Feb 11 09:34:23 2013 +1300
+++ b/src/modules/client/api.py	Tue Feb 19 14:58:42 2013 -0800
@@ -21,7 +21,7 @@
 #
 
 #
-# Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
 #
 
 """This module provides the supported, documented interface for clients to
@@ -3146,9 +3146,7 @@
                                 try:
                                         opub = pub_map[pub.prefix]
                                 except KeyError:
-                                        nrepo = None
-                                        if pub.prefix in pkg_pub_map:
-                                                nrepo = publisher.Repository()
+                                        nrepo = publisher.Repository()
                                         opub = publisher.Publisher(pub.prefix,
                                             catalog=compkcat, repository=nrepo)
                                         pub_map[pub.prefix] = opub
--- a/src/tests/cli/t_pkg_composite.py	Mon Feb 11 09:34:23 2013 +1300
+++ b/src/tests/cli/t_pkg_composite.py	Tue Feb 19 14:58:42 2013 -0800
@@ -20,7 +20,7 @@
 # CDDL HEADER END
 #
 
-# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
 
 import testutils
 if __name__ == "__main__":
@@ -177,7 +177,7 @@
 
         def setUp(self):
                 pkg5unittest.ManyDepotTestCase.setUp(self, ["test", "test",
-                    "test", "empty"])
+                    "test", "empty", "void"])
                 self.make_misc_files(self.misc_files)
 
                 # First repository will contain all packages.
@@ -193,6 +193,10 @@
                 self.empty_rurl = self.dcs[4].get_repo_url()
                 self.pkgrepo("refresh -s %s" % self.empty_rurl)
 
+                # Fifth will have a publisher named 'void', but no packages.
+                self.void_rurl = self.dcs[5].get_repo_url()
+                self.pkgrepo("refresh -s %s" % self.void_rurl)
+
                 # Setup base test paths.
                 self.path_to_certs = os.path.join(self.ro_data_root,
                     "signing_certs", "produced")
@@ -548,6 +552,25 @@
                 output = output[:output.find("pkg: ")] + "\n"
                 self.assertEqualDiff(expected, output)
 
+        def test_05_empty(self):
+                """Verify empty repositories and repositories with a publisher,
+                but no packages, can be used with -g."""
+
+                self.image_create(repourl=None, prefix=None)
+
+                # Verify usage alone.
+                for uri in (self.empty_rurl, self.void_rurl):
+                        self.pkg("list -afH -g %s '*'" % uri, exit=1)
+                        self.pkg("contents -H -g %s '*'" % uri, exit=1)
+
+                # Verify usage in combination with non-empty.
+                self.pkg("list -afH -g %s -g %s -g %s '*'" % (self.empty_rurl,
+                    self.void_rurl, self.foo_rurl))
+                expected = \
+                    ("foo (test) 1.0 ---\n")
+                output = self.reduceSpaces(self.output)
+                self.assertEqualDiff(expected, output)
+
 
 if __name__ == "__main__":
         unittest.main()