1540 changes to authorities should include refresh
authorBrock Pytlik <bpytlik@sun.com>
Wed, 17 Sep 2008 18:51:19 -0700
changeset 537 3dc9fc9b5fee
parent 536 75353b99aacd
child 538 69e50f8b3782
1540 changes to authorities should include refresh 2886 pkg image-update fails when unable to contact an authority 3121 install should attempt to refresh the catalogs before running 3122 all commands which automatically refresh catalogs should have a --dont-refresh flag
src/client.py
src/man/pkg.1.txt
src/modules/client/image.py
src/packagemanager.py
src/tests/baseline.txt
src/tests/cli/t_actions.py
src/tests/cli/t_commandline.py
src/tests/cli/t_pkg_install_corrupt_image.py
src/tests/cli/t_pkg_list.py
src/tests/cli/t_refresh.py
src/tests/cli/t_rename.py
src/tests/cli/t_search_multi.py
src/tests/cli/t_twodepot.py
--- a/src/client.py	Wed Sep 17 17:46:28 2008 -0700
+++ b/src/client.py	Wed Sep 17 18:51:19 2008 -0700
@@ -453,8 +453,8 @@
                 # SUNWipkg is available.
                 try:
                         newimg.retrieve_catalogs()
-                except RuntimeError, failures:
-                        display_catalog_failures(failures)
+                except image.CatalogRefreshException, cre:
+                        display_catalog_failures(cre)
                         error(_("SUNWipkg update check failed."))
                         return False
 
@@ -492,10 +492,13 @@
         # Verify validity of certificates before attempting network operations
         if not img.check_cert_validity():
                 return 1
+
+        ret_code = 0
         
-        opts, pargs = getopt.getopt(args, "b:fnvq")
+        opts, pargs = getopt.getopt(args, "b:fnvq", ["no-refresh"])
 
         force = quiet = noexecute = verbose = False
+        refresh_catalogs = True
         for opt, arg in opts:
                 if opt == "-n":
                         noexecute = True
@@ -507,6 +510,8 @@
                         quiet = True
                 elif opt == "-f":
                         force = True
+                elif opt == "--no-refresh":
+                        refresh_catalogs = False
 
         if verbose and quiet:
                 usage(_("image-update: -v and -q may not be combined"))
@@ -518,18 +523,19 @@
         progresstracker = get_tracker(quiet)
         img.load_catalogs(progresstracker)
 
-        try:
-                img.retrieve_catalogs()
-        except RuntimeError, failures:
-                if display_catalog_failures(failures) == 0:
-                        if not noexecute:
-                                return 1
-                else:
-                        if not noexecute:
-                                return 3
+        if refresh_catalogs:
+                try:
+                        img.retrieve_catalogs()
+                except image.CatalogRefreshException, cre:
+                        if display_catalog_failures(cre) == 0:
+                                if not noexecute:
+                                        return 1
+                        else:
+                                ret_code = 3
 
-        # Reload catalog.  This picks up the update from retrieve_catalogs.
-        img.load_catalogs(progresstracker)
+                # Reload catalog. This picks up the update from
+                # retrieve_catalogs.
+                img.load_catalogs(progresstracker)
 
         #
         # If we can find SUNWipkg and SUNWcs in the target image, then
@@ -560,10 +566,10 @@
 
         if img.imageplan.nothingtodo():
                 msg(_("No updates available for this image."))
-                return 0
+                return ret_code
 
         if noexecute:
-                return 0
+                return ret_code
 
         try:
                 img.imageplan.preexecute()
@@ -586,7 +592,6 @@
         try:
                 img.imageplan.execute()
                 be.activate_image()
-                ret_code = 0
         except RuntimeError, e:
                 error(_("image-update failed: %s") % e)
                 be.restore_image()
@@ -631,9 +636,12 @@
         if not img.check_cert_validity():
                 return 1
 
-        opts, pargs = getopt.getopt(args, "nvb:f:q")
+        ret_code = 0
+        
+        opts, pargs = getopt.getopt(args, "nvb:f:q", ["no-refresh"])
 
         quiet = noexecute = verbose = False
+        refresh_catalogs = True
         filters = []
         for opt, arg in opts:
                 if opt == "-n":
@@ -646,6 +654,8 @@
                         filters += [ arg ]
                 elif opt == "-q":
                         quiet = True
