fix(chv): 生产级审核 P1-01~P1-10 修复(堆叠于 #270 之上)
This commit is contained in:
1 parent
8c8d62f70d
commit
971e054938
12 files changed
+1545
-120
No files matched your search
+32
-3
@@ -80,15 +80,39 @@ class ChvConfig:
|
||||
def _base_fragment(params: dict, env: dict) -> dict:
|
||||
"""身份/资源基底片段:二进制、内核、根盘、CPU/内存、
|
||||
state_dir、KVM/cpuinfo 路径、ch-remote、模型。无校验,
|
||||
取值口径与旧 build_chv_config 内联 base 逐字一致。"""
|
||||
取值口径与旧 build_chv_config 内联 base 逐字一致,
|
||||
只有一处新增(feat-chv-p1fix,P1-07):能解析出的
|
||||
CPU/内存非正值直接 ValueError,不再一路进 VmConfig
|
||||
到 VMM 侧才炸;解析不出的格式仍留给 preflight 报
|
||||
config_invalid(构造时不改旧报错时机分工)。"""
|
||||
# 显式 cpus=0 不再经 or 链静默回落成 2:0 是非法值,
|
||||
# 应报出来(P1-07);None 仍走 env/默认值。
|
||||
_cpus_raw = params.get("cpus") if params.get("cpus") is not None \
|
||||
else (env.get("CHV_CPU") or "2")
|
||||
cpus = str(_cpus_raw)
|
||||
# 解析不出的格式留给 preflight(旧时机分工不变):
|
||||
# 只对“解析成功且 <=0”的值在这里报,格式错误不报。
|
||||
try:
|
||||
_cpus_parsed = int(cpus)
|
||||
except (TypeError, ValueError):
|
||||
_cpus_parsed = None
|
||||
if _cpus_parsed is not None and _cpus_parsed <= 0:
|
||||
raise ValueError("CHV_CPU 必须是大于 0 的整数")
|
||||
memory = params.get("memory") or env.get("CHV_MEM") or "2G"
|
||||
try:
|
||||
_mem_parsed = _parse_memory_bytes(memory)
|
||||
except ValueError:
|
||||
_mem_parsed = None
|
||||
if _mem_parsed is not None and _mem_parsed <= 0:
|
||||
raise ValueError("CHV_MEM 必须是大于 0")
|
||||
return {
|
||||
"binary": params.get("binary") or env.get("CHV_BINARY")
|
||||
or "cloud-hypervisor",
|
||||
"kernel": params.get("kernel") or env.get("CHV_KERNEL"),
|
||||
"rootfs": params.get("rootfs") or params.get("image")
|
||||
or env.get("CHV_ROOTFS") or env.get("CHV_IMAGE"),
|
||||
"cpus": str(params.get("cpus") or env.get("CHV_CPU") or "2"),
|
||||
"memory": params.get("memory") or env.get("CHV_MEM") or "2G",
|
||||
"cpus": cpus,
|
||||
"memory": memory,
|
||||
"state_dir": params.get("state_dir")
|
||||
or env.get("CHV_STATE_DIR")
|
||||
or os.path.join(os.path.expanduser("~"),
|
||||
@@ -221,6 +245,11 @@ def _timeout_fragment(params: dict, env: dict) -> dict:
|
||||
task_timeout_raw = env.get("CHV_TASK_TIMEOUT")
|
||||
task_timeout = _to_float(task_timeout_raw) \
|
||||
if task_timeout_raw else None
|
||||
# feat-chv-p1fix(P1-07):显式设的任务超时非正即非法。
|
||||
# None = 不限(旧语义,保留);0/负数过去一路进 VmConfig
|
||||
# 相关路径(runner timeout=0/负),现在构造时即 ValueError。
|
||||
if task_timeout is not None and task_timeout <= 0:
|
||||
raise ValueError("CHV_TASK_TIMEOUT 必须是大于 0 的数字")
|
||||
try:
|
||||
api_timeout = _to_float(
|
||||
params.get("api_timeout")
|
||||
|
||||
Reference in new issue
Block a user