16922545 build failure causes pkg/depot user interface to die
authorTim Foster <tim.s.foster@oracle.com>
Fri, 27 Sep 2013 10:19:27 +1200
changeset 2955 796cde775790
parent 2954 4b449f059c78
child 2958 868e07939116
16922545 build failure causes pkg/depot user interface to die
src/tests/cli/t_depot_config.py
src/tests/pkg5unittest.py
src/util/apache2/depot/depot_index.py
--- a/src/tests/cli/t_depot_config.py	Mon Sep 23 17:30:41 2013 -0700
+++ b/src/tests/cli/t_depot_config.py	Fri Sep 27 10:19:27 2013 +1200
@@ -336,6 +336,8 @@
 
                 fmris = self.pkgsend_bulk(self.dcs[1].get_repo_url(),
                     self.new_pkg)
+                r2_fmris = self.pkgsend_bulk(self.dcs[2].get_repo_url(),
+                    self.sample_pkg)
                 self.depotconfig("")
                 self.start_depot()
 
@@ -361,18 +363,70 @@
                         "/depot/default/en/search.shtml?token=pkg&action=Search"
                 ]
 
-                for p in paths:
-                        url_path = "%s%s" % (self.ac.url, p % conf)
+                def get_url(url_path):
                         try:
-                                url_obj = urllib2.urlopen(url_path)
+                                url_obj = urllib2.urlopen(url_path, timeout=10)
                                 self.assert_(url_obj.code == 200,
                                     "Failed to open %s: %s" % (url_path,
                                     url_obj.code))
+                                url_obj.close()
                         except urllib2.HTTPError, e:
                                 self.debug("Failed to open %s: %s" %
                                     (url_path, e))
                                 raise
 
+                for p in paths:
+                        get_url("%s%s" % (self.ac.url, p % conf))
+
+                self.ac.stop()
+
+                # test that pkg.depot-config detects missing repos
+                broken_rdir = self.rdir2 + "foo"
+                os.rename(self.rdir2, broken_rdir)
+                self.depotconfig("", exit=1)
+
+                # test that when we break one of the repositories we're
+                # serving, that the remaining repositories are still accessible
+                # from the bui. We need to fix the repo dir before rebuilding
+                # the configuration, then break it once the depot has started
+                os.rename(broken_rdir, self.rdir2)
+                self.depotconfig("")
+                os.rename(self.rdir2, broken_rdir)
+                self.start_depot(build_indexes=False)
+
+                # check the first request to the BUI works as expected
+                get_url(self.ac.url)
+
+                # and check that we get a 404 for the missing repo
+                bad_url = "%s/usr/test2/en/catalog.shtml" % self.ac.url
+                raised_404 = False
+                try:
+                        url_obj = urllib2.urlopen(bad_url, timeout=10)
+                        url_obj.close()
+                except urllib2.HTTPError, e:
+                        if e.code == 404:
+                                raised_404 = True
+                self.assert_(raised_404, "Didn't get a 404 opening %s" %
+                    bad_url)
+
+                # check that we can still reach other valid paths
+                paths = [
+                        "/",
+                        "/default/test1",
+                        "/default/en",
+                        "/default/en/index.shtml",
+                        "/default/en/catalog.shtml",
+                        "/default/p5i/0/new.p5i",
+                        "/default/info/0/%(esc_full_fmri)s",
+                        "/default/test1/info/0/%(esc_full_fmri)s",
+                        "/default/manifest/0/%(esc_full_fmri)s",
+                        "/default/en/search.shtml",
+                ]
+                for p in paths:
+                        self.debug(p)
+                        get_url("%s%s" % (self.ac.url, p % conf))
+                os.rename(broken_rdir, self.rdir2)
+
         def test_12_htpkgclient(self):
                 """A depot-config can act as a repository server for pkg(1)
                 clients, with all functionality supported."""
--- a/src/tests/pkg5unittest.py	Mon Sep 23 17:30:41 2013 -0700
+++ b/src/tests/pkg5unittest.py	Fri Sep 27 10:19:27 2013 +1200
@@ -4297,7 +4297,10 @@
 
         def _network_ping(self):
                 try:
-                        urllib2.urlopen(self.url)
+                        # Ping the versions URL, rather than the default /
+                        # so that we don't initialize the BUI code yet.
+                        urllib2.urlopen(urlparse.urljoin(self.url,
+                            "versions/0"))
                 except urllib2.HTTPError, e:
                         if e.code == httplib.FORBIDDEN:
                                 return True
--- a/src/util/apache2/depot/depot_index.py	Mon Sep 23 17:30:41 2013 -0700
+++ b/src/util/apache2/depot/depot_index.py	Fri Sep 27 10:19:27 2013 +1200
@@ -302,8 +302,13 @@
                         # if the index dir exists for this repository, we do not
                         # automatically attempt a refresh.
                         refresh_index = not os.path.exists(index_dir)
-                        repo = sr.Repository(root=path,
-                        read_only=True, writable_root=index_dir)
+                        try:
+                                repo = sr.Repository(root=path,
+                                    read_only=True, writable_root=index_dir)
+                        except sr.RepositoryError, e:
+                                print("Error initializing repository at %s: "
+                                    "%s" % (path, e))
+                                continue
 
                         repositories[prefix] = repo
                         dconf = sd.DepotConfig()
@@ -675,9 +680,9 @@
                             "message": httplib.responses[httplib.NOT_FOUND],
                             "traceback": "",
                             "version": cherrypy.__version__}
-                        print "Path that raised exception was %s" % \
-                            cherrypy.request.path_info
-                        print message
+                        print("Path that raised exception was %s" %
+                            cherrypy.request.path_info)
+                        print(message)
                         return error
                 else:
                         error = cherrypy._cperror._HTTPErrorTemplate % \