15771543 set-publisher -p should simply update existing publisher sources
authorthejaswini.k@oracle.com
Mon, 15 Apr 2013 11:06:30 +0530
changeset 2891 c8c988eec7ac
parent 2890 7a90486da579
child 2892 ab4b61eb9b57
15771543 set-publisher -p should simply update existing publisher sources 15769004 pkg unset-publisher could use a progress tracker
src/client.py
src/modules/client/progress.py
src/tests/cli/t_pkg_publisher.py
src/tests/cli/t_pkg_sysrepo.py
--- a/src/client.py	Fri Apr 12 11:03:46 2013 -0700
+++ b/src/client.py	Mon Apr 15 11:06:30 2013 +0530
@@ -3871,28 +3871,16 @@
                         search_after = prefix
                         search_before = None
                 else:
-                        # The update case is special and requires some
-                        # finesse.  In particular, the update should
-                        # only happen if the repo_uri specified is
-                        # already known to the existing publisher.  This
-                        # is just a sanity check to ensure that random
-                        # repositories can't attempt to hijack other
-                        # publishers.
+                        add_origins = []
+                        add_mirrors = []
                         dest_pub = api_inst.get_publisher(prefix=prefix,
                             duplicate=True)
                         dest_repo = dest_pub.repository
-
                         if dest_repo.origins and \
-                            not dest_repo.has_origin(repo_uri):
-                                failed.append((prefix, _("""\
-    The specified repository location is not a known source of publisher
-    configuration updates for '%s'.
-
-    This new repository location must be added as an origin to the publisher
-    to accept configuration updates from this repository.""") % prefix))
-                                continue
-
-                        if not src_repo:
+                                not dest_repo.has_origin(repo_uri):
+                                        add_origins = [repo_uri]
+
+                        if not src_repo and not add_origins:
                                 # The repository doesn't have to provide origin
                                 # information for publishers.  If it doesn't,
                                 # the origin of every publisher returned is
@@ -3901,10 +3889,7 @@
                                 # nothing special needs to be done.
                                 if not dest_repo.origins:
                                         add_origins = [repo_uri]
-                                else:
-                                        add_origins = []
-                                add_mirrors = []
-                        else:
+                        elif src_repo:
                                 # Avoid duplicates by adding only those mirrors
                                 # or origins not already known.
                                 add_mirrors = [
@@ -4157,7 +4142,11 @@
                     cmd="unset-publisher")
 
         errors = []
+        goal = len(args)
+        progtrack = api_inst.progresstracker
+        progtrack.job_start(progtrack.JOB_PKG_CACHE, goal=goal)
         for name in args:
+
                 try:
                         api_inst.remove_publisher(prefix=name, alias=name)
                 except api_errors.ImageFormatUpdateNeeded, e:
@@ -4167,7 +4156,10 @@
                     api_errors.PublisherError,
                     api_errors.ModifyingSyspubException), e:
                         errors.append((name, e))
-
+                finally:
+                        progtrack.job_add_progress(progtrack.JOB_PKG_CACHE)
+
+        progtrack.job_done(progtrack.JOB_PKG_CACHE)
         retcode = EXIT_OK
         if errors:
                 if len(errors) == len(args):
--- a/src/modules/client/progress.py	Fri Apr 12 11:03:46 2013 -0700
+++ b/src/modules/client/progress.py	Mon Apr 15 11:06:30 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.
 #
 
 #
@@ -1505,11 +1505,14 @@
         def job_start(self, jobid, goal=None):
                 jobitem = self._jobitems[jobid]
                 jobitem.reset()
+                outspec = OutSpec()
                 if goal:
                         if not isinstance(jobitem, GoalTrackerItem):
                                 raise RuntimeError(
                                     "can't set goal on non-goal tracker")
                         jobitem.goalitems = goal
+                jobitem.printed = True
+                self._job_output(outspec, jobitem)
 
         def job_add_progress(self, jobid, nitems=1):
                 jobitem = self._jobitems[jobid]
--- a/src/tests/cli/t_pkg_publisher.py	Fri Apr 12 11:03:46 2013 -0700
+++ b/src/tests/cli/t_pkg_publisher.py	Mon Apr 15 11:06:30 2013 +0530
@@ -801,13 +801,6 @@
                 self.__update_repo_pub_cfg(self.dcs[6], t6cfg)
                 self.dcs[6].start()
 
-                # Should fail since even though repository publisher prefix
-                # matches test3, the new origin isn't configured for test3,
-                # and as a result isn't a known source for publisher updates.
-                self.pkg("set-publisher -p %s" % durl6, exit=1)
-
-                # So, add the new origin to the publisher.
-                self.pkg("set-publisher -g %s test3" % durl6)
                 self.pkg("set-publisher -p %s" % durl6)
 
                 # Load image configuration to verify publisher was configured
--- a/src/tests/cli/t_pkg_sysrepo.py	Fri Apr 12 11:03:46 2013 -0700
+++ b/src/tests/cli/t_pkg_sysrepo.py	Mon Apr 15 11:06:30 2013 +0530
@@ -21,7 +21,7 @@
 #
 
 #
-# 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
@@ -1026,13 +1026,8 @@
                 # Have the user configure test1 at the same time that test1 is
                 # made a system publisher.
                 self.__set_responses("test1")
-                # This fails in the same way that doing set-publisher -p for a
-                # repository which provides packages for an already configured
-                # publisher fails.
-                self.pkg("set-publisher -p %s" % self.rurl1, exit=1)
-                # Adding the origin to the publisher which now exists should
-                # work fine.
-                self.pkg("set-publisher -g %s test1" % self.rurl1)
+
+                self.pkg("set-publisher -p %s" % self.rurl1)
                 expected = """\
 PUBLISHER\tSTICKY\tSYSPUB\tENABLED\tTYPE\tSTATUS\tURI\tPROXY
 test1\ttrue\ttrue\ttrue\torigin\tonline\t%(rurl1)s/\t-
@@ -1040,6 +1035,10 @@
 """ % {"rurl1": self.rurl1, "durl1": self.durl1, "port": self.sysrepo_port}
                 self.__check_publisher_info(expected)
 
+                # Adding the origin to the publisher which now exists should
+                # fail.
+                self.pkg("set-publisher -g %s test1" % self.rurl1, exit=1)
+
                 # The user adds an origin to test12 at the same time that test12
                 # first becomes known to the image.
                 self.__set_responses("test12")