13f085823Sopenharmony_ci#!/usr/bin/env python3
23f085823Sopenharmony_ci# coding=utf-8
33f085823Sopenharmony_ci
43f085823Sopenharmony_ci#
53f085823Sopenharmony_ci# Copyright (c) 2020-2023 Huawei Device Co., Ltd.
63f085823Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
73f085823Sopenharmony_ci# you may not use this file except in compliance with the License.
83f085823Sopenharmony_ci# You may obtain a copy of the License at
93f085823Sopenharmony_ci#
103f085823Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
113f085823Sopenharmony_ci#
123f085823Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
133f085823Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
143f085823Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
153f085823Sopenharmony_ci# See the License for the specific language governing permissions and
163f085823Sopenharmony_ci# limitations under the License.
173f085823Sopenharmony_ci#
183f085823Sopenharmony_ci
193f085823Sopenharmony_ciimport os
203f085823Sopenharmony_ciimport shutil
213f085823Sopenharmony_ciimport subprocess
223f085823Sopenharmony_ciimport json
233f085823Sopenharmony_ciimport sys
243f085823Sopenharmony_ciimport time
253f085823Sopenharmony_ciimport xml.etree.ElementTree as ET
263f085823Sopenharmony_cifrom public_method import get_server_dict, get_config_ip, get_sn_list
273f085823Sopenharmony_ciimport stat
283f085823Sopenharmony_ci
293f085823Sopenharmony_ciFLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL
303f085823Sopenharmony_ciMODES = stat.S_IWUSR | stat.S_IRUSR
313f085823Sopenharmony_ci
323f085823Sopenharmony_ci
333f085823Sopenharmony_cidef _init_sys_config():
343f085823Sopenharmony_ci    sys.localcoverage_path = os.path.join(current_path, "..")
353f085823Sopenharmony_ci    sys.path.insert(0, sys.localcoverage_path)
363f085823Sopenharmony_ci
373f085823Sopenharmony_ci
383f085823Sopenharmony_cidef modify_init_file(developer_path, hdc_str):
393f085823Sopenharmony_ci    """
403f085823Sopenharmony_ci    /etc/init.cfg文件添加cmds
413f085823Sopenharmony_ci    """
423f085823Sopenharmony_ci    recv_path = os.path.join(developer_path, "local_coverage/resident_service/resources")
433f085823Sopenharmony_ci    print("%s file recv /etc/init.cfg %s" % (hdc_str, recv_path))
443f085823Sopenharmony_ci    coverage_command("%s file recv /etc/init.cfg %s" % (hdc_str, recv_path))
453f085823Sopenharmony_ci    recv_restores_path = os.path.join(recv_path, "restores_environment")
463f085823Sopenharmony_ci    if not os.path.exists(recv_restores_path):
473f085823Sopenharmony_ci        os.mkdir(recv_restores_path)
483f085823Sopenharmony_ci    recv_restores_name = os.path.join(recv_restores_path, "init.cfg")
493f085823Sopenharmony_ci    if not os.path.exists(recv_restores_name):
503f085823Sopenharmony_ci        coverage_command("%s file recv /etc/init.cfg %s" % (hdc_str, recv_restores_path))
513f085823Sopenharmony_ci    else:
523f085823Sopenharmony_ci        print("INFO: file exit", recv_restores_name)
533f085823Sopenharmony_ci
543f085823Sopenharmony_ci    cfg_file_path = os.path.join(recv_path, "init.cfg")
553f085823Sopenharmony_ci    if os.path.exists(cfg_file_path):
563f085823Sopenharmony_ci        with open(cfg_file_path, "r") as fp:
573f085823Sopenharmony_ci            json_data = json.load(fp)
583f085823Sopenharmony_ci
593f085823Sopenharmony_ci        for jobs_list in json_data["jobs"]:
603f085823Sopenharmony_ci            if jobs_list["name"] == "init":
613f085823Sopenharmony_ci                if jobs_list["cmds"][-1] != "export GCOV_FETCH_METHOD FM_SIGNA":
623f085823Sopenharmony_ci                    jobs_list["cmds"].append("mkdir /data/gcov 0777 system system")
633f085823Sopenharmony_ci                    jobs_list["cmds"].append("export GCOV_PREFIX /data/gcov")
643f085823Sopenharmony_ci                    jobs_list["cmds"].append("export GCOV_FETCH_METHOD FM_SIGNA")
653f085823Sopenharmony_ci                else:
663f085823Sopenharmony_ci                    return
673f085823Sopenharmony_ci        json_str = json.dumps(json_data, indent=2)
683f085823Sopenharmony_ci        if os.path.exists(cfg_file_path):
693f085823Sopenharmony_ci            os.remove(cfg_file_path)
703f085823Sopenharmony_ci        with os.fdopen(os.open(cfg_file_path, FLAGS, MODES), 'w') as json_file:
713f085823Sopenharmony_ci            json_file.write(json_str)
723f085823Sopenharmony_ci    else:
733f085823Sopenharmony_ci        print("init.cfg file not exists")
743f085823Sopenharmony_ci        return
753f085823Sopenharmony_ci    print("%s shell mount -o rw,remount / > /dev/null 2>&1" % hdc_str)
763f085823Sopenharmony_ci    coverage_command("%s shell mount -o rw,remount / > /dev/null 2>&1" % hdc_str)
773f085823Sopenharmony_ci    print("%s target mount" % hdc_str)
783f085823Sopenharmony_ci    coverage_command("%s target mount" % hdc_str)
793f085823Sopenharmony_ci    print("%s file send %s %s" % (hdc_str, cfg_file_path, "/etc/"))
803f085823Sopenharmony_ci    coverage_command("%s file send %s %s" % (hdc_str, cfg_file_path, "/etc/"))
813f085823Sopenharmony_ci    coverage_command("%s shell param set persist.appspawn.client.timeout 120 > /dev/null 2>&1" % hdc_str)
823f085823Sopenharmony_ci    return
833f085823Sopenharmony_ci
843f085823Sopenharmony_ci
853f085823Sopenharmony_cidef modify_faultloggerd_file(developer_path, hdc_str):
863f085823Sopenharmony_ci    _, enforce = subprocess.getstatusoutput("%s shell getenforce" % hdc_str)
873f085823Sopenharmony_ci    coverage_command("%s shell mount -o rw,remount /" % hdc_str)
883f085823Sopenharmony_ci    print("%s shell mount -o rw,remount /" % hdc_str)
893f085823Sopenharmony_ci    coverage_command("%s target mount" % hdc_str)
903f085823Sopenharmony_ci    if enforce != "Permissive":
913f085823Sopenharmony_ci        coverage_command("%s shell sed -i 's/enforcing/permissive/g' /system/etc/selinux/config" % hdc_str)
923f085823Sopenharmony_ci
933f085823Sopenharmony_ci    recv_path = os.path.join(developer_path, "local_coverage/resident_service/resources")
943f085823Sopenharmony_ci    print("%s file recv /system/etc/init/faultloggerd.cfg %s" % (hdc_str, recv_path))
953f085823Sopenharmony_ci    coverage_command("%s file recv /system/etc/init/faultloggerd.cfg %s" % (hdc_str, recv_path))
963f085823Sopenharmony_ci
973f085823Sopenharmony_ci    cfg_file_path = os.path.join(recv_path, "faultloggerd.cfg")
983f085823Sopenharmony_ci    if os.path.exists(cfg_file_path):
993f085823Sopenharmony_ci        with open(cfg_file_path, "r") as fp:
1003f085823Sopenharmony_ci            json_data = json.load(fp)
1013f085823Sopenharmony_ci        if json_data.get("jobs") and json_data["jobs"][0]["name"] != "pre-init":
1023f085823Sopenharmony_ci            json_data["jobs"].insert(0, {
1033f085823Sopenharmony_ci                "name": "pre-init",
1043f085823Sopenharmony_ci                "cmds": [
1053f085823Sopenharmony_ci                    "export LD_PRELOAD libcoverage_signal_handler.z.so"
1063f085823Sopenharmony_ci                ]
1073f085823Sopenharmony_ci            })
1083f085823Sopenharmony_ci            json_str = json.dumps(json_data, indent=4)
1093f085823Sopenharmony_ci            if os.path.exists(cfg_file_path):
1103f085823Sopenharmony_ci                os.remove(cfg_file_path)
1113f085823Sopenharmony_ci            with os.fdopen(os.open(cfg_file_path, FLAGS, MODES), 'w') as json_file:
1123f085823Sopenharmony_ci                json_file.write(json_str)
1133f085823Sopenharmony_ci            print("%s file send %s %s" % (hdc_str, cfg_file_path, "/system/etc/init/"))
1143f085823Sopenharmony_ci            coverage_command("%s file send %s %s" % (hdc_str, cfg_file_path, "/system/etc/init/"))
1153f085823Sopenharmony_ci    else:
1163f085823Sopenharmony_ci        print("faultloggerd.cfg file not exists.")
1173f085823Sopenharmony_ci
1183f085823Sopenharmony_ci    return
1193f085823Sopenharmony_ci
1203f085823Sopenharmony_ci
1213f085823Sopenharmony_cidef modify_foundation_xml(serv, config_path, origin_xml) -> str:
1223f085823Sopenharmony_ci    """
1233f085823Sopenharmony_ci    修改foundation.xml文件,删去拆分的进程相关
1243f085823Sopenharmony_ci    :param serv: 拆分进程
1253f085823Sopenharmony_ci    :param config_path: 配置文件路径
1263f085823Sopenharmony_ci    :param origin_xml: 原foundation.xml
1273f085823Sopenharmony_ci    :return: 修改后foundation.xml路径
1283f085823Sopenharmony_ci    """
1293f085823Sopenharmony_ci    lib_list = FoundationServer.lib_dict.get(serv)
1303f085823Sopenharmony_ci
1313f085823Sopenharmony_ci    tree = ET.parse(origin_xml)
1323f085823Sopenharmony_ci    root = tree.getroot()
1333f085823Sopenharmony_ci    loadlibs = root.find("loadlibs")
1343f085823Sopenharmony_ci
1353f085823Sopenharmony_ci    for lib in lib_list:
1363f085823Sopenharmony_ci        for sa in root.findall('systemability'):
1373f085823Sopenharmony_ci            if lib in sa.find('libpath').text:
1383f085823Sopenharmony_ci                root.remove(sa)
1393f085823Sopenharmony_ci        for ll in loadlibs.findall('libpath'):
1403f085823Sopenharmony_ci            if lib in ll.text:
1413f085823Sopenharmony_ci                loadlibs.remove(ll)
1423f085823Sopenharmony_ci
1433f085823Sopenharmony_ci    tree.write(os.path.join(config_path, 'foundation.xml'), encoding='utf-8', xml_declaration=True)
1443f085823Sopenharmony_ci    return os.path.join(config_path, 'foundation.xml')
1453f085823Sopenharmony_ci
1463f085823Sopenharmony_ci
1473f085823Sopenharmony_cidef modify_foundation_json(serv, config_path, origin_json) -> str:
1483f085823Sopenharmony_ci    """
1493f085823Sopenharmony_ci    修改foundation.json文件,删去拆分的进程相关
1503f085823Sopenharmony_ci    :param serv: 拆分进程
1513f085823Sopenharmony_ci    :param config_path: 配置文件路径
1523f085823Sopenharmony_ci    :param origin_json: 原foundation.json
1533f085823Sopenharmony_ci    :return: 修改后foundation.json路径
1543f085823Sopenharmony_ci    """
1553f085823Sopenharmony_ci    lib_list = FoundationServer.lib_dict.get(serv)
1563f085823Sopenharmony_ci
1573f085823Sopenharmony_ci    with open(origin_json, "r", encoding="UTF-8") as f:
1583f085823Sopenharmony_ci        f_dict = json.load(f)
1593f085823Sopenharmony_ci
1603f085823Sopenharmony_ci    tmp_list = list()
1613f085823Sopenharmony_ci    for i in range(len(f_dict["systemability"])):
1623f085823Sopenharmony_ci        if f_dict["systemability"][i]["libpath"] not in lib_list:
1633f085823Sopenharmony_ci            tmp_list.append(f_dict["systemability"][i])
1643f085823Sopenharmony_ci    f_dict["systemability"] = tmp_list
1653f085823Sopenharmony_ci
1663f085823Sopenharmony_ci    new_json = os.path.join(config_path, 'foundation.json')
1673f085823Sopenharmony_ci    if os.path.exists(new_json):
1683f085823Sopenharmony_ci        os.remove(new_json)
1693f085823Sopenharmony_ci    with os.fdopen(os.open(new_json, FLAGS, MODES), 'w') as f:
1703f085823Sopenharmony_ci        json.dump(f_dict, f, indent=4)
1713f085823Sopenharmony_ci
1723f085823Sopenharmony_ci    return new_json
1733f085823Sopenharmony_ci
1743f085823Sopenharmony_ci
1753f085823Sopenharmony_cidef create_service_json(serv, config_path, origin_json) -> str:
1763f085823Sopenharmony_ci    """
1773f085823Sopenharmony_ci    创建进程json
1783f085823Sopenharmony_ci    :param serv: 进程名
1793f085823Sopenharmony_ci    :param config_path:配置文件所在目录
1803f085823Sopenharmony_ci    :param origin_json: 原foundation.json
1813f085823Sopenharmony_ci    :return: json文件路径
1823f085823Sopenharmony_ci    """
1833f085823Sopenharmony_ci    lib_list = FoundationServer.lib_dict.get(serv)
1843f085823Sopenharmony_ci    with open(origin_json, "r", encoding="UTF-8") as f:
1853f085823Sopenharmony_ci        f_dict = json.load(f)
1863f085823Sopenharmony_ci
1873f085823Sopenharmony_ci    tmp_list = list()
1883f085823Sopenharmony_ci    for lib in lib_list:
1893f085823Sopenharmony_ci        for i in range(len(f_dict["systemability"])):
1903f085823Sopenharmony_ci            if f_dict["systemability"][i]["libpath"] == lib:
1913f085823Sopenharmony_ci                tmp_list.append(f_dict["systemability"][i])
1923f085823Sopenharmony_ci    f_dict["systemability"] = tmp_list
1933f085823Sopenharmony_ci    f_dict["process"] = "{}".format(serv)
1943f085823Sopenharmony_ci
1953f085823Sopenharmony_ci    new_json = os.path.join(config_path, '{}.json'.format(serv))
1963f085823Sopenharmony_ci    if os.path.exists(new_json):
1973f085823Sopenharmony_ci        os.remove(new_json)
1983f085823Sopenharmony_ci    with os.fdopen(os.open(new_json, FLAGS, MODES), 'w') as f:
1993f085823Sopenharmony_ci        json.dump(f_dict, f, indent=4)
2003f085823Sopenharmony_ci
2013f085823Sopenharmony_ci    return new_json
2023f085823Sopenharmony_ci
2033f085823Sopenharmony_ci
2043f085823Sopenharmony_cidef create_service_xml(serv, config_path, origin_xml) -> str:
2053f085823Sopenharmony_ci    """
2063f085823Sopenharmony_ci    创建进程xml
2073f085823Sopenharmony_ci    :param serv: 进程名
2083f085823Sopenharmony_ci    :param config_path:配置文件所在目录
2093f085823Sopenharmony_ci    :param origin_xml: 原foundation.xml
2103f085823Sopenharmony_ci    :return: xml文件路径
2113f085823Sopenharmony_ci    """
2123f085823Sopenharmony_ci    lib_list = FoundationServer.lib_dict.get(serv)
2133f085823Sopenharmony_ci
2143f085823Sopenharmony_ci    tree = ET.parse(origin_xml)
2153f085823Sopenharmony_ci    root = tree.getroot()
2163f085823Sopenharmony_ci    loadlibs = root.find("loadlibs")
2173f085823Sopenharmony_ci
2183f085823Sopenharmony_ci    for lib in lib_list:
2193f085823Sopenharmony_ci        for sa in root.findall('systemability'):
2203f085823Sopenharmony_ci            if lib not in sa.find('libpath').text:
2213f085823Sopenharmony_ci                root.remove(sa)
2223f085823Sopenharmony_ci        for lp in loadlibs.findall('libpath'):
2233f085823Sopenharmony_ci            if lib not in lp.text:
2243f085823Sopenharmony_ci                loadlibs.remove(lp)
2253f085823Sopenharmony_ci
2263f085823Sopenharmony_ci    tree.write(os.path.join(config_path, '{}.xml'.format(serv)), encoding='utf-8', xml_declaration=True)
2273f085823Sopenharmony_ci    return os.path.join(config_path, '{}.xml'.format(serv))
2283f085823Sopenharmony_ci
2293f085823Sopenharmony_ci
2303f085823Sopenharmony_cidef create_service_cfg(serv, config_path, origin_cfg) -> str:
2313f085823Sopenharmony_ci    """
2323f085823Sopenharmony_ci    创建进程cfg文件
2333f085823Sopenharmony_ci    :param serv: 进程名
2343f085823Sopenharmony_ci    :param config_path:配置文件所在目录
2353f085823Sopenharmony_ci    :param origin_cfg: 原foundation.cfg
2363f085823Sopenharmony_ci    :return: cfg文件路径
2373f085823Sopenharmony_ci    """
2383f085823Sopenharmony_ci    with open(origin_cfg, "r") as jf:
2393f085823Sopenharmony_ci        json_obj = json.load(jf)
2403f085823Sopenharmony_ci        json_obj["jobs"][0]["name"] = "services:{}".format(serv)
2413f085823Sopenharmony_ci
2423f085823Sopenharmony_ci        json_obj["services"][0]["name"] = "{}".format(serv)
2433f085823Sopenharmony_ci
2443f085823Sopenharmony_ci        path_list = json_obj["services"][0]["path"]
2453f085823Sopenharmony_ci        path_list.remove("/system/profile/foundation.json")
2463f085823Sopenharmony_ci        path_list.append("/system/profile/{}.json".format(serv))
2473f085823Sopenharmony_ci        json_obj["services"][0]["path"] = path_list
2483f085823Sopenharmony_ci
2493f085823Sopenharmony_ci        json_obj["services"][0]["jobs"]["on-start"] = "services:{}".format(serv)
2503f085823Sopenharmony_ci
2513f085823Sopenharmony_ci    cfg_path = os.path.join(config_path, "{}.cfg".format(serv))
2523f085823Sopenharmony_ci    if os.path.exists(cfg_path):
2533f085823Sopenharmony_ci        os.remove(cfg_path)
2543f085823Sopenharmony_ci    with os.fdopen(os.open(cfg_path, FLAGS, MODES), 'w') as r:
2553f085823Sopenharmony_ci        json.dump(json_obj, r, indent=4)
2563f085823Sopenharmony_ci    return cfg_path
2573f085823Sopenharmony_ci
2583f085823Sopenharmony_ci
2593f085823Sopenharmony_cidef remove_configs(config_path):
2603f085823Sopenharmony_ci    """
2613f085823Sopenharmony_ci    清理配置文件目录下的xml和cfg文件
2623f085823Sopenharmony_ci    :param config_path: 配置文件目录
2633f085823Sopenharmony_ci    :return:
2643f085823Sopenharmony_ci    """
2653f085823Sopenharmony_ci    logger("Clear config path...", "INFO")
2663f085823Sopenharmony_ci    shutil.rmtree(config_path)
2673f085823Sopenharmony_ci    os.mkdir(config_path)
2683f085823Sopenharmony_ci
2693f085823Sopenharmony_ci
2703f085823Sopenharmony_cidef split_foundation_services(developer_path, system_info_dict, home_path, hdc_dict):
2713f085823Sopenharmony_ci    """
2723f085823Sopenharmony_ci    foundation.xmlXXX.xml文件推送到 /system/profile
2733f085823Sopenharmony_ci    XXX.cfg文件推送到/etc/init/
2743f085823Sopenharmony_ci    reboot设备,可以将服务从foundation中拆分出来,成为一个独立服务进程
2753f085823Sopenharmony_ci    """
2763f085823Sopenharmony_ci    config_path = os.path.join(developer_path, "local_coverage", "resident_service", "config")
2773f085823Sopenharmony_ci    remove_configs(config_path)
2783f085823Sopenharmony_ci
2793f085823Sopenharmony_ci    device_ip = hdc_dict["device_ip"]
2803f085823Sopenharmony_ci    hdc_port = hdc_dict["device_port"]
2813f085823Sopenharmony_ci    device_sn = hdc_dict["device_sn_str"]
2823f085823Sopenharmony_ci
2833f085823Sopenharmony_ci    hdc_command(device_ip, hdc_port, device_sn, "file recv /system/profile/foundation.json {}".format(config_path))
2843f085823Sopenharmony_ci    hdc_command(device_ip, hdc_port, device_sn, "file recv /etc/init/foundation.cfg {}".format(config_path))
2853f085823Sopenharmony_ci
2863f085823Sopenharmony_ci    if os.path.exists(os.path.join(config_path, "foundation.json")):
2873f085823Sopenharmony_ci        origin_json = os.path.join(config_path, "foundation_origin.json")
2883f085823Sopenharmony_ci        os.rename(os.path.join(config_path, "foundation.json"), origin_json)
2893f085823Sopenharmony_ci    else:
2903f085823Sopenharmony_ci        logger("{} not exist, Cannot modify.".format(os.path.join(config_path, "foundation.json")), "ERROR")
2913f085823Sopenharmony_ci        return
2923f085823Sopenharmony_ci
2933f085823Sopenharmony_ci    if os.path.exists(os.path.join(config_path, "foundation.cfg")):
2943f085823Sopenharmony_ci        origin_cfg = os.path.join(config_path, "foundation_origin.cfg")
2953f085823Sopenharmony_ci        os.rename(os.path.join(config_path, "foundation.cfg"), origin_cfg)
2963f085823Sopenharmony_ci    else:
2973f085823Sopenharmony_ci        logger("{} not exist, Cannot modify.".format(os.path.join(config_path, "foundation.cfg")), "ERROR")
2983f085823Sopenharmony_ci        return
2993f085823Sopenharmony_ci
3003f085823Sopenharmony_ci    foundation_process_list = FoundationServer.lib_dict.keys()
3013f085823Sopenharmony_ci
3023f085823Sopenharmony_ci    # 推送配置文件
3033f085823Sopenharmony_ci    for _, value_list in system_info_dict.items():
3043f085823Sopenharmony_ci        for process_str in value_list:
3053f085823Sopenharmony_ci            if process_str in foundation_process_list:
3063f085823Sopenharmony_ci                foundation_json = modify_foundation_json(process_str, config_path, origin_json)
3073f085823Sopenharmony_ci                service_json = create_service_json(process_str, config_path, origin_json)
3083f085823Sopenharmony_ci                service_cfg = create_service_cfg(process_str, config_path, origin_cfg)
3093f085823Sopenharmony_ci
3103f085823Sopenharmony_ci                hdc_command(device_ip, hdc_port, device_sn, "shell rm -rf {}".format(home_path))
3113f085823Sopenharmony_ci                hdc_command(device_ip, hdc_port, device_sn, "file send {} /system/profile/".format(foundation_json))
3123f085823Sopenharmony_ci                hdc_command(device_ip, hdc_port, device_sn, "file send {} /system/profile/".format(service_json))
3133f085823Sopenharmony_ci                hdc_command(device_ip, hdc_port, device_sn, "file send {} /etc/init/".format(service_cfg))
3143f085823Sopenharmony_ci
3153f085823Sopenharmony_ci    return
3163f085823Sopenharmony_ci
3173f085823Sopenharmony_ci
3183f085823Sopenharmony_cidef modify_cfg_xml_file(developer_path, device_ip, device_sn_list,
3193f085823Sopenharmony_ci                        system_info_dict, home_path, device_port):
3203f085823Sopenharmony_ci    if device_ip and len(device_sn_list) >= 1:
3213f085823Sopenharmony_ci        for device_sn_str in device_sn_list:
3223f085823Sopenharmony_ci            hdc_str = "hdc -s %s:%s -t %s" % (device_ip, device_port, device_sn_str)
3233f085823Sopenharmony_ci            hdc_dict = {"device_ip": device_ip, "device_port": device_port, "device_sn_str": device_sn_str}
3243f085823Sopenharmony_ci            modify_init_file(developer_path, hdc_str)
3253f085823Sopenharmony_ci            modify_faultloggerd_file(
3263f085823Sopenharmony_ci                developer_path, hdc_str)
3273f085823Sopenharmony_ci            # 推送服务对应的配置文件
3283f085823Sopenharmony_ci            split_foundation_services(developer_path, system_info_dict, home_path, hdc_dict)
3293f085823Sopenharmony_ci            logger("{} shell reboot".format(hdc_str), "INFO")
3303f085823Sopenharmony_ci            coverage_command("%s shell reboot > /dev/null 2>&1" % hdc_str)
3313f085823Sopenharmony_ci            while True:
3323f085823Sopenharmony_ci                after_sn_list = get_sn_list("hdc -s %s:%s list targets" % (device_ip, device_port))
3333f085823Sopenharmony_ci                time.sleep(10)
3343f085823Sopenharmony_ci                if device_sn_str in after_sn_list:
3353f085823Sopenharmony_ci                    break
3363f085823Sopenharmony_ci            coverage_command("%s shell getenforce" % hdc_str)
3373f085823Sopenharmony_ci    else:
3383f085823Sopenharmony_ci        logger("user_config.xml device ip not config", "ERROR")
3393f085823Sopenharmony_ci
3403f085823Sopenharmony_ci
3413f085823Sopenharmony_ciif __name__ == '__main__':
3423f085823Sopenharmony_ci    command_args = sys.argv[1]
3433f085823Sopenharmony_ci    command_str = command_args.split("command_str=")[1].replace(",", " ")
3443f085823Sopenharmony_ci    current_path = os.getcwd()
3453f085823Sopenharmony_ci    _init_sys_config()
3463f085823Sopenharmony_ci    from local_coverage.utils import coverage_command, \
3473f085823Sopenharmony_ci        logger, hdc_command, FoundationServer
3483f085823Sopenharmony_ci
3493f085823Sopenharmony_ci    root_path = current_path.split("/test/testfwk/developer_test")[0]
3503f085823Sopenharmony_ci    developer_test_path = os.path.join(root_path, "test/testfwk/developer_test")
3513f085823Sopenharmony_ci    home_paths = '/'.join(root_path.split("/")[:3])
3523f085823Sopenharmony_ci
3533f085823Sopenharmony_ci    # 获取user_config中的device ip
3543f085823Sopenharmony_ci    ip, port, sn = get_config_ip(os.path.join(developer_test_path, "config/user_config.xml"))
3553f085823Sopenharmony_ci    if not port:
3563f085823Sopenharmony_ci        port = "8710"
3573f085823Sopenharmony_ci    sn_list = []
3583f085823Sopenharmony_ci    if sn:
3593f085823Sopenharmony_ci        sn_list.extend(sn.replace(" ", "").split(";"))
3603f085823Sopenharmony_ci    else:
3613f085823Sopenharmony_ci        sn_list = get_sn_list("hdc -s %s:%s list targets" % (ip, port))
3623f085823Sopenharmony_ci
3633f085823Sopenharmony_ci    # 获取子系统部件与服务的关系
3643f085823Sopenharmony_ci    system_dict, _, _ = get_server_dict(command_str)
3653f085823Sopenharmony_ci
3663f085823Sopenharmony_ci    # 修改设备init.cfg, faultloggerd.cfg等文件
3673f085823Sopenharmony_ci    modify_cfg_xml_file(developer_test_path, ip, sn_list,
3683f085823Sopenharmony_ci                        system_dict, home_paths, port)
369