7170813 AI fails on client hits assert (prefix or refresh_allowed) or not repo_uri
authorDarren Kenny <Darren.Kenny@Oracle.COM>
Thu, 31 May 2012 16:41:08 +0100
changeset 1692 aa8503663e0f
parent 1691 e18daaf0b780
child 1693 f1af33034951
7170813 AI fails on client hits assert (prefix or refresh_allowed) or not repo_uri
usr/src/lib/install_transfer/ips.py
usr/src/lib/install_transfer/test/test_ips.py
--- a/usr/src/lib/install_transfer/ips.py	Wed May 30 08:54:28 2012 -0700
+++ b/usr/src/lib/install_transfer/ips.py	Thu May 31 16:41:08 2012 +0100
@@ -430,7 +430,7 @@
         except api_errors.CatalogRefreshException, cre:
             #  Handle CatalogRefreshException especially since it doesn't
             #  pretty-print it's contents in a __str__() impl.
-            
+
             raise RuntimeError(self.catalog_failures_to_str(cre))
         finally:
             self._cleanup()
@@ -480,9 +480,31 @@
 
         self.prog_tracker = self.image_args.get("progtrack", self.prog_tracker)
 
-        # Set the image args we always want set.
+        invalid_prefix_uri = None
         if self.img_action == self.CREATE:
+            # Set the image args we always want set.
             self.set_image_args()
+        elif not self.dry_run and not self._publ:
+            # It's either None or empty string, so fail
+            # Should always have index 0 since DTD won't allow otherwise, but
+            # should ignore in case of dry_run since unlikely to be set.
+            invalid_prefix_uri = self._origin[0]
+
+        if invalid_prefix_uri is None:
+            for idx, element in enumerate(self._add_publ):
+                if not element:
+                    # It's either None or empty string, so fail
+                    # Should always have index 0 since DTD won't allow
+                    # otherwise.
+                    invalid_prefix_uri = self._add_origin[idx][0]
+                    break
+
+        if invalid_prefix_uri is not None:
+            raise ValueError(
+                "Only the publisher being used for image creation can have\n"
+                "its prefix auto-discovered, please specify the prefix for\n"
+                "the publisher with the URI:\n  %s"
+                % invalid_prefix_uri)
 
     def _transfer(self):
         '''If an update of the image has been specified, the publishers of the
@@ -780,6 +802,10 @@
            prefix, repo_uri, origins, and mirrors.  If we're creating a
            zone image, we also need to set the use-system-repo property
            in the props argument.
+
+           For the publisher used to create the image, it is possible to
+           omit the prefix (_publ) and allow IPS to do auto-discovery from
+           the repo itself.
         '''
         self._image_args = copy.copy(self.image_args)
         self._image_args["progtrack"] = self.prog_tracker
@@ -847,7 +873,7 @@
                     pkg_client_name=PKG_CLIENT_NAME,
                     version_id=PKG5_API_VERSION, root=self.dst,
                     imgtype=self.completeness, is_zone=self.is_zone,
-                    refresh_allowed=False, force=True, **self._image_args)
+                    force=True, **self._image_args)
 
                 # The above call will end up leaving our process's cwd in
                 # the image's root area, which will cause pain later on
--- a/usr/src/lib/install_transfer/test/test_ips.py	Wed May 30 08:54:28 2012 -0700
+++ b/usr/src/lib/install_transfer/test/test_ips.py	Thu May 31 16:41:08 2012 +0100
@@ -523,6 +523,84 @@
         except Exception as err:
             self.fail(str(err))
 
+    def test_source_omit_name_first_success(self):
+        '''Test that omitting name is allowed for first publisher'''
+        src = Source()
+        pub = Publisher("")
+        origin = Origin("http://ipkg.sfbay.sun.com/dev/")
+        pub.insert_children([origin])
+        src.insert_children([pub])
+        self.soft_node.insert_children([src])
+        try:
+            self.tr_ips.execute(dry_run=DRY_RUN)
+        except Exception as err:
+            self.fail(str(err))
+
+    def test_source_omit_additional_publ_name_fails_1(self):
+        '''Test that adding additional sources omitting name fails'''
+        src = Source()
+        pub = Publisher("")
+        origin = Origin("http://ipkg.sfbay.sun.com/dev/")
+        pub.insert_children([origin])
+        src.insert_children([pub])
+        self.soft_node.insert_children([src])
+        try:
+            self.tr_ips.execute(dry_run=DRY_RUN)
+        except Exception as err:
+            self.fail(str(err))
+
+        # Now add another publisher to the repo
+        self.ips_image.action = "update"
+        pub2 = Publisher("")
+        origin2 = Origin("http://ipkg.sfbay.sun.com/extra/")
+        pub2.insert_children([origin2])
+        src.insert_children([pub2])
+        try:
+            self.tr_ips.execute(dry_run=DRY_RUN)
+            self.fail("Shouldn't succeed omitting name of second publisher")
+        except ValueError as err:
+            pass
+        except Exception as err:
+            self.fail(str(err))
+
+    def test_source_omit_additional_publ_name_fails_2(self):
+        '''Test that adding additional sources omitting name fails'''
+        src = Source()
+        pub = Publisher("")
+        origin = Origin("http://ipkg.sfbay.sun.com/dev/")
+        pub.insert_children([origin])
+        src.insert_children([pub])
+        self.soft_node.insert_children([src])
+        try:
+            self.tr_ips.execute(dry_run=DRY_RUN)
+        except Exception as err:
+            self.fail(str(err))
+
+        # Now add another publisher to the repo
+        self.ips_image.action = "update"
+        pub2 = Publisher("extra")
+        origin2 = Origin("http://ipkg.sfbay.sun.com/extra/")
+        pub2.insert_children([origin2])
+        src.insert_children([pub2])
+        try:
+            self.tr_ips.execute(dry_run=DRY_RUN)
+        except Exception as err:
+            self.fail(str(err))
+
+        # Now add another publisher to the repo
+        self.ips_image.action = "update"
+        pub3 = Publisher("")
+        origin3 = Origin("http://ipkg.sfbay.sun.com/an-other/")
+        pub3.insert_children([origin3])
+        src.insert_children([pub3])
+        try:
+            self.tr_ips.execute(dry_run=DRY_RUN)
+            self.fail("Shouldn't succeed omitting name of third publisher")
+        except ValueError as err:
+            pass
+        except Exception as err:
+            self.fail(str(err))
+
     def test_source_replacement(self):
         '''Test that replacing a source succeeds'''
         # Setup an IPS image