Files
zaza-openstack-tests/zaza/charm_lifecycle/configure.py
T
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 sys
import zaza.charm_lifecycle.utils as utils
def run_configure_list(functions):
"""Run the configure scripts as defined in the list of test classes in
series.
:param functions: List of configure functions functions
:type tests: ['zaza.charms_tests.svc.setup', ...]
"""
for func in functions:
utils.get_class(func)()
def configure(model_name, functions):
"""Run all post-deployment configuration steps
:param functions: List of configure functions functions
:type tests: ['zaza.charms_tests.svc.setup', ...]"""
utils.set_juju_model(model_name)
run_configure_list(functions)
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('-c', '--configfuncs', nargs='+',
help='Space sperated list of config functions',
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 configuration defined by the command line args or if none were
provided read the configuration functions from the charms tests.yaml
config file"""
logging.basicConfig(level=logging.INFO)
args = parse_args(sys.argv[1:])
funcs = args.configfuncs or utils.get_charm_config()['configure']
configure(args.model_name, funcs)
asyncio.get_event_loop().close()