def del_log(key, maxFileNum): # 删除Log中文件 try: path = conf_value['log']['path'] if key: Misc.del_file_the_earliest(dir=path, maxFileNum=maxFileNum) log.debug('remove log=>ok') else: log.debug('remove log=>No') except: msg = u'操作Log中文件失败' log.error(msg)
def del_caseFile(test_dir): # 删除执行目录中的用例 try: delete_TestDir = "yes" if delete_TestDir == 'yes': Misc.del_file(dir=test_dir, filename='l') log.debug('remove=>ok') else: log.debug('remove=>No') except: msg = u'操作执行目录失败' log.error(msg) raise msg
def del_report(test_Report_path, maxFileNum): # 删除TestReport中文件 try: delete_report = run.del_report log.debug('is_del_report:{},report_path:{}'.format( delete_report, test_Report_path)) if delete_report: Misc.del_file_the_earliest(dir=test_Report_path, maxFileNum=maxFileNum) log.debug('remove TestReport=>ok') else: log.debug('remove TestReport=>No') except: msg = u'操作TestReport中文件失败' log.error(msg)
def send(self,send_data): send_data = Misc.jsonToStr(send_data) try: log.debug("send data:{}".format(send_data)) # 发送成功响应值是发送数据的长度 send_len = self.client_socket.sendto(send_data, self.address) # res = self.client_socket.sendto('sdfasfd', ('172.16.16.1',2048)) log.debug('send succ [len:{}]'.format(send_len)) return send_len except: log.error('send error') return 0
def move_case(self, main_case_path, case_name, test_dir): """ 移动case文件 :param main_case_path: :param case_name: :param test_dir: :return: """ if type(main_case_path) == list: for path in main_case_path: # 寻找将执行用例的文件名称 log.debug('case_name:%s' % case_name) find_case_path = Misc.ABSpath() + path # 寻找将执行用例的路径 log.debug('find_case_path:' + str(find_case_path)) case_path = find_case_path + case_name # 找到要执行的用例文件路径 log.debug('case_path:' + str(case_path)) Misc.copy_file(case_path, test_dir) else: log.debug('case_name:%s' % case_name) find_case_path = Misc.ABSpath() + main_case_path # 寻找将执行用例的路径 log.debug('find_case_path:' + str(find_case_path)) case_path = find_case_path + case_name # 找到要执行的用例文件路径 log.debug('case_path:' + str(case_path)) Misc.copy_file(case_path, test_dir)
def recv(self): self.receive_data, self.sender_address = self.client_socket.recvfrom(2048) try: res = Misc.strtojson(self.receive_data) log.debug("recv data: {}".format(res)) if not isinstance(res,dict): log.error('res is not dict:500') return res except BaseException as msg: log.error('recv data:{}'.format(self.receive_data)) raise msg except: msg = 'recv timeout' log.error(msg)
def getInparam(self, new_parm): """拿入参""" self.case_name = '' try: conf_value = getconfig('config') umac_enable = conf_value['base']['umac_enable'] uip_enable = conf_value['base']['uip_enable'] if new_parm: in_param_up =new_parm if isinstance(in_param_up, dict): info = in_param_up['info'] self.case_name = info['casename'] for key, value in info.items(): log.debug('{}:{}'.format(key,value)) self.in_param = in_param_up['param'] try: self.expect = in_param_up['expect'] except: pass try: umac = conf_value['base']['umac'] except: umac = 'not found' if self.dict_has_key(self.in_param,'umac') and umac_enable: self.rep_value(self.in_param, 'umac', umac) if self.expect and self.dict_has_key(self.expect,'umac') and umac_enable: self.rep_value(self.expect,'umac',umac) try: uip = conf_value['base']['uip'] except: uip = 'not found' if self.dict_has_key(self.in_param,'uip') and uip_enable: self.rep_value(self.in_param,'uip',uip) if self.expect and self.dict_has_key(self.expect,'uip') and uip_enable: self.rep_value(self.expect,'uip',uip) id = Misc.generate_id() if self.dict_has_key(self.in_param,'id'): self.rep_value( self.in_param,'id',id) if self.expect and self.dict_has_key(self.expect,'id'): self.rep_value(self.expect, 'id', id) return {'in_param':self.in_param,'expect':self.expect} except BaseException as msg: log.error(msg)
def __init__(): # 读取配置信息 read_test_dir = conf_value['path']['test_dir'] read_test_report = conf_value['path']['test_report'] read_send_report = conf_value['path']['send_report'] # test_dir : 用例执行目录 test_dir = Misc.ABSpath() + read_test_dir Misc.mkdir(path=Misc.ABSpath() + '/output', name="Testdir") log.debug('test_dir:%s' % test_dir) # global_dir : 存放中间数据的文件夹 Misc.mkdir(path=Misc.ABSpath() + '/output', name="Global") # 统计主程序执行次数 set_times() # 提前清空执行目录 Misc.del_file(dir=test_dir, filename='l') log.debug('remove_testdir=>ok') # test_report_path : 测试报告存放 test_Report_path = Misc.ABSpath() + read_test_report Misc.mkdir(path=Misc.ABSpath() + "/output", name='TestReport') log.debug('test_Report_path:%s' % test_Report_path) # send_Report_path : 根据系统指定不同发送报告存放路径 send_Report_path = Misc.ABSpath() + read_send_report Misc.mkdir(path=Misc.ABSpath() + "/output", name='SendReport') log.debug('send_Report_path:%s' % send_Report_path) self = { 'test_dir': test_dir, 'test_Report_path': test_Report_path, } return self
def del_log(key, maxFileNum): # 删除Log中文件 try: path = conf_value['log']['path'] if key: Misc.del_file_the_earliest(dir=path, maxFileNum=maxFileNum) log.debug('remove log=>ok') else: log.debug('remove log=>No') except: msg = u'操作Log中文件失败' log.error(msg) # 组装流程 time_stamp = Misc.getTimeStamp_now() g_map.set(time_stamp=time_stamp) starttime = time.time() run_start_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(starttime)) rep = __init__() test_dir = rep['test_dir'] test_Report_path = rep['test_Report_path'] main(test_dir, test_Report_path) del_caseFile(test_dir) # email(test_Report_path) del_report(test_Report_path, 5) del_log(True, 5) stoptime = time.time() run_end_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(stoptime)) dotime = stoptime - starttime g_map.set(run_total_time=str("%.2f" % dotime),