3617 Testsuite should allow choice for base port to use
authorBrock Pytlik <brock.pytlik@oracle.com>
Tue, 22 Mar 2011 15:01:13 -0700
changeset 2272 d81ea073d050
parent 2271 543c2c6e40e1
child 2273 78f75ad858b7
3617 Testsuite should allow choice for base port to use 18018 ro_data directory should only be copied in for tests which need it
src/modules/client/publisher.py
src/setup.py
src/tests/api/t_p5p.py
src/tests/api/t_publisher.py
src/tests/cli/t_pkg_depotd.py
src/tests/cli/t_pkg_publisher.py
src/tests/cli/t_pkg_temp_sources.py
src/tests/cli/t_pkgrepo.py
src/tests/cli/t_pkgsign.py
src/tests/pkg5unittest.py
src/tests/run.py
--- a/src/modules/client/publisher.py	Mon Mar 21 15:18:53 2011 -0700
+++ b/src/modules/client/publisher.py	Tue Mar 22 15:01:13 2011 -0700
@@ -50,6 +50,7 @@
 import uuid
 
 from pkg.client import global_settings
+from pkg.client.debugvalues import DebugValues
 logger = global_settings.logger
 
 import pkg.catalog
@@ -2008,6 +2009,15 @@
                 if not uri.startswith("http://") and \
                     not uri.startswith("file://"):
                         raise api_errors.InvalidResourceLocation(uri.strip())
+                crl_host = DebugValues.get_value("crl_host")
+                if crl_host:
+                        orig = urlparse.urlparse(uri)
+                        crl = urlparse.urlparse(crl_host)
+                        uri = urlparse.urlunparse(urlparse.ParseResult(
+                            scheme=crl.scheme, netloc=crl.netloc,
+                            path=orig.path,
+                            params=orig.params, query=orig.params,
+                            fragment=orig.fragment))
                 fn = urllib.quote(uri, "")
                 assert os.path.isdir(self.__crl_root)
                 fpath = os.path.join(self.__crl_root, fn)
--- a/src/setup.py	Mon Mar 21 15:18:53 2011 -0700
+++ b/src/setup.py	Tue Mar 22 15:01:13 2011 -0700
@@ -781,6 +781,7 @@
             ("genbaseline", 'g', "generate test baseline"),
             ("only=", "o", "only <regex>"),
             ("parseable", 'p', "parseable output"),
+            ("port=", "z", "lowest port to start a depot on"),
             ("timing", "t", "timing file <file>"),
             ("verbosemode", 'v', "run tests in verbose mode"),
             ("stoponerr", 'x', "stop when a baseline mismatch occurs"),
@@ -804,6 +805,7 @@
                 self.showonexpectedfail = 0
                 self.startattest = ""
                 self.archivedir = ""
+                self.port = 12001
 
         def finalize_options(self):
                 pass
--- a/src/tests/api/t_p5p.py	Mon Mar 21 15:18:53 2011 -0700
+++ b/src/tests/api/t_p5p.py	Tue Mar 22 15:01:13 2011 -0700
@@ -51,6 +51,8 @@
 
         # Don't recreate repository and publish packages for every test.
         persistent_setup = True
