From 5bd7b8d098134f7149b9d25bf23a95dba26f0c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=9B=BD=E8=BE=89?= Date: Tue, 27 May 2025 21:08:12 +0800 Subject: [PATCH 1/7] =?UTF-8?q?Signed-off-by:=20=E9=BB=84=E5=9B=BD?= =?UTF-8?q?=E8=BE=89=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- local_coverage/resident_service/init_gcov.py | 72 ++++++++++--------- .../resident_service/public_method.py | 23 ++++++ .../resident_service/pull_service_gcda.py | 29 ++++---- 3 files changed, 80 insertions(+), 44 deletions(-) diff --git a/local_coverage/resident_service/init_gcov.py b/local_coverage/resident_service/init_gcov.py index e414e76..086bae1 100644 --- a/local_coverage/resident_service/init_gcov.py +++ b/local_coverage/resident_service/init_gcov.py @@ -23,7 +23,7 @@ import json import sys import time import xml.etree.ElementTree as ET -from public_method import get_server_dict, get_config_ip, get_sn_list +from public_method import get_server_dict, get_config_ip_info, get_sn_list import stat FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL @@ -315,27 +315,30 @@ def split_foundation_services(developer_path, system_info_dict, home_path, hdc_d return -def modify_cfg_xml_file(developer_path, device_ip, device_sn_list, - system_info_dict, home_path, device_port): - if device_ip and len(device_sn_list) >= 1: - for device_sn_str in device_sn_list: - hdc_str = "hdc -s %s:%s -t %s" % (device_ip, device_port, device_sn_str) - hdc_dict = {"device_ip": device_ip, "device_port": device_port, "device_sn_str": device_sn_str} - modify_init_file(developer_path, hdc_str) - modify_faultloggerd_file( - developer_path, hdc_str) - # 推送服务对应的配置文件 - split_foundation_services(developer_path, system_info_dict, home_path, hdc_dict) - logger("{} shell reboot".format(hdc_str), "INFO") - coverage_command("%s shell reboot > /dev/null 2>&1" % hdc_str) - while True: - after_sn_list = get_sn_list("hdc -s %s:%s list targets" % (device_ip, device_port)) - time.sleep(10) - if device_sn_str in after_sn_list: - break - coverage_command("%s shell getenforce" % hdc_str) - else: - logger("user_config.xml device ip not config", "ERROR") +def modify_cfg_xml_file(developer_path, device_ip_list, device_sn_list, + system_info_dict, home_path, device_port_list): + for i in range(len(device_ip_list)): + device_ip = device_ip_list[i] + device_port = device_port_list[i] + if device_ip and len(device_sn_list) >= 1: + for device_sn_str in device_sn_list: + hdc_str = "hdc -s %s:%s -t %s" % (device_ip, device_port, device_sn_str) + hdc_dict = {"device_ip": device_ip, "device_port": device_port, "device_sn_str": device_sn_str} + modify_init_file(developer_path, hdc_str) + modify_faultloggerd_file( + developer_path, hdc_str) + # 推送服务对应的配置文件 + split_foundation_services(developer_path, system_info_dict, home_path, hdc_dict) + logger("{} shell reboot".format(hdc_str), "INFO") + coverage_command("%s shell reboot > /dev/null 2>&1" % hdc_str) + while True: + after_sn_list = get_sn_list("hdc -s %s:%s list targets" % (device_ip, device_port)) + time.sleep(10) + if device_sn_str in after_sn_list: + break + coverage_command("%s shell getenforce" % hdc_str) + else: + logger("user_config.xml device ip not config", "ERROR") if __name__ == '__main__': @@ -351,18 +354,23 @@ if __name__ == '__main__': home_paths = '/'.join(root_path.split("/")[:3]) # 获取user_config中的device ip - ip, port, sn = get_config_ip(os.path.join(developer_test_path, "config/user_config.xml")) - if not port: - port = "8710" - sn_list = [] - if sn: - sn_list.extend(sn.replace(" ", "").split(";")) - else: - sn_list = get_sn_list("hdc -s %s:%s list targets" % (ip, port)) + ip_list, port_list, sn_list = get_config_ip_info(os.path.join(developer_test_path, "config/user_config.xml")) + if not port_list: + port_list = ["8710"] * len(ip_list) + # sn_list = [] + # if sn: + # sn_list.extend(sn.replace(" ", "").split(";")) + # else: + # sn_list = get_sn_list("hdc -s %s:%s list targets" % (ip, port)) + if not sn_list: + for i in range(list(ip_list)): + ip = ip_list[i] + port = port_list[i] + sn_list.extend(get_sn_list("hdc -s %s:%s list targets" % (ip, port))) # 获取子系统部件与服务的关系 system_dict, _, _ = get_server_dict(command_str) # 修改设备init.cfg, faultloggerd.cfg等文件 - modify_cfg_xml_file(developer_test_path, ip, sn_list, - system_dict, home_paths, port) + modify_cfg_xml_file(developer_test_path, ip_list, sn_list, + system_dict, home_paths, port_list) diff --git a/local_coverage/resident_service/public_method.py b/local_coverage/resident_service/public_method.py index 1cca156..766ca82 100644 --- a/local_coverage/resident_service/public_method.py +++ b/local_coverage/resident_service/public_method.py @@ -45,6 +45,29 @@ def get_config_ip(filepath): return ip_config, port, sn +def get_config_ip_info(filepath): + ip_config_list = [] + sn_list = [] + port_list = [] + try: + data_dic = {} + if os.path.exists(filepath): + tree = ET.parse(filepath) + root = tree.getroot() + for node in root.findall("environment/device"): + if node.attrib["type"] != "usb-hdc": + continue + for sub in node: + if sub.tag == "info": + ip_config_list.append(sub.attrib["ip"]) + port_list.append(sub.attrib["port"]) + sn_list.append(sub.attrib["sn"]) + except ET.ParseError as xml_exception: + print("occurs exception:{}".format(xml_exception.args)) + + return ip_config_list, port_list, sn_list + + def get_sn_list(command): device_sn_list = [] # 执行查询设备sn号命令并获取执行结果 diff --git a/local_coverage/resident_service/pull_service_gcda.py b/local_coverage/resident_service/pull_service_gcda.py index d3f740f..c300af2 100644 --- a/local_coverage/resident_service/pull_service_gcda.py +++ b/local_coverage/resident_service/pull_service_gcda.py @@ -19,7 +19,7 @@ import os import sys -from public_method import get_server_dict, get_config_ip, get_sn_list +from public_method import get_server_dict, get_config_ip_info, get_sn_list def _init_sys_config(): @@ -148,17 +148,22 @@ if __name__ == '__main__': # 获取子系统部件与服务的关系 system_dict, services_dict, component_dict = get_server_dict(command_str) - ip, port, sn = get_config_ip(os.path.join(developer_test_path, "config/user_config.xml")) - if not port: - port = "8710" - device_sn_list = [] - if sn: - device_sn_list.extend(sn.replace(" ", "").split(";")) - else: - device_sn_list = get_sn_list("hdc -s %s:%s list targets" % (ip, port)) - - if ip and len(device_sn_list) >= 1 and len(system_dict.keys()) >= 1: - for sn_str in device_sn_list: + ip_list, port_list, sn_list = get_config_ip_info(os.path.join(developer_test_path, "config/user_config.xml")) + if not port_list: + port_list = ["8710"] * len(ip_list) + # sn_list = [] + # if sn: + # sn_list.extend(sn.replace(" ", "").split(";")) + # else: + # sn_list = get_sn_list("hdc -s %s:%s list targets" % (ip, port)) + if not sn_list: + for i in range(list(ip_list)): + ip = ip_list[i] + port = port_list[i] + sn_list.extend(get_sn_list("hdc -s %s:%s list targets" % (ip, port))) + + if ip and len(sn_list) >= 1 and len(system_dict.keys()) >= 1: + for sn_str in sn_list: get_service_list(ip, sn_str, system_dict, services_dict, component_dict, developer_test_path, service_path, root_path, port) restore_config(ip, port, sn_str, config_path) -- Gitee From e724eb4ed5f6ca4ab6665a22d66961a36342a503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=9B=BD=E8=BE=89?= Date: Wed, 28 May 2025 10:45:38 +0800 Subject: [PATCH 2/7] =?UTF-8?q?Signed-off-by:=20=E9=BB=84=E5=9B=BD?= =?UTF-8?q?=E8=BE=89=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- local_coverage/resident_service/init_gcov.py | 4 +-- .../resident_service/public_method.py | 26 +++++++++++++++++++ .../resident_service/pull_service_gcda.py | 4 +-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/local_coverage/resident_service/init_gcov.py b/local_coverage/resident_service/init_gcov.py index e414e76..e3579d5 100644 --- a/local_coverage/resident_service/init_gcov.py +++ b/local_coverage/resident_service/init_gcov.py @@ -23,7 +23,7 @@ import json import sys import time import xml.etree.ElementTree as ET -from public_method import get_server_dict, get_config_ip, get_sn_list +from public_method import get_server_dict, get_config_ip_info, get_sn_list import stat FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL @@ -351,7 +351,7 @@ if __name__ == '__main__': home_paths = '/'.join(root_path.split("/")[:3]) # 获取user_config中的device ip - ip, port, sn = get_config_ip(os.path.join(developer_test_path, "config/user_config.xml")) + ip, port, sn = get_config_ip_info(os.path.join(developer_test_path, "config/user_config.xml")) if not port: port = "8710" sn_list = [] diff --git a/local_coverage/resident_service/public_method.py b/local_coverage/resident_service/public_method.py index 1cca156..ad728ec 100644 --- a/local_coverage/resident_service/public_method.py +++ b/local_coverage/resident_service/public_method.py @@ -45,6 +45,32 @@ def get_config_ip(filepath): return ip_config, port, sn +def get_config_ip_info(filepath): + ip_config_list = [] + sn_list = [] + port_list = [] + try: + data_dic = {} + if os.path.exists(filepath): + tree = ET.parse(filepath) + root = tree.getroot() + for node in root.findall("environment/device"): + if node.attrib["type"] != "usb-hdc": + continue + for sub in node: + data_dic[sub.tag] = sub.text if sub.text else "" + + for sub in node: + if sub.tag == "info": + ip_config = sub.attrib["ip"] if sub.attrib["ip"] else "" + port = sub.attrib["port"] if sub.attrib["port"] else "" + sn = sub.attrib["sn"] if sub.attrib["sn"] else "" + except ET.ParseError as xml_exception: + print("occurs exception:{}".format(xml_exception.args)) + + return ip_config, port, sn + + def get_sn_list(command): device_sn_list = [] # 执行查询设备sn号命令并获取执行结果 diff --git a/local_coverage/resident_service/pull_service_gcda.py b/local_coverage/resident_service/pull_service_gcda.py index d3f740f..da60d54 100644 --- a/local_coverage/resident_service/pull_service_gcda.py +++ b/local_coverage/resident_service/pull_service_gcda.py @@ -19,7 +19,7 @@ import os import sys -from public_method import get_server_dict, get_config_ip, get_sn_list +from public_method import get_server_dict, get_config_ip_info, get_sn_list def _init_sys_config(): @@ -148,7 +148,7 @@ if __name__ == '__main__': # 获取子系统部件与服务的关系 system_dict, services_dict, component_dict = get_server_dict(command_str) - ip, port, sn = get_config_ip(os.path.join(developer_test_path, "config/user_config.xml")) + ip, port, sn = get_config_ip_info(os.path.join(developer_test_path, "config/user_config.xml")) if not port: port = "8710" device_sn_list = [] -- Gitee From 911bcd25d26f2111e0d9f70ac5a85bc4f8fec26f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=9B=BD=E8=BE=89?= Date: Wed, 28 May 2025 12:25:01 +0800 Subject: [PATCH 3/7] =?UTF-8?q?Signed-off-by:=20=E9=BB=84=E5=9B=BD?= =?UTF-8?q?=E8=BE=89=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- local_coverage/push_coverage_so/push_coverage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/local_coverage/push_coverage_so/push_coverage.py b/local_coverage/push_coverage_so/push_coverage.py index bb75224..4d82f23 100644 --- a/local_coverage/push_coverage_so/push_coverage.py +++ b/local_coverage/push_coverage_so/push_coverage.py @@ -152,7 +152,7 @@ if __name__ == "__main__": current_path = os.path.abspath(os.path.dirname(__name__)) _init_sys_config() - from local_coverage.resident_service.public_method import get_config_ip, get_sn_list + from local_coverage.resident_service.public_method import get_config_ip_info, get_sn_list from local_coverage.utils import get_product_name, hdc_command, tree_find_file_endswith,\ json_parse, logger, is_elffile @@ -161,7 +161,7 @@ if __name__ == "__main__": developer_path = os.path.join(root_path, "test", "testfwk", "developer_test") # 获取远程映射相关hdc参数 - device_ip, device_port, device_sn_strs = get_config_ip(os.path.join(developer_path, "config", "user_config.xml")) + device_ip, device_port, device_sn_strs = get_config_ip_info(os.path.join(developer_path, "config", "user_config.xml")) if not device_port: device_port = "8710" if not device_sn_strs: -- Gitee From 6ed7128925bbc05129f2e41a5d9821a0d3aa59fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=9B=BD=E8=BE=89?= Date: Wed, 28 May 2025 12:34:35 +0800 Subject: [PATCH 4/7] =?UTF-8?q?Signed-off-by:=20=E9=BB=84=E5=9B=BD?= =?UTF-8?q?=E8=BE=89=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- local_coverage/resident_service/init_gcov.py | 45 +++++++++---------- .../resident_service/pull_service_gcda.py | 4 +- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/local_coverage/resident_service/init_gcov.py b/local_coverage/resident_service/init_gcov.py index 0f68079..062d525 100644 --- a/local_coverage/resident_service/init_gcov.py +++ b/local_coverage/resident_service/init_gcov.py @@ -315,30 +315,27 @@ def split_foundation_services(developer_path, system_info_dict, home_path, hdc_d return -def modify_cfg_xml_file(developer_path, device_ip_list, device_sn_list, - system_info_dict, home_path, device_port_list): - for i in range(len(device_ip_list)): - device_ip = device_ip_list[i] - device_port = device_port_list[i] - if device_ip and len(device_sn_list) >= 1: - for device_sn_str in device_sn_list: - hdc_str = "hdc -s %s:%s -t %s" % (device_ip, device_port, device_sn_str) - hdc_dict = {"device_ip": device_ip, "device_port": device_port, "device_sn_str": device_sn_str} - modify_init_file(developer_path, hdc_str) - modify_faultloggerd_file( - developer_path, hdc_str) - # 推送服务对应的配置文件 - split_foundation_services(developer_path, system_info_dict, home_path, hdc_dict) - logger("{} shell reboot".format(hdc_str), "INFO") - coverage_command("%s shell reboot > /dev/null 2>&1" % hdc_str) - while True: - after_sn_list = get_sn_list("hdc -s %s:%s list targets" % (device_ip, device_port)) - time.sleep(10) - if device_sn_str in after_sn_list: - break - coverage_command("%s shell getenforce" % hdc_str) - else: - logger("user_config.xml device ip not config", "ERROR") +def modify_cfg_xml_file(developer_path, device_ip, device_sn_list, + system_info_dict, home_path, device_port): + if device_ip and len(device_sn_list) >= 1: + for device_sn_str in device_sn_list: + hdc_str = "hdc -s %s:%s -t %s" % (device_ip, device_port, device_sn_str) + hdc_dict = {"device_ip": device_ip, "device_port": device_port, "device_sn_str": device_sn_str} + modify_init_file(developer_path, hdc_str) + modify_faultloggerd_file( + developer_path, hdc_str) + # 推送服务对应的配置文件 + split_foundation_services(developer_path, system_info_dict, home_path, hdc_dict) + logger("{} shell reboot".format(hdc_str), "INFO") + coverage_command("%s shell reboot > /dev/null 2>&1" % hdc_str) + while True: + after_sn_list = get_sn_list("hdc -s %s:%s list targets" % (device_ip, device_port)) + time.sleep(10) + if device_sn_str in after_sn_list: + break + coverage_command("%s shell getenforce" % hdc_str) + else: + logger("user_config.xml device ip not config", "ERROR") if __name__ == '__main__': diff --git a/local_coverage/resident_service/pull_service_gcda.py b/local_coverage/resident_service/pull_service_gcda.py index 4a94b29..da60d54 100644 --- a/local_coverage/resident_service/pull_service_gcda.py +++ b/local_coverage/resident_service/pull_service_gcda.py @@ -157,8 +157,8 @@ if __name__ == '__main__': else: device_sn_list = get_sn_list("hdc -s %s:%s list targets" % (ip, port)) - if ip and len(sn_list) >= 1 and len(system_dict.keys()) >= 1: - for sn_str in sn_list: + if ip and len(device_sn_list) >= 1 and len(system_dict.keys()) >= 1: + for sn_str in device_sn_list: get_service_list(ip, sn_str, system_dict, services_dict, component_dict, developer_test_path, service_path, root_path, port) restore_config(ip, port, sn_str, config_path) -- Gitee From ac02e9b5ba53137349570bb9020c18da8e25e0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=9B=BD=E8=BE=89?= Date: Wed, 28 May 2025 12:38:15 +0800 Subject: [PATCH 5/7] =?UTF-8?q?Signed-off-by:=20=E9=BB=84=E5=9B=BD?= =?UTF-8?q?=E8=BE=89=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- local_coverage/resident_service/init_gcov.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/local_coverage/resident_service/init_gcov.py b/local_coverage/resident_service/init_gcov.py index 062d525..e3579d5 100644 --- a/local_coverage/resident_service/init_gcov.py +++ b/local_coverage/resident_service/init_gcov.py @@ -364,5 +364,5 @@ if __name__ == '__main__': system_dict, _, _ = get_server_dict(command_str) # 修改设备init.cfg, faultloggerd.cfg等文件 - modify_cfg_xml_file(developer_test_path, ip_list, sn_list, - system_dict, home_paths, port_list) + modify_cfg_xml_file(developer_test_path, ip, sn_list, + system_dict, home_paths, port) -- Gitee From f7dff475f0418b0aaff89d953acb03728d62aa11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=9B=BD=E8=BE=89?= Date: Wed, 28 May 2025 20:23:02 +0800 Subject: [PATCH 6/7] =?UTF-8?q?Signed-off-by:=20=E9=BB=84=E5=9B=BD?= =?UTF-8?q?=E8=BE=89=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resident_service/public_method.py | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/local_coverage/resident_service/public_method.py b/local_coverage/resident_service/public_method.py index ad728ec..5933b0c 100644 --- a/local_coverage/resident_service/public_method.py +++ b/local_coverage/resident_service/public_method.py @@ -46,29 +46,28 @@ def get_config_ip(filepath): def get_config_ip_info(filepath): - ip_config_list = [] - sn_list = [] - port_list = [] + ip_config = "" + sn = "" + port = "" try: data_dic = {} - if os.path.exists(filepath): - tree = ET.parse(filepath) - root = tree.getroot() - for node in root.findall("environment/device"): - if node.attrib["type"] != "usb-hdc": + if not os.path.exists(filepath): + return ip_config, port, sn + tree = ET.parse(filepath) + root = tree.getroot() + for node in root.findall("environment/device"): + if node.attrib["type"] != "usb-hdc": + continue + for sub in node: + if sub.tag != "info": continue - for sub in node: - data_dic[sub.tag] = sub.text if sub.text else "" - - for sub in node: - if sub.tag == "info": - ip_config = sub.attrib["ip"] if sub.attrib["ip"] else "" - port = sub.attrib["port"] if sub.attrib["port"] else "" - sn = sub.attrib["sn"] if sub.attrib["sn"] else "" + ip_config = sub.attrib["ip"] + port = sub.attrib["port"] + sn = sub.attrib["sn"] except ET.ParseError as xml_exception: print("occurs exception:{}".format(xml_exception.args)) - - return ip_config, port, sn + finally: + return ip_config, port, sn def get_sn_list(command): -- Gitee From f12c654100c7845c41a713971ba2346af7f0e4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=9B=BD=E8=BE=89?= Date: Thu, 29 May 2025 09:27:36 +0800 Subject: [PATCH 7/7] =?UTF-8?q?Signed-off-by:=20=E9=BB=84=E5=9B=BD?= =?UTF-8?q?=E8=BE=89=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resident_service/public_method.py | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/local_coverage/resident_service/public_method.py b/local_coverage/resident_service/public_method.py index 5933b0c..386fc1a 100644 --- a/local_coverage/resident_service/public_method.py +++ b/local_coverage/resident_service/public_method.py @@ -49,25 +49,27 @@ def get_config_ip_info(filepath): ip_config = "" sn = "" port = "" + if not os.path.exists(filepath): + return ip_config, port, sn try: data_dic = {} - if not os.path.exists(filepath): - return ip_config, port, sn tree = ET.parse(filepath) root = tree.getroot() for node in root.findall("environment/device"): - if node.attrib["type"] != "usb-hdc": + if node.attrib["type"] == "usb-hdc": + break + for sub in node: + if sub.tag != "info": continue - for sub in node: - if sub.tag != "info": - continue - ip_config = sub.attrib["ip"] - port = sub.attrib["port"] - sn = sub.attrib["sn"] + ip_config = sub.attrib["ip"] + port = sub.attrib["port"] + sn = sub.attrib["sn"] except ET.ParseError as xml_exception: print("occurs exception:{}".format(xml_exception.args)) - finally: - return ip_config, port, sn + except KeyError as err: + print(f"Key error: {err}") + + return ip_config, port, sn def get_sn_list(command): -- Gitee