+                elif opt == "--no-refresh":
+                        refresh_catalogs = False
 
         if not pargs:
                 usage(_("install: at least one package name required"))
@@ -660,6 +670,21 @@
 
         img.load_catalogs(progresstracker)
 
+        if refresh_catalogs:
+        
+                try:
+                        img.retrieve_catalogs()
+                except image.CatalogRefreshException, cre:
+                        if not display_catalog_failures(cre):
+                                if not noexecute:
+                                        return 1
+                        else:
+                                ret_code = 3
+
+                # Reload catalog. This picks up the update from
+                # retrieve_catalogs.
+                img.load_catalogs(progresstracker)
+
         pkg_list = [ pat.replace("*", ".*").replace("?", ".")
             for pat in pargs ]
 
@@ -685,10 +710,10 @@
         if img.imageplan.nothingtodo():
                 msg(_("Nothing to install in this image (is this package " \
                     "already installed?)"))
-                return 0
+                return ret_code
 
         if noexecute:
-                return 0
+                return ret_code
 
         try:
                 img.imageplan.preexecute()
@@ -706,7 +731,6 @@
         try:
                 img.imageplan.execute()
                 be.activate_install_uninstall()
-                ret_code = 0
         except RuntimeError, e:
                 error(_("installation failed: %s") % e)
                 be.restore_install_uninstall()
@@ -1432,11 +1456,12 @@
 
         return err
 
-def display_catalog_failures(failures):
-        total, succeeded = failures.args[1:3]
+def display_catalog_failures(cre):
+        total = cre.total
+        succeeded = cre.succeeded
         msg(_("pkg: %s/%s catalogs successfully updated:") % (succeeded, total))
 
-        for auth, err in failures.args[0]:
+        for auth, err in cre.failed:
                 if isinstance(err, urllib2.HTTPError):
                         emsg("   %s: %s - %s" % \
                             (err.filename, err.code, err.msg))
@@ -1495,8 +1520,8 @@
 
         try:
                 img.retrieve_catalogs(full_refresh, auths_to_refresh)
-        except RuntimeError, failures:
-                if display_catalog_failures(failures) == 0:
+        except image.CatalogRefreshException, cre:
+                if display_catalog_failures(cre) == 0:
                         return 1
                 else:
                         return 3
