fix(deploy): include legacy longconn profile during migration checks
The exported live-deployment baseline declares longconn under a Compose profile. Default profile filtering can omit the already-running receiver and make preflight report an unexpected service set. Explicitly select only the known longconn profile for config and targeted migration commands. Preserve strict service-set validation and report only missing/extra service names, never resolved environment or secrets. Up still targets connector/router with --no-deps, without starting another receiver. Add regressions for profiled service omission and safe mismatch diagnostics. Validation: 242 passed, 3 skipped (no real PostgreSQL), 30 existing dependency warnings. Tool-specific coverage: 29 passed. Python 3.7 syntax and diff pass. Actual ECS preflight must be rerun to verify its current service set; no remote configuration, key material or running containers were changed.
This commit is contained in:
@@ -170,3 +170,11 @@ Windows / Python 3.12.10,平台桩、临时证书/密钥、SQLite及带Lua的F
|
||||
本地新增工具策略测试26项,覆盖7份配置保留、独立旧镜像、准备不启动服务、密钥不覆盖、路径/配置漂移、私有入口拒绝、产品权限格式、候选失败不标就绪、候选换标签拒绝、客户端就绪门槛、离线构建和仅重建两服务。最后完整回归:**239 passed,3 skipped,30 warnings**(46.94秒);跳过项需要真实PostgreSQL,warnings仍为旧依赖弃用提示。宿主脚本通过Python3.7语法兼容检查、CLI help及diff检查。
|
||||
|
||||
测试中Docker命令均为受控桩,不声称实际执行Compose合并、ARM64构建或密钥挂载。真实Compose/ARM64、PostgreSQL/Redis、多用户平台、客户端升级和密钥恢复仍待执行,因此阶段5总体尚未验收完成。
|
||||
|
||||
### 现机预检查兼容修订
|
||||
|
||||
用户已通过HTTP拉取da1b423,执行只读preflight返回unexpected Compose services;未创建密钥或重启。核对原导出compose.yaml发现longconn带`profiles: [longconn]`,而首版脚本未指定profile,存在漏解析该服务的明确兼容缺口。
|
||||
|
||||
修订Compose命令统一显式指定`--profile longconn`,不启用未知profile;保留服务集合严格校验并在不符时仅输出missing/extra服务名。后续up仍限connector/router且带--no-deps。新增3项回归模拟被profile隐藏的服务及缺失/多出服务的安全诊断,本地工具测试29项通过;现机实际解析结果仍需更新后重跑确认,不将该推断当作已经现场复现的唯一原因。
|
||||
|
||||
修订后完整本地回归:**242 passed,3 skipped,30 warnings**(48.50秒)。跳过与warnings类型同上,宿主脚本Python3.7语法及diff检查通过。
|
||||
|
||||
@@ -29,6 +29,8 @@ sudo python3 deployable/scripts/broker_deploy.py preflight \
|
||||
|
||||
脚本只依赖Python标准库(Python≥3.7)及现有Docker/Compose,不要求服务器安装本机开发venv、pytest或cryptography。`preflight`读取容器/镜像/Compose,仅输出项目、文件数量、实际镜像及模式,不打印解析后的配置、Secret或Token;不写密钥、不构建、不重启。
|
||||
|
||||
兼容修订:原部署将longconn声明在`longconn` profile。脚本显式携带`--profile longconn`解析完整现有服务集合,而不是默认省略它;不使用`--profile '*'`开放未知服务。预检查仍只读;后续up仍只指定connector/router并使用`--no-deps`,不会因此启动第二个longconn。服务集合不符时报告缺失/多出服务名并停止,不打印环境配置。
|
||||
|
||||
**当前客户端尚未适配v2,执行到这里即可。** 后续prepare/check/build同样不启用新模式,但需要产品权限集合;activate必须等新客户端和测试计划就绪,不能因为代码测试通过就切换现网。
|
||||
|
||||
## 3. 产品权限与准备阶段
|
||||
|
||||
@@ -61,7 +61,8 @@ def service(project, name):
|
||||
|
||||
def compose(plan, override=None):
|
||||
args = ["docker", "compose", "--project-directory", plan["deployment_root"],
|
||||
"--env-file", str(Path(plan["deployment_root"])/".env"), "-p", plan["project"]]
|
||||
"--env-file", str(Path(plan["deployment_root"])/".env"), "-p", plan["project"],
|
||||
"--profile", "longconn"]
|
||||
for file in plan["compose_files"]:
|
||||
args.extend(["-f", file])
|
||||
if override:
|
||||
@@ -69,6 +70,14 @@ def compose(plan, override=None):
|
||||
return args
|
||||
|
||||
|
||||
def require_services(names):
|
||||
expected = {"connector","router","longconn","enrollment-signer","postgres","redis","edge"}
|
||||
if set(names) != expected:
|
||||
# Service names only, never resolved environment/configuration contents.
|
||||
raise DeployError("unexpected Compose services; missing="+json.dumps(sorted(expected-set(names)))
|
||||
+"; extra="+json.dumps(sorted(set(names)-expected)))
|
||||
|
||||
|
||||
def profiles_from(path):
|
||||
try:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
@@ -86,8 +95,8 @@ def profiles_from(path):
|
||||
|
||||
def validate_overlay(base, merged, candidate):
|
||||
old, new = base["services"], merged["services"]
|
||||
if set(old) != set(new) or set(old) != {"connector","router","longconn","enrollment-signer","postgres","redis","edge"}:
|
||||
raise DeployError("unexpected Compose services; migration requires review")
|
||||
require_services(old)
|
||||
require_services(new)
|
||||
for name in set(old)-{"connector","router"}:
|
||||
if old[name] != new[name]:
|
||||
raise DeployError("overlay changes an unrelated relay service: "+name)
|
||||
@@ -147,8 +156,7 @@ def preflight(args):
|
||||
"compose_files":[str(p) for p in files]}
|
||||
base = run(compose(plan)+["config","--format","json"],True)
|
||||
names = set(base["services"])
|
||||
if names != {"connector","router","longconn","enrollment-signer","postgres","redis","edge"}:
|
||||
raise DeployError("unexpected Compose services")
|
||||
require_services(names)
|
||||
architecture = run(["docker","image","inspect",current["image"],"--format","{{.Architecture}}"])
|
||||
if architecture != "arm64":
|
||||
raise DeployError("expected current ARM64 runtime")
|
||||
@@ -158,6 +166,7 @@ def preflight(args):
|
||||
env = base["services"]["connector"].get("environment",{})
|
||||
print("Project: "+plan["project"])
|
||||
print("Compose files: "+str(len(files)))
|
||||
print("Compose profile included: longconn (configuration parsing; no service startup)")
|
||||
print("Current credential mode: "+env.get("HN_CREDENTIAL_MODE","legacy"))
|
||||
print("Preflight complete; no files, keys or services changed. Resolved settings withheld.")
|
||||
|
||||
|
||||
@@ -91,6 +91,43 @@ def test_preflight_is_read_only_and_redacted(scenario,capsys):
|
||||
assert not any("up" in c or "build" in c or "tag" in c for c in scenario["calls"])
|
||||
|
||||
|
||||
def test_legacy_longconn_profile_included_without_enabling_all_profiles(scenario,monkeypatch):
|
||||
original = deploy.run
|
||||
def profiled(args,*a,**kw):
|
||||
result = original(args,*a,**kw)
|
||||
if args[:2] == ["docker","compose"] and "config" in args:
|
||||
# Mirror Compose's omission of disabled profile services.
|
||||
result["services"]["longconn"]["profiles"] = ["longconn"]
|
||||
if "--profile" not in args or args[args.index("--profile")+1] != "longconn":
|
||||
result["services"].pop("longconn")
|
||||
return result
|
||||
monkeypatch.setattr(deploy,"run",profiled)
|
||||
deploy.preflight(scenario["args"])
|
||||
plan = prepared(scenario)
|
||||
deploy.check(scenario["output"],plan)
|
||||
deploy.build(scenario["output"],plan)
|
||||
deploy.activate(scenario["output"],plan,True)
|
||||
for command in scenario["calls"]:
|
||||
if command[:2] == ["docker","compose"]:
|
||||
assert command[command.index("--profile")+1] == "longconn"
|
||||
assert "*" not in command
|
||||
if "up" in command:
|
||||
assert command[-2:] == ["connector","router"] and "--no-deps" in command
|
||||
|
||||
|
||||
@pytest.mark.parametrize("missing,extra", [("longconn",None),(None,"unexpected-service")])
|
||||
def test_service_mismatch_reports_only_names_and_still_stops(scenario,missing,extra):
|
||||
if missing:
|
||||
scenario["base"]["services"].pop(missing)
|
||||
if extra:
|
||||
scenario["base"]["services"][extra] = {"environment":{"SECRET":"synthetic-do-not-print"}}
|
||||
with pytest.raises(deploy.DeployError) as error:
|
||||
deploy.preflight(scenario["args"])
|
||||
assert (missing or extra) in str(error.value)
|
||||
assert "synthetic" not in str(error.value)
|
||||
assert not scenario["output"].exists()
|
||||
|
||||
|
||||
def test_prepare_preserves_all_seven_files_runtime_identity_and_no_service_changes(scenario,capsys):
|
||||
original = (scenario["live"]/".env").read_bytes()
|
||||
plan = prepared(scenario)
|
||||
|
||||
Reference in New Issue
Block a user