Freeze HA scoring and document reported production failover

This commit is contained in:
Lyncoln
2026-09-12 18:07:28 -04:00
parent c8636ed6d4
commit 488a1672d7
29 changed files with 2285 additions and 46 deletions
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
import importlib.util
from pathlib import Path
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location('cleanup', ROOT / 'scripts/plan-promotion-cleanup.py')
cleanup = importlib.util.module_from_spec(spec); spec.loader.exec_module(cleanup)
class Cleanup(unittest.TestCase):
def plan(self, extra='', role='Promoted'):
with tempfile.TemporaryDirectory() as directory:
p = Path(directory) / 'cib.xml'
p.write_text(f'''<cib><configuration><resources><clone id="postgresql-ha-clone">
<meta_attributes id="meta"><nvpair name="target-role" value="{role}"/></meta_attributes>
</clone></resources><constraints><rsc_location id="actual-eve-preference" rsc="postgresql-ha-clone">
<rule id="actual-rule" role="Promoted" score="200"><expression attribute="#uname" operation="eq" value="david-eve"/></rule>
{extra}</rsc_location></constraints></configuration></cib>''')
return cleanup.plan(p, 'postgresql-ha-clone', 'david-eve')
def test_exact_commands_from_real_ids(self):
self.assertEqual(self.plan(), ['sudo pcs constraint remove actual-eve-preference'])
def test_preserve_unrelated_rule(self):
self.assertEqual(self.plan('<rule id="unrelated" role="Unpromoted" score="10"/>')[0],
'sudo pcs constraint remove actual-rule')
def test_ambiguous_match_refused(self):
with self.assertRaises(ValueError):
self.plan('<rule id="duplicate" role="Promoted" score="200"><expression attribute="#uname" operation="eq" value="david-eve"/></rule>')
def test_unexpected_target_role_refused(self):
with self.assertRaises(ValueError):
self.plan(role='Started')
if __name__ == '__main__':
unittest.main(verbosity=2)