I iterated the last bit on the tests on #pkg5.  All reviewers are, I
believe, happy.

I have attached an hg exported patch of my changed, merged to tip and
recommitted.

Thanks in advance to someone for committing them.

--Mark
# HG changeset patch
# User Mark J. Nelson <[email protected]>
# Date 1252709677 21600
# Node ID f9f0217c9bd6e24e70d6bc4ebdd8878928d3373c
# Parent  b9535ddac1c6828a47a440c8a6a9652ac7d326bf
6572 ability to trigger repository index refresh desired
6573 ability to control publication refresh-index behaviour desired

diff --git a/src/man/pkgsend.1.txt b/src/man/pkgsend.1.txt
--- a/src/man/pkgsend.1.txt
+++ b/src/man/pkgsend.1.txt
@@ -13,7 +13,8 @@
      /usr/bin/pkgsend import [-T pattern] bundlefile ...
      /usr/bin/pkgsend include [-d basedir] ... [manifest] ...
      /usr/bin/pkgsend publish [-d basedir] ... pkg_fmri [manifest] ...
-     /usr/bin/pkgsend close [-A]
+     /usr/bin/pkgsend close [-A | --no-index]
+     /usr/bin/pkgsend refresh-index
 
 DESCRIPTION
      pkgsend allows the publication of new packages and new package
@@ -89,7 +90,8 @@
 
      close [-A]
           Close current transaction.  With -A, abandon the current
-          transaction.
+          transaction.  With --no-index, do not update the repository's
+         search indices.
 
      publish [ -d basedir] ... fmri [manifest] ...
           Combines open, include and publish in a single operation.
@@ -103,6 +105,10 @@
           analyzed, added, etc before being passed to the publish or import
           subcommands.
 
+     refresh-index
+          Update the repository's search indices.  Should be used after
+         closing one or more transactions using --no-index.
+     
 
 ENVIRONMENT VARIABLES
      The following environment variables are supported:
diff --git a/src/modules/publish/transaction.py 
b/src/modules/publish/transaction.py
--- a/src/modules/publish/transaction.py
+++ b/src/modules/publish/transaction.py
@@ -413,12 +413,34 @@
 
                 return self.trans_id
 
-        @staticmethod
-        def refresh_index():
-                """Currently unsupported."""
+        def refresh_index(self):
+                """Instructs the repository to refresh its search indices.
+                Returns nothing."""
 
-                raise TransactionOperationError("refresh_index",
-                        status=httplib.NOT_FOUND)
+                op = "index"
+               subop = "refresh"
+
+                headers = {}
+
+                try:
+                        c, v = versioned_urlopen(self.origin_url, op, [0],
+                            subop, headers=headers)
+                except (httplib.BadStatusLine, RuntimeError), e:
+                        status = httplib.INTERNAL_SERVER_ERROR
+                        msg = str(e)
+                except (urllib2.HTTPError, urllib2.URLError), e:
+                        status, msg = self.__get_urllib_error(e)
+                except RuntimeError, e:
+                        # Assume the server can't perform the operation.
+                        status = httplib.NOT_FOUND
+                        msg = str(e)
+                else:
+                        msg = None
+                        status = c.code
+
+                if status / 100 == 4 or status / 100 == 5:
+                        raise TransactionOperationError(op,
+                            trans_id=self.trans_id, status=status, msg=msg)
 
 
 class NullTransaction(object):
diff --git a/src/modules/server/depot.py b/src/modules/server/depot.py
--- a/src/modules/server/depot.py
+++ b/src/modules/server/depot.py
@@ -86,7 +86,8 @@
             "abandon",
             "add",
             "p5i",
-            "publisher"
+            "publisher",
+           "index"
         ]
 
         REPO_OPS_READONLY = [
@@ -711,6 +712,25 @@
                 "response.timeout": 3600,
         }
 
+        def index_0(self, *tokens):
+                """Triggers a refresh of the search indices.
+                Returns no output."""
+
+               cmd = tokens[0]
+               
+               if cmd == "refresh":
+                       try:
+                               self.__repo.refresh_index()
+                       except repo.RepositoryError, e:
+                               # Assume a bad request was made.  A 404 can't be
+                               # returned here as misc.versioned_urlopen will 
interpret
+                               # that to mean that the server doesn't support 
this
+                               # operation.
+                               raise cherrypy.HTTPError(httplib.BAD_REQUEST, 
str(e))
+               else:
+                        cherrypy.log("Unknown index subcommand: %s" % cmd)
+                        raise cherrypy.HTTPError(httplib.NOT_FOUND, str(e))
+
         @cherrypy.tools.response_headers(headers = \
             [("Content-Type", "text/plain")])
         def info_0(self, *tokens):