+        # Tests in this suite use the read only data directory.
+        need_ro_data = True
 
         pkgs = """
             open pkg://test/[email protected]
--- a/src/tests/api/t_publisher.py	Mon Mar 21 15:18:53 2011 -0700
+++ b/src/tests/api/t_publisher.py	Tue Mar 22 15:01:13 2011 -0700
@@ -21,7 +21,7 @@
 #
 
 #
-# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
 #
 
 
@@ -47,6 +47,9 @@
         """Class to test the functionality of the pkg.client.publisher module.
         """
 
+        # Tests in this suite use the read only data directory.
+        need_ro_data = True
+
         misc_files = [ "test.cert", "test.key", "test2.cert", "test2.key" ]
 
         def setUp(self):
--- a/src/tests/cli/t_pkg_depotd.py	Mon Mar 21 15:18:53 2011 -0700
+++ b/src/tests/cli/t_pkg_depotd.py	Tue Mar 22 15:01:13 2011 -0700
@@ -443,7 +443,7 @@
                 self.__dc.kill()
 
         def testStartStop(self):
-                self.__dc.set_port(12000)
+                self.__dc.set_port(self.next_free_port)
                 for i in range(0, 5):
                         self.__dc.start()
                         self.assert_(self.__dc.is_alive())
@@ -454,7 +454,7 @@
                 cfg_file = os.path.join(self.test_root, "cfg2")
                 fh = open(cfg_file, "w")
                 fh.close()
-                self.__dc.set_port(12000)
+                self.__dc.set_port(self.next_free_port)
                 self.__dc.set_cfg_file(cfg_file)
                 self.__dc.start()
 
@@ -507,7 +507,7 @@
                                         time.sleep(1)
                         self.assert_(got)
 
-                self.__dc.set_port(12000)
+                self.__dc.set_port(self.next_free_port)
                 durl = self.__dc.get_depot_url()
 
                 repo = self.__dc.get_repo()
@@ -551,7 +551,7 @@
                 self.pkg("search -r cat")
 
         def testBadArgs(self):
-                self.__dc.set_port(12000)
+                self.__dc.set_port(self.next_free_port)
                 self.__dc.set_readonly()
                 self.__dc.set_rebuild()
                 self.__dc.set_norefresh_index()
@@ -594,7 +594,7 @@
                 # For this disabled case, /catalog/1/ should return
                 # a NOT_FOUND error.
                 self.__dc.set_disable_ops(["catalog/1"])
-                self.__dc.set_port(12000)
+                self.__dc.set_port(self.next_free_port)
                 self.__dc.start()
                 durl = self.__dc.get_depot_url()
                 try:
@@ -606,7 +606,7 @@
                 # For this disabled case, all /catalog/ operations should return
                 # a NOT_FOUND error.
                 self.__dc.set_disable_ops(["catalog"])
-                self.__dc.set_port(12000)
+                self.__dc.set_port(self.next_free_port)
                 self.__dc.start()
                 durl = self.__dc.get_depot_url()
                 for ver in (0, 1):
@@ -986,7 +986,7 @@
 
                 # Check that IPv6 address can be used.
                 self.dc.set_address("::1")
-                self.dc.set_port(12000)
+                self.dc.set_port(self.next_free_port)
                 self.dc.start()
                 self.assert_(self.dc.is_alive())
                 self.assert_(self.dc.is_alive())
--- a/src/tests/cli/t_pkg_publisher.py	Mon Mar 21 15:18:53 2011 -0700
+++ b/src/tests/cli/t_pkg_publisher.py	Tue Mar 22 15:01:13 2011 -0700
@@ -39,6 +39,8 @@
 class TestPkgPublisherBasics(pkg5unittest.SingleDepotTestCase):
         # Only start/stop the depot once (instead of for every test)
         persistent_setup = True
+        # Tests in this suite use the read only data directory.
+        need_ro_data = True
 
         def test_pkg_publisher_bogus_opts(self):
                 """ pkg bogus option checks """
@@ -388,6 +390,8 @@
 class TestPkgPublisherMany(pkg5unittest.ManyDepotTestCase):
         # Only start/stop the depot once (instead of for every test)
         persistent_setup = True
+        # Tests in this suite use the read only data directory.
+        need_ro_data = True
 
         foo1 = """
             open foo@1,5.11-0
@@ -849,6 +853,8 @@
 
 
 class TestPkgPublisherCACerts(pkg5unittest.ManyDepotTestCase):
+        # Tests in this suite use the read only data directory.
+        need_ro_data = True
 
         def setUp(self):
                 # This test suite needs actual depots.
--- a/src/tests/cli/t_pkg_temp_sources.py	Mon Mar 21 15:18:53 2011 -0700
+++ b/src/tests/cli/t_pkg_temp_sources.py	Tue Mar 22 15:01:13 2011 -0700
@@ -42,6 +42,8 @@
 
         # Don't discard repository or setUp() every test.
         persistent_setup = True
+        # Tests in this suite use the read only data directory.
+        need_ro_data = True
 
         foo_pkg = """
             open pkg://test/[email protected]
--- a/src/tests/cli/t_pkgrepo.py	Mon Mar 21 15:18:53 2011 -0700
+++ b/src/tests/cli/t_pkgrepo.py	Tue Mar 22 15:01:13 2011 -0700
@@ -47,6 +47,8 @@
 class TestPkgRepo(pkg5unittest.SingleDepotTestCase):
         # Cleanup after every test.
         persistent_setup = False
+        # Tests in this suite use the read only data directory.
+        need_ro_data = True
 
         tree10 = """
             open [email protected],5.11-0
--- a/src/tests/cli/t_pkgsign.py	Mon Mar 21 15:18:53 2011 -0700
+++ b/src/tests/cli/t_pkgsign.py	Tue Mar 22 15:01:13 2011 -0700
@@ -42,8 +42,12 @@
 import pkg.portable as portable
 import M2Crypto as m2
 
+from pkg.client.debugvalues import DebugValues
+
 class TestPkgSign(pkg5unittest.SingleDepotTestCase):
