Phase 25: Interrupted deployment reconciliation
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
"""Reconcile interrupted disposable deployments without guessing intent."""
|
||||
|
||||
from core.locking import DeploymentLock
|
||||
|
||||
|
||||
def reconcile(planner, rollback, services, *, confirmation=None, fingerprint=None):
|
||||
if (confirmation is None) != (fingerprint is None):
|
||||
raise ValueError("Both recovery confirmation and plan fingerprint are required")
|
||||
with DeploymentLock(planner.lock_path):
|
||||
plan = planner._inspect()
|
||||
if plan["status"] in {"CLEAR", "VERIFIED"}:
|
||||
if confirmation is not None:
|
||||
raise ValueError("There is no eligible interrupted activation")
|
||||
return plan
|
||||
if confirmation is None:
|
||||
services.quiesce()
|
||||
if not services.stopped():
|
||||
raise RuntimeError("Unable to contain interrupted deployment")
|
||||
return plan
|
||||
if rollback.planner is not planner:
|
||||
raise ValueError("Rollback uses different transaction state")
|
||||
return rollback._execute(confirmation, fingerprint)
|
||||
@@ -0,0 +1,22 @@
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock
|
||||
|
||||
from core.dev3.reconcile import reconcile
|
||||
|
||||
|
||||
class ReconciliationTests(unittest.TestCase):
|
||||
def test_interrupted_activation_contains_until_explicit_confirmation(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
planner, rollback, services = Mock(), Mock(), Mock()
|
||||
planner.lock_path = Path(directory).resolve() / "site.lock"
|
||||
rollback.planner = planner
|
||||
planner._inspect.return_value = {"status": "ROLLBACK_REVIEW_READY"}
|
||||
services.stopped.return_value = True
|
||||
self.assertEqual(reconcile(planner, rollback, services)["status"],
|
||||
"ROLLBACK_REVIEW_READY")
|
||||
services.quiesce.assert_called_once()
|
||||
rollback._execute.assert_not_called()
|
||||
reconcile(planner, rollback, services, confirmation="confirm", fingerprint="hash")
|
||||
rollback._execute.assert_called_once_with("confirm", "hash")
|
||||
Reference in New Issue
Block a user