diff options
| author | zhangchengwei <[email protected]> | 2022-05-27 21:29:54 +0800 |
|---|---|---|
| committer | zhangchengwei <[email protected]> | 2022-05-27 21:29:54 +0800 |
| commit | d1cc65ebb0480dbb5674272f6d895f915f9c3891 (patch) | |
| tree | 9943cf27a8505ff1cf7de7b7856651f99ae474a9 | |
| parent | 51e47051c7631b95539835c1e3865ad9d560f25b (diff) | |
修改删除历史数据逻辑
| -rw-r--r-- | control/business.py | 53 | ||||
| -rw-r--r-- | control/control_config.ini | 11 | ||||
| -rw-r--r-- | control/remote_command.py | 18 |
3 files changed, 68 insertions, 14 deletions
diff --git a/control/business.py b/control/business.py index ca62978..3747589 100644 --- a/control/business.py +++ b/control/business.py @@ -69,7 +69,37 @@ def kill_all(instructNo_setup_json_abs_path, tsglogger): tsglogger.info(f"需要杀掉的父进程pid:{ppid}") subprocess.Popen(['kill','-STOP', str(ppid) ], stdout=subprocess.PIPE,universal_newlines=True) #暂停进程 - time.sleep(1) + #subprocess.Popen(['kill','-CONT', str(ppid) ], stdout=subprocess.PIPE,universal_newlines=True) #继续启动进程 + print("父进程:{}".format(ppid)) + def kill_child(ppid): + #找到子进程 + child_process = subprocess.Popen("pgrep -P {}".format(ppid), stdout=subprocess.PIPE, shell=True, universal_newlines=True) + child_pid_list = child_process.communicate()[0].split() + print("子进程:{}".format(child_pid_list)) + #找到子进程的子进程 + child_child_list = [] + if len(child_pid_list) > 0: + for i in child_pid_list: + child_child_process = subprocess.Popen("pgrep -P {}".format(i), stdout=subprocess.PIPE, shell=True, universal_newlines=True) + child_child_list0 = child_child_process.communicate()[0].split() + child_child_list.extend(child_child_list0) + print("子子进程:{}".format(child_child_list)) + + #kill掉子子的进程 + if len(child_child_list) > 0: + for child_pid in child_child_list: + kill_child_process = subprocess.Popen(['sudo','kill','-2', child_pid ], stdout=subprocess.PIPE,universal_newlines=True) + output = kill_child_process.communicate() + + for child_pid in child_child_list: + kill_child_process = subprocess.Popen(['sudo','kill','-2', child_pid ], stdout=subprocess.PIPE,universal_newlines=True) + #output = kill_child_process.communicate() + + kill_child(ppid) + + + """ + #time.sleep(1) #读取父进程下的子进程pid child_process = subprocess.Popen(['pgrep','-P', str(ppid) ], stdout=subprocess.PIPE,universal_newlines=True) child_pid = child_process.communicate() @@ -93,22 +123,28 @@ def kill_all(instructNo_setup_json_abs_path, tsglogger): #杀掉父进程 time.sleep(3) #subprocess.Popen(['kill','-CONT', str(ppid) ], stdout=subprocess.PIPE,universal_newlines=True) #继续启动进程 + """ + time.sleep(0.5) for i in range(2): kill_parent_process = subprocess.Popen(['sudo','kill','-9', ppid ], stdout=subprocess.PIPE,universal_newlines=True) tsglogger.info(f"父进程的结果:{kill_parent_process.communicate()}") + exit(0) def clear_historical_reort(instructNo_setup_json_abs_path): """ 清楚控制层中report的历史文件,清楚agent server层中report的历史文件 - :param instructNo_setup_json_abs_path: #/opt/test/automation/tasks/2022051813000002800100859508 + :param instructNo_setup_json_abs_path: #/opt/test/automation/tasks/2022052717210703000103027569/setup_2022052717210703000103027569.json :return: """ + print("清楚历史数据...:{}".format(instructNo_setup_json_abs_path)) control_config = configparser.ConfigParser() global config_abs_path control_config.read(config_abs_path) control_layer_retention_time = int(control_config.get("report_retention_time", "control_layer_retention_time")) agent_server_layer_retention_time = int(control_config.get("report_retention_time", "agent_server_layer_retention_time")) + agent_server_layer_cache_retention_time = int(control_config.get("report_retention_time", "agent_server_layer_cache_retention_time")) + #确认删除时间之前的文件 now_time = time.time() last_control_layer_retention_time = now_time - 3600*24*control_layer_retention_time @@ -132,6 +168,17 @@ def clear_historical_reort(instructNo_setup_json_abs_path): agent_server_host.connect() clear_cmd = 'find /root/work/oss -ctime +{} -type d -name "20*" -exec rm -rf {{}} \\;'.format(agent_server_layer_retention_time) clear_result = agent_server_host.send(clear_cmd) + + clear_cmd2 = 'find /root/work -ctime +{} -type d -name "20*" -exec rm -rf {{}} \\;'.format(agent_server_layer_retention_time) + clear_result2 = agent_server_host.send(clear_cmd2) + + clear_cmd3 = 'find /root/work -ctime +{} -type d -name "dry*" -exec rm -rf {{}} \\;'.format(agent_server_layer_retention_time) + clear_result3 = agent_server_host.send(clear_cmd3) + + clear_cmd_b = 'find /root/work/b -ctime +{} -exec rm -rf {{}} \\;'.format(agent_server_layer_cache_retention_time) + clear_result_b = agent_server_host.send(clear_cmd_b) + time.sleep(0.5) + agent_server_host.close() @@ -974,7 +1021,7 @@ client_info_dict = {} #此列表用于存放不同的线程号---客户端对 "iphone12":["facebook", "gmail", "instagram", "instagram", "psiphon3", "qq", "skype", "tachyon", "taobao", "telegram", "tor", "twitter", "wechat", "whatsapp", "wireguard", "youtube"], "xiaomi":["freegate", "psiphon3", "tachyon", "tor"], - "iphonexr":["freegate", "psiphon3", "tachyon", "youtube"] + "iphoneXR":["freegate", "psiphon3", "tachyon", "youtube"] }""" mobile_info_dict = get_mobile_info_dict() mobile_case_list = [] #类别中元素的位置会改变 diff --git a/control/control_config.ini b/control/control_config.ini index 3d01764..4df6318 100644 --- a/control/control_config.ini +++ b/control/control_config.ini @@ -21,13 +21,14 @@ capture_eth = ens16 [mobile_info] mobile_info_dict = { "vivoV2031A":["facebook", "freegate", "gmail", "instagram", "instagram", "psiphon3", "qq", "skype", "tachyon", - "taobao", "telegram", "tor", "twitter", "wechat", "whatsapp", "wireguard", "youtube"], + "taobao", "telegram", "tor", "twitter", "wechat", "whatsapp", "wireguard", "youtube"], "iphone12":["facebook", "gmail", "instagram", "instagram", "psiphon3", "qq", "skype", "tachyon", - "taobao", "telegram", "tor", "twitter", "wechat", "whatsapp", "wireguard", "youtube"], + "taobao", "telegram", "tor", "twitter", "wechat", "whatsapp", "wireguard", "youtube"], "xiaomi":["freegate", "psiphon3", "tachyon", "tor"], - "iphonexr":["freegate", "psiphon3", "tachyon", "youtube"] + "iphoneXR":["freegate", "psiphon3", "tachyon", "youtube"] } [report_retention_time] -control_layer_retention_time = 7 -agent_server_layer_retention_time = 10
\ No newline at end of file +control_layer_retention_time = 3 +agent_server_layer_retention_time = 15 +agent_server_layer_cache_retention_time = 2
\ No newline at end of file diff --git a/control/remote_command.py b/control/remote_command.py index 04d53ca..5745f23 100644 --- a/control/remote_command.py +++ b/control/remote_command.py @@ -43,10 +43,16 @@ class Linux(): cmd += "\r" result = "" self.chan.send(cmd) - while True: - time.sleep(0.5) - ret = self.chan.recv(65535) - ret = ret.decode("utf-8") + time.sleep(0.5) + while self.chan.exit_status_ready(): + result1 = "" + sign_1 = self.chan.recv(65535) + ret = sign_1.decode("utf-8") result += ret - print(result) - return result + result1 += ret + print(result1) + # print(self.chan.recv_ready()) + # print(2) + time.sleep(0.5) + + return result |
