Merge pull request #11 from gnuoy/keep-model

Add option to functest-run-suite to skip model deletion
This commit is contained in:
Chris MacNaughton
2018-04-12 10:04:15 +02:00
committed by GitHub
2 changed files with 38 additions and 3 deletions

View File

@@ -6,6 +6,12 @@ import unit_tests.utils as ut_utils
class TestCharmLifecycleFuncTestRunner(ut_utils.BaseTestCase):
def test_parser(self):
args = lc_func_test_runner.parse_args(['--keep-model'])
self.assertTrue(args.keep_model)
args = lc_func_test_runner.parse_args([])
self.assertFalse(args.keep_model)
def test_func_test_runner(self):
self.patch_object(lc_func_test_runner.utils, 'get_charm_config')
self.patch_object(lc_func_test_runner, 'generate_model_name')

View File

@@ -1,7 +1,9 @@
import argparse
import asyncio
import datetime
import logging
import os
import sys
import zaza.charm_lifecycle.configure as configure
import zaza.charm_lifecycle.destroy as destroy
@@ -16,10 +18,14 @@ def generate_model_name(charm_name, bundle_name):
return '{}{}{}'.format(charm_name, bundle_name, timestamp)
def func_test_runner():
def func_test_runner(keep_model=False):
"""Deploy the bundles and run the tests as defined by the charms tests.yaml
:param keep_model: Whether to destroy model at end of run
:type keep_model: boolean
"""
test_config = utils.get_charm_config()
last_test = test_config['gate_bundles'][-1]
for t in test_config['gate_bundles']:
model_name = generate_model_name(test_config['charm_name'], t)
# Prepare
@@ -33,10 +39,33 @@ def func_test_runner():
# Test
test.test(model_name, test_config['tests'])
# Destroy
destroy.destroy(model_name)
# Keep the model from the last run if keep_model is true, this is to
# maintian compat with osci and should change when the zaza collect
# functions take over from osci for artifact collection.
if keep_model and t == last_test:
pass
else:
destroy.destroy(model_name)
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('--keep-model', dest='keep_model',
help='Keep model at the end of the run',
action='store_true')
parser.set_defaults(keep_model=False)
return parser.parse_args(args)
def main():
logging.basicConfig(level=logging.INFO)
func_test_runner()
args = parse_args(sys.argv[1:])
func_test_runner(keep_model=args.keep_model)
asyncio.get_event_loop().close()