diff options
author | Morgan Richomme <morgan.richomme@orange.com> | 2017-01-17 13:23:11 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-01-17 13:23:11 +0000 |
commit | 810387a6ce1d20ba85af9480e21710c9f2909fc2 (patch) | |
tree | 0820f1703c47900347629da64bcafe5134f90c1d /functest/ci/prepare_env.py | |
parent | 9277dab7fc82030a5f3d7b55ea7b2a741a51a8a3 (diff) | |
parent | 47935c2fe486bce6d154589229c989271ebd0f08 (diff) |
Merge "Refactoring of args and parser variable in ci/run_tests, prepare_env"
Diffstat (limited to 'functest/ci/prepare_env.py')
-rwxr-xr-x | functest/ci/prepare_env.py | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/functest/ci/prepare_env.py b/functest/ci/prepare_env.py index 3df3a0e0..77bb14a8 100755 --- a/functest/ci/prepare_env.py +++ b/functest/ci/prepare_env.py @@ -29,12 +29,6 @@ import functest.utils.openstack_utils as os_utils from functest.utils.constants import CONST actions = ['start', 'check'] -parser = argparse.ArgumentParser() -parser.add_argument("action", help="Possible actions are: " - "'{d[0]}|{d[1]}' ".format(d=actions)) -parser.add_argument("-d", "--debug", help="Debug mode", action="store_true") -args = parser.parse_args() - """ logging configuration """ logger = ft_logger.Logger("prepare_env").getLogger() @@ -48,6 +42,19 @@ with open(CONFIG_PATCH_PATH) as f: functest_patch_yaml = yaml.safe_load(f) +class PrepareEnvParser(): + + def __init__(self): + self.parser = argparse.ArgumentParser() + self.parser.add_argument("action", help="Possible actions are: " + "'{d[0]}|{d[1]}' ".format(d=actions)) + self.parser.add_argument("-d", "--debug", help="Debug mode", + action="store_true") + + def parse_args(self, argv=[]): + return vars(self.parser.parse_args(argv)) + + def print_separator(): logger.info("==============================================") @@ -270,12 +277,12 @@ def check_environment(): logger.info("Functest environment installed.") -def main(): - if not (args.action in actions): +def main(**kwargs): + if not (kwargs['action'] in actions): logger.error('Argument not valid.') sys.exit() - if args.action == "start": + if kwargs['action'] == "start": logger.info("######### Preparing Functest environment #########\n") check_env_variables() create_directories() @@ -289,11 +296,13 @@ def main(): check_environment() - if args.action == "check": + if kwargs['action'] == "check": check_environment() exit(0) if __name__ == '__main__': - main() + parser = PrepareEnvParser() + args = parser.parse_args(sys.argv[1:]) + main(**args) |