Freeze HA scoring and document reported production failover
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user