From 62647de9eab2a74a736f72cec2eb614d70943a4c Mon Sep 17 00:00:00 2001 From: xuchuan19 Date: Sat, 9 Aug 2025 16:30:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BD=AF=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ascend_deployer/library/install_sys_pkg.py | 6 +++++- ascend_deployer/library/process_hccn.py | 4 +++- ascend_deployer/library/process_test.py | 7 ++++++- ascend_deployer/library/system_report.py | 5 ++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ascend_deployer/library/install_sys_pkg.py b/ascend_deployer/library/install_sys_pkg.py index 6f0213c7..2f2bedf0 100644 --- a/ascend_deployer/library/install_sys_pkg.py +++ b/ascend_deployer/library/install_sys_pkg.py @@ -127,7 +127,11 @@ class SysInstaller: def _modify_conf(self, pattern, repl): if self.os_and_arch in (OSName.BCLINUX_21_10_AARCH64, OSName.BCLINUX_21_10U4_AARCH64): - with open("/etc/dnf/plugins/license-manager.conf", "r+") as f: + file = "/etc/dnf/plugins/license-manager.conf" + if os.path.islink(file): + self.module.fail_json(changed=False, rc=1, + msg="{} should not be a symbolic link file".format(file)) + with open(file, "r+") as f: content = f.read() content = re.sub(pattern, repl, content) f.seek(0) diff --git a/ascend_deployer/library/process_hccn.py b/ascend_deployer/library/process_hccn.py index 8c3f3092..4dc64d51 100644 --- a/ascend_deployer/library/process_hccn.py +++ b/ascend_deployer/library/process_hccn.py @@ -432,7 +432,9 @@ class HCCN(BaseModule): conf = self.template.generate_hccn_conf( basic_info, is_standard_npu_card, gateway_set, mac_addresses) - + if os.path.islink(self._HCCN_CONF_PATH): + self.module.fail_json(changed=False, rc=1, + msg="{} should not be a symbolic link file".format(self._HCCN_CONF_PATH)) fd = os.open(self._HCCN_CONF_PATH, os.O_RDWR | os.O_CREAT | os.O_TRUNC, self._FILE_OPEN_MODE) with os.fdopen(fd, 'w') as f: f.write(conf) diff --git a/ascend_deployer/library/process_test.py b/ascend_deployer/library/process_test.py index 3f0082c1..10cbfe1b 100644 --- a/ascend_deployer/library/process_test.py +++ b/ascend_deployer/library/process_test.py @@ -64,6 +64,8 @@ def info_to_dict(file_path): info_dict = dict() if not os.path.isfile(file_path): return info_dict + if os.path.islink(file_path): + raise Exception("{} should not be a symbolic link file".format(file_path)) with open(os.path.expanduser(file_path)) as fid: for line in fid: split_line = line.split("=") @@ -188,7 +190,10 @@ def test_firmware(): {"LD_LIBRARY_PATH": "/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/common:" "/usr/local/Ascend/driver/lib64/driver:"}) if ok and "succeed" in output: - with open('/usr/local/Ascend/firmware/version.info', 'r') as file: + file_path = '/usr/local/Ascend/firmware/version.info' + if os.path.islink(file_path): + raise Exception("{} should not be a symbolic link file".format(file_path)) + with open(file_path, 'r') as file: content = file.read() pattern = r"Version=(\S+)" match = re.search(pattern, content) diff --git a/ascend_deployer/library/system_report.py b/ascend_deployer/library/system_report.py index 21828b24..090dc17f 100644 --- a/ascend_deployer/library/system_report.py +++ b/ascend_deployer/library/system_report.py @@ -46,6 +46,8 @@ def info_to_dict(file_path): info_dict = dict() if not os.path.isfile(file_path): return info_dict + if os.path.islink(file_path): + raise Exception("{} should not be a symbolic link file".format(file_path)) with open(os.path.expanduser(file_path)) as fid: for line in fid: split_line = line.split("=") @@ -74,6 +76,8 @@ def find_files(dir_path, file_name): def getinfo_from_xml(file_path, root_path): if not os.path.exists(file_path): return {} + if os.path.islink(file_path): + raise Exception("{} should not be a symbolic link file".format(file_path)) with open(file_path, 'r') as f: lines = f.readlines() arches = {'ARM': 'aarch64', 'x86': 'x86_64'} @@ -268,7 +272,6 @@ def main(): for app in app_info.get("result", []): outputs.append("{:<16} {:<16}".format(app['name'], app['version'])) return module.exit_json(changed=True, rc=0, msg="\n".join(outputs)) - with open(os.path.expanduser("~/smartkit/display.json"), 'w') as fid: json.dump(app_info, fid, indent=4) -- Gitee