aboutsummaryrefslogtreecommitdiffstats
path: root/functest/ci/prepare_env.py
diff options
context:
space:
mode:
authorashishk1994 <ashishk.iiit@gmail.com>2016-12-29 20:11:28 +0530
committerashishk1994 <ashishk.iiit@gmail.com>2017-01-09 17:57:24 +0530
commit47935c2fe486bce6d154589229c989271ebd0f08 (patch)
treee0088f9ec955fbced98fdb3fc3edc2e910fbd330 /functest/ci/prepare_env.py
parent254a7e643bccd48bf562f8362745783dfb9542b4 (diff)
Refactoring of args and parser variable in ci/run_tests, prepare_env
Can't import run_tests in test_run_tests.py (new unit test file). It is throwing error: nosetests: error: unrecognized arguments It is because of declaration of parser and args which are global in file, So to allow safe import of this file, we need to declare it into __main__ branch. Change-Id: Ie11ebcfd8a1b8e692bd8bf4260a54f752b67fd5e Signed-off-by: ashishk1994 <ashishk.iiit@gmail.com>
Diffstat (limited to 'functest/ci/prepare_env.py')
-rwxr-xr-xfunctest/ci/prepare_env.py31
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)