fix(deploy): tolerate absent Docker health state during router recovery
Containers without a configured HEALTHCHECK omit State.Health. Direct map field access in the new inspect template made recovery prechecks fail on longconn/edge before the router path could be repaired. Use a guarded map index and report health=none without weakening image/config/key checks. Distinguish service lookup errors from inspect/template failures instead of misreporting every query failure as no unique container. Identify the container-inspect stage in safe command errors. Add regressions for absent health state through state and the full partial router repair, plus accurate inspect failure classification. Validation: 265 passed, 3 skipped (no real PostgreSQL), 30 existing warnings; tool tests 52 passed. Python 3.7 syntax and staged diff checks pass. No remote keys/configuration or containers were changed; rerun the existing repair-router plan after updating, do not prepare or activate again.
This commit is contained in:
@@ -344,6 +344,50 @@ def test_state_sees_exited_candidate_without_showing_logs_or_secrets(scenario,mo
|
||||
assert not any('up' in c or 'tag' in c for c in scenario['calls'])
|
||||
|
||||
|
||||
def test_containers_without_healthcheck_do_not_break_state_or_router_repair(scenario,monkeypatch,capsys):
|
||||
plan=partial_old_plan(scenario)
|
||||
original=deploy.run
|
||||
inspected=[]
|
||||
def optional_health(args,*a,**kw):
|
||||
if args[:2]==['docker','inspect']:
|
||||
template=args[args.index('--format')+1]
|
||||
name=args[2].replace('container-','').replace('hainuo-relay-','').removesuffix('-1')
|
||||
inspected.append(name)
|
||||
if name in {'longconn','edge'}:
|
||||
# Docker map templates fail on missing .State.Health; index
|
||||
# returns nil and the with/else branch emits health="none".
|
||||
if '.State.Health' in template:
|
||||
raise deploy.DeployError('container-inspect failed; no map entry')
|
||||
assert 'index .State "Health"' in template
|
||||
result=copy.deepcopy(original(args,*a,**kw))
|
||||
result['state']={'status':'running','health':'none','exit_code':0,'restart_count':0}
|
||||
return result
|
||||
return original(args,*a,**kw)
|
||||
monkeypatch.setattr(deploy,'run',optional_health)
|
||||
deploy.deployment_state(scenario['output'],plan)
|
||||
output=capsys.readouterr().out
|
||||
assert 'longconn: image=original status=running health=none' in output
|
||||
assert 'edge: image=original status=running health=none' in output
|
||||
deploy.repair_router(scenario['output'],plan)
|
||||
assert {'longconn','edge','connector','router'}.issubset(inspected)
|
||||
commands=[c for c in scenario['calls'] if 'up' in c]
|
||||
assert len(commands)==1 and commands[0][-1]=='router'
|
||||
|
||||
|
||||
def test_state_does_not_misreport_inspect_failure_as_missing_container(scenario,monkeypatch,capsys):
|
||||
plan=prepared(scenario)
|
||||
original=deploy.run
|
||||
def failure(args,*a,**kw):
|
||||
if args[:2]==['docker','inspect'] and args[2]=='container-edge':
|
||||
raise deploy.DeployError('container-inspect failed')
|
||||
return original(args,*a,**kw)
|
||||
monkeypatch.setattr(deploy,'run',failure)
|
||||
deploy.deployment_state(scenario['output'],plan)
|
||||
output=capsys.readouterr().out
|
||||
assert 'edge: container inspection failed' in output
|
||||
assert 'edge: no unique existing container' not in output
|
||||
|
||||
|
||||
def test_rollback_checks_allow_stopped_known_candidate_but_reject_other_image(scenario):
|
||||
plan=prepared(scenario)
|
||||
scenario['roles']['connector']['image']='sha256:'+'a'*64
|
||||
|
||||
Reference in New Issue
Block a user