@@ -1505,8 +1530,8 @@
 
 def authority_set(img, args):
         """pkg set-authority [-P] [-k ssl_key] [-c ssl_cert]
-            [-O origin_url] [-m mirror to add] [-M mirror to remove]
-            authority"""
+            [-O origin_url] [-m mirror to add] [-M mirror to remove] 
+            [--no-refresh] authority"""
 
         preferred = False
         ssl_key = None
@@ -1514,9 +1539,11 @@
         origin_url = None
         add_mirror = None
         remove_mirror = None
+        ret_code = 0
+        refresh_catalogs = True
 
         opts, pargs = getopt.getopt(args, "Pk:c:O:M:m:",
-            ["add-mirror=", "remove-mirror="])
+            ["add-mirror=", "remove-mirror=", "no-refresh"])
 
         for opt, arg in opts:
                 if opt == "-P":
@@ -1531,6 +1558,8 @@
                         add_mirror = arg
                 if opt == "-M" or opt == "--remove-mirror":
                         remove_mirror = arg
+                if opt == "--no-refresh":
+                        refresh_catalogs = False
 
         if len(pargs) != 1:
                 usage(
@@ -1569,10 +1598,16 @@
 
         try:
                 img.set_authority(auth, origin_url = origin_url,
-                        ssl_key = ssl_key, ssl_cert = ssl_cert)
+                        ssl_key = ssl_key, ssl_cert = ssl_cert,
+                        refresh_allowed = refresh_catalogs)
         except RuntimeError, e:
                 error(_("set-authority failed: %s") % e)
                 return 1
+        except image.CatalogRefreshException, cre:
+                msg = "Could not refresh the catalog for %s" % \
+                    auth
+                error(_(msg))
+                ret_code = 1
 
         if preferred:
                 img.set_preferred_authority(auth)
@@ -1604,7 +1639,7 @@
                 img.del_mirror(auth, remove_mirror)
 
 
-        return 0
+        return ret_code
 
 def authority_unset(img, args):
         """pkg unset-authority authority ..."""
@@ -1732,9 +1767,10 @@
         ssl_cert = None
         auth_name = None
         auth_url = None
+        refresh_catalogs = True
 
         opts, pargs = getopt.getopt(args, "FPUza:k:c:",
-            ["full", "partial", "user", "zone", "authority="])
+            ["full", "partial", "user", "zone", "authority=", "no-refresh"])
 
         for opt, arg in opts:
                 if opt == "-F" or opt == "--full":
@@ -1745,6 +1781,8 @@
                         imgtype = image.IMG_USER
                 if opt == "-z" or opt == "--zone":
                         is_zone = True
+                if opt == "--no-refresh":
+                        refresh_catalogs = False
                 if opt == "-k":
                         ssl_key = arg
                 if opt == "-c":
@@ -1803,15 +1841,15 @@
                     (pargs[0], e.args[1]))
                 return 1
 
-        try:
-                img.retrieve_catalogs()
-        except RuntimeError, failures:
-                if display_catalog_failures(failures) == 0:
-                        return 1
-                else:
-                        return 3
-        else:
-                return 0
+        if refresh_catalogs:
+                try:
+                        img.retrieve_catalogs()
+                except image.CatalogRefreshException, cre:
+                        if display_catalog_failures(cre) == 0:
+                                return 1
+                        else:
+                                return 3
+        return 0
 
 
 def rebuild_index(img, pargs):
--- a/src/man/pkg.1.txt	Wed Sep 17 17:46:28 2008 -0700
+++ b/src/man/pkg.1.txt	Wed Sep 17 18:51:19 2008 -0700
@@ -7,7 +7,7 @@
 SYNOPSIS
      /usr/bin/pkg [options] command [cmd_options] [operands]
 
-     /usr/bin/pkg install [-nvq] pkg_fmri ...
+     /usr/bin/pkg install [-nvq] [--no-refresh] pkg_fmri ...
      /usr/bin/pkg uninstall [-nrvq] pkg_fmri ...
 
      /usr/bin/pkg verify [-Hvq] [pkg_fmri_pattern ...]
@@ -20,11 +20,11 @@
      /usr/bin/pkg refresh [--full] [authority ...]
 
      /usr/bin/pkg image-create [-FPUz] [--full|--partial|--user] [--zone]
-         [-k ssl_key] [-c ssl_cert] -a authority=origin_url dir
-     /usr/bin/pkg image-update [-nvq]
+         [-k ssl_key] [-c ssl_cert] [--no-refresh] -a authority=origin_url dir
+     /usr/bin/pkg image-update [-nvq] [--no-refresh]
 
      /usr/bin/pkg set-authority [-P] [-k ssl_key] [-c ssl_cert]
-         [-O origin_url] authority
+         [-O origin_url] [--no-refresh] authority
      /usr/bin/pkg unset-authority authority ...
      /usr/bin/pkg authority [-HP] [authname ...]
 
@@ -68,7 +68,7 @@
      The following subcommands are supported:
 
      image-create [-FPUz] [--full|--partial|--user] [--zone] [-k ssl_key]
-       [-c ssl_cert] -a authority=origin_url dir
+       [-c ssl_cert] [--no-refresh] -a authority=origin_url dir
           Create, at location given by dir, an image suitable for package
           operations.  The default image type is user, as given by the -U
           (--user) option.  The image type may be set to a full image (-F
@@ -85,13 +85,18 @@
           If the image is to be run within nonglobal zone context, then
           the -z (--zone) option can be used to set an appropriate filter.
 
-     image-update [-fnvq]
+          With --no-refresh, do not attempt to contact the image's authority
+          to retrieve its catalog.
+
+     image-update [-fnvq] [--no-refresh] 
           Update all installed packages in the current image to the
           latest available version.  With the -f option, skip safety
           checks.  With the -n option, execute the requested operation
           but make no persistent changes to the image.  With the -v
           option, issue verbose progress messages during the requested
-          operation.  With the -q option, be completely silent.
+          operation.  With the -q option, be completely silent. With 
+          --no-refresh, do not attempt to contact the image's authority
+          to retrieve its catalog.
 
      refresh [--full] [authority ...]
           Retrieve updates to the catalogs for each authority specified.
@@ -99,7 +104,7 @@
           registered within the image. With --full, retrieve the full
           catalogs.
 
-     install [-nvq] pkg_fmri ...
+     install [-nvq] [--no-refresh] pkg_fmri ...
      uninstall [-nrvq] pkg_fmri ...
           Install or remove the package specified by pkg_fmri or
           matching pkg_fmri as a substring.  With the -n option, execute
@@ -111,6 +116,9 @@
           uninstall any packages which are dependent on the initial
           package.
 
+          With --no-refresh, do not attempt to contact the image's authority
+          to retrieve its catalog.
+
      info [-lr] [--license] [pkg_fmri_pattern ...]
           Display information about packages in a human-readable form.
           Multiple FMRI patterns may be specified; with no patterns,
@@ -215,13 +223,17 @@
 
           The -H option causes the headers to be omitted.
 
-     set-authority [-P] [-k ssl_key] [-c ssl_cert] [-O origin_url] authority
+     set-authority [-P] [-k ssl_key] [-c ssl_cert] [-O origin_url] 
+                   [--no-refresh] authority
           Update an existing authority or add an additional package
           authority.  With -P, set the specified authority as the
           preferred authority.  With -c and -k, specify client SSL
           certificate and key respectively.  The -O option sets the URL
           prefix for the origin packaging repository for the authority.
 
+          With --no-refresh, do not attempt to contact the image's authority
+          to retrieve its catalog.
+
      unset-authority authority ...
           Remove the configuration associated with the given authority
           or authorities.
--- a/src/modules/client/image.py	Wed Sep 17 17:46:28 2008 -0700
+++ b/src/modules/client/image.py	Wed Sep 17 18:51:19 2008 -0700
@@ -71,6 +71,13 @@
 # Minimum number of days to issue warning before a certificate expires
 MIN_WARN_DAYS = datetime.timedelta(days=30)
 
+class CatalogRefreshException(Exception):
+        def __init__(self, failed, total, succeeded):
+                Exception.__init__(self)
+                self.failed = failed
+                self.total = total
+                self.succeeded = succeeded
+
 class InventoryException(Exception):
         def __init__(self, notfound=None, illegal=None):
                 Exception.__init__(self)
@@ -497,6 +504,8 @@
 
                 self.cfg_cache.delete_authority(auth_name)
                 self.cfg_cache.write("%s/cfg_cache" % self.imgdir)
+                self.destroy_catalog(auth_name)
+                self.cache_catalogs()
 
         def get_authority(self, auth_name):
                 if not self.has_authority(auth_name):
@@ -528,16 +537,19 @@
                 self.cfg_cache.write("%s/cfg_cache" % self.imgdir)
 
         def set_authority(self, auth_name, origin_url = None, ssl_key = None,
-            ssl_cert = None):
+            ssl_cert = None, refresh_allowed = True):
 
                 auths = self.cfg_cache.authorities
 
+                refresh_needed = False
+
                 if auth_name in auths:
                         # If authority already exists, only update non-NULL
                         # values passed to set_authority
                         if origin_url:
                                 auths[auth_name]["origin"] = \
                                     misc.url_affix_trailing_slash(origin_url)
+                                refresh_needed = True
                         if ssl_key:
                                 auths[auth_name]["ssl_key"] = ssl_key
                         if ssl_cert:
@@ -551,8 +563,15 @@
                         auths[auth_name]["mirrors"] = []
                         auths[auth_name]["ssl_key"] = ssl_key
                         auths[auth_name]["ssl_cert"] = ssl_cert
+                        refresh_needed = True
 
                 self.cfg_cache.write("%s/cfg_cache" % self.imgdir)
+                
+                if refresh_needed and refresh_allowed:
+                        self.destroy_catalog(auth_name)
+                        self.destroy_catalog_cache()
+                        self.retrieve_catalogs(full_refresh=True,
+                            auths=[auths[auth_name]])
                         
         def add_mirror(self, auth_name, mirror):
                 """Add the mirror URL contained in mirror to
