diff options
author | 2016-07-03 23:04:40 +0800 | |
---|---|---|
committer | 2016-07-05 20:05:26 +0800 | |
commit | 4c7387f811c01bd74b5ae6e0d0cca4bc98d298e8 (patch) | |
tree | 3ca8f61a152b196ca65ef526ae9659c0bddbb411 /func/cli.py | |
parent | 1560721b960531785a29d70a572f0ee791234fb0 (diff) |
Add some UT test cases and fix pep8 errors for cli and env_setup.
JIRA:QTIP-89
Change-Id: I4a46898071001f679f1a032a560d605dffc8eb9f
Signed-off-by: zhifeng.jiang <jiang.zhifeng@zte.com.cn>
Diffstat (limited to 'func/cli.py')
-rw-r--r-- | func/cli.py | 121 |
1 files changed, 61 insertions, 60 deletions
diff --git a/func/cli.py b/func/cli.py index 129ab96c..5e8f02cf 100644 --- a/func/cli.py +++ b/func/cli.py @@ -15,94 +15,95 @@ from func.spawn_vm import SpawnVM import argparse -class cli(): - - def _getfile(self, filepath): - - with open('test_list/'+filepath,'r') as finput: - _benchmarks=finput.readlines() - for items in range( len(_benchmarks)): - _benchmarks[items]=_benchmarks[items].rstrip() +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 - def _getsuite(self, filepath): + @staticmethod + def _getsuite(file_path): - return filepath + return file_path - def _checkTestList(self, filename): + @staticmethod + def _check_test_list(filename): - if os.path.isfile('test_list/'+filename): + if os.path.isfile('test_list/' + filename): return True else: return False - def _checkLabName(self, labname): + @staticmethod + def _check_lab_name(lab_name): - if os.path.isdir('test_cases/'+labname): + if os.path.isdir('test_cases/' + lab_name): return True else: return False - def _get_fname(self,file_name): + @staticmethod + def _get_f_name(file_name): return file_name[0: file_name.find('.')] - def __init__(self): - - suite=[] + @staticmethod + def _parse_args(args): parser = argparse.ArgumentParser() - parser.add_argument('-l ', '--lab', help='Name of Lab on which being tested, These can' \ - 'be found in the test_cases/ directory. Please ' \ - 'ensure that you have edited the respective files '\ - 'before using them. For testing other than through Jenkins'\ - ' The user should list default after -l . all the fields in'\ - ' the files are necessary and should be filled') - parser.add_argument('-f', '--file', help = 'File in test_list with the list of tests. there are three files' \ - '\n compute '\ - '\n storage '\ - '\n network '\ - 'They contain all the tests that will be run. They are listed by suite.' \ - 'Please ensure there are no empty lines') - args = parser.parse_args() - - if not self._checkTestList(args.file): + parser.add_argument('-l ', '--lab', help='Name of Lab on which being tested, These can' + 'be found in the test_cases/ directory. Please ' + 'ensure that you have edited the respective files ' + 'before using them. For testing other than through Jenkins' + ' The user should list default after -l . all the fields in' + ' the files are necessary and should be filled') + parser.add_argument('-f', '--file', help='File in test_list with the list of tests. there are three files' + '\n compute ' + '\n storage ' + '\n network ' + 'They contain all the tests that will be run. They are listed by suite.' + 'Please ensure there are no empty lines') + return parser.parse_args(args) + + def __init__(self, args=sys.argv[1:]): + + suite = [] + args = self._parse_args(args) + + if not self._check_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._checkLabName(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 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' sys.exit(0) benchmarks = self._getfile(args.file) suite.append(args.file) - suite=self._getsuite(suite) - for items in range (len(benchmarks)): - if (suite and benchmarks): - - roles='' - vm_info='' - benchmark_details='' - pip='' - obj='' + 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, roles, vm_info, benchmark_details, pip, proxy_info] = obj.parse('./test_cases/' - +args.lab.lower()+'/'+suite[0]+'/'+benchmarks[items]) + 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]) if len(vm_info) != 0: - vmObj ='' - vmObj = SpawnVM(vm_info) - if obj.callpingtest(): - obj.callsshtest() - obj.updateAnsible() - dvr = Driver() - dvr.drive_bench(benchmark, - obj.roles_dict.items(), - self._get_fname(benchmarks[items]), - benchmark_details, - obj.ip_pw_dict.items(), - proxy_info) + 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') |