15620551 search for package along with the publisher should work.
authorthejaswini.k@oracle.com
Fri, 02 Aug 2013 10:34:41 +0530
changeset 2920 69f5dd9b9488
parent 2919 8d48e4b3aad7
child 2922 37531d03eb31
15620551 search for package along with the publisher should work. 16190165 pkg search may traceback when query is malformed
src/client.py
src/modules/actions/depend.py
src/tests/cli/t_pkg_search.py
--- a/src/client.py	Thu Jul 25 12:42:45 2013 +0530
+++ b/src/client.py	Fri Aug 02 10:34:41 2013 +0530
@@ -2688,8 +2688,14 @@
 
         searches = []
 
+        # Strip pkg:/ or pkg:/// from the fmri.
+        # If fmri has pkg:// then strip the prefix
+        # from 'pkg://' upto the first slash.
+
+        qtext = re.sub(r"pkg:///|pkg://[^/]*/|pkg:/", "", " ".join(pargs))
+
         try:
-                query = [api.Query(" ".join(pargs), case_sensitive,
+                query = [api.Query(qtext, case_sensitive,
                     return_actions)]
         except api_errors.BooleanQueryException, e:
                 error(e)
--- a/src/modules/actions/depend.py	Thu Jul 25 12:42:45 2013 +0530
+++ b/src/modules/actions/depend.py	Fri Aug 02 10:34:41 2013 +0530
@@ -32,6 +32,7 @@
 """
 
 import generic
+import re
 
 import pkg.actions
 import pkg.client.pkgdefs as pkgdefs
@@ -318,15 +319,15 @@
                 # it creating a dummy timestamp.  So we have to split it apart
                 # manually.
                 #
-                # XXX This code will need to change if we start using fmris
-                # with publishers in dependencies.
-                #
                 if isinstance(pfmris, basestring):
                         pfmris = [pfmris]
                 inds = []
+                pat = re.compile(r"pkg:///|pkg://[^/]*/|pkg:/") 
                 for p in pfmris:
-                        if p.startswith("pkg:/"):
-                                p = p[5:]
+                        # Strip pkg:/ or pkg:/// from the fmri.
+                        # If fmri has pkg:// then strip the prefix
+                        # from 'pkg://' upto the first slash.
+                        p = pat.sub("", p)
                         # Note that this creates a directory hierarchy!
                         inds.append(
                                 ("depend", ctype, p, None)
--- a/src/tests/cli/t_pkg_search.py	Thu Jul 25 12:42:45 2013 +0530
+++ b/src/tests/cli/t_pkg_search.py	Fri Aug 02 10:34:41 2013 +0530
@@ -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.
 #
 
 import testutils
@@ -457,6 +457,7 @@
                 self.pkg("search -a -r 'e* AND <e*>'", exit=1)
                 self.pkg("search -a -r '<e*> OR e*'", exit=1)
                 self.pkg("search -a -r 'e* OR <e*>'", exit=1)
+                self._search_op(True, "pkg:/example_path", self.res_remote_path)
 
         def _run_local_tests(self):
                 outfile = os.path.join(self.test_root, "res")
@@ -530,6 +531,7 @@
                 self.pkg("search -a -l 'e* AND <e*>'", exit=1)
                 self.pkg("search -a -l '<e*> OR e*'", exit=1)
                 self.pkg("search -a -l 'e* OR <e*>'", exit=1)
+                self._search_op(False, "pkg:/example_path", self.res_local_path)
 
         def _run_local_empty_tests(self):
                 self.pkg("search -a -l example_pkg", exit=1)
@@ -967,7 +969,6 @@
                 self.assertEqualDiff(expected, actual)
                 self.pkg("search example_path", exit=1)
 
-
 class TestSearchMultiPublisher(pkg5unittest.ManyDepotTestCase):
 
         same_pub1 = """
@@ -982,9 +983,32 @@
             add file tmp/samepub_file2 mode=0555 owner=root group=bin path=/bin/samepub_file2
             close """
 
+        example_pkg11 = """
+            open pkg://test1/[email protected],5.11-0
+            add dir mode=0755 owner=root group=bin path=/bin
+            add file tmp/example_file mode=0555 owner=root group=bin path=/bin/example_path12
+            close """
+        
+        incorp_pkg11 = """
+            open pkg://test1/[email protected],5.11-0
+            add depend fmri=pkg://test1/[email protected],5.11-0 type=incorporate
+            close """
+
+        example_pkg12 = """
+            open pkg://test2/[email protected],5.11-0
+            add dir mode=0755 owner=root group=bin path=/bin
+            add file tmp/example_file mode=0555 owner=root group=bin path=/bin/example_path12
+            close """
+        
+        incorp_pkg12 = """
+            open pkg://test2/[email protected],5.11-0
+            add depend fmri=pkg://test2/[email protected],5.11-0 type=incorporate
+            close """
+
         misc_files = {
             "tmp/samepub_file1": "magic",
             "tmp/samepub_file2": "magic",
+            "tmp/example_file": "magic",
         }
 
         def setUp(self):
@@ -992,14 +1016,14 @@
                     start_depots=True)
                 self.make_misc_files(self.misc_files)
                 self.durl1 = self.dcs[1].get_depot_url()
-                self.pkgsend_bulk(self.durl1, self.same_pub1, refresh_index=True)
                 self.durl2 = self.dcs[2].get_depot_url()
-                self.pkgsend_bulk(self.durl2, self.same_pub2, refresh_index=True)
 
         def test_7140657(self):
                 """ Check that pkg search with -s works as intended when there are
                 two repositories with same publisher name configured."""
 
+                self.pkgsend_bulk(self.durl1, self.same_pub1, refresh_index=True)
+                self.pkgsend_bulk(self.durl2, self.same_pub2, refresh_index=True)
                 self.image_create(self.durl1, prefix="samepub")
                 self.pkg("set-publisher -g %s samepub" % self.durl2)
                 self.pkg("search -s %s samepub_file1" % self.durl1)
@@ -1013,5 +1037,43 @@
                 self.assertEqualDiff(expected, actual)
                 self.pkg("search -s %s samepub_file1" % self.durl2, exit=1)
 
+        def test_16190165(self):
+                """ Check that pkg search works fine with structured queries
+                    and the scheme name "pkg://" in the query """
+		
+                self.pkgsend_bulk(self.durl1, self.example_pkg11, refresh_index=True)
+                self.pkgsend_bulk(self.durl2, self.example_pkg12, refresh_index=True)
+                self.pkgsend_bulk(self.durl1, self.incorp_pkg11, refresh_index=True)
+                self.pkgsend_bulk(self.durl2, self.incorp_pkg12, refresh_index=True)
+                self.image_create(self.durl1, prefix="test1")
+                self.pkg("set-publisher -g %s test2" % self.durl2)
+
+                expected_out1 = \
+                "incorporate\tdepend\tpkg://test1/[email protected],5.11-0\tpkg:/[email protected]\n" \
+                "incorporate\tdepend\tpkg://test2/[email protected],5.11-0\tpkg:/[email protected]\n"
+
+                self.pkg("search -H :depend:incorporate:example_pkg",
+                     exit=0)
+                actual = self.reduceSpaces(self.output)
+                expected = self.reduceSpaces(expected_out1)
+                self.assertEqualDiff(expected, actual)
+
+        	expected_out2 = \
+		"pkg.fmri\tset\ttest1/example_pkg\tpkg:/[email protected]\n" \
+                "incorporate\tdepend\tpkg://test1/[email protected],5.11-0\tpkg:/[email protected]\n" \
+                "pkg.fmri\tset\ttest2/example_pkg\tpkg:/[email protected]\n" \
+                "incorporate\tdepend\tpkg://test2/[email protected],5.11-0\tpkg:/[email protected]\n"
+
+		self.pkg("search -H pkg://test1/example_pkg",exit=0)
+                actual = self.reduceSpaces(self.output)
+                expected = self.reduceSpaces(expected_out2)
+                self.assertEqualDiff(expected, actual)
+
+		self.pkg("search -H pkg:/example_pkg",exit=0)
+                actual = self.reduceSpaces(self.output)
+                expected = self.reduceSpaces(expected_out2)
+                self.assertEqualDiff(expected, actual)
+
+
 if __name__ == "__main__":
         unittest.main()