修复IWDG超时未配置与dhara resume回滚:看门狗误复位与复位后写入全部丢失,台架全量自检PASS
This commit is contained in:
+31
-11
@@ -86,31 +86,51 @@ def _tool_cmd(py, cmd, *rest, timeout=15):
|
||||
return data, out
|
||||
|
||||
|
||||
def _ftp_quit(ftp):
|
||||
"""尽力关闭 FTP 控制连接(QUIT 失败不影响判定)。"""
|
||||
try:
|
||||
ftp.quit()
|
||||
except (OSError, ftplib.Error):
|
||||
pass
|
||||
|
||||
|
||||
def _fetch_selftest_log(device_ip, out_dir, stamp):
|
||||
"""从设备 FTP 抓取 /log/selftest.log(lftpd :21 匿名,根目录 = 卷根)。
|
||||
|
||||
成功返回本地路径字符串;失败(网络不可达 / FTP 错误 / 设备侧文件缺失)返回 ""
|
||||
(按 S7 语义视为无故障记录;此处打 WARN,调用方不判整体 FAIL)。
|
||||
|
||||
2026-10-02 台架修复:原实现只 `except OSError`,而 ftplib 的 error_temp /
|
||||
error_perm 继承自 Exception 而非 OSError —— 台账"仅故障才写",干净设备上
|
||||
/log/selftest.log 根本不存在,RETR 返回 450 直接抛出未捕获异常,令整个
|
||||
`@test --require-selftest-pass` 在最后一步崩掉(而它本该是 PASS 路径)。
|
||||
现把"设备侧无此文件"单列为正常路径(INFO),其余 FTP 错误保留 WARN。
|
||||
"""
|
||||
local = Path(out_dir) / "selftest_log_{}.log".format(stamp)
|
||||
ftp = ftplib.FTP()
|
||||
try:
|
||||
ftp = ftplib.FTP()
|
||||
ftp.connect(device_ip, 21, timeout=10)
|
||||
ftp.login() # 匿名(lftpd 接受 USER anonymous / 空 PASS)
|
||||
buf = bytearray()
|
||||
ftp.retrbinary("RETR /log/selftest.log", buf.extend)
|
||||
try:
|
||||
ftp.quit()
|
||||
except OSError:
|
||||
pass
|
||||
local.write_bytes(bytes(buf))
|
||||
print("SELFTEST_FETCH: {} -> {} ({} bytes)".format(device_ip, local, len(buf)))
|
||||
return str(local)
|
||||
except OSError as e:
|
||||
except (OSError, ftplib.Error) as e:
|
||||
print("RUN_TEST_WARN: selftest fetch failed: {} "
|
||||
"(按 S7 语义视为无记录;设备网络/FTP 需另行排查)".format(e))
|
||||
return ""
|
||||
|
||||
buf = bytearray()
|
||||
try:
|
||||
ftp.retrbinary("RETR /log/selftest.log", buf.extend)
|
||||
except ftplib.all_errors as e:
|
||||
# 450/550 = 设备侧无此文件:干净台账,S7 判 PASS(正常路径,非故障)
|
||||
print("SELFTEST_FETCH: {} -> (ledger absent: {}) 按 S7 视为无故障记录"
|
||||
.format(device_ip, str(e).strip()))
|
||||
_ftp_quit(ftp)
|
||||
return ""
|
||||
|
||||
_ftp_quit(ftp)
|
||||
local.write_bytes(bytes(buf))
|
||||
print("SELFTEST_FETCH: {} -> {} ({} bytes)".format(device_ip, local, len(buf)))
|
||||
return str(local)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
# 控制台输出固定 UTF-8:Windows 代码页只影响显示,不会让脚本崩溃
|
||||
|
||||
Reference in New Issue
Block a user