#!/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''' {extra}''') 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('')[0], 'sudo pcs constraint remove actual-rule') def test_ambiguous_match_refused(self): with self.assertRaises(ValueError): self.plan('') def test_unexpected_target_role_refused(self): with self.assertRaises(ValueError): self.plan(role='Started') if __name__ == '__main__': unittest.main(verbosity=2)