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
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import argparse
|
||||
import logging
|
||||
import sys
|
||||
@@ -16,11 +17,12 @@ def run_configure_list(functions):
|
||||
utils.get_class(func)()
|
||||
|
||||
|
||||
def configure(functions):
|
||||
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)
|
||||
|
||||
|
||||
@@ -36,6 +38,8 @@ def parse_args(args):
|
||||
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)
|
||||
|
||||
|
||||
@@ -46,4 +50,5 @@ def main():
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
args = parse_args(sys.argv[1:])
|
||||
funcs = args.configfuncs or utils.get_charm_config()['configure']
|
||||
configure(funcs)
|
||||
configure(args.model_name, funcs)
|
||||
asyncio.get_event_loop().close()
|
||||
|
||||
@@ -60,4 +60,4 @@ def main():
|
||||
"""Deploy bundle"""
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
args = parse_args(sys.argv[1:])
|
||||
deploy_bundle(args.bundle, args.model, wait=args.wait)
|
||||
deploy(args.bundle, args.model, wait=args.wait)
|
||||
|
||||
@@ -27,9 +27,9 @@ def func_test_runner():
|
||||
os.path.join(utils.BUNDLE_DIR, '{}.yaml'.format(t)),
|
||||
model_name)
|
||||
# Configure
|
||||
configure.configure(test_config['configure'])
|
||||
configure.configure(model_name, test_config['configure'])
|
||||
# Test
|
||||
test.test(test_config['tests'])
|
||||
test.test(model_name, test_config['tests'])
|
||||
# Destroy
|
||||
destroy.destroy(model_name)
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import argparse
|
||||
import logging
|
||||
import unittest
|
||||
@@ -20,8 +21,9 @@ def run_test_list(tests):
|
||||
assert test_result.wasSuccessful(), "Test run failed"
|
||||
|
||||
|
||||
def test(tests):
|
||||
def test(model_name, tests):
|
||||
"""Run all steps to execute tests against the model"""
|
||||
utils.set_juju_model(model_name)
|
||||
run_test_list(tests)
|
||||
|
||||
|
||||
@@ -37,6 +39,8 @@ def parse_args(args):
|
||||
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)
|
||||
|
||||
|
||||
@@ -46,4 +50,5 @@ def main():
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
args = parse_args(sys.argv[1:])
|
||||
tests = args.tests or utils.get_charm_config()['tests']
|
||||
test(tests)
|
||||
test(args.model_name, tests)
|
||||
asyncio.get_event_loop().close()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import importlib
|
||||
import os
|
||||
import yaml
|
||||
|
||||
BUNDLE_DIR = "./tests/bundles/"
|
||||
@@ -34,3 +35,21 @@ def get_class(class_str):
|
||||
class_name = class_str.split('.')[-1]
|
||||
module = importlib.import_module(module_name)
|
||||
return getattr(module, class_name)
|
||||
|
||||
|
||||
def set_juju_model(model_name):
|
||||
"""Point environment at the given model
|
||||
|
||||
:param model_name: Model to point environment at
|
||||
:type model_name: str
|
||||
"""
|
||||
os.environ["JUJU_MODEL"] = model_name
|
||||
|
||||
|
||||
def get_juju_model():
|
||||
"""Retrieve current model from environment
|
||||
|
||||
:returns: In focus model name
|
||||
:rtype: str
|
||||
"""
|
||||
return os.environ["JUJU_MODEL"]
|
||||
|
||||
Reference in New Issue
Block a user