Archive verified rollbacks of interrupted activation journals
ABSDEV Framework CI / framework-ci (push) Successful in 20s
ABSDEV Framework CI / framework-ci (push) Successful in 20s
This commit is contained in:
+4
-5
@@ -11,6 +11,9 @@ from core.compatibility import (
|
|||||||
from core.locking import DeploymentLock
|
from core.locking import DeploymentLock
|
||||||
|
|
||||||
|
|
||||||
|
ROLLBACK_ELIGIBLE_PHASES = frozenset({"ACTIVATING", "ACTIVATED", "FAILED"})
|
||||||
|
|
||||||
|
|
||||||
class RecoveryError(RuntimeError):
|
class RecoveryError(RuntimeError):
|
||||||
"""Recovery safety could not be established."""
|
"""Recovery safety could not be established."""
|
||||||
|
|
||||||
@@ -140,11 +143,7 @@ class RecoveryPlanner:
|
|||||||
)
|
)
|
||||||
|
|
||||||
require(
|
require(
|
||||||
transaction["phase"] in (
|
transaction["phase"] in ROLLBACK_ELIGIBLE_PHASES,
|
||||||
"ACTIVATING",
|
|
||||||
"ACTIVATED",
|
|
||||||
"FAILED",
|
|
||||||
),
|
|
||||||
"Transaction phase does not permit rollback review",
|
"Transaction phase does not permit rollback review",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ from core.compatibility import (
|
|||||||
validate_provenance,
|
validate_provenance,
|
||||||
)
|
)
|
||||||
from core.locking import DeploymentLock
|
from core.locking import DeploymentLock
|
||||||
|
from core.recovery import ROLLBACK_ELIGIBLE_PHASES
|
||||||
|
|
||||||
|
|
||||||
class RollbackArchiveReader:
|
class RollbackArchiveReader:
|
||||||
@@ -65,10 +66,10 @@ class RollbackArchiveReader:
|
|||||||
)
|
)
|
||||||
|
|
||||||
require(
|
require(
|
||||||
transaction["phase"] == "FAILED"
|
transaction["phase"] in ROLLBACK_ELIGIBLE_PHASES
|
||||||
and intent["status"] == "ROLLBACK_INTENT"
|
and intent["status"] == "ROLLBACK_INTENT"
|
||||||
and result["status"] == "ROLLED_BACK",
|
and result["status"] == "ROLLED_BACK",
|
||||||
"Completed failed-transaction rollback required",
|
"Completed rollback of a failed or interrupted activation required",
|
||||||
)
|
)
|
||||||
|
|
||||||
phases = {
|
phases = {
|
||||||
@@ -195,9 +196,9 @@ class RollbackArchive(RollbackArchiveReader):
|
|||||||
|
|
||||||
require(
|
require(
|
||||||
transaction is not None
|
transaction is not None
|
||||||
and transaction["phase"] == "FAILED"
|
and transaction["phase"] in ROLLBACK_ELIGIBLE_PHASES
|
||||||
and transaction["site"] == self.planner.site,
|
and transaction["site"] == self.planner.site,
|
||||||
"Failed deployment transaction required",
|
"Failed or interrupted deployment transaction required",
|
||||||
)
|
)
|
||||||
|
|
||||||
identifier = transaction["transaction_id"]
|
identifier = transaction["transaction_id"]
|
||||||
@@ -339,6 +340,7 @@ class RollbackArchive(RollbackArchiveReader):
|
|||||||
) from None
|
) from None
|
||||||
|
|
||||||
def _execute(self, confirmation, fingerprint):
|
def _execute(self, confirmation, fingerprint):
|
||||||
|
self.journal.require_writes_allowed()
|
||||||
plan = self._plan()
|
plan = self._plan()
|
||||||
|
|
||||||
require(
|
require(
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ supply `--site` with the configured site identifier. Each archive must pass
|
|||||||
the framework's transaction and backup evidence validation. When the live
|
the framework's transaction and backup evidence validation. When the live
|
||||||
journal is absent, exactly one archived verified transaction must match the
|
journal is absent, exactly one archived verified transaction must match the
|
||||||
active release. Rollback archives also require their original rollback and
|
active release. Rollback archives also require their original rollback and
|
||||||
backup evidence and the failed release's matching quarantine marker. All
|
backup evidence and the failed release's matching quarantine marker. A
|
||||||
|
verified rollback can retire a journal left in an interrupted activation
|
||||||
|
phase while preserving its original history. All
|
||||||
releases referenced by validated archives are protected. Unknown, ambiguous
|
releases referenced by validated archives are protected. Unknown, ambiguous
|
||||||
or corrupt archive entries deny planning pending review.
|
or corrupt archive entries deny planning pending review.
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ class RecoveryTests(unittest.TestCase):
|
|||||||
runtime_check=self.runtime_check,
|
runtime_check=self.runtime_check,
|
||||||
)
|
)
|
||||||
|
|
||||||
def prepare(self, failed=True):
|
def prepare(self, failed=True, *, interrupted=False):
|
||||||
|
|
||||||
transaction = self.journal.create(
|
transaction = self.journal.create(
|
||||||
"example-absdev-net",
|
"example-absdev-net",
|
||||||
@@ -150,6 +150,8 @@ class RecoveryTests(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.releases.activate("2")
|
self.releases.activate("2")
|
||||||
|
if interrupted:
|
||||||
|
return transaction
|
||||||
|
|
||||||
transaction = self.journal.transition(
|
transaction = self.journal.transition(
|
||||||
transaction["transaction_id"],
|
transaction["transaction_id"],
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import unittest
|
|||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import test_rollback
|
import test_rollback
|
||||||
|
import test_recovery
|
||||||
|
|
||||||
from core.rollback_archive import RollbackArchive, ArchiveError
|
from core.rollback_archive import RollbackArchive, ArchiveError
|
||||||
from core.compatibility import canonical_hash
|
from core.compatibility import canonical_hash
|
||||||
@@ -250,3 +251,41 @@ class RollbackArchiveTests(unittest.TestCase):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
||||||
|
class InterruptedRollbackArchiveTests(unittest.TestCase):
|
||||||
|
def test_confirmed_rollback_can_archive_interrupted_activation(self):
|
||||||
|
prepare = test_recovery.RecoveryTests.prepare
|
||||||
|
|
||||||
|
def interrupted(recovery):
|
||||||
|
return prepare(recovery, interrupted=True)
|
||||||
|
|
||||||
|
fixture = RollbackArchiveTests()
|
||||||
|
self.addCleanup(fixture.doCleanups)
|
||||||
|
with patch.object(test_recovery.RecoveryTests, "prepare", interrupted):
|
||||||
|
fixture.setUp()
|
||||||
|
self.assertEqual(fixture.transaction["phase"], "ACTIVATING")
|
||||||
|
result = fixture.execute()
|
||||||
|
self.assertEqual(result["transaction"]["phase"], "ACTIVATING")
|
||||||
|
self.assertIsNone(fixture.journal.load())
|
||||||
|
self.assertTrue(fixture.marker.is_file())
|
||||||
|
self.assertEqual(fixture.archive.load(fixture.identifier), result)
|
||||||
|
|
||||||
|
|
||||||
|
def test_unfinished_migration_blocks_rollback_journal_retirement(self):
|
||||||
|
from core.approval_store import ApprovalStore
|
||||||
|
|
||||||
|
fixture = RollbackArchiveTests()
|
||||||
|
self.addCleanup(fixture.doCleanups)
|
||||||
|
fixture.setUp()
|
||||||
|
approvals = fixture.recovery.root / "approvals"
|
||||||
|
approvals.mkdir(mode=0o700, exist_ok=True)
|
||||||
|
fixture.journal.bind_migration_guard(ApprovalStore(approvals))
|
||||||
|
blocker = approvals / ("b" * 32 + ".migration-intent.json")
|
||||||
|
blocker.write_text("{}")
|
||||||
|
before = fixture.journal.path.read_bytes()
|
||||||
|
with self.assertRaises(ArchiveError):
|
||||||
|
fixture.execute()
|
||||||
|
self.assertEqual(fixture.journal.path.read_bytes(), before)
|
||||||
|
self.assertFalse(fixture.marker.exists())
|
||||||
|
self.assertFalse(fixture.archive.path(fixture.identifier).exists())
|
||||||
|
|||||||
Reference in New Issue
Block a user