Wait for B2 Core readiness and reconcile exact failed foundation002
This commit is contained in:
@@ -2962,6 +2962,9 @@ GITEA_SALVAGE_UNSUPPORTED_SCHEMA_TABLES = tuple(
|
||||
)
|
||||
|
||||
COMPONENTS = {
|
||||
"device-b2-foundation-reconciliation": {
|
||||
"payload_root": DEVICE_PLANE_ROOT, "artifact_only": True, "services": (),
|
||||
},
|
||||
"device-b2-foundation": {
|
||||
"payload_root": DEVICE_PLANE_ROOT, "compose_root": DEVICE_PLANE_ROOT,
|
||||
"compose_project": "nodedc-device-plane", "compose_no_deps": True,
|
||||
@@ -4988,6 +4991,10 @@ def denied_payload_path(component, rel):
|
||||
|
||||
def allowed_payload_path(component, rel):
|
||||
validate_posix_path(rel)
|
||||
if component == "device-b2-foundation-reconciliation":
|
||||
if rel in ("deployment", DEVICE_B2_RECON_ENTRY):
|
||||
return True
|
||||
die("Device B2 reconciliation accepts only its fixed descriptor")
|
||||
if component == "device-b2-foundation":
|
||||
if rel in ("deployment", *DEVICE_B2_ENTRIES):
|
||||
return True
|
||||
@@ -11624,6 +11631,8 @@ def load_artifact(artifact, work_dir):
|
||||
die(f"files.txt entry missing in payload: {rel}")
|
||||
|
||||
validate_payload_tree(manifest["component"], payload_dir, entries)
|
||||
if manifest["component"] == "device-b2-foundation-reconciliation":
|
||||
validate_device_b2_reconciliation_payload(payload_dir, entries, manifest["id"])
|
||||
if manifest["component"] == "device-b2-foundation":
|
||||
validate_device_b2_payload(payload_dir, entries, manifest["id"])
|
||||
if manifest["component"] == "device-core-network-priority":
|
||||
@@ -22484,6 +22493,10 @@ def is_platform_provider_catalog_only(entries):
|
||||
|
||||
|
||||
def component_services(component, entries=None):
|
||||
if component == "device-b2-foundation-reconciliation":
|
||||
if tuple(entries or ()) != (DEVICE_B2_RECON_ENTRY,):
|
||||
die("Device B2 reconciliation requires the exact descriptor entry")
|
||||
return ()
|
||||
if component == "device-b2-foundation":
|
||||
if tuple(entries or ()) != DEVICE_B2_ENTRIES:
|
||||
die("Device B2 foundation requires all three exact entries")
|
||||
@@ -33321,6 +33334,8 @@ def plan_artifact(artifact):
|
||||
gitea_salvage_preflight = None
|
||||
with tempfile.TemporaryDirectory(prefix="plan-", dir=TMP_DIR) as tmp:
|
||||
manifest, entries, payload_dir = load_artifact(artifact, Path(tmp))
|
||||
if manifest["component"] == "device-b2-foundation-reconciliation":
|
||||
preflight_device_b2_reconciliation(payload_dir, entries, manifest["id"])
|
||||
if manifest["component"] == "device-b2-foundation":
|
||||
preflight_device_b2(payload_dir, entries, manifest["id"])
|
||||
print("device_b2_scope=core-only;same-image;build=none;new-ports=none")
|
||||
@@ -39517,6 +39532,11 @@ process.stdout.write('engine-l2-closed-loop:0.7.0:cas+safe-profile+external-plan
|
||||
|
||||
|
||||
def run_healthchecks(component, entries=None, services=None):
|
||||
if component == "device-b2-foundation-reconciliation":
|
||||
if tuple(services or ()) != ():
|
||||
die("Device B2 reconciliation cannot select services")
|
||||
preflight_device_b2_reconciliation(DEVICE_PLANE_ROOT, entries, DEVICE_B2_RECON_ID, marker_installed=True)
|
||||
return
|
||||
if component == "device-b2-foundation":
|
||||
if tuple(entries or ()) != DEVICE_B2_ENTRIES or tuple(services or ()) != ("device-control-core",):
|
||||
die("Device B2 foundation health scope mismatch")
|
||||
@@ -40700,6 +40720,8 @@ def apply_artifact(artifact):
|
||||
compose_root = component_compose_root(component)
|
||||
bootstrap_root = bool(COMPONENTS[component].get("bootstrap_root"))
|
||||
services = component_services(component, entries)
|
||||
if component == "device-b2-foundation-reconciliation":
|
||||
preflight_device_b2_reconciliation(payload_dir, entries, patch_id)
|
||||
if component == "device-b2-foundation":
|
||||
device_b2_before = preflight_device_b2(payload_dir, entries, patch_id)
|
||||
if component == "device-core-network-priority":
|
||||
@@ -41499,6 +41521,12 @@ def apply_artifact(artifact):
|
||||
rollback_status = "ok:device-core-autodeploy-bootstrap"
|
||||
except Exception as rollback_exc:
|
||||
rollback_status = "failed:" + type(rollback_exc).__name__
|
||||
elif component == "device-b2-foundation-reconciliation":
|
||||
try:
|
||||
rollback_device_b2_reconciliation(root, backup_dir, entries, current_stamp)
|
||||
rollback_status = "ok:device-b2-reconciliation-marker-only"
|
||||
except Exception as rollback_exc:
|
||||
rollback_status = "failed:" + type(rollback_exc).__name__
|
||||
elif component == "device-core-release-reconciliation":
|
||||
try:
|
||||
restore_platform_overlay(root, backup_dir, entries, current_stamp)
|
||||
@@ -42805,7 +42833,7 @@ def main(argv):
|
||||
|
||||
|
||||
# Additive external VPS management foundation. The payload never contains keys.
|
||||
DEVICE_B2_ID = 'device-b2-foundation-v1-20260930-002'
|
||||
DEVICE_B2_ID = 'device-b2-foundation-v1-20260930-003'
|
||||
DEVICE_B2_DESCRIPTOR = 'deployment/device-b2-foundation-v1.json'
|
||||
DEVICE_B2_SQL = 'deployment/device-b2-foundation-v1.sql'
|
||||
DEVICE_B2_OVERRIDE = 'docker-compose.device-b2-foundation.yml'
|
||||
@@ -42850,11 +42878,14 @@ def validate_device_b2_payload(root, entries, identity):
|
||||
def device_b2_failed_barrier():
|
||||
for row in load_state(FAILED_STATE_FILE):
|
||||
if (row.get('component') == 'device-b2-foundation' and row.get('started_apply')
|
||||
and row.get('rollback_status') != 'ok:device-b2-foundation'):
|
||||
and row.get('rollback_status') != 'ok:device-b2-foundation'
|
||||
and not device_b2_002_reconciled(row)):
|
||||
die('Device B2 foundation requires failed-state reconciliation')
|
||||
|
||||
|
||||
def device_b2_compose_files(files):
|
||||
# A failed foundation rollback blocks ordinary releases too, even when the
|
||||
# old source files were already restored and no overlay remains.
|
||||
device_b2_failed_barrier()
|
||||
present = [(DEVICE_PLANE_ROOT / p).exists() or (DEVICE_PLANE_ROOT / p).is_symlink() for p in DEVICE_B2_ENTRIES]
|
||||
rows = [r for r in load_state(STATE_FILE) if r.get('component') == 'device-b2-foundation']
|
||||
@@ -43055,6 +43086,9 @@ def validate_installed_device_b2():
|
||||
|
||||
|
||||
def accept_device_b2(before, backup_dir, rollback=False):
|
||||
# Compose "Started" is not readiness. Both the candidate and a restored
|
||||
# generation must pass the existing bounded grace + HTTP checks first.
|
||||
run_healthchecks('device-core-release', DEVICE_RELEASE_ENTRIES, DEVICE_RELEASE_SERVICES)
|
||||
current = device_release_runtime_snapshot_v2()
|
||||
for service, old in before['runtime'].items():
|
||||
new = current[service]
|
||||
@@ -43082,7 +43116,6 @@ def accept_device_b2(before, backup_dir, rollback=False):
|
||||
receipt = read_strict_json(backup_dir / 'device-b2-schema.json','Device B2 schema receipt')
|
||||
if validate_device_b2_schema(device_b2_schema()) != receipt['schemaSha256']:
|
||||
die('Device B2 foundation schema changed after migration')
|
||||
run_healthchecks('device-core-release', DEVICE_RELEASE_ENTRIES, DEVICE_RELEASE_SERVICES)
|
||||
print('device_b2_accept='+('rollback' if rollback else 'private-vault+three-tables')+';ports=preserved;image=preserved;scope=core-only')
|
||||
|
||||
|
||||
@@ -43107,6 +43140,132 @@ def rollback_device_b2(root, backup_dir, entries, stamp, before, runtime_started
|
||||
accept_device_b2(before,backup_dir,rollback=True)
|
||||
|
||||
|
||||
DEVICE_B2_RECON_ID = 'device-b2-foundation-reconciliation-v1-20260930-001'
|
||||
DEVICE_B2_RECON_ENTRY = 'deployment/device-b2-foundation-reconciliation-v1.json'
|
||||
DEVICE_B2_002_ID = 'device-b2-foundation-v1-20260930-002'
|
||||
DEVICE_B2_002_SHA = 'da1c97fb0fd2ed9f50acf198c0492b27a5d7273009c0a85b9231fd8c60a70222'
|
||||
DEVICE_B2_002_BACKUP = 'device-b2-foundation-device-b2-foundation-v1-20260930-002-20260930-164433'
|
||||
DEVICE_B2_002_BACKUP_HASHES = {
|
||||
'device-b2-before.json': '70ba33a7917c75593586758a93ea9c83fb4c0d958544d1bf4d024e7449f684cb',
|
||||
'device-b2-schema.json': '144b3fb60b46ead20570869452d21dd91871fc7049045b3ee969beb9ad9ac34e',
|
||||
'manifest.env': '74917c5b06429307d7b875c01971a7e8e01a52d890ea11ba634357821c96cebf',
|
||||
'files.txt': '83ec615f1fcc5443d7afe89c23b3dcf068f928874d62bc8bfbbc55f04d74bf23',
|
||||
'existing-files.txt': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
|
||||
'missing-files.txt': '83ec615f1fcc5443d7afe89c23b3dcf068f928874d62bc8bfbbc55f04d74bf23',
|
||||
'source-before.tgz': '8d10ddfcb56c0b9e7b3cc4bf39cfcd7623594bbe8d68d1e13bc8115c5796991e',
|
||||
}
|
||||
|
||||
|
||||
def device_b2_002_failed_row():
|
||||
return {'artifact': 'nodedc-' + DEVICE_B2_002_ID + '.tgz.20260930-164433',
|
||||
'backup_id': DEVICE_B2_002_BACKUP, 'component': 'device-b2-foundation',
|
||||
'failed_at': '2026-09-30T13:45:49+00:00', 'id': DEVICE_B2_002_ID,
|
||||
'message': 'Device Core predecessor service is not healthy: device-control-core',
|
||||
'rollback_status': 'failed:DeployError', 'sha256': DEVICE_B2_002_SHA,
|
||||
'started_apply': True, 'status': 'failed'}
|
||||
|
||||
|
||||
def device_b2_reconciliation_descriptor():
|
||||
return {'schemaVersion': 'nodedc.device-b2-foundation-reconciliation.v1',
|
||||
'releaseId': DEVICE_B2_RECON_ID, 'failedReleaseId': DEVICE_B2_002_ID,
|
||||
'failedSha256': DEVICE_B2_002_SHA, 'backupId': DEVICE_B2_002_BACKUP,
|
||||
'mode': 'prove-restored-r14;metadata-only;no-runtime-mutation'}
|
||||
|
||||
|
||||
def validate_device_b2_reconciliation_payload(payload, entries, identity):
|
||||
if tuple(entries or ()) != (DEVICE_B2_RECON_ENTRY,) or identity != DEVICE_B2_RECON_ID:
|
||||
die('Device B2 reconciliation identity/entry mismatch')
|
||||
if read_strict_json(payload / DEVICE_B2_RECON_ENTRY, 'Device B2 reconciliation') != device_b2_reconciliation_descriptor():
|
||||
die('Device B2 reconciliation descriptor mismatch')
|
||||
|
||||
|
||||
def device_b2_002_evidence():
|
||||
expected = device_b2_002_failed_row()
|
||||
failures = load_state(FAILED_STATE_FILE)
|
||||
matching = [r for r in failures if r.get('id') == DEVICE_B2_002_ID or r.get('sha256') == DEVICE_B2_002_SHA]
|
||||
if matching != [expected]:
|
||||
die('Device B2 reconciliation failed journal mismatch')
|
||||
if any(r.get('id') == DEVICE_B2_002_ID or r.get('sha256') == DEVICE_B2_002_SHA for r in load_state(STATE_FILE)):
|
||||
die('Device B2 failed foundation conflicts with applied journal')
|
||||
archive = FAILED_DIR / expected['artifact']
|
||||
if archive.is_symlink() or not archive.is_file() or sha256_file(archive) != DEVICE_B2_002_SHA:
|
||||
die('Device B2 reconciliation failed archive mismatch')
|
||||
backup = BACKUPS_DIR / DEVICE_B2_002_BACKUP
|
||||
if backup.is_symlink() or not backup.is_dir():
|
||||
die('Device B2 reconciliation backup is missing or unsafe')
|
||||
for name, digest in DEVICE_B2_002_BACKUP_HASHES.items():
|
||||
path = backup / name
|
||||
if path.is_symlink() or not path.is_file() or sha256_file(path) != digest:
|
||||
die('Device B2 reconciliation backup digest mismatch: ' + name)
|
||||
existing = read_backup_path_list(backup / 'existing-files.txt')
|
||||
missing = read_backup_path_list(backup / 'missing-files.txt')
|
||||
validate_backup_partition(DEVICE_B2_ENTRIES, existing, missing, 'Device B2 reconciliation')
|
||||
if existing or set(missing) != set(DEVICE_B2_ENTRIES):
|
||||
die('Device B2 reconciliation backup partition mismatch')
|
||||
return read_strict_json(backup / 'device-b2-before.json', 'Device B2 incident baseline', max_bytes=256*1024)
|
||||
|
||||
|
||||
def preflight_device_b2_reconciliation(payload, entries, identity, *, marker_installed=False):
|
||||
validate_device_b2_reconciliation_payload(payload, entries, identity)
|
||||
marker = DEVICE_PLANE_ROOT / DEVICE_B2_RECON_ENTRY
|
||||
if not marker_installed and (marker.exists() or marker.is_symlink()):
|
||||
die('Device B2 reconciliation marker already exists')
|
||||
if marker_installed and (marker.is_symlink() or not marker.is_file()):
|
||||
die('Device B2 reconciliation installed marker is unsafe')
|
||||
before = device_b2_002_evidence()
|
||||
# Reconciliation cannot mask a different incomplete transition.
|
||||
for row in load_state(FAILED_STATE_FILE):
|
||||
if (row.get('component') == 'device-b2-foundation' and row.get('started_apply')
|
||||
and row.get('rollback_status') != 'ok:device-b2-foundation'
|
||||
and row != device_b2_002_failed_row()):
|
||||
die('Device B2 reconciliation found another unresolved foundation')
|
||||
applied = load_state(STATE_FILE)
|
||||
releases = [r for r in applied if r.get('component') == 'device-core-release']
|
||||
if (not releases or releases[-1].get('id') != DEVICE_B2_BASELINE_ID
|
||||
or releases[-1].get('sha256') != DEVICE_B2_BASELINE_SHA
|
||||
or any(r.get('component') == 'device-b2-foundation' for r in applied)):
|
||||
die('Device B2 reconciliation requires the exact restored r14 baseline')
|
||||
if any((DEVICE_PLANE_ROOT / p).exists() or (DEVICE_PLANE_ROOT / p).is_symlink() for p in DEVICE_B2_ENTRIES):
|
||||
die('Device B2 reconciliation retains unexpected foundation files')
|
||||
if DEVICE_B2_SECRET_ROOT.exists() or DEVICE_B2_SECRET_ROOT.is_symlink():
|
||||
die('Device B2 reconciliation retains unexpected private storage')
|
||||
if device_b2_schema():
|
||||
die('Device B2 reconciliation retains unexpected schema; no mutation allowed')
|
||||
accept_device_b2(before, BACKUPS_DIR / DEVICE_B2_002_BACKUP, rollback=True)
|
||||
print('device_b2_reconciliation=restored-r14-proven;services=none;build=none;runtime-mutation=none;schema=absent;vault=absent')
|
||||
return before
|
||||
|
||||
|
||||
def rollback_device_b2_reconciliation(root, backup_dir, entries, stamp):
|
||||
if tuple(entries or ()) != (DEVICE_B2_RECON_ENTRY,):
|
||||
die('Device B2 reconciliation rollback scope mismatch')
|
||||
restore_platform_overlay(root, backup_dir, entries, stamp)
|
||||
if (root / DEVICE_B2_RECON_ENTRY).exists() or (root / DEVICE_B2_RECON_ENTRY).is_symlink():
|
||||
die('Device B2 reconciliation rollback left a marker')
|
||||
|
||||
|
||||
def device_b2_002_reconciled(row):
|
||||
if row != device_b2_002_failed_row():
|
||||
return False
|
||||
marker = DEVICE_PLANE_ROOT / DEVICE_B2_RECON_ENTRY
|
||||
if not marker.exists() and not marker.is_symlink():
|
||||
return False
|
||||
if marker.is_symlink() or not marker.is_file():
|
||||
die('Device B2 reconciliation marker is unsafe')
|
||||
validate_device_b2_reconciliation_payload(DEVICE_PLANE_ROOT, (DEVICE_B2_RECON_ENTRY,), DEVICE_B2_RECON_ID)
|
||||
records = [r for r in load_state(STATE_FILE) if r.get('id') == DEVICE_B2_RECON_ID]
|
||||
if len(records) != 1 or records[0].get('component') != 'device-b2-foundation-reconciliation':
|
||||
die('Device B2 reconciliation marker lacks its unique applied receipt')
|
||||
with tempfile.TemporaryDirectory(prefix='device-b2-reconciled-', dir=TMP_DIR) as tmp:
|
||||
manifest, entries, payload = load_artifact(device_release_applied_archive(records[0]), Path(tmp))
|
||||
if manifest['component'] != 'device-b2-foundation-reconciliation' or manifest['id'] != DEVICE_B2_RECON_ID:
|
||||
die('Device B2 reconciliation archive owner mismatch')
|
||||
if sha256_file(payload / DEVICE_B2_RECON_ENTRY) != sha256_file(marker):
|
||||
die('Device B2 reconciliation installed marker drift')
|
||||
device_b2_002_evidence() # Historical evidence remains immutable after acknowledgement.
|
||||
return True
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user