@@ -1138,9 +1157,9 @@
                                 succeeded += 1
 
                 self.cache_catalogs()
-
+                
                 if failed:
-                        raise RuntimeError, (failed, total, succeeded)
+                        raise CatalogRefreshException(failed, total, succeeded)
 
         CATALOG_CACHE_VERSION = 1
 
@@ -1232,6 +1251,22 @@
                 except RuntimeError:
                         self.cache_catalogs()
 
+        def destroy_catalog_cache(self):
+                pickle_file = os.path.join(self.imgdir, "catalog/catalog.pkl")
+                try:
+                        portable.remove(pickle_file)
+                except OSError, e:
+                        if e.errno != errno.ENOENT:
+                                raise
+                        
+        def destroy_catalog(self, auth_name):
+                try:
+                        shutil.rmtree("%s/catalog/%s" %
+                            (self.imgdir, auth_name))
+                except OSError, e:
+                        if e.errno != errno.ENOENT:
+                                raise
+
         def fmri_is_same_pkg(self, cfmri, pfmri):
                 """Determine whether fmri and pfmri share the same package
                 name, even if they're not equivalent versions.  This
--- a/src/packagemanager.py	Wed Sep 17 17:46:28 2008 -0700
+++ b/src/packagemanager.py	Wed Sep 17 18:51:19 2008 -0700
@@ -1059,7 +1059,7 @@
 
                 try:
                         img.retrieve_catalogs()
-                except RuntimeError:
+                except image.CatalogRefreshException:
                         raise
                 # Reload catalog.  This picks up the update from retrieve_catalogs.
                 img.load_catalogs(self.pr)
--- a/src/tests/baseline.txt	Wed Sep 17 17:46:28 2008 -0700
+++ b/src/tests/baseline.txt	Wed Sep 17 18:51:19 2008 -0700
@@ -275,6 +275,7 @@
 cli.t_recv.py TestPkgRecv.test_bad_opts|pass
 cli.t_recv.py TestPkgRecv.test_recv_send|pass
 cli.t_refresh.py TestPkgRefresh.test_general_refresh|pass
+cli.t_refresh.py TestPkgRefresh.test_set_authority_induces_delayed_full_refresh|pass
 cli.t_refresh.py TestPkgRefresh.test_set_authority_induces_full_refresh|pass
 cli.t_refresh.py TestPkgRefresh.test_specific_refresh|pass
 cli.t_rename.py TestRename.test_rename1|pass
--- a/src/tests/cli/t_actions.py	Wed Sep 17 17:46:28 2008 -0700
+++ b/src/tests/cli/t_actions.py	Wed Sep 17 18:51:19 2008 -0700
@@ -210,7 +210,6 @@
                 self.pkg("contents -m usertest")
 
                 self.pkgsend_bulk(durl, self.usertest11)
-                self.pkg("refresh")
                 self.pkg("install usertest")
                 self.pkg("verify")
                 self.pkg("contents -m usertest")
--- a/src/tests/cli/t_commandline.py	Wed Sep 17 17:46:28 2008 -0700
+++ b/src/tests/cli/t_commandline.py	Wed Sep 17 18:51:19 2008 -0700
@@ -124,9 +124,11 @@
                 durl = self.dc.get_depot_url()
                 self.image_create(durl)
 
-                self.pkg("set-authority -O http://test1 test1")
+                self.pkg("set-authority -O http://test1 test1", exit=1)
+                self.pkg("set-authority --no-refresh -O http://test1 test1")
                 self.pkg("authority | grep test")
-                self.pkg("set-authority -P -O http://test2 test2")
+                self.pkg("set-authority -P -O http://test2 test2", exit=1)
+                self.pkg("set-authority -P --no-refresh -O http://test2 test2")
                 self.pkg("authority | grep test2")
                 self.pkg("unset-authority test1")
                 self.pkg("authority | grep test1", exit=1)
@@ -144,8 +146,10 @@
                     "set-authority -O http://test1 test1 -O http://test2 test2",
                      exit=2)
 
-                self.pkg("set-authority -O http://test1 test1")
-                self.pkg("set-authority -O http://test2 test2")
+                self.pkg("set-authority -O http://test1 test1", exit=1)
+                self.pkg("set-authority -O http://test2 test2", exit=1)
+                self.pkg("set-authority --no-refresh -O http://test1 test1")
+                self.pkg("set-authority --no-refresh -O http://test2 test2")
 
                 self.pkg("set-authority -k %s test1" % key_path)
                 os.close(key_fh)
@@ -166,7 +170,8 @@
                 durl = self.dc.get_depot_url()
                 self.image_create(durl)
 
-                self.pkg("set-authority -O http://test1 test1")
+                self.pkg("set-authority -O http://test1 test1", exit=1)
+                self.pkg("set-authority --no-refresh -O http://test1 test1")
 
                 self.pkg("set-authority -O http://test2 $%^8", exit=1)
                 self.pkg("set-authority -O http://test2 8^$%", exit=1)
--- a/src/tests/cli/t_pkg_install_corrupt_image.py	Wed Sep 17 17:46:28 2008 -0700
+++ b/src/tests/cli/t_pkg_install_corrupt_image.py	Wed Sep 17 18:51:19 2008 -0700
@@ -166,7 +166,8 @@
 
                 # This is expected to fail because it will see an empty
                 # catalog directory and not rebuild the files as needed
-                self.pkg("install [email protected]", exit = 1)
+                self.pkg("install --no-refresh [email protected]", exit=1)
+                self.pkg("install [email protected]")
 
         def test_var_pkg_missing_catalog_empty_hit_then_refreshed_then_hit(
             self):
@@ -182,7 +183,7 @@
                 self.corrupt_image_create(durl, set(["catalog_empty"]),
                     ["var/pkg"])
 
-                self.pkg("install [email protected]", exit = 1)
+                self.pkg("install --no-refresh [email protected]", exit = 1)
                 self.pkg("refresh")
                 self.pkg("install [email protected]")
 
@@ -296,7 +297,7 @@
                 self.corrupt_image_create(durl, set(["catalog_empty"]),
                     [".org.opensolaris,pkg"])
 
-                self.pkg("install [email protected]", exit = 1)
+                self.pkg("install --no-refresh [email protected]", exit = 1)
 
         def test_ospkg_missing_catalog_empty_hit_then_refreshed_then_hit(self):
                 """ Creates bad_dir with all dirs and files present, but