diff --git a/src/publish.py b/src/publish.py
--- a/src/publish.py
+++ b/src/publish.py
@@ -85,9 +85,10 @@
         pkgsend add action arguments
         pkgsend import [-T file_pattern] bundlefile ...
         pkgsend include [-d basedir] .. [manifest] ...
-        pkgsend close [-A]
+        pkgsend close [-A | --no-index]
         pkgsend publish [-d basedir] ... fmri [manifest] ...
         pkgsend generate [-T file_pattern] bundlefile ....
+       pkgsend refresh-index
 
 Options:
         -s repo_uri     target repository URI
@@ -141,14 +142,17 @@
 def trans_close(repo_uri, args):
         abandon = False
         trans_id = None
+       refresh_index = True
 
-        opts, pargs = getopt.getopt(args, "At:")
+        opts, pargs = getopt.getopt(args, "At:", ["no-index"])
 
         for opt, arg in opts:
                 if opt == "-A":
                         abandon = True
-                if opt == "-t":
+                elif opt == "-t":
                         trans_id = arg
+                elif opt == "--no-index":
+                        refresh_index = False
 
         if trans_id is None:
                 try:
@@ -158,7 +162,7 @@
                             "$PKG_TRANS_ID."), cmd="close")
 
         t = trans.Transaction(repo_uri, trans_id=trans_id)
-        pkg_state, pkg_fmri = t.close(abandon)
+        pkg_state, pkg_fmri = t.close(abandon, refresh_index)
         for val in (pkg_state, pkg_fmri):
                 if val is not None:
                         msg(val)
@@ -384,6 +388,20 @@
 
         return 0
 
+def trans_refresh_index(repo_uri, args):
+        """Refreshes the indices at the location indicated by repo_uri."""
+
+        if args:
+                usage(_("command does not take operands"),
+                    cmd="refresh-index")
+
+        try:
+                t = trans.Transaction(repo_uri).refresh_index()
+        except trans.TransactionError, e:
+                error(e, cmd="refresh-index")
+                return 1
+        return 0
+
 def main_func():
 
         # XXX /usr/lib/locale is OpenSolaris-specific.
@@ -434,6 +452,8 @@
                         ret = trans_publish(repo_uri, pargs)
                 elif subcommand == "generate":
                         ret = trans_generate(pargs)
+               elif subcommand == "refresh-index":
+                        ret = trans_refresh_index(repo_uri, pargs)
                 else:
                         usage(_("unknown subcommand '%s'") % subcommand)
         except getopt.GetoptError, e:
diff --git a/src/tests/baseline.txt b/src/tests/baseline.txt
--- a/src/tests/baseline.txt
+++ b/src/tests/baseline.txt
@@ -439,13 +439,13 @@
 cli.t_pkg_install.py TestPkgInstallBasics.test_recursive_uninstall|pass
 cli.t_pkg_install.py 
TestPkgInstallCircularDependencies.test_anchored_circular_dependencies|pass
 cli.t_pkg_install.py 
TestPkgInstallCircularDependencies.test_unanchored_circular_dependencies|pass
+cli.t_pkg_install.py TestPkgInstallUpgrade.test_driver_policy_removal|pass
 cli.t_pkg_install.py TestPkgInstallUpgrade.test_incorp_install|pass
 cli.t_pkg_install.py TestPkgInstallUpgrade.test_upgrade1|pass
 cli.t_pkg_install.py TestPkgInstallUpgrade.test_upgrade2|pass
 cli.t_pkg_install.py TestPkgInstallUpgrade.test_upgrade3|pass
 cli.t_pkg_install.py TestPkgInstallUpgrade.test_upgrade4|pass
 cli.t_pkg_install.py TestPkgInstallUpgrade.test_upgrade_driver_conflicts|pass
-cli.t_pkg_install.py TestPkgInstallUpgrade.test_driver_policy_removal|pass
 cli.t_pkg_install.py TestPkgInstallUpgrade.test_upgrade_liveroot|pass
 cli.t_pkg_intent.py TestPkgIntent.test_0_info|pass
 cli.t_pkg_intent.py TestPkgIntent.test_1_install_uninstall|pass
@@ -498,8 +498,8 @@
 cli.t_pkg_uninstall.py TestCommandLine.test_dependencies|pass
 cli.t_pkg_uninstall.py TestCommandLine.test_pkg_bogus_opts|pass
 cli.t_pkg_uninstall.py TestCommandLine.test_rmdir_cwd|pass
+cli.t_pkg_verify.py TestPkgVerify.test_bug_1463|pass
 cli.t_pkg_verify.py TestPkgVerify.test_pkg_verify_bad_opts|pass
