diff options
author | 2016-08-20 16:29:26 +0800 | |
---|---|---|
committer | 2016-08-21 14:23:13 +0800 | |
commit | 9b23320f77639f07d2156a4add18fb2f99771520 (patch) | |
tree | 3593b673535bd109fc7031eeb7f00848c5c8b0fb /func/cli.py | |
parent | e0482d626cedfb1f30712e82df288454af65c76c (diff) |
Code refactoring cli.py so that it can be reused by restful server.
modification:
Move function in cli.py to args_handler.py
Add unit test for args_handler.py
Add unit test for cli.py
Delete print in driver.py to pass unit test
JIRA:QTIP-99
Change-Id: Ib670d7dff494f3e04cdbe1de5c247d382b1052c1
Signed-off-by: zhifeng.jiang <jiang.zhifeng@zte.com.cn>
Diffstat (limited to 'func/cli.py')
-rw-r--r-- | func/cli.py | 81 |
1 files changed, 13 insertions, 68 deletions
diff --git a/func/cli.py b/func/cli.py index 4613b507..01694a9b 100644 --- a/func/cli.py +++ b/func/cli.py @@ -8,50 +8,13 @@ ############################################################################## import sys -import os -from func.env_setup import Env_setup -from func.driver import Driver -from func.spawn_vm import SpawnVM +import args_handler import argparse class cli: @staticmethod - def _getfile(file_path): - with open('test_list/' + file_path, 'r') as fin_put: - _benchmarks = fin_put.readlines() - for items in range(len(_benchmarks)): - _benchmarks[items] = _benchmarks[items].rstrip() - return _benchmarks - - @staticmethod - def _getsuite(file_path): - - return file_path - - @staticmethod - def _check_test_list(filename): - - if os.path.isfile('test_list/' + filename): - return True - else: - return False - - @staticmethod - def _check_lab_name(lab_name): - - if os.path.isdir('test_cases/' + lab_name): - return True - else: - return False - - @staticmethod - def _get_f_name(file_name): - - return file_name[0: file_name.find('.')] - - @staticmethod def _parse_args(args): parser = argparse.ArgumentParser() parser.add_argument('-l ', '--lab', required=True, help='Name of Lab ' @@ -72,40 +35,22 @@ class cli: def __init__(self, args=sys.argv[1:]): - suite = [] args = self._parse_args(args) - - if not self._check_test_list(args.file): + if not args_handler.check_suit_in_test_list(args.file): print '\n\n ERROR: Test File Does not exist in test_list/ please enter correct file \n\n' sys.exit(0) - if not self._check_lab_name(args.lab): - print '\n\n You have specified a lab that is not present in test_cases/ please enter correct \ - file. If unsure how to proceed, use -l default.\n\n' + if not args_handler.check_lab_name(args.lab): + print '\n\n You have specified a lab that is not present in test_cases/ please enter \ + correct file. If unsure how to proceed, use -l default.\n\n' sys.exit(0) + suite = args.file + benchmarks = args_handler.get_files_in_test_list(suite) + test_cases = args_handler.get_files_in_test_case(args.lab, suite) + benchmarks_list = filter(lambda x: x in test_cases, benchmarks) - benchmarks = self._getfile(args.file) - suite.append(args.file) - suite = self._getsuite(suite) - for items in range(len(benchmarks)): - if suite and benchmarks: - obj = Env_setup() - if os.path.isfile('./test_cases/' + args.lab.lower() + '/' + suite[0] + '/' + benchmarks[items]): - [benchmark, vm_info, benchmark_details, proxy_info] = \ - obj.parse('./test_cases/' + args.lab.lower() + '/' + suite[0] + '/' + benchmarks[items]) + map(lambda x: args_handler.prepare_and_run_benchmark( + args_handler.get_benchmark_path(args.lab.lower(), suite, x)), benchmarks_list) - if len(vm_info) != 0: - SpawnVM(vm_info) - obj.call_ping_test() - obj.call_ssh_test() - obj.update_ansible() - dvr = Driver() - dvr.drive_bench(benchmark, - obj.roles_dict.items(), - self._get_f_name(benchmarks[items]), - benchmark_details, - obj.ip_pw_dict.items(), - proxy_info) - else: - print (benchmarks[items], ' is not a Template in the Directory - \ - Enter a Valid file name. or use qtip.py -h for list') + print('{0} is not a Template in the Directory Enter a Valid file name.' + 'or use qtip.py -h for list'.format(filter(lambda x: x not in test_cases, benchmarks))) |