Don't destroy env on test failure And add some docs and misc cleanup
Project: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/commit/4e51f73a Tree: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/tree/4e51f73a Diff: http://git-wip-us.apache.org/repos/asf/trafficserver-qa/diff/4e51f73a Branch: refs/heads/master Commit: 4e51f73a33dd91591f172d2335364d53c8d86fd3 Parents: 3047c3c Author: Thomas Jackson <[email protected]> Authored: Thu Jan 8 19:14:18 2015 -0800 Committer: Thomas Jackson <[email protected]> Committed: Thu Jan 8 19:14:18 2015 -0800 ---------------------------------------------------------------------- README.rst | 7 +++++++ tsqa/configs.py | 2 ++ tsqa/environment.py | 2 +- tsqa/test_cases.py | 21 ++++++++++++++++----- 4 files changed, 26 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver-qa/blob/4e51f73a/README.rst ---------------------------------------------------------------------- diff --git a/README.rst b/README.rst index 48b2356..5a6bc55 100644 --- a/README.rst +++ b/README.rst @@ -59,3 +59,10 @@ server in a separate thread with APIs to register endpoints and track requests. test_cases ========== These are intended to be test cases that you would subclass to create your own test. + + +Environment Variables +===================== +TSQA_LAYOUT_PREFIX: Prefix to create layouts for each test execution (defaults to /tmp) +TSQA_LOG_LEVEL: Log level for TSQA (defaults to INFO) +TSQA_TMP_DIR: temp directory for building of source (environment factory) http://git-wip-us.apache.org/repos/asf/trafficserver-qa/blob/4e51f73a/tsqa/configs.py ---------------------------------------------------------------------- diff --git a/tsqa/configs.py b/tsqa/configs.py index 7a0fbe6..abfec7f 100644 --- a/tsqa/configs.py +++ b/tsqa/configs.py @@ -1,3 +1,5 @@ +# TODO: keep track of stat when it was loaded? So we don't clobber manual file changes... + class Config(object): ''' Class to represent a config file http://git-wip-us.apache.org/repos/asf/trafficserver-qa/blob/4e51f73a/tsqa/environment.py ---------------------------------------------------------------------- diff --git a/tsqa/environment.py b/tsqa/environment.py index fb97bc7..c39f388 100644 --- a/tsqa/environment.py +++ b/tsqa/environment.py @@ -277,7 +277,7 @@ class Environment: """ # First, make the prefix directory. if self.layout is None: - self.layout = Layout(tempfile.mkdtemp()) + self.layout = Layout(tempfile.mkdtemp(prefix=os.environ.get('TSQA_LAYOUT_PREFIX', ''))) else: os.makedirs(self.layout.prefix) os.chmod(self.layout.prefix, 0777) # Make the tmp dir readable by all http://git-wip-us.apache.org/repos/asf/trafficserver-qa/blob/4e51f73a/tsqa/test_cases.py ---------------------------------------------------------------------- diff --git a/tsqa/test_cases.py b/tsqa/test_cases.py index da7f8e9..9708f0c 100644 --- a/tsqa/test_cases.py +++ b/tsqa/test_cases.py @@ -11,15 +11,20 @@ unittest = tsqa.utils.import_unittest() import os -# Example environment case +# Base environment case class EnvironmentCase(unittest.TestCase): ''' - This class will get an environment (which is unique) but won't start it + This class will get an environment (which is unique) ''' # TODO: better naming?? environment_factory = {'configure': None, 'env': None, } + + def run(self, result=None): + unittest.TestCase.run(self, result) + self.__successful &= result.result.wasSuccessful() + @classmethod def setUpClass(cls): # call parent constructor @@ -30,6 +35,7 @@ class EnvironmentCase(unittest.TestCase): # get an environment cls.environment = cls.getEnv() + logging.info('Environment prefix is {0}'.format(cls.environment.layout.prefix)) cfg_dir = os.path.join(cls.environment.layout.prefix, 'etc', 'trafficserver') @@ -52,6 +58,9 @@ class EnvironmentCase(unittest.TestCase): # start ATS cls.environment.start() + # we assume the tests passed + cls.__successful = True + @classmethod def getEnv(cls): ''' @@ -73,15 +82,16 @@ class EnvironmentCase(unittest.TestCase): @classmethod def tearDownClass(cls): - # TODO: some better checking that we didn't crash - if cls.environment.cop is not None and not cls.environment.running: + if not cls.environment.running: raise Exception('ATS died during the test run') # stop ATS cls.environment.stop() # call parent destructor super(EnvironmentCase, cls).tearDownClass() - cls.environment.destroy() # this will tear down any processes that we started + # if the test was successful, tear down the env + if self.__successful: + cls.environment.destroy() # this will tear down any processes that we started # Some helpful properties @property @@ -92,6 +102,7 @@ class EnvironmentCase(unittest.TestCase): # TODO: create a better dict by parsing the config-- to handle http/https ports in the string return {'http': 'http://127.0.0.1:{0}'.format(self.configs['records.config']['CONFIG']['proxy.config.http.server_ports'])} + class DynamicHTTPEndpointCase(unittest.TestCase): ''' This class will set up a dynamic http endpoint that is local to this class
