Files
cozystack/packages/system/linstor/tests/test_migration_render.py
T
Andrei Kvapil 944fbc8e7d fix(linstor): leave piraeus untouched while blockstor adopts volumes
The migration runbook freezes CSI and stops LINSTOR before blockstor
adopts the volumes, and repoints CSI only after adoption converges.
One backend flip cannot express that order: piraeus-operator goes to
external mode at once, deletes linstor-controller and repoints
linstor-csi before a single volume is adopted.

blockstorMigration splits the switch into steps. Under hold and adopt
every piraeus object renders exactly as under backend linstor, so
piraeus-operator, which keeps running as in blockstor's runbook, finds
LINSTOR's shape and keeps linstor-csi on LINSTOR until adoption has
converged. It does not undo the freeze either: it applies its
Deployments without a replica count, since the LinstorCluster sets
none, so linstor-controller and linstor-csi-controller stay at zero.
Keeping the operator up rather than stopping it also keeps its
validating webhooks served, so the release passes them at every step
without relaxing their failurePolicy.

hold also keeps the blockstor controller at zero replicas until the
converted manifests are in: a scale by hand did not survive the next
upgrade. Clearing the value is the only step that changes piraeus.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
2026-11-29 23:03:55 +01:00

52 lines
2.0 KiB
Python

from pathlib import Path
import shutil
import subprocess
import unittest
CHART = Path(__file__).resolve().parents[1]
# Every template that renders a piraeus.io object, or something one of them
# references. While blockstorMigration is set the release must give piraeus
# nothing new: the operator keeps running through the migration, and has to
# find LINSTOR's shape and keep linstor-csi on LINSTOR until the value is
# cleared. helm-unittest asserts on one render at a time, so the comparison
# across renders lives here.
PIRAEUS_TEMPLATES = [
"templates/cluster.yaml",
"templates/satellites-cozy.yaml",
"templates/satellites-plunger.yaml",
"templates/satellites-reloader.yaml",
"templates/satellites-talos.yaml",
"templates/plunger/configmap-scripts.yaml",
"templates/linstor-api-tls.yaml",
"templates/linstor-internal-tls.yaml",
"templates/podscrape.yaml",
]
def render(*values):
args = ["helm", "template", "linstor", str(CHART), "--namespace", "cozy-linstor",
"--api-versions", "operator.victoriametrics.com/v1beta1"]
for value in values:
args += ["--set", value]
out = subprocess.run(args, check=True, capture_output=True, text=True).stdout
sources = [f"# Source: cozy-linstor/{template}" for template in PIRAEUS_TEMPLATES]
docs = [doc.removeprefix("---\n") for doc in out.split("\n---\n")]
return [doc for doc in docs if doc.split("\n", 1)[0] in sources]
@unittest.skipUnless(shutil.which("helm"), "helm is required")
class MigrationLeavesPiraeusAlone(unittest.TestCase):
def test_hold_and_adopt_render_piraeus_as_linstor(self):
linstor = render("backend=linstor")
for step in ("hold", "adopt"):
with self.subTest(step=step):
self.assertEqual(render("backend=blockstor", f"blockstorMigration={step}"), linstor)
def test_completed_migration_changes_piraeus(self):
self.assertNotEqual(render("backend=blockstor"), render("backend=linstor"))
if __name__ == "__main__":
unittest.main()