From 3951d6f389abd95a6a9c4b9370e64fe719f5e37f Mon Sep 17 00:00:00 2001 From: Liam Young Date: Mon, 26 Mar 2018 08:25:42 +0000 Subject: [PATCH] Fix lint --- zaza/charm_testing/configure.py | 7 +++++-- zaza/charm_testing/deploy.py | 5 ++--- zaza/charm_testing/destroy.py | 5 ++++- zaza/charm_testing/func_test_runner.py | 3 ++- zaza/charm_testing/prepare.py | 5 ++++- zaza/charm_testing/test.py | 7 +++++-- zaza/charm_testing/utils.py | 3 ++- zaza/charm_tests/test_utils.py | 4 ++-- 8 files changed, 26 insertions(+), 13 deletions(-) diff --git a/zaza/charm_testing/configure.py b/zaza/charm_testing/configure.py index 78a08df..4d2f772 100644 --- a/zaza/charm_testing/configure.py +++ b/zaza/charm_testing/configure.py @@ -3,6 +3,7 @@ import logging import zaza.charm_testing.utils as utils + def run_configure_list(functions): """Run the configure scripts as defined in the list of test classes in series. @@ -13,6 +14,7 @@ def run_configure_list(functions): for func in functions: utils.get_class(func)() + def configure(functions): """Run all post-deployment configuration steps @@ -20,15 +22,16 @@ def configure(functions): :type tests: ['zaza.charms_tests.svc.setup', ...]""" run_configure_list(functions) + 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) parser = argparse.ArgumentParser() - parser.add_argument('-c','--configfuncs', nargs='+', + parser.add_argument('-c', '--configfuncs', nargs='+', help='Space sperated list of config functions', required=False) args = parser.parse_args() - funcs = args.configfuncs or get_test_config()['configure'] + funcs = args.configfuncs or utils.get_charm_config()['configure'] configure(funcs) diff --git a/zaza/charm_testing/deploy.py b/zaza/charm_testing/deploy.py index c4d5792..ac7b430 100755 --- a/zaza/charm_testing/deploy.py +++ b/zaza/charm_testing/deploy.py @@ -1,7 +1,6 @@ import argparse import logging import subprocess -import sys import juju_wait @@ -25,10 +24,10 @@ def main(): """Deploy bundle""" logging.basicConfig(level=logging.INFO) parser = argparse.ArgumentParser() - parser.add_argument('-m','--model', + parser.add_argument('-m', '--model', help='Model to deploy to', required=True) - parser.add_argument('-b','--bundle', + parser.add_argument('-b', '--bundle', help='Bundle name (excluding file ext)', required=True) parser.add_argument('--no-wait', dest='wait', diff --git a/zaza/charm_testing/destroy.py b/zaza/charm_testing/destroy.py index 89c6576..075682c 100644 --- a/zaza/charm_testing/destroy.py +++ b/zaza/charm_testing/destroy.py @@ -2,6 +2,7 @@ import argparse import logging import subprocess + def destroy_model(model_name): """Remove a model with the given name @@ -11,6 +12,7 @@ def destroy_model(model_name): logging.info("Remove model {}".format(model_name)) subprocess.check_call(['juju', 'destroy-model', '--yes', model_name]) + def clean_up(model_name): """Run all steps to cleaup after a test run @@ -19,11 +21,12 @@ def clean_up(model_name): """ destroy_model(model_name) + def main(): """Cleanup after test run""" logging.basicConfig(level=logging.INFO) parser = argparse.ArgumentParser() - parser.add_argument('-m','--model-name', help='Name of model to remove', + parser.add_argument('-m', '--model-name', help='Name of model to remove', required=True) args = parser.parse_args() clean_up(args.model_name) diff --git a/zaza/charm_testing/func_test_runner.py b/zaza/charm_testing/func_test_runner.py index 39bc4a5..8ddd232 100644 --- a/zaza/charm_testing/func_test_runner.py +++ b/zaza/charm_testing/func_test_runner.py @@ -1,5 +1,4 @@ import datetime -import logging import os import zaza.charm_testing.configure as configure @@ -9,6 +8,7 @@ import zaza.charm_testing.prepare as prepare import zaza.charm_testing.deploy as deploy import zaza.charm_testing.test as test + def func_test_runner(): """Deploy the bundles and run the tests as defined by the charms tests.yaml """ @@ -29,5 +29,6 @@ def func_test_runner(): # Destroy destroy.clean_up(model_name) + def main(): func_test_runner() diff --git a/zaza/charm_testing/prepare.py b/zaza/charm_testing/prepare.py index 79aabf3..814ef64 100644 --- a/zaza/charm_testing/prepare.py +++ b/zaza/charm_testing/prepare.py @@ -2,6 +2,7 @@ import argparse import logging import subprocess + def add_model(model_name): """Add a model with the given name @@ -11,6 +12,7 @@ def add_model(model_name): logging.info("Adding model {}".format(model_name)) subprocess.check_call(['juju', 'add-model', model_name]) + def prepare(model_name): """Run all steps to prepare the environment before a functional test run @@ -19,11 +21,12 @@ def prepare(model_name): """ add_model(model_name) + def main(): """Add a new model""" logging.basicConfig(level=logging.INFO) parser = argparse.ArgumentParser() - parser.add_argument('-m','--model-name', help='Name of new model', + parser.add_argument('-m', '--model-name', help='Name of new model', required=True) args = parser.parse_args() prepare(args.model_name) diff --git a/zaza/charm_testing/test.py b/zaza/charm_testing/test.py index 58c5836..353e7cd 100644 --- a/zaza/charm_testing/test.py +++ b/zaza/charm_testing/test.py @@ -4,6 +4,7 @@ import unittest import zaza.charm_testing.utils as utils + def run_test_list(tests): """Run the tests as defined in the list of test classes in series. @@ -17,18 +18,20 @@ def run_test_list(tests): test_result = unittest.TextTestRunner(verbosity=2).run(suite) assert test_result.wasSuccessful(), "Test run failed" + def test(tests): """Run all steps to execute tests against the model""" run_test_list(tests) + 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) parser = argparse.ArgumentParser() - parser.add_argument('-t','--tests', nargs='+', + parser.add_argument('-t', '--tests', nargs='+', help='Space sperated list of test classes', required=False) args = parser.parse_args() - tests = args.tests or get_test_config()['tests'] + tests = args.tests or utils.get_charm_config()['tests'] test(tests) diff --git a/zaza/charm_testing/utils.py b/zaza/charm_testing/utils.py index 5494b84..26bd94d 100644 --- a/zaza/charm_testing/utils.py +++ b/zaza/charm_testing/utils.py @@ -4,6 +4,7 @@ import yaml BUNDLE_DIR = "./tests/bundles/" DEFAULT_TEST_CONFIG = "./tests/tests.yaml" + def get_charm_config(): """Read the yaml test config file and return the resulting config @@ -13,6 +14,7 @@ def get_charm_config(): with open(DEFAULT_TEST_CONFIG, 'r') as stream: return yaml.load(stream) + def get_class(class_str): """Get the class represented by the given string @@ -28,4 +30,3 @@ def get_class(class_str): class_name = class_str.split('.')[-1] module = importlib.import_module(module_name) return getattr(module, class_name) - diff --git a/zaza/charm_tests/test_utils.py b/zaza/charm_tests/test_utils.py index 3e81a95..e5e2bd7 100644 --- a/zaza/charm_tests/test_utils.py +++ b/zaza/charm_tests/test_utils.py @@ -1,5 +1,4 @@ import logging -import unittest import zaza.model @@ -9,7 +8,8 @@ def skipIfNotHA(service_name): if len(zaza.model.get_app_ips(service_name)) > 1: return f(*args, **kwargs) else: - logging.warn("Skipping HA test for non-ha service {}".format(service_name)) + logging.warn("Skipping HA test for non-ha service {}".format( + service_name)) return _skipIfNotHA_inner_2 return _skipIfNotHA_inner_1