18193 transport can traceback for packages that belong to a publisher not in configuration
authorShawn Walker <shawn.walker@oracle.com>
Mon, 02 May 2011 15:29:50 -0700
changeset 2322 06de944cbceb
parent 2321 5741d6cd0988
child 2323 3171b0efc406
18193 transport can traceback for packages that belong to a publisher not in configuration 18195 transport adds all publisher caches from multi-publisher file repositories
src/modules/client/api_errors.py
src/modules/client/transport/transport.py
src/tests/cli/t_fix.py
--- a/src/modules/client/api_errors.py	Fri Apr 29 10:56:29 2011 -0700
+++ b/src/modules/client/api_errors.py	Mon May 02 15:29:50 2011 -0700
@@ -1524,14 +1524,18 @@
                     "publisher.") % self.data
 
 
-class NoPublisherRepositories(PublisherError):
+class NoPublisherRepositories(TransportError):
         """Used to indicate that a Publisher has no repository information
         configured and so transport operations cannot be performed."""
 
+        def __init__(self, prefix):
+                TransportError.__init__(self)
+                self.publisher = prefix
+
         def __str__(self):
                 return _("Unable to retrieve requested package data for "
                     "publisher %s; no repositories are currently configured "
-                    "for use with this publisher.") % self.data
+                    "for use with this publisher.") % self.publisher
 
 
 class MoveRelativeToSelf(PublisherError):
--- a/src/modules/client/transport/transport.py	Fri Apr 29 10:56:29 2011 -0700
+++ b/src/modules/client/transport/transport.py	Mon May 02 15:29:50 2011 -0700
@@ -223,6 +223,13 @@
                                         for rstore in frepo.rstores:
                                                 if not rstore.file_root:
                                                         continue
+                                                if rstore.publisher and \
+                                                    rstore.publisher != pub.prefix:
+                                                        # If the repository
+                                                        # storage object is for
+                                                        # a different publisher,
+                                                        # skip it.
+                                                        continue
                                                 self.add_cache(rstore.file_root,
                                                     pub=rstore.publisher,
                                                     readonly=True)
@@ -1883,7 +1890,8 @@
                         repo = alt_repo
                 elif isinstance(pub, publisher.Publisher):
                         repo = pub.repository
-                        assert repo
+                        if not repo:
+                                raise apx.NoPublisherRepositories(pub)
 
                 if repo and origin_only:
                         repolist = repo.origins
@@ -1993,6 +2001,8 @@
                                 repolist.extend(alt_repo.mirrors)
                 elif isinstance(pub, publisher.Publisher):
                         repo = pub.repository
+                        if not repo:
+                                raise apx.NoPublisherRepositories(pub)
                         repolist = repo.origins[:]
                         if not origin_only:
                                 repolist.extend(repo.mirrors)
--- a/src/tests/cli/t_fix.py	Fri Apr 29 10:56:29 2011 -0700
+++ b/src/tests/cli/t_fix.py	Mon May 02 15:29:50 2011 -0700
@@ -127,6 +127,9 @@
                 files, and make sure it gets fixed.  """
 
                 self.image_create(self.rurl)
+                # Cache must be flushed after install for tests to work as
+                # expected.
+                self.pkg("set-property flush-content-cache-on-success True")
                 self.pkg("install [email protected]")
 
                 index_dir = self.get_img_api_obj().img.index_dir
@@ -159,6 +162,13 @@
                 new_mtime = os.stat(index_file).st_mtime
                 self.assertEqual(orig_mtime, new_mtime)
 
+                # Verify that removing the publisher of a package that needs
+                # fixing results in graceful failure (not a traceback).
+                self.file_append(victim, "foobar")
+                self.pkg("set-publisher -P --no-refresh -g %s foo" % self.rurl)
+                self.pkg("unset-publisher test")
+                self.pkg("fix", exit=1)
+
         def test_02_hardlinks(self):
                 """Hardlink test: make sure that a file getting fixed gets any
                 hardlinks that point to it updated"""