-cli.t_pkg_verify.py TestPkgVerify.test_bug_1463|pass
 cli.t_pkg_version.py TestPkgVersion.test_pkg_version_bad_opts|pass
 cli.t_pkgdep.py TestPkgdepBasics.test_opts|pass
 cli.t_pkgdep.py TestPkgdepBasics.test_output|pass
@@ -516,6 +516,10 @@
 cli.t_pkgrecv.py TestPkgrecvMulti.test_4_timever|pass
 cli.t_pkgrecv.py TestPkgrecvMulti.test_5_recv_env|pass
 cli.t_pkgsend.py TestPkgsendBasics.test_0_pkgsend_bad_opts|pass
+cli.t_pkgsend.py TestPkgsendBasics.test_10_bundle_dir|pass
+cli.t_pkgsend.py TestPkgsendBasics.test_11_bundle_sysv_dir|pass
+cli.t_pkgsend.py TestPkgsendBasics.test_12_bundle_sysv_datastream|pass
+cli.t_pkgsend.py TestPkgsendBasics.test_13_pkgsend_indexcontrol|pass
 cli.t_pkgsend.py TestPkgsendBasics.test_1_pkgsend_abandon|pass
 cli.t_pkgsend.py TestPkgsendBasics.test_2_invalid_url|pass
 cli.t_pkgsend.py TestPkgsendBasics.test_3_bad_transaction|pass
@@ -525,9 +529,6 @@
 cli.t_pkgsend.py TestPkgsendBasics.test_7_create_repo|pass
 cli.t_pkgsend.py TestPkgsendBasics.test_8_bug_7908|pass
 cli.t_pkgsend.py TestPkgsendBasics.test_9_multiple_dirs|pass
-cli.t_pkgsend.py TestPkgsendBasics.test_10_bundle_dir|pass
-cli.t_pkgsend.py TestPkgsendBasics.test_11_bundle_sysv_dir|pass
-cli.t_pkgsend.py TestPkgsendBasics.test_12_bundle_sysv_datastream|pass
 cli.t_setUp.py TestSetUp.test_first_depot_start|pass
 cli.t_setUp.py TestSetUp.test_second_depot_start|pass
 cli.t_variants.py TestPkgVariants.test_old_zones_pkgs|pass
diff --git a/src/tests/cli/t_pkgsend.py b/src/tests/cli/t_pkgsend.py
--- a/src/tests/cli/t_pkgsend.py
+++ b/src/tests/cli/t_pkgsend.py
@@ -31,6 +31,7 @@
 import shutil
 import tempfile
 import unittest
+import urllib
 
 class TestPkgsendBasics(testutils.SingleDepotTestCase):
         persistent_depot = False
@@ -370,5 +371,52 @@
                 self.pkg("install nopkg")
                 self.image_destroy()
 
+        def test_13_pkgsend_indexcontrol(self):
+                """Verify that "pkgsend close --no-index" suppresses
+               indexing and that "pkgsend refresh-index" triggers
+               indexing."""
+
+                dhurl = self.dc.get_depot_url()
+                dfurl = "file://%s" % 
urllib.pathname2url(self.dc.get_repodir())
+
+                fd, fpath = tempfile.mkstemp(dir=self.get_test_prefix())
+
+               self.image_create(dhurl)
+
+               self.dc.stop()
+               self.dc.set_readonly()
+
+               self.pkgsend(dfurl, "open [email protected]")
+               self.pkgsend(dfurl, "add file %s %s path=/tmp/f.foo" \
+                   % ( fpath, "mode=0755 owner=root group=bin" ))
+               self.pkgsend(dfurl, "close --no-index")
+
+               self.dc.start()
+               self.pkg("search file:::", exit=1)
+
+               self.dc.stop()
+               self.pkgsend(dfurl, "refresh-index")
+               self.dc.start()
+               self.pkg("search file:::")
+
+               self.dc.stop()
+               self.dc.set_readwrite()
+               self.dc.start()
+
+               self.pkgsend(dhurl, "open [email protected]")
+               self.pkgsend(dhurl, "add file %s %s path=/tmp/f.foo" \
+                   % ( fpath, "mode=0755 owner=root group=bin" ))
+               self.pkgsend(dhurl, "close --no-index")
+
+               self.pkg("search http:::", exit=1)
+
+               self.pkgsend(dhurl, "refresh-index")
+
+               self.pkg("search http:::")
+
+               self.image_destroy()
+               os.close(fd)
+               os.unlink(fpath)
+
 if __name__ == "__main__":
         unittest.main()
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss

Reply via email to