FIX - NAS DEPLOY: reconcile Foundry map runtime generation
This commit is contained in:
@@ -8,6 +8,7 @@ import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
from contextlib import ExitStack
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
@@ -202,7 +203,7 @@ class ModuleFoundryRuntimeRecoveryTest(unittest.TestCase):
|
||||
RUNNER,
|
||||
"module_foundry_runtime_inventory",
|
||||
side_effect=[candidate, before],
|
||||
),
|
||||
) as inventory,
|
||||
mock.patch.object(
|
||||
RUNNER,
|
||||
"inspect_local_image",
|
||||
@@ -221,6 +222,10 @@ class ModuleFoundryRuntimeRecoveryTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(result, "source+runtime-restored:1")
|
||||
self.assertEqual(
|
||||
inventory.call_args_list[0].kwargs,
|
||||
{"required": False, "require_healthy": False},
|
||||
)
|
||||
process.assert_called_once_with(
|
||||
[
|
||||
str(RUNNER.DOCKER),
|
||||
@@ -264,7 +269,7 @@ class ModuleFoundryRuntimeRecoveryTest(unittest.TestCase):
|
||||
|
||||
def test_recovery_accepts_only_exact_failed_partial_predecessor(self):
|
||||
with tempfile.TemporaryDirectory(
|
||||
prefix="module-foundry-sector-evidence-"
|
||||
prefix="module-foundry-map-evidence-"
|
||||
) as directory:
|
||||
work = Path(directory)
|
||||
backups = work / "backups"
|
||||
@@ -276,43 +281,79 @@ class ModuleFoundryRuntimeRecoveryTest(unittest.TestCase):
|
||||
for path in (backups, failed, state, tmp, installed, candidate):
|
||||
path.mkdir()
|
||||
|
||||
entries = RUNNER.MODULE_FOUNDRY_SECTOR_RECOVERY_ENTRIES
|
||||
for index, rel in enumerate(entries):
|
||||
for root in (installed, candidate):
|
||||
recovery_entries = (
|
||||
"apps/catalog/src",
|
||||
"scripts",
|
||||
"server/map-grid-persistence.test.mjs",
|
||||
)
|
||||
missing_entries = ("server/map-grid-persistence.test.mjs",)
|
||||
failed_entries = (
|
||||
"apps/catalog/src/MapFixturePreview.tsx",
|
||||
"scripts/map-sector-grid.test.mjs",
|
||||
)
|
||||
candidate_files = {
|
||||
"apps/catalog/src/MapFixturePreview.tsx": "sector-current\n",
|
||||
"apps/catalog/src/CesiumMapRenderer.tsx": "renderer-next\n",
|
||||
"scripts/map-sector-grid.test.mjs": "sector-test-current\n",
|
||||
"scripts/map-grid-lod.test.mjs": "grid-test-next\n",
|
||||
"server/map-grid-persistence.test.mjs": "server-test-next\n",
|
||||
}
|
||||
installed_files = {
|
||||
"apps/catalog/src/MapFixturePreview.tsx": "sector-current\n",
|
||||
"apps/catalog/src/CesiumMapRenderer.tsx": "renderer-old\n",
|
||||
"scripts/map-sector-grid.test.mjs": "sector-test-current\n",
|
||||
"scripts/map-grid-lod.test.mjs": "grid-test-old\n",
|
||||
}
|
||||
for root, values in (
|
||||
(candidate, candidate_files),
|
||||
(installed, installed_files),
|
||||
):
|
||||
for rel, value in values.items():
|
||||
path = root / rel
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(f"payload-{index}\n", encoding="utf-8")
|
||||
path.write_text(value, encoding="utf-8")
|
||||
|
||||
backup = backups / RUNNER.MODULE_FOUNDRY_SECTOR_FAILED_BACKUP_ID
|
||||
failed_patch_id = "module-foundry-map-failed-test"
|
||||
failed_artifact_name = "module-foundry-map-failed-test.tgz.1"
|
||||
failed_backup_id = "module-foundry-map-failed-test-backup"
|
||||
recovery_patch_id = "module-foundry-map-recovery-test"
|
||||
failed_message = "test build failed"
|
||||
|
||||
backup = backups / failed_backup_id
|
||||
backup.mkdir()
|
||||
for name in RUNNER.MODULE_FOUNDRY_SECTOR_FAILED_BACKUP_SHA256:
|
||||
backup_names = {
|
||||
"existing-files.txt",
|
||||
"files.txt",
|
||||
"manifest.env",
|
||||
"missing-files.txt",
|
||||
"source-before.tgz",
|
||||
}
|
||||
for name in backup_names:
|
||||
(backup / name).write_text(f"{name}\n", encoding="utf-8")
|
||||
backup_hashes = {
|
||||
name: hashlib.sha256((backup / name).read_bytes()).hexdigest()
|
||||
for name in RUNNER.MODULE_FOUNDRY_SECTOR_FAILED_BACKUP_SHA256
|
||||
for name in backup_names
|
||||
}
|
||||
|
||||
archive_source = work / "archive-source"
|
||||
(archive_source / "payload").mkdir(parents=True)
|
||||
(archive_source / "manifest.env").write_text(
|
||||
"id="
|
||||
f"{RUNNER.MODULE_FOUNDRY_SECTOR_FAILED_PATCH_ID}\n"
|
||||
f"{failed_patch_id}\n"
|
||||
"component=module-foundry\n"
|
||||
"type=app-overlay\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
(archive_source / "files.txt").write_text(
|
||||
"\n".join(entries) + "\n",
|
||||
"\n".join(failed_entries) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
for rel in entries:
|
||||
for rel in failed_entries:
|
||||
source = candidate / rel
|
||||
target = archive_source / "payload" / rel
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(source.read_bytes())
|
||||
failed_artifact = (
|
||||
failed / RUNNER.MODULE_FOUNDRY_SECTOR_FAILED_ARTIFACT
|
||||
)
|
||||
failed_artifact = failed / failed_artifact_name
|
||||
with tarfile.open(failed_artifact, "w:gz") as archive:
|
||||
archive.add(
|
||||
archive_source / "manifest.env",
|
||||
@@ -331,11 +372,11 @@ class ModuleFoundryRuntimeRecoveryTest(unittest.TestCase):
|
||||
journal.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"artifact": RUNNER.MODULE_FOUNDRY_SECTOR_FAILED_ARTIFACT,
|
||||
"backup_id": RUNNER.MODULE_FOUNDRY_SECTOR_FAILED_BACKUP_ID,
|
||||
"artifact": failed_artifact_name,
|
||||
"backup_id": failed_backup_id,
|
||||
"component": "module-foundry",
|
||||
"id": RUNNER.MODULE_FOUNDRY_SECTOR_FAILED_PATCH_ID,
|
||||
"message": RUNNER.MODULE_FOUNDRY_SECTOR_FAILED_MESSAGE,
|
||||
"id": failed_patch_id,
|
||||
"message": failed_message,
|
||||
"rollback_status": "not-required",
|
||||
"sha256": failed_sha256,
|
||||
"started_apply": True,
|
||||
@@ -346,55 +387,83 @@ class ModuleFoundryRuntimeRecoveryTest(unittest.TestCase):
|
||||
encoding="utf-8",
|
||||
)
|
||||
manifest = {
|
||||
"id": RUNNER.MODULE_FOUNDRY_SECTOR_RECOVERY_PATCH_ID,
|
||||
"id": recovery_patch_id,
|
||||
"component": "module-foundry",
|
||||
"type": "app-overlay",
|
||||
}
|
||||
|
||||
patches = (
|
||||
mock.patch.object(RUNNER, "BACKUPS_DIR", backups),
|
||||
mock.patch.object(RUNNER, "FAILED_DIR", failed),
|
||||
mock.patch.object(RUNNER, "FAILED_STATE_FILE", journal),
|
||||
mock.patch.object(RUNNER, "TMP_DIR", tmp),
|
||||
mock.patch.object(
|
||||
RUNNER,
|
||||
"MODULE_FOUNDRY_SECTOR_FAILED_ARTIFACT_SHA256",
|
||||
failed_sha256,
|
||||
),
|
||||
mock.patch.object(
|
||||
RUNNER,
|
||||
"MODULE_FOUNDRY_SECTOR_FAILED_BACKUP_SHA256",
|
||||
backup_hashes,
|
||||
),
|
||||
mock.patch.object(
|
||||
RUNNER,
|
||||
"component_root",
|
||||
return_value=installed,
|
||||
),
|
||||
mock.patch.object(
|
||||
RUNNER,
|
||||
"module_foundry_runtime_inventory",
|
||||
return_value=runtime(),
|
||||
),
|
||||
candidate_tree = RUNNER.exact_file_map_sha256(
|
||||
RUNNER.collect_exact_files(
|
||||
candidate,
|
||||
recovery_entries,
|
||||
"candidate",
|
||||
)
|
||||
)
|
||||
with patches[0], patches[1], patches[2], patches[3], patches[4], patches[5], patches[6], patches[7]:
|
||||
result = RUNNER.validate_module_foundry_sector_recovery_evidence(
|
||||
installed_tree = RUNNER.exact_file_map_sha256(
|
||||
RUNNER.collect_exact_files(
|
||||
installed,
|
||||
recovery_entries[:-1],
|
||||
"installed",
|
||||
)
|
||||
)
|
||||
|
||||
patches = {
|
||||
"BACKUPS_DIR": backups,
|
||||
"FAILED_DIR": failed,
|
||||
"FAILED_STATE_FILE": journal,
|
||||
"TMP_DIR": tmp,
|
||||
"MODULE_FOUNDRY_MAP_RECOVERY_PATCH_ID": recovery_patch_id,
|
||||
"MODULE_FOUNDRY_MAP_RECOVERY_ENTRIES": recovery_entries,
|
||||
"MODULE_FOUNDRY_MAP_RECOVERY_MISSING_PREDECESSOR_ENTRIES": (
|
||||
missing_entries
|
||||
),
|
||||
"MODULE_FOUNDRY_MAP_RECOVERY_INSTALLED_TREE_SHA256": (
|
||||
installed_tree
|
||||
),
|
||||
"MODULE_FOUNDRY_MAP_RECOVERY_CANDIDATE_TREE_SHA256": (
|
||||
candidate_tree
|
||||
),
|
||||
"MODULE_FOUNDRY_SECTOR_FAILED_ENTRIES": failed_entries,
|
||||
"MODULE_FOUNDRY_MAP_FAILED_PATCH_ID": failed_patch_id,
|
||||
"MODULE_FOUNDRY_MAP_FAILED_ARTIFACT": failed_artifact_name,
|
||||
"MODULE_FOUNDRY_MAP_FAILED_ARTIFACT_SHA256": failed_sha256,
|
||||
"MODULE_FOUNDRY_MAP_FAILED_BACKUP_ID": failed_backup_id,
|
||||
"MODULE_FOUNDRY_MAP_FAILED_MESSAGE": failed_message,
|
||||
"MODULE_FOUNDRY_MAP_FAILED_BACKUP_SHA256": backup_hashes,
|
||||
}
|
||||
with ExitStack() as stack:
|
||||
for name, value in patches.items():
|
||||
stack.enter_context(mock.patch.object(RUNNER, name, value))
|
||||
stack.enter_context(
|
||||
mock.patch.object(
|
||||
RUNNER,
|
||||
"component_root",
|
||||
return_value=installed,
|
||||
)
|
||||
)
|
||||
stack.enter_context(
|
||||
mock.patch.object(
|
||||
RUNNER,
|
||||
"module_foundry_runtime_inventory",
|
||||
return_value=runtime(),
|
||||
)
|
||||
)
|
||||
result = RUNNER.validate_module_foundry_map_recovery_evidence(
|
||||
manifest,
|
||||
entries,
|
||||
recovery_entries,
|
||||
candidate,
|
||||
)
|
||||
self.assertEqual(
|
||||
result["mode"],
|
||||
"failed-overlay-runtime-reconciliation",
|
||||
"failed-map-overlay-source+runtime-reconciliation",
|
||||
)
|
||||
(installed / entries[0]).write_text(
|
||||
(installed / failed_entries[0]).write_text(
|
||||
"drift\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
with self.assertRaises(RUNNER.DeployError):
|
||||
RUNNER.validate_module_foundry_sector_recovery_evidence(
|
||||
RUNNER.validate_module_foundry_map_recovery_evidence(
|
||||
manifest,
|
||||
entries,
|
||||
recovery_entries,
|
||||
candidate,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user