@@ -311,7 +312,7 @@
                 self.corrupt_image_create(durl, set(["catalog_empty"]),
                     [".org.opensolaris,pkg"])
 
-                self.pkg("install [email protected]", exit = 1)
+                self.pkg("install --no-refresh [email protected]", exit = 1)
                 self.pkg("refresh")
                 self.pkg("install [email protected]")
 
--- a/src/tests/cli/t_pkg_list.py	Wed Sep 17 17:46:28 2008 -0700
+++ b/src/tests/cli/t_pkg_list.py	Wed Sep 17 18:51:19 2008 -0700
@@ -89,8 +89,6 @@
 
                 self.pkg("set-authority -O " + durl2 + " test2")
 
-                self.pkg("refresh")
-
         def reduceSpaces(self, string):
                 """Reduce runs of spaces down to a single space."""
                 return re.sub(" +", " ", string)
--- a/src/tests/cli/t_refresh.py	Wed Sep 17 17:46:28 2008 -0700
+++ b/src/tests/cli/t_refresh.py	Wed Sep 17 18:51:19 2008 -0700
@@ -59,6 +59,12 @@
             open [email protected],5.11-0
             close """
 
+        def setUp(self):
+                testutils.ManyDepotTestCase.setUp(self, 2)
+
+                self.durl1 = self.dcs[1].get_depot_url()
+                self.durl2 = self.dcs[2].get_depot_url()
+        
         def reduce_spaces(self, string):
                 """Reduce runs of spaces down to a single space."""
                 return re.sub(" +", " ", string)
@@ -90,12 +96,6 @@
                     self.reduce_spaces(expected),
                     self.reduce_spaces(actual))
         
-        def setUp(self):
-                testutils.ManyDepotTestCase.setUp(self, 2)
-
-                self.durl1 = self.dcs[1].get_depot_url()
-                self.durl2 = self.dcs[2].get_depot_url()
-
         def test_general_refresh(self):
                 self.image_create(self.durl1, prefix = "test1")
                 self.pkg("set-authority -O " + self.durl2 + " test2")
@@ -111,9 +111,6 @@
         def test_specific_refresh(self):
                 self.image_create(self.durl1, prefix = "test1")
                 self.pkg("set-authority -O " + self.durl2 + " test2")
-                # Need this refresh to avoid triggering the changing full
-                # refresh code below.
-                self.pkg("refresh")
                 self.pkgsend_bulk(self.durl1, self.foo10)
                 self.pkgsend_bulk(self.durl2, self.foo12)
                 self.pkg("refresh test1")
@@ -128,22 +125,33 @@
                     "foo (test2) 1.2-0 known ----\n"
                 self.checkAnswer(expected, self.output)
                 self.pkg("refresh unknownAuth", exit=1)
+                self.pkg("set-authority -P test2")
+                self.pkg("list -aH pkg:/foo")
+                expected = \
+                    "foo (test1) 1.0-0 known u---\n" + \
+                    "foo 1.2-0 known ----\n"
                 self.pkgsend_bulk(self.durl1, self.foo11)
                 self.pkgsend_bulk(self.durl2, self.foo11)
                 self.pkg("refresh test1 test2")
                 self.pkg("list -aH pkg:/foo")
                 expected = \
-                    "foo 1.0-0 known u---\n" + \
+                    "foo (test1) 1.0-0 known u---\n" + \
+                    "foo (test1) 1.1-0 known u---\n" + \
                     "foo 1.1-0 known u---\n" + \
-                    "foo (test2) 1.1-0 known u---\n" + \
-                    "foo (test2) 1.2-0 known ----\n"
+                    "foo 1.2-0 known ----\n"
                 self.checkAnswer(expected, self.output)
 
+
         def test_set_authority_induces_full_refresh(self):
                 self.pkgsend_bulk(self.durl2, self.foo11)
+                self.pkgsend_bulk(self.durl1, self.foo10)
                 self.image_create(self.durl1, prefix = "test1")
-                self.pkgsend_bulk(self.durl1, self.foo10)
-                self.pkg("refresh")
+                self.pkg("list -aH pkg:/foo")
+                expected = \
+                    "foo 1.0-0 known ----\n"
+                self.checkAnswer(expected, self.output)
+                self.pkg("set-authority --no-refresh -O " +
+                    self.durl2 + " test1")
                 self.pkg("list -aH pkg:/foo")
                 expected = \
                     "foo 1.0-0 known ----\n"
@@ -151,8 +159,28 @@
                 self.pkg("set-authority -O " + self.durl2 + " test1") 
                 self.pkg("list -aH pkg:/foo")
                 expected = \
+                    "foo 1.1-0 known ----\n"
+                self.checkAnswer(expected, self.output)
+                self.pkg("set-authority -O " + self.durl1 + " test2")
+                self.pkg("list -aH pkg:/foo")
+                expected = \
+                    "foo 1.1-0 known ----\n" \
+                    "foo (test2) 1.0-0 known ----\n"
+                
+        def test_set_authority_induces_delayed_full_refresh(self):
+                self.pkgsend_bulk(self.durl2, self.foo11)
+                self.pkgsend_bulk(self.durl1, self.foo10)
+                self.image_create(self.durl1, prefix = "test1")
+                self.pkg("list -aH pkg:/foo")
+                expected = \
                     "foo 1.0-0 known ----\n"
                 self.checkAnswer(expected, self.output)
+                self.dcs[2].stop()
+                self.pkg("set-authority -O " + self.durl2 + " test1", exit=1)
+                self.pkg("set-authority -O " + self.durl2 + " test1", exit=1)
+                self.pkg("set-authority -O " + self.durl2 + " test1", exit=1)
+                self.pkg("list -aH pkg:/foo", exit=1)
+                self.dcs[2].start()
                 self.pkg("refresh test1")
                 self.pkg("list -aH pkg:/foo")
                 expected = \
--- a/src/tests/cli/t_rename.py	Wed Sep 17 17:46:28 2008 -0700
+++ b/src/tests/cli/t_rename.py	Wed Sep 17 18:51:19 2008 -0700
@@ -78,7 +78,6 @@
 
                 self.pkgsend(durl, "rename [email protected],5.11-0 [email protected],5.11-0")
 
-                self.pkg("refresh")
 		self.pkg("install bar")
 		self.pkg("verify")
 
--- a/src/tests/cli/t_search_multi.py	Wed Sep 17 17:46:28 2008 -0700
+++ b/src/tests/cli/t_search_multi.py	Wed Sep 17 18:51:19 2008 -0700
@@ -52,7 +52,6 @@
 
                 self.image_create(durl1, prefix = "test1")
                 self.pkg("set-authority -O " + durl2 + " test2")
-                self.pkg("refresh")
 
         def test_bug_2955(self):
                 """See http://defect.opensolaris.org/bz/show_bug.cgi?id=2955"""
--- a/src/tests/cli/t_twodepot.py	Wed Sep 17 17:46:28 2008 -0700
+++ b/src/tests/cli/t_twodepot.py	Wed Sep 17 18:51:19 2008 -0700
@@ -112,9 +112,6 @@
                 # Create second authority using depot #2
                 self.pkg("set-authority -O " + durl2 + " test2")
 
-                self.pkg("refresh")
-
-
         def tearDown(self):
                 testutils.ManyDepotTestCase.tearDown(self)