Files
zaza-openstack-tests/zaza/charm_lifecycle/test.py
Liam Young cb5d9caf66 Misc fixes to functional testing code
* Add calls to asyncio.get_event_loop().close() to close loop. libjuju does
  not do this for you and needs to be done just before exiting.
* Require model to be explicitly set when running command line tools. This is
  part of the drive to ensure that eventually multiple runs can be performed
  concurrently.
* Add set_juju_model/get_juju_model functions to manage which model is in
  focus
2018-03-28 11:48:53 +00:00

55 lines
1.7 KiB
Python

import asyncio
import argparse
import logging
import unittest
import sys
import zaza.charm_lifecycle.utils as utils
def run_test_list(tests):
"""Run the tests as defined in the list of test classes in series.
:param tests: List of test class strings
:type tests: ['zaza.charms_tests.svc.TestSVCClass1', ...]
:raises: AssertionError if test run fails
"""
for _testcase in tests:
testcase = utils.get_class(_testcase)
suite = unittest.TestLoader().loadTestsFromTestCase(testcase)
test_result = unittest.TextTestRunner(verbosity=2).run(suite)
assert test_result.wasSuccessful(), "Test run failed"
def test(model_name, tests):
"""Run all steps to execute tests against the model"""
utils.set_juju_model(model_name)
run_test_list(tests)
def parse_args(args):
"""Parse command line arguments
:param args: List of configure functions functions
:type list: [str1, str2,...] List of command line arguments
:returns: Parsed arguments
:rtype: Namespace
"""
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--tests', nargs='+',
help='Space sperated list of test classes',
required=False)
parser.add_argument('-m', '--model-name', help='Name of model to remove',
required=True)
return parser.parse_args(args)
def main():
"""Run the tests defined by the command line args or if none were provided
read the tests from the charms tests.yaml config file"""
logging.basicConfig(level=logging.INFO)
args = parse_args(sys.argv[1:])
tests = args.tests or utils.get_charm_config()['tests']
test(args.model_name, tests)
asyncio.get_event_loop().close()