-
+        # Tests in this suite use the read only data directory.
+        need_ro_data = True
+        
         example_pkg10 = """
             open [email protected],5.11-0
             add dir mode=0755 owner=root group=bin path=/bin
@@ -107,11 +111,21 @@
                         with open(os.path.join(self.img_path, f), "wb") as fh:
                                 fh.close()
 
+        def pkg(self, command, *args, **kwargs):
+                # The value for crl_host is pulled from DebugValues because
+                # crl__host needs to be set there so the api object calls work
+                # as desired.
+                command = "--debug crl_host=%s %s" % \
+                    (DebugValues["crl_host"], command)
+                return pkg5unittest.SingleDepotTestCase.pkg(self, command,
+                    *args, **kwargs)
+
         def setUp(self):
                 pkg5unittest.SingleDepotTestCase.setUp(self)
                 self.make_misc_files(self.misc_files)
                 self.durl1 = self.dcs[1].get_depot_url()
                 self.rurl1 = self.dcs[1].get_repo_url()
+                DebugValues["crl_host"] = self.durl1
                 self.ta_dir = None
 
                 self.path_to_certs = os.path.join(self.ro_data_root,
--- a/src/tests/pkg5unittest.py	Mon Mar 21 15:18:53 2011 -0700
+++ b/src/tests/pkg5unittest.py	Tue Mar 22 15:01:13 2011 -0700
@@ -62,6 +62,9 @@
 if "DEBUG" in os.environ:
         g_debug_output = True
 
+# The lowest port to use in the test suite.
+g_base_port = None
+
 #
 # XXX?
 #
@@ -198,10 +201,13 @@
 
         def __init__(self, methodName='runTest'):
                 super(Pkg5TestCase, self).__init__(methodName)
+                assert g_base_port
                 self.__test_root = None
                 self.__pid = os.getpid()
                 self.__pwd = os.getcwd()
                 self.__didteardown = False
+                self._base_port = g_base_port
+                self.next_free_port = self._base_port
                 setup_logging(self)
 
         def __str__(self):
@@ -351,8 +357,9 @@
                                 raise e
                 test_relative = os.path.sep.join(["..", "..", "src", "tests"])
                 test_src = os.path.join(g_proto_area, test_relative)
-                shutil.copytree(os.path.join(test_src, "ro_data"),
-                    self.ro_data_root)
+                if getattr(self, "need_ro_data", False):
+                        shutil.copytree(os.path.join(test_src, "ro_data"),
+                            self.ro_data_root)
                 #
                 # TMPDIR affects the behavior of mkdtemp and mkstemp.
                 # Setting this here should ensure that tests will make temp
@@ -1993,9 +2000,11 @@
                         # We pick an arbitrary base port.  This could be more
                         # automated in the future.
                         repodir = os.path.join(testdir, "repo_contents%d" % i)
-                        self.dcs[i] = self.prep_depot(12000 + i, repodir,
+                        self.dcs[i] = self.prep_depot(self.next_free_port + n,
+                            repodir,
                             depot_logfile, debug_features=debug_features,
                             properties=props, start=start_depots)
+                        self.next_free_port += 1
 
         def check_traceback(self, logpath):
                 """ Scan logpath looking for tracebacks.
--- a/src/tests/run.py	Mon Mar 21 15:18:53 2011 -0700
+++ b/src/tests/run.py	Tue Mar 22 15:01:13 2011 -0700
@@ -21,7 +21,7 @@
 #
 
 #
-# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
 #
 
 import os
@@ -190,18 +190,19 @@
                 "[-o regexp]" % sys.argv[0]
         print >> sys.stderr, \
 """   -a <dir>       Archive failed test cases to <dir>/$pid/$testcasename
+   -b <filename>  Baseline filename
    -c             Collect code coverage data
    -d             Show debug output, including commands run, and outputs
    -f             Show fail/error information even when test is expected to fail
    -g             Generate result baseline
    -h             This help message
+   -o <regexp>    Run only tests that match regexp
    -p             Parseable output format
+   -s <regexp>    Run tests starting at regexp
    -t             Generate timing info file
    -v             Verbose output
    -x             Stop after the first baseline mismatch
-   -b <filename>  Baseline filename
-   -o <regexp>    Run only tests that match regexp
-   -s <regexp>    Run tests starting at regexp
+   -z <port>      Lowest port the test suite should use
 """
         sys.exit(2)
 
@@ -217,9 +218,9 @@
                 # If you add options here, you need to also update setup.py's
                 # test_func to include said options.
                 #
-                opts, pargs = getopt.getopt(sys.argv[1:], "a:cdfghptvxb:o:s:",
-                    ["generate-baseline", "parseable", "timing", "verbose",
-                    "baseline-file", "only"])
+                opts, pargs = getopt.getopt(sys.argv[1:], "a:cdfghptvxb:o:s:z:",
+                    ["generate-baseline", "parseable", "port", "timing",
+                    "verbose", "baseline-file", "only"])
         except getopt.GetoptError, e:
                 print >> sys.stderr, "Illegal option -- %s" % e.opt
                 sys.exit(1)
@@ -235,6 +236,7 @@
         debug_output = False
         show_on_expected_fail = False
         archive_dir = None
+        port = 12001
 
         for opt, arg in opts:
                 if opt == "-v":
@@ -261,6 +263,13 @@
                         startattest = arg
                 if opt == "-a":
                         archive_dir = arg
+                if opt == "-z":
+                        try:
+                                port = int(arg)
+                        except ValueError:
+                                print >> sys.stderr, "The provided port must " \
+                                    "be an integer."
+                                usage()
                 if opt == "-h":
 			usage()
         if (bailonfail or startattest) and generate:
@@ -280,6 +289,8 @@
                 if not os.path.exists(archive_dir):
                         os.makedirs(archive_dir)
 
+        pkg5unittest.g_base_port = port
+
         import pkg.portable
 
         if not pkg.portable